/* Low-Poly Tower Defense — HUD styling.
   Light and dark themes, no web fonts, no images. */

:root {
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #fbfaf6;
  --ink: #16222c;
  --ink-dim: #55636f;
  --line: rgba(22, 34, 44, 0.14);
  --accent: #a8621a;
  --accent-soft: rgba(168, 98, 26, 0.14);
  --good: #1f7a48;
  --bad: #ab2f28;
  --shadow: 0 10px 26px rgba(15, 30, 42, 0.18);
  --radius: 14px;
  --track: rgba(22, 34, 44, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --panel: rgba(15, 20, 26, 0.8);
    --panel-solid: #131a21;
    --ink: #edf3f8;
    --ink-dim: #9fadb9;
    --line: rgba(237, 243, 248, 0.16);
    --accent: #f2b45c;
    --accent-soft: rgba(242, 180, 92, 0.18);
    --good: #74d3a0;
    --bad: #ff8f80;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
    --track: rgba(237, 243, 248, 0.1);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #bfe4f7;
  color: var(--ink);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

#scene.focused {
  box-shadow: inset 0 0 0 3px var(--accent);
}

#boot-error {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0e1418;
  color: #fff;
  z-index: 40;
  text-align: center;
}

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

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

body[data-phase="start"] #hud,
body[data-phase="victory"] #hud,
body[data-phase="defeat"] #hud { display: none; }

#topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: stretch;
  gap: 10px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.grow { flex: 1 1 auto; pointer-events: none !important; }

.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 84px;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.stat .val {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat .lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.stat.wide { min-width: 148px; }
.stat.hit { animation: hit 0.5s ease-out; }
@keyframes hit {
  0% { background: rgba(200, 40, 30, 0.5); transform: translateY(0); }
  40% { transform: translateY(3px); }
  100% { background: var(--panel); transform: translateY(0); }
}

.seg {
  display: flex;
  gap: 4px;
  padding: 5px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 7px 12px;
  transition: background 0.14s ease, transform 0.08s ease, border-color 0.14s ease;
}
button:hover:not(:disabled) { background: var(--accent-soft); }
button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.chip { min-width: 48px; font-weight: 600; }
.chip.active { background: var(--accent); color: #fff; border-color: transparent; }
@media (prefers-color-scheme: dark) {
  .chip.active { color: #1a1206; }
}

.preview {
  position: absolute;
  top: 76px;
  left: 12px;
  margin: 0;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13px;
  color: var(--ink-dim);
  backdrop-filter: blur(8px);
  max-width: min(560px, 60vw);
}
.preview[data-state="live"] { color: var(--ink); border-color: var(--accent); }

#bottom {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
#bottom > * { pointer-events: auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  padding: 10px;
}

#buildbar {
  display: flex;
  gap: 8px;
}

.build {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "k nm cost" "role role role";
  align-items: center;
  gap: 2px 8px;
  min-width: 148px;
  padding: 9px 12px;
  text-align: left;
  background: var(--panel-solid);
}
.build .k {
  grid-area: k;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--track);
  font-size: 12px;
  font-weight: 700;
}
.build .nm { grid-area: nm; font-weight: 700; }
.build .cost { grid-area: cost; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }
.build .cost::after { content: " g"; font-weight: 400; font-size: 11px; color: var(--ink-dim); }
.build .role { grid-area: role; font-size: 11px; color: var(--ink-dim); }
.build.armed { border-color: var(--accent); background: var(--accent-soft); }
.build.unaffordable .cost { color: var(--bad); }

.center-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-bottom: 2px;
}
.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.primary:hover:not(:disabled) { filter: brightness(1.07); background: var(--accent); }
@media (prefers-color-scheme: dark) {
  .primary { color: #1a1206; }
}
.primary.big { font-size: 17px; padding: 14px 30px; }
.card .primary.big { margin-top: 14px; }
.kbdhint {
  margin: 0;
  font-size: 11px;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  backdrop-filter: blur(8px);
}

#selection-panel { max-width: 320px; }
#selection-panel h2 { margin: 0 0 6px; font-size: 14px; }
#selection-body .stats { margin: 0 0 8px; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 12px;
  margin: 0;
  font-size: 12px;
}
.stats > div { display: flex; justify-content: space-between; gap: 8px; }
.stats dt { color: var(--ink-dim); }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.stats.end { grid-template-columns: 1fr; font-size: 15px; }
.stats.end > div { border-bottom: 1px solid var(--line); padding: 5px 0; }
.stats.end dd { font-size: 16px; }

.action {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 6px;
  background: var(--panel-solid);
  font-weight: 600;
}
.action .sub {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}
.action.sell { border-color: rgba(171, 47, 40, 0.4); }
.build-list .action { margin-top: 4px; }
.hint { margin: 6px 0 0; font-size: 11px; color: var(--ink-dim); }

/* ---------- toasts + popups ---------- */

#toasts {
  position: absolute;
  left: 50%;
  bottom: 116px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(16, 22, 28, 0.86);
  color: #f4f8fb;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: rise 0.18s ease-out;
  transition: opacity 0.5s ease;
}
.toast.out { opacity: 0; }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

#popups {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}
.pop {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  font-weight: 800;
  font-size: 14px;
  color: #ffe08a;
  text-shadow: 0 1px 3px rgba(20, 26, 12, 0.85);
  will-change: transform, opacity;
}

/* ---------- full screen overlays ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 26, 38, 0.42);
  backdrop-filter: blur(6px);
}
.card {
  width: min(620px, 94vw);
  max-height: 92vh;
  overflow: auto;
  padding: 26px 28px 24px;
  border-radius: 20px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(8, 20, 30, 0.4);
  text-align: center;
}
.eyebrow {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.card h1 { margin: 0 0 10px; font-size: 30px; letter-spacing: -0.02em; }
.goal {
  margin: 0 auto 8px;
  font-size: 19px;
  font-weight: 700;
  max-width: 34ch;
}
.best {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}
.controls {
  margin: 0 auto 18px;
  text-align: left;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--track);
}
.controls h2 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
.controls ul { margin: 0; padding-left: 18px; font-size: 13px; }
.controls li { margin: 3px 0; }
.card .hint { margin-top: 14px; font-size: 12px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 900px) {
  #bottom { flex-wrap: wrap; align-items: stretch; }
  #buildbar { order: 1; flex: 1 1 100%; justify-content: space-between; }
  .build { min-width: 0; flex: 1; }
  .center-col { order: 3; flex: 1 1 100%; }
  #selection-panel { order: 2; max-width: none; flex: 1 1 100%; }
  #toasts { bottom: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
