/* Game HUD: top and bottom bars */

#game-top-bar,
#game-bottom-bar {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  background: rgba(17, 70, 17, 0.9);
  display: none;
}

#game-top-bar.visible {
  display: flex;
}

#game-bottom-bar.visible {
  display: flex;
}

/* ── Top Bar ─────────────────────────────────────────────────── */

#game-top-bar {
  top: 0;
  height: 32px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.5);
  align-items: center;
  padding: 0 8px;
  gap: 8px;
}

#resources-display {
  display: flex;
  flex: 1;
  justify-content: space-evenly;
  align-items: center;
  overflow: hidden;
}

.resource-item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.resource-item img {
  width: 18px;
  height: 18px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.resource-value {
  color: #FFD700;
  font-size: 13px;
  font-family: system-ui, sans-serif;
  min-width: 28px;
  font-variant-numeric: tabular-nums;
}

#game-menu-btn {
  flex-shrink: 0;
  width: 34px;
  height: 24px;
  background: rgba(17, 70, 17, 0.7);
  border: 1px solid rgba(255, 215, 0, 0.8);
  color: #FFD700;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-menu-btn:hover {
  background: rgba(34, 139, 34, 0.8);
}

/* ── Bottom Bar ───────────────────────────────────────────────── */

#game-bottom-bar {
  bottom: 0;
  height: 72px;
  border-top: 1px solid rgba(255, 215, 0, 0.5);
  align-items: stretch;
  overflow: hidden;
}

/* ── Building Slots Panel ─────────────────────────────────────── */

#building-slots-panel {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 4px;
  gap: 4px;
  flex-wrap: wrap;
}

.building-slot {
  width: 64px;
  height: 64px;
  cursor: pointer;
  background: rgba(17, 70, 17, 0.7);
  border: 1px solid rgba(255, 215, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 2px 2px;
  gap: 2px;
  flex-shrink: 0;
  position: relative;
}

.building-slot:hover {
  border-color: #FFD700;
  background: rgba(34, 139, 34, 0.7);
}

.building-slot.selected {
  border-color: #FFD700;
  border-width: 2px;
  background: rgba(34, 139, 34, 0.9);
}

.building-slot.unaffordable {
  opacity: 0.3;
  cursor: not-allowed;
}

.building-slot img {
  width: 44px;
  height: 44px;
  image-rendering: pixelated;
}

.slot-name {
  color: #FFD700;
  font-size: 10px;
  font-family: system-ui, sans-serif;
  text-align: center;
  line-height: 1.1;
  max-width: 62px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Building Info Panel ──────────────────────────────────────── */

#building-info-panel {
  display: none;
  flex: 1;
  align-items: center;
  padding: 4px 10px;
  gap: 10px;
  overflow: hidden;
}

#building-info-panel.visible {
  display: flex;
}

.bi-icon {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  flex-shrink: 0;
  align-self: center;
}

.bi-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex-shrink: 1;
}

.bi-name {
  color: #FFD700;
  font-size: 15px;
  font-weight: bold;
  font-family: system-ui, sans-serif;
  white-space: nowrap;
}

.bi-desc {
  color: #fff;
  font-size: 11px;
  font-family: system-ui, sans-serif;
}

.bi-stats {
  color: #ADD8E6;
  font-size: 11px;
  font-family: system-ui, sans-serif;
}

.bi-life {
  color: #00ff00;
  font-size: 12px;
  font-family: system-ui, sans-serif;
}

.bi-extra {
  color: #ADD8E6;
  font-size: 11px;
  font-family: system-ui, sans-serif;
}

.bi-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  padding: 4px 0;
}

/* Action buttons (upgrade, specialize, sell, branch) */
.bi-btn {
  background: rgba(0, 100, 0, 0.7);
  border: 1px solid rgba(255, 215, 0, 0.8);
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 10px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  max-width: min(50dvw, 470px);
  height: 68px;
}

.bi-btn:hover:not(:disabled) {
  background: rgba(34, 139, 34, 0.9);
  border-color: #FFD700;
}

