* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #14100b;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body { position: fixed; inset: 0; }

#game {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: #e8d5b0;
}

#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(8px + env(safe-area-inset-top)) 12px 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#hud-top2 {
  position: absolute;
  top: calc(48px + env(safe-area-inset-top));
  left: 12px; right: 116px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gauge.slim { max-width: 180px; }
.gauge.slim .bar { height: 10px; }

.sel-chip.rival { border-color: #a33020; color: #ff9a7a; }

#minimap {
  position: absolute;
  top: calc(48px + env(safe-area-inset-top));
  right: 10px;
  width: 96px;
  height: 144px;
  border: 1px solid #5a4a33;
  border-radius: 6px;
  background: #14100b;
  z-index: 5;
  touch-action: none;
}

/* ---------- info panel ---------- */

#panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, 92vw);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid #6e5a3a;
  border-radius: 14px;
  background: rgba(24, 17, 10, 0.95);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  animation: panel-in 0.14s ease-out;
}

@keyframes panel-in {
  from { opacity: 0; transform: translate(-50%, -47%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

/* event feed, left edge */
#notify {
  position: absolute;
  left: 8px;
  top: 34%;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 46vw;
  pointer-events: none;
  z-index: 6;
}

.note {
  padding: 6px 10px;
  border: 1px solid #5a4a33;
  border-left: 3px solid #e07b28;
  border-radius: 7px;
  background: rgba(24, 17, 10, 0.88);
  color: #e8d5b0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  opacity: 1;
  transition: opacity 0.6s;
  animation: note-in 0.18s ease-out;
}

.note.bad { border-left-color: #d84a2a; color: #ffb09a; }
.note.good { border-left-color: #6fbf5a; }
.note.fading { opacity: 0; }

@keyframes note-in {
  from { opacity: 0; transform: translateX(-10px); }
  to   { opacity: 1; transform: translateX(0); }
}

#portrait {
  width: 72px; height: 72px;
  border: 1px solid #5a4a33;
  border-radius: 8px;
  flex: none;
}

#panel-body { flex: 1; min-width: 0; }

#panel-title {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #ffd9a0;
}

#panel-desc {
  margin-top: 2px;
  font-size: 11.5px;
  line-height: 1.45;
  color: #b39b73;
}

#panel-bars { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }

.pbar { display: flex; align-items: center; gap: 6px; }
.pbar span { font-size: 9px; letter-spacing: 1px; color: #b39b73; min-width: 32px; }
.pbar .bar { height: 9px; }
.fill-hp { background: linear-gradient(90deg, #4d8a4a, #7cc65f); }

#panel-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#panel-actions button {
  padding: 9px 14px;
  border: 1px solid #6e5a3a;
  border-radius: 10px;
  background: rgba(46, 34, 20, 0.9);
  color: #ffd9a0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}

#panel-actions button:disabled { opacity: 0.35; }

#panel-close {
  flex: none;
  width: 32px; height: 32px;
  font-size: 14px;
}

.sel-chip {
  min-width: 30px;
  padding: 4px 0;
  text-align: center;
  border: 1px solid #8a5a24;
  border-radius: 8px;
  background: rgba(46, 34, 20, 0.9);
  color: #ffd9a0;
  font-size: 12px;
  font-weight: 800;
}

#hud button { pointer-events: auto; }

.icon-btn {
  width: 40px; height: 40px;
  border: 1px solid #5a4a33;
  border-radius: 8px;
  background: rgba(30, 22, 14, 0.85);
  color: #e8d5b0;
  font-size: 18px;
}

#hud-spice {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gauge {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gauge-label {
  font-size: 10px;
  letter-spacing: 1px;
  color: #b39b73;
}

.bar {
  flex: 1;
  height: 14px;
  border: 1px solid #5a4a33;
  border-radius: 7px;
  background: rgba(20, 14, 8, 0.8);
  overflow: hidden;
}

.bar > div {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  transition: width 0.15s linear;
}

#spice-fill { background: linear-gradient(90deg, #a34712, #e07b28); }
.fill-load  { background: linear-gradient(90deg, #b4531e, #e08a30); }
.fill-fuel  { background: linear-gradient(90deg, #4d8a4a, #7cc65f); }
.fill-fuel.low { background: linear-gradient(90deg, #a33020, #d84a2a); }
.fill-water { background: linear-gradient(90deg, #2e6a9c, #5ab4e8); }

#spice-label {
  font-size: 12px;
  font-weight: 700;
  min-width: 34px;
  text-align: right;
}

#worm-warn {
  color: #ff8a5e;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 1px;
  animation: warn-pulse 0.7s infinite;
}

@keyframes warn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

#btn-call, #btn-fence, #btn-trap {
  padding: 10px 16px;
  border: 1px solid #6e5a3a;
  border-radius: 10px;
  background: rgba(46, 34, 20, 0.9);
  color: #ffd9a0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}

#btn-call:disabled, #btn-fence:disabled, #btn-trap:disabled {
  opacity: 0.35;
}

#btn-fence.active, #btn-trap.active {
  border-color: #6fbf5a;
  background: rgba(30, 56, 24, 0.95);
  color: #b8f0a0;
}

#toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border: 1px solid #a33020;
  border-radius: 10px;
  background: rgba(30, 12, 8, 0.9);
  color: #ff9a7a;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 2px;
  pointer-events: none;
  animation: toast-in 0.2s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---------- overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(14, 10, 6, 0.82);
  color: #e8d5b0;
  text-align: center;
}

#menu {
  background:
    radial-gradient(ellipse at 50% 120%, rgba(190, 110, 40, 0.25), transparent 60%),
    rgba(14, 10, 6, 0.9);
}

.title {
  font-size: clamp(44px, 13vw, 76px);
  line-height: 0.95;
  font-weight: 900;
  letter-spacing: 4px;
  color: #e07b28;
  text-shadow: 0 4px 0 #5a2c0c, 0 8px 24px rgba(224, 123, 40, 0.35);
}

.subtitle {
  font-size: 13px;
  letter-spacing: 3px;
  color: #b39b73;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.big-msg {
  font-size: clamp(30px, 9vw, 52px);
  line-height: 1.02;
  font-weight: 900;
  letter-spacing: 3px;
}

.win-msg  { color: #8fd06a; text-shadow: 0 3px 0 #2c4a1c; }
.lose-msg { color: #e05a3a; text-shadow: 0 3px 0 #4a1c10; }

.stats {
  font-size: 14px;
  color: #b39b73;
  letter-spacing: 1px;
}

.big-btn {
  min-width: 220px;
  padding: 16px 28px;
  border: 2px solid #8a5a24;
  border-radius: 14px;
  background: linear-gradient(180deg, #c96f2b, #9c4d16);
  color: #fff3df;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 6px 0 #5a2c0c;
}

.big-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 #5a2c0c; }

.big-btn span {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  color: #ffd9a0;
}

.menu-btn {
  min-width: 220px;
  padding: 12px 20px;
  border: 1px solid #5a4a33;
  border-radius: 10px;
  background: rgba(40, 30, 18, 0.9);
  color: #e8d5b0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 2px;
}

.tips {
  margin-top: 18px;
  max-width: 340px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #9a8563;
}

.veg-btn { width: 34px; height: 34px; font-size: 15px; pointer-events: auto; }
.veg-btn.active {
  border-color: #6fbf5a;
  background: rgba(30, 56, 24, 0.95);
}

/* command panel: harvesters first, then the unlockable powers */
#cmd-panel {
  position: absolute;
  top: calc(84px + env(safe-area-inset-top));
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: auto;
  z-index: 5;
}

#fleet-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cmd-btn {
  width: 40px; height: 40px;
  border: 1.5px solid #5a4a33;
  border-radius: 9px;
  background: rgba(30, 22, 14, 0.88);
  font-size: 17px;
  line-height: 1;
}

.cmd-btn.active {
  border-color: #6fbf5a;
  background: rgba(30, 56, 24, 0.95);
}

.cmd-btn.locked { opacity: 0.4; }
.fleet-chip {
  position: relative;
  width: 40px; height: 40px;
  border: 1.5px solid #5a4a33;
  border-radius: 9px;
  background: rgba(30, 22, 14, 0.88);
  color: #e8d5b0;
  font-size: 15px;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.fleet-chip .n { font-size: 9px; font-weight: 800; color: #b39b73; }
.fleet-chip::after {
  content: '';
  position: absolute;
  top: 3px; right: 3px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #6fbf5a;
}
.fleet-chip.idle { border-color: #d8a03c; }
.fleet-chip.idle::after { background: #ffc04a; animation: warn-pulse 1s infinite; }
.fleet-chip.air::after { background: #5ab4e8; }
.fleet-chip.dock::after { background: #9a8f7c; }
.fleet-chip.dead { opacity: 0.45; }
.fleet-chip.dead::after { background: #d84a2a; }

.sel-chip.emp { border-color: #b8962e; color: #ffe28a; }
.sel-chip.emp.urgent { border-color: #d84a2a; color: #ff9a7a; animation: warn-pulse 0.8s infinite; }

.fleet-chip.blocked { border-color: #d84a2a; }
.fleet-chip.blocked::after { background: #ff5030; animation: warn-pulse 0.6s infinite; }

.aim-cancel {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 30;
  display: none;
  padding: 10px 26px;
  font-size: 15px;
  background: #6a2418;
  border-color: #d84a2a;
}
