/* Ironhold — layout and chrome. The board itself is drawn on canvas;
   everything here is the frame around it. */

:root {
  --bg: #080c11;
  --bg-2: #0d1319;
  --panel: #121922;
  --panel-2: #182130;
  --line: #22303f;
  --ink: #e7eef7;
  --ink-dim: #8ea0b5;
  --ink-faint: #5d6e83;
  --gold: #fbbf24;
  --life: #f87171;
  --accent: #38bdf8;
  --good: #4ade80;
  --arrow: #7dd3fc;
  --cannon: #fbbf24;
  --frost: #a5b4fc;
  --tesla: #c084fc;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* `hidden` is only a UA stylesheet rule, so any author rule that sets
   `display` keeps the element painted while `el.hidden` reads true.
   The overlay below sets `display: grid`, which is exactly that case. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(1100px 600px at 18% -10%, #14212e 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #1a1426 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- top bar ---------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20,28,38,0.95), rgba(12,18,25,0.9));
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: conic-gradient(from 210deg, var(--arrow), var(--tesla), var(--gold), var(--arrow));
  box-shadow: 0 0 14px rgba(56,189,248,0.35);
}

.brand-text {
  font-weight: 800;
  letter-spacing: 0.18em;
  font-size: 15px;
  background: linear-gradient(90deg, #e2f3ff, #9ec8e8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stats { display: flex; gap: 8px; flex-wrap: wrap; }

.stat {
  display: flex; flex-direction: column; align-items: flex-end;
  min-width: 62px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(16,23,31,0.7);
  transition: transform 120ms ease, border-color 200ms ease, background 200ms ease;
}

.stat-k { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-faint); }
.stat-v { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-v .dim { font-size: 12px; font-weight: 600; color: var(--ink-faint); }

#stat-lives .stat-v { color: var(--life); }
#stat-gold .stat-v { color: var(--gold); }
.stat.bump { transform: scale(1.09); border-color: currentColor; }
.stat.warn { border-color: var(--life); background: rgba(248,113,113,0.12); }

/* ---- layout ----------------------------------------------------------- */

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 312px;
  gap: 14px;
  padding: 14px;
}

/* The stage centres a fixed-ratio canvas. The canvas is sized in script from
   the measured wrapper — a flex/grid item that stretches makes aspect-ratio
   inert, and a hidden pane measures zero, so both are handled there. */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

/* Two stacked canvases: WebGL for the world, a transparent 2D canvas above it
   for health bars, particles and the wave banner. */
.board-stack {
  position: relative;
  line-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 22px 60px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(255,255,255,0.03);
}

#board {
  display: block;
  background: #0d141b;
  touch-action: none;
  cursor: crosshair;
}

#board.is-orbiting { cursor: grabbing; }

#board-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(6,10,14,0.72);
  backdrop-filter: blur(3px);
  border-radius: var(--radius);
  z-index: 5;
}

.modal {
  text-align: center;
  padding: clamp(18px, 5cqh, 34px) clamp(20px, 6cqw, 44px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(24,33,48,0.97), rgba(14,20,28,0.97));
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  max-width: 92%;
}

.modal h2 { margin: 0 0 8px; font-size: clamp(20px, 5cqh, 30px); letter-spacing: 0.02em; }
.modal p { margin: 0 0 18px; color: var(--ink-dim); line-height: 1.55; white-space: pre-line; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

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

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  padding: 11px 12px 12px;
  flex: 0 0 auto;
}

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.card-head h2 { margin: 0; font-size: 12px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-dim); font-weight: 700; }
.hint { font-size: 11px; color: var(--ink-faint); }

/* shop */

.shop { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.tower-btn {
  position: relative;
  display: flex; flex-direction: column; gap: 5px;
  padding: 9px 9px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10,15,21,0.65);
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, transform 90ms ease, background 140ms ease;
}

.tower-btn:hover:not(:disabled) { border-color: var(--t-color); transform: translateY(-1px); }
.tower-btn.is-on { border-color: var(--t-color); background: color-mix(in srgb, var(--t-color) 13%, transparent); box-shadow: 0 0 0 1px var(--t-color) inset; }
.tower-btn:disabled { opacity: 0.42; cursor: not-allowed; }

.tower-row { display: flex; align-items: center; gap: 7px; }
.tower-ico { width: 20px; height: 20px; flex: 0 0 auto; }
.tower-name { font-weight: 700; font-size: 12.5px; }
.tower-key {
  position: absolute; top: 6px; right: 7px;
  font-size: 9.5px; color: var(--ink-faint);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}
.tower-cost { font-size: 12px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.tower-desc { font-size: 10.5px; color: var(--ink-faint); line-height: 1.35; }

/* selection */

.sel-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; margin-bottom: 10px; }
.sel-stats div { display: flex; justify-content: space-between; gap: 6px; font-size: 11.5px; }
.sel-stats span { color: var(--ink-faint); }
.sel-stats b { font-variant-numeric: tabular-nums; font-weight: 700; }
.sel-stats .up { color: var(--good); font-weight: 700; font-size: 10.5px; }
.sel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }

.x {
  background: none; border: 0; color: var(--ink-faint);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.x:hover { color: var(--ink); }

/* buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(12,18,25,0.8);
  color: var(--ink);
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: border-color 140ms ease, background 140ms ease, transform 90ms ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn b { font-variant-numeric: tabular-nums; color: var(--gold); }

.btn-primary { background: linear-gradient(180deg, #1d4ed8, #1e3a8a); border-color: #2b52a8; margin-bottom: 8px; }
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #2563eb, #1d4ed8); }
.btn-primary b { color: #cfe4ff; }
.btn-up { border-color: rgba(74,222,128,0.35); }
.btn-sell { border-color: rgba(248,113,113,0.3); }
.btn-sell b { color: var(--life); }
.btn-ghost { background: rgba(255,255,255,0.03); }

.speed { display: grid; grid-template-columns: 1.5fr 1fr 1fr 1fr; gap: 6px; }
.speed .btn { padding: 7px 4px; }
.speed-btn.is-on { border-color: var(--accent); background: rgba(56,189,248,0.16); color: #bae6fd; }

/* wave preview + legend */

.wave-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 9px; min-height: 22px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(10,15,21,0.6);
  font-size: 11px; font-weight: 700;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill.boss { border-color: rgba(232,121,249,0.5); background: rgba(232,121,249,0.12); }

.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--ink-dim); }
.legend i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.legend b { color: var(--ink); font-weight: 700; }
.legend .tag { margin-left: auto; font-size: 9.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.07em; }

.keys { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 11px; color: var(--ink-faint); }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px; padding: 1px 4px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  background: rgba(255,255,255,0.04); color: var(--ink-dim);
}

/* ---- narrow screens --------------------------------------------------- */

@media (max-width: 900px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100%; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel { overflow: visible; }
  /* `container-type: size` means this cannot be sized by the board inside it,
     so fit() sets an explicit height for the stacked layout. */
  .stage { min-height: 0; }
  .card-help { display: none; }
  .shop { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .stat { min-width: 54px; padding: 3px 7px; }
  .stat-v { font-size: 15px; }
  .stat-best { display: none; }
  .layout { padding: 8px; gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; }
}

.icon-btn {
  align-self: stretch;
  min-width: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(16,23,31,0.7);
  color: var(--ink-dim);
  font-size: 15px;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}
.icon-btn:hover { color: var(--ink); border-color: var(--accent); }
.icon-btn.is-off { color: var(--ink-faint); text-decoration: line-through; }