.bi-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.bi-btn.unaffordable {
  background: rgba(50, 50, 50, 0.7);
  border-color: rgba(150, 150, 150, 0.5);
}

.bi-btn-icon {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.bi-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.bi-btn-title {
  font-weight: bold;
  font-size: 16px;
  color: #FFD700;
  text-align: left;
}

.bi-btn-sub {
  font-size: 12px;
  color: #ccc;
  text-align: left;
}

.bi-btn-cost {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
}

.bi-btn-cost-item {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  color: #FFD700;
}

.bi-btn-cost-item img {
  width: 14px;
  height: 14px;
  image-rendering: pixelated;
}

/* Market sell buttons */
.bi-sell-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bi-sell-btn {
  background: rgba(50, 50, 50, 0.7);
  border: 1px solid rgba(255, 215, 0, 0.6);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  width: 34px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.bi-sell-btn.active {
  background: rgba(0, 100, 0, 0.8);
  border-color: #FFD700;
}

.bi-sell-btn:hover {
  background: rgba(34, 139, 34, 0.7);
}

/* Specialize back button */
.bi-back-btn {
  background: rgba(50, 50, 50, 0.8);
  border: 1px solid rgba(136, 136, 136, 0.8);
  color: #ccc;
  font-family: system-ui, sans-serif;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 10px;
  height: 68px;
  flex-shrink: 0;
}

.bi-back-btn:hover {
  background: rgba(80, 80, 80, 0.9);
}

/* ── Tooltip ──────────────────────────────────────────────────── */

#hud-tooltip {
  position: fixed;
  z-index: 20;
  background: rgba(17, 70, 17, 0.97);
  border: 1px solid rgba(255, 215, 0, 0.7);
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: 13px;
  padding: 8px 10px;
  pointer-events: none;
  display: none;
  max-width: 260px;
  min-width: 160px;
  gap: 4px;
  flex-direction: column;
}

#hud-tooltip.visible {
  display: flex;
}

.tooltip-title {
  color: #FFD700;
  font-size: 14px;
  font-weight: bold;
}

.tooltip-desc {
  color: #fff;
  font-size: 12px;
}

.tooltip-details {
  color: #ccc;
  font-size: 11px;
  font-style: italic;
}

.tooltip-costs {
  color: #FFD700;
  font-size: 11px;
  margin-top: 4px;
}

/* ── Minimap ──────────────────────────────────────────────────── */

#minimap-container {
  position: fixed;
  top: 31px;
  right: -1px;
  width: 224px;
  height: 224px;
  z-index: 15;
  display: none;
  transition: all 1s ease-in-out;
}

body.playing-mode #minimap-container {
  display: block;
}

#minimap-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: rgba(17, 70, 17, 0.85);
  border: 1px solid rgba(255, 215, 0, 0.5);
}

#minimap-toggle {
  position: absolute;
  bottom: 1px;
  left: 1px;
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
  color: #FFD700;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0.65;
  transition: opacity 0.15s ease-in-out;
}

#minimap-toggle:hover {
  opacity: 1;
}

.minimap-toggle-icon {
  display: inline-block;
  transform: rotate(45deg);
  line-height: 1;
  font-size: 1.25rem;
  pointer-events: none;
  transition: transform .5s ease-in-out;
}

/* Minimized: shrink container height to 50% */
body.minimap-minimized #minimap-container {
  height: 112px;
  width: 112px;
}

body.minimap-minimized .minimap-toggle-icon {
  transform: rotate(225deg);
}

/* Shift objectives panel up when minimap is minimized (desktop) */
body.minimap-minimized #objectives-panel {
  top: 142px; /* 31px + 112px - 1px border */
  max-height: calc(100dvh - 142px - 72px);
}

/* ── Objectives panel (below minimap) ────────────────────────── */

