/* Pirate Siege — Tower Defense */

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --fg: #e8e8e8;
  --fg2: #b0b0b0;
  --accent: #e94560;
  --accent2: #f5a623;
  --accent3: #4ecca3;
  --panel-bg: rgba(22, 33, 62, 0.95);
  --panel-border: rgba(233, 69, 96, 0.3);
  --shadow: rgba(0, 0, 0, 0.5);
  --gold: #ffd700;
  --hp-green: #4c4;
  --hp-yellow: #cc4;
  --hp-red: #c44;
}

html[data-theme="light"] {
  --bg: #f0ece4;
  --bg2: #e8e0d4;
  --bg3: #d4c8b8;
  --fg: #2a2a2a;
  --fg2: #555;
  --accent: #c44;
  --accent2: #d4880a;
  --accent3: #2a8a6a;
  --panel-bg: rgba(240, 236, 228, 0.97);
  --panel-border: rgba(196, 68, 68, 0.3);
  --shadow: rgba(0, 0, 0, 0.15);
  --gold: #b8860b;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  touch-action: manipulation;
}

#app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Top Bar ── */
#top-bar {
  height: 48px;
  min-height: 48px;
  background: var(--panel-bg);
  border-bottom: 2px solid var(--panel-border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 16px;
  z-index: 10;
  flex-shrink: 0;
}

#top-bar > div {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

#gold-display { color: var(--gold); }
#lives-display { color: var(--accent); }
#wave-display { color: var(--accent3); }
#level-display { color: var(--accent2); }

#speed-display {
  margin-left: auto;
  gap: 6px;
}

#speed-slider {
  width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Canvas ── */
#game-canvas {
  flex: 1;
  display: block;
  cursor: crosshair;
  image-rendering: pixelated;
}

/* ── Build Panel ── */
#build-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--panel-bg);
  border-top: 2px solid var(--panel-border);
  padding: 8px 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  flex-shrink: 0;
}

#build-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent2);
  white-space: nowrap;
  margin-right: 4px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.build-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 10px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  cursor: pointer;
  min-width: 80px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.build-item:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--accent);
}

.build-item.selected {
  background: rgba(233, 69, 96, 0.2);
  border-color: var(--accent);
}

.build-icon { font-size: 20px; }
.build-name { font-size: 10px; font-weight: 600; margin: 2px 0; }
.build-cost { font-size: 10px; color: var(--gold); }
.build-stats { font-size: 9px; color: var(--fg2); }

/* ── Overlay ── */
#overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.overlay-content {
  text-align: center;
  padding: 32px;
  max-width: 500px;
  width: 90%;
}

.game-title {
  font-weight: 900;
  font-size: clamp(28px, 6vw, 48px);
  color: var(--accent2);
  text-shadow: 0 0 20px rgba(245, 166, 35, 0.5), 2px 2px 0 #000;
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.game-subtitle {
  font-size: 16px;
  color: var(--fg2);
  margin-bottom: 24px;
  letter-spacing: 0.1em;
}

.menu-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-val {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent2);
}

.stat-label {
  font-size: 11px;
  color: var(--fg2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.overlay-title {
  font-weight: 700;
  font-size: clamp(20px, 5vw, 32px);
  margin-bottom: 16px;
}

.complete-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  margin: 4px;
  letter-spacing: 0.05em;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px var(--shadow);
}

.btn-primary:hover {
  background: #ff5577;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px var(--shadow);
}

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--fg);
  border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

/* ── Level Grid ── */
.level-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  margin: 16px 0;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
}

.level-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  min-height: 36px;
}

.level-cell:hover:not(.locked) {
  background: rgba(233, 69, 96, 0.3);
  transform: scale(1.1);
}

.level-cell.locked {
  opacity: 0.3;
  cursor: not-allowed;
}

.level-num {
  font-size: 14px;
  font-weight: 700;
}

.level-best {
  font-size: 8px;
  color: var(--gold);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #top-bar {
    gap: 8px;
    padding: 0 8px;
    font-size: 12px;
  }
  #speed-slider { width: 60px; }
  .build-item { min-width: 64px; padding: 4px 6px; }
  .build-icon { font-size: 16px; }
  .build-name { font-size: 9px; }
  .build-cost, .build-stats { font-size: 8px; }
  .level-grid { grid-template-columns: repeat(8, 1fr); }
  .btn { padding: 10px 20px; font-size: 14px; }
}

@media (max-width: 360px) {
  #top-bar { gap: 4px; font-size: 11px; }
  .level-grid { grid-template-columns: repeat(6, 1fr); }
}
