/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #1a1410; font-family: 'Segoe UI', system-ui, sans-serif; color: #e8dcc8; }

/* ── Hidden utility ──────────────────────────────────────── */
#hud-bar.hidden, #game-ui-overlay.hidden { display: none; }

/* ── Top HUD Bar ─────────────────────────────────────────── */
#hud-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 40px;
  padding: 0 16px;
  background: linear-gradient(180deg, #282018 0%, #1c1810 100%);
  border-bottom: 1px solid rgba(212,160,74,0.15);
  font-size: 13px;
  user-select: none;
  z-index: 30;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.hud-icon { font-size: 15px; opacity: 0.8; }
.hud-label { color: #8a7a6a; font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px; font-weight: 600; }
.hud-value { color: #d4a04a; font-weight: 700; font-size: 14px; }
.hud-value.green { color: #6aaa50; }
.hud-value.red { color: #c0392b; }
.hud-value.blue { color: #3498db; }
.hud-sub { color: #6a5a4a; font-size: 11px; }

.hud-divider {
  width: 1px;
  height: 22px;
  background: rgba(212,160,74,0.12);
}

/* Speed controls */
.speed-controls {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.speed-btn {
  background: rgba(30,26,18,0.8);
  border: 1px solid rgba(80,65,45,0.4);
  color: #8a7a6a;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 2px;
}
.speed-btn:hover { background: rgba(80,65,45,0.4); color: #e8dcc8; }
.speed-btn.active { background: #d4a04a; color: #1a1410; border-color: #d4a04a; font-weight: 600; }

.hud-time {
  color: #9a8a70;
  font-size: 12px;
  font-weight: 500;
}

/* ── Save/Load controls ─────────────────────────────────── */
.save-controls {
  display: flex;
  gap: 4px;
}
.save-btn {
  background: rgba(30,26,18,0.8);
  border: 1px solid rgba(80,65,45,0.4);
  color: #8a7a6a;
  padding: 3px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 3px;
}
.save-btn:hover { background: rgba(80,65,45,0.4); color: #e8dcc8; }
.save-btn-menu { color: #6a5a4a; }
.save-btn-menu:hover { color: #c0a060; }

/* ── Canvas ──────────────────────────────────────────────── */
#game-canvas {
  display: block;
  cursor: crosshair;
  touch-action: none; /* prevent browser gestures on canvas */
}

/* ── Build Menu (left side) ──────────────────────────────── */
#build-menu {
  position: fixed;
  left: 8px;
  top: 52px;
  width: 145px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}

.build-category {
  background: rgba(26,22,16,0.94);
  border: 1px solid rgba(80,65,45,0.4);
  border-radius: 5px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.category-label {
  background: rgba(40,32,22,0.95);
  padding: 4px 8px;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #9a8a6a;
  border-bottom: 1px solid rgba(80,65,45,0.3);
  font-weight: 600;
}

.build-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(58, 48, 32, 0.3);
  color: #e8dcc8;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.build-btn:last-child { border-bottom: none; }
.build-btn:hover { background: rgba(212, 160, 74, 0.12); }
.build-btn.active { background: rgba(212, 160, 74, 0.25); border-left: 2px solid #d4a04a; }
.build-btn.cant-afford { opacity: 0.35; }

.build-symbol {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  font-weight: bold;
  font-size: 11px;
  font-family: serif;
  color: #d4a04a;
}
.build-name { flex: 1; font-size: 11px; }
.build-cost { color: #b8944a; font-size: 10px; font-weight: 600; }

/* ── Info Panel (right side) ─────────────────────────────── */
#info-panel {
  position: fixed;
  right: 8px;
  top: 52px;
  width: 210px;
  background: rgba(26,22,16,0.96);
  border: 1px solid rgba(80,65,45,0.4);
  border-radius: 5px;
  padding: 12px;
  z-index: 20;
  font-size: 13px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
#info-panel.hidden { display: none; }
#info-panel h3 {
  color: #d4a04a;
  font-size: 14px;
  margin-bottom: 6px;
  font-weight: 600;
}
.info-desc {
  color: #8a7a6a;
  font-size: 11px;
  margin-bottom: 8px;
  line-height: 1.4;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  font-size: 12px;
}
.info-row span:first-child { color: #8a7a6a; }
.info-row span:last-child { color: #e8dcc8; font-weight: 500; }

.info-next {
  color: #d4a04a;
  font-size: 11px;
  margin-top: 8px;
  margin-bottom: 4px;
  font-weight: 600;
}
.info-reqs {
  list-style: none;
  font-size: 11px;
}
.info-reqs li { padding: 1px 0; }
.info-reqs li.met { color: #6aaa50; }
.info-reqs li.met::before { content: "\2713 "; }
.info-reqs li.unmet { color: #c0392b; }
.info-reqs li.unmet::before { content: "\2717 "; }

.demolish-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 6px;
  background: rgba(90,32,32,0.8);
  border: 1px solid rgba(140,50,50,0.5);
  border-radius: 4px;
  color: #e8dcc8;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.demolish-btn:hover { background: rgba(140,50,50,0.8); }

/* ── Objectives Panel (right side, below info panel) ─────── */
#objectives-panel {
  position: fixed;
  right: 8px;
  bottom: 130px;
  width: 220px;
  background: rgba(26,22,16,0.96);
  border: 1px solid rgba(80,65,45,0.4);
  border-radius: 5px;
  padding: 12px;
  z-index: 20;
  font-size: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
#objectives-panel.hidden { display: none; }
#objectives-panel h3 {
  color: #d4a04a;
  font-size: 13px;
  margin-bottom: 8px;
  font-weight: 600;
}

.obj-won {
  color: #6aaa50;
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 8px;
  text-align: center;
}

.obj-list {
  list-style: none;
  padding: 0;
}
.obj-list li {
  margin-bottom: 8px;
}
.obj-label {
  display: block;
  color: #c0b090;
  font-size: 11px;
  margin-bottom: 3px;
  line-height: 1.3;
}
.obj-done .obj-label { color: #6aaa50; }
.obj-done .obj-label::before { content: "\2713 "; }
.obj-pending .obj-label::before { content: "\25cb "; color: #8a7a6a; }

.obj-bar-bg {
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 2px;
}
.obj-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #b8880a, #d4a04a);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.obj-bar-complete {
  background: linear-gradient(90deg, #4a9a3a, #6aaa50);
}
.obj-progress {
  color: #6a5a4a;
  font-size: 10px;
}

/* ── Overlay indicator ───────────────────────────────────── */
#overlay-indicator {
  position: fixed;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,22,16,0.94);
  border: 1px solid rgba(212,160,74,0.3);
  border-radius: 4px;
  padding: 4px 16px;
  font-size: 11px;
  color: #d4a04a;
  z-index: 25;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#overlay-indicator.hidden { display: none; }

#build-version {
  position: fixed;
  right: 10px;
  bottom: 42px;
  background: rgba(26,22,16,0.92);
  border: 1px solid rgba(212,160,74,0.24);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 10px;
  color: #bda57a;
  z-index: 15;
  letter-spacing: 0.04em;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.24);
  pointer-events: none;
}

/* ── Help tooltip (bottom) ───────────────────────────────── */
#help-bar {
  position: fixed;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,22,16,0.88);
  border: 1px solid rgba(80,65,45,0.3);
  border-radius: 4px;
  padding: 4px 16px;
  font-size: 10px;
  color: #6a5a4a;
  z-index: 10;
  white-space: nowrap;
}
#help-bar kbd {
  background: rgba(80,65,45,0.4);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  color: #a89a7a;
  font-weight: 500;
}

/* ── Mobile Help Bar ────────────────────────────────────────── */
#help-bar-mobile {
  display: none; /* shown via media query */
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26,22,16,0.88);
  border: 1px solid rgba(80,65,45,0.3);
  border-radius: 4px;
  padding: 4px 14px;
  font-size: 10px;
  color: #6a5a4a;
  z-index: 10;
  white-space: nowrap;
}

/* ── Drawer Scrim (mobile overlay backdrop) ─────────────────── */
#drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 18;
}
#drawer-scrim.hidden { display: none; }

/* ── Panel Toggle Buttons ───────────────────────────────────── */
#panel-toggles {
  display: none; /* shown via media query */
  position: fixed;
  top: 46px;
  right: 8px;
  z-index: 22;
  gap: 4px;
}
.panel-toggle-btn {
  width: 36px;
  height: 36px;
  background: rgba(26,22,16,0.94);
  border: 1px solid rgba(80,65,45,0.5);
  border-radius: 6px;
  color: #d4a04a;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.panel-toggle-btn:hover, .panel-toggle-btn.active {
  background: rgba(212,160,74,0.2);
  border-color: #d4a04a;
}

/* ── Mobile Action Bar ──────────────────────────────────────── */
#mobile-action-bar {
  display: none; /* shown via media query */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 46px;
  background: linear-gradient(180deg, #282018 0%, #1c1810 100%);
  border-top: 1px solid rgba(212,160,74,0.15);
  z-index: 25;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 8px;
}
.action-btn {
  width: 38px;
  height: 34px;
  background: rgba(30,26,18,0.8);
  border: 1px solid rgba(80,65,45,0.4);
  color: #8a7a6a;
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.action-btn:active { background: rgba(212,160,74,0.25); color: #e8dcc8; }
.action-btn.active { background: #d4a04a; color: #1a1410; border-color: #d4a04a; }

/* ── Mobile-first responsive ────────────────────────────────── */
@media (max-width: 768px) {
  /* HUD Bar: compact for narrow screens */
  #hud-bar {
    height: auto;
    min-height: 38px;
    padding: 4px 8px;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 11px;
  }
  .hud-label { display: none; }
  .hud-icon { font-size: 13px; }
  .hud-value { font-size: 12px; }
  .hud-sub { font-size: 9px; }
  .hud-time { font-size: 10px; }
  .hud-divider { height: 16px; }

  .speed-controls { margin-left: 0; }
  .speed-btn { padding: 2px 6px; font-size: 11px; min-width: 28px; min-height: 26px; }

  .save-controls { gap: 2px; }
  .save-btn { padding: 2px 6px; font-size: 10px; min-height: 26px; }

  /* Panel toggles visible */
  #panel-toggles { display: flex; }

  /* Build menu: slide-in drawer from left */
  #build-menu {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 160px;
    max-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: rgba(26,22,16,0.98);
    border-right: 1px solid rgba(80,65,45,0.4);
    z-index: 19;
    padding-top: 42px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #build-menu.mobile-open {
    transform: translateX(0);
  }

  /* Info panel: bottom sheet */
  #info-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 46px;
    top: auto;
    width: 100%;
    max-height: 45vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px 12px 0 0;
    z-index: 19;
  }

  /* Objectives panel: bottom sheet */
  #objectives-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 46px;
    top: auto;
    width: 100%;
    max-height: 40vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px 12px 0 0;
    z-index: 19;
  }

  /* Show mobile action bar, hide desktop help bar */
  #mobile-action-bar { display: flex; }
  #help-bar { display: none; }
  #help-bar-mobile { display: block; }

  /* Minimap smaller on mobile */
  /* (handled in renderer but leave space) */

  /* Build version label repositioned */
  #build-version {
    bottom: 52px;
    right: 6px;
    font-size: 9px;
  }

  /* Overlay indicator below HUD */
  #overlay-indicator {
    top: auto;
    bottom: 52px;
    left: 50%;
    font-size: 10px;
    padding: 3px 10px;
  }
}

/* Very narrow phones */
@media (max-width: 420px) {
  #hud-bar {
    gap: 4px;
    padding: 3px 4px;
  }
  .hud-sub { display: none; }
  .hud-value { font-size: 11px; }
  .speed-btn { padding: 1px 5px; font-size: 10px; min-width: 24px; }
  .save-btn { padding: 1px 5px; font-size: 9px; }
  #build-menu { width: 145px; }
}