#objectives-panel {
  position: fixed;
  top: 254px; /* 31px top bar + 224px minimap - 1px border */
  right: -1px;
  width: 224px;
  background: rgba(17, 70, 17, 0.85);
  border: 1px solid rgba(255, 215, 0, 0.5);
  z-index: 14;
  display: none;
  max-height: calc(100dvh - 254px - 72px);
  overflow-y: auto;
  padding: 6px;
  box-sizing: border-box;
  font-family: system-ui, sans-serif;
  transition: top 1s ease-in-out, max-height .75s ease-in-out;
}

#objectives-panel #objectives-list {
  transition: all .5s ease-in-out;
  transition-delay: .25s;
}

#objectives-panel.visible {
  display: block;
}

/* Minimized: hide list, collapse to header only */
#objectives-panel.minimized {
  overflow: hidden;
  max-height: 26px !important;
}

#objectives-panel.minimized #objectives-list {
  transition-delay: 0s;
  opacity: 0;
}

#objectives-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #FFD700;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 215, 0, 0.3);
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
}

.objectives-toggle-btn {
  display: contents;
  background: none;
  border: none;
  color: #FFD700;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.65;
  flex-shrink: 0;
  transition: all .15s ease-in-out;
}

.objectives-toggle-btn:hover {
  opacity: 1;
}

.objective-item {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  padding: 3px 0;
  font-size: 11px;
  color: #eee;
  line-height: 1.3;
}

.objective-item.completed {
  color: rgba(255, 215, 0, 0.65);
}

.objective-checkmark {
  flex-shrink: 0;
  width: 12px;
  font-size: 11px;
}

.objective-progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  margin-top: 3px;
}

.objective-progress-fill {
  height: 100%;
  background: #FFD700;
  border-radius: 2px;
  transition: width 0.3s ease-in-out;
}

/* ── Phase banner (centered overlay) ────────────────────────── */

#phase-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(17, 70, 17, 0.95);
  border: 2px solid rgba(255, 215, 0, 0.8);
  color: #FFD700;
  font-family: system-ui, sans-serif;
  font-size: 20px;
  font-weight: bold;
  padding: 16px 32px;
  z-index: 50;
  text-align: center;
  box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
  max-width: 80vw;
}

#phase-banner.visible {
  opacity: 1;
}

/* ── Narrative dialog (Pokemon-style, above bottom bar) ────── */

#narrative-box {
  position: fixed;
  bottom: 80px; /* 72px bottom bar + 8px gap */
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 40px));
  background: rgba(28, 28, 28, 0.85);
  border: 2px solid #888;
  border-radius: 4px;
  padding: 12px 40px 12px 18px; /* right padding leaves room for close btn */
  z-index: 15;
  display: none;
  box-sizing: border-box;
  box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  user-select: none;
}

#narrative-box.visible {
  display: block;
}

#narrative-text {
  display: block;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  line-height: 1.65;
  color: #f0f0f0;
  white-space: pre-wrap;
}

#narrative-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 5px;
}

#narrative-close:hover {
  color: #fff;
}

/* ── Mobile ───────────────────────────────────────────────────── */

@media (max-width: 600px), (max-height: 600px) {
  #game-bottom-bar {
    height: 56px;
  }

  #building-slots-panel {
    padding: 4px;
    gap: 4px;
  }

  .building-slot {
    width: 48px;
    height: 48px;
  }

  .building-slot img {
    width: 24px;
    height: 24px;
  }

  .resource-item img {
    width: 16px;
    height: 16px;
  }

  .resource-value {
    font-size: 12px;
  }

  #minimap-container {
    width: 172px;
    height: 172px;
  }

  body.minimap-minimized #minimap-container {
    width: 86px;
    height: 86px;
  }

  #objectives-panel {
    top: 31px;
    left: -1px;
    right: auto;
    width: 172px;
    max-height: calc(100dvh - 33px - 56px);
  }

  /* On mobile, objectives stay on the left — don't shift when minimap minimizes */
  body.minimap-minimized #objectives-panel {
    top: 31px;
    max-height: calc(100dvh - 33px - 56px);
  }

  #narrative-box {
    bottom: 64px; /* 56px bottom bar + 8px gap */
  }
}
