/* DEMOLITION — styles.css
   Lab retro-arcade dark, same token names as sandfall/serpent so
   /theme-light.css (loaded by embed.js for ?theme=light) can override them.
   Motif: caution tape. Gold = target zone, red = neighbours / hits,
   magenta = small charge, gold = large charge, cyan = focus + primary. */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --control-line: #5e5e80;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;

  --brick: #c2553a;
  --steel: #8a97b2;
  --glass: #6fd9f2;
  --neighbour: #323857;
  --tape: repeating-linear-gradient(-45deg, var(--gold) 0 10px, #111118 10px 20px);

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --glow-gold: 0 0 14px rgba(255, 200, 87, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1100px 480px at 50% -12%, rgba(255, 200, 87, 0.06), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(255, 200, 87, 0.3); }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

/* ---------- header ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }
.level { margin: 0; font-family: var(--pixel); font-size: 9px; letter-spacing: 3px; color: var(--gold); }
.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(255, 200, 87, 0.55), 3px 3px 0 var(--red);
}
.tagline { margin: 0; font-family: var(--mono); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); }
.cursor { color: var(--gold); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

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

main {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 16px var(--space-gutter) 72px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.game-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
.stage-col { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- level chips ---------- */

.level-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-family: var(--pixel);
  font-size: 9px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, transform 0.12s var(--ease-out), box-shadow 0.12s;
}
.chip-stars { font-family: var(--mono); font-size: 10px; letter-spacing: 1px; color: var(--gold); }
.chip:hover:not(:disabled) { border-color: var(--gold); color: var(--text); transform: translateY(-1px); }
.chip[aria-current="true"] {
  border-color: var(--gold);
  color: var(--text);
  box-shadow: inset 0 -3px 0 var(--gold), var(--glow-gold);
}
.chip:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- brief ---------- */

.brief { display: grid; gap: 4px; }
.level-title { margin: 0; font-family: var(--pixel); font-size: clamp(12px, 2vw, 15px); color: var(--gold); letter-spacing: 1px; }
.level-brief { margin: 0; max-width: 70ch; color: var(--text); }
.level-hint { margin: 2px 0 0; max-width: 70ch; padding: 6px 10px; border-left: 3px solid var(--gold); background: var(--surface); color: var(--text); font-size: 14px; }
.hint-tag { margin-right: 8px; font-family: var(--pixel); font-size: 9px; letter-spacing: 1px; color: var(--gold); }
.fiction-tag { margin: 0; font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--dim); text-transform: uppercase; }
.how-line { margin: 0; font-size: 13px; color: var(--dim); }

/* ---------- stage ---------- */

.stage {
  position: relative;
  scroll-margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #07070e;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5), 0 0 28px rgba(255, 200, 87, 0.06);
}
.stage::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  background: var(--tape);
  opacity: 0.85;
  z-index: 1;
  pointer-events: none;
}

/* .stage clips its children, so the canvas focus ring is drawn on the stage. */
.stage:has(> #siteCanvas:focus-visible) {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15), inset 0 0 60px rgba(0, 0, 0, 0.5);
}
#siteCanvas:focus-visible { outline-offset: -3px; box-shadow: none; }
@supports selector(:has(*)) {
  #siteCanvas:focus-visible { outline: none; }
}

#siteCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  image-rendering: pixelated;
  touch-action: manipulation;
  cursor: crosshair;
}
.stage[data-phase="blast"] #siteCanvas,
.stage[data-phase="result"] #siteCanvas { cursor: default; }

.overlay {
  position: absolute;
  top: 16px;
  right: 12px;
  z-index: 2;
  display: grid;
  gap: 6px;
  width: min(360px, calc(100% - 24px));
  padding: 16px 16px 14px;
  background: rgba(10, 10, 18, 0.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  animation: card-in 0.28s var(--ease-out) both;
  scroll-margin: 12px 0;
}
.overlay::before {
  content: "";
  position: absolute;
  inset: -1px -1px auto -1px;
  height: 8px;
  border-radius: 10px 10px 0 0;
  background: var(--tape);
}
.overlay[data-pass="false"]::before { background: repeating-linear-gradient(-45deg, var(--red) 0 10px, #111118 10px 20px); }
@keyframes card-in { from { opacity: 0; transform: translateY(12px); } }

.result-title { margin: 6px 0 0; font-family: var(--pixel); font-size: 14px; color: var(--gold); }
.overlay[data-pass="false"] .result-title { color: var(--red); }
.result-stars { margin: 0; font-size: 22px; letter-spacing: 6px; color: var(--gold); text-shadow: var(--glow-gold); }
.result-reason { margin: 0; color: var(--text); }
.result-stats, .result-checks { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; font-family: var(--mono); font-size: 11.5px; color: var(--dim); }
.result-stats { grid-template-columns: 1fr 1fr; column-gap: 14px; }
.result-stats li { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding: 2px 0; }
.result-stats strong { color: var(--text); }
.result-checks li { display: flex; gap: 6px; }
.result-checks li[data-ok="true"] { color: var(--gold); }
.result-checks li[data-ok="false"] { color: var(--dim); }
.check-mark { flex: 0 0 auto; }
.result-hint { margin: 2px 0 0; font-family: var(--mono); font-size: 11.5px; color: var(--gold); }
.result-best { color: var(--green); font-family: var(--pixel); font-size: 9px; margin-left: 8px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-title { margin: 0; font-family: var(--pixel); font-size: 10px; letter-spacing: 1px; color: var(--gold); text-shadow: 0 0 8px rgba(255, 200, 87, 0.4); }

.kind-row { display: grid; gap: 8px; }
.kind-btn {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--dim);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s, transform 0.12s var(--ease-out);
}
.kind-btn:hover { border-color: var(--control-line); color: var(--text); }
.kind-btn[aria-pressed="true"] { border-color: var(--cyan); color: var(--text); box-shadow: 0 0 0 2px rgba(69, 240, 255, 0.18), 0 0 16px rgba(69, 240, 255, 0.2); }
.kind-btn:active { transform: translateY(1px); }
.kind-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.kind-text { display: grid; gap: 2px; min-width: 0; }
.kind-text strong { font-family: var(--pixel); font-size: 10px; font-weight: 400; letter-spacing: 1px; }
.kind-text small { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.kind-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #05050d; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35); }
.kind-dot-small { background: var(--magenta); }
.kind-dot-large { background: var(--gold); width: 20px; height: 20px; }

.hud { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.hud > div { display: grid; gap: 4px; padding: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.hud span { font-family: var(--mono); font-size: 10px; letter-spacing: 1px; color: var(--dim); }
.hud strong { font-family: var(--pixel); font-size: 12px; font-weight: 400; color: var(--text); }
#bestOut { color: var(--gold); letter-spacing: 2px; }

.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action-wide { grid-column: 1 / -1; }
.mute-btn { align-self: flex-start; }

.legend { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 13px; color: var(--dim); }
.legend li { display: flex; align-items: center; gap: 10px; }
.sw { width: 18px; height: 12px; border: 1px solid rgba(255, 255, 255, 0.2); flex: 0 0 auto; }
.sw-brick { background: var(--brick); }
.sw-steel { background: var(--steel); }
.sw-glass { background: var(--glass); }
.sw-neighbour { background: var(--neighbour); box-shadow: inset 0 0 0 2px var(--red); }
.sw-zone { background: var(--tape); }
.sw-ring { width: 16px; height: 16px; margin: 0 1px; border-radius: 50%; border: 2px dashed var(--magenta); background: transparent; }
.sw-ring-glass { border: 2px dotted var(--glass); }

.status { min-height: 1.5em; margin: 8px 0 0; font-family: var(--mono); font-size: 12.5px; color: var(--dim); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: var(--cyan); border-color: var(--cyan); color: #05050d; }
.btn-primary:hover:not(:disabled) { box-shadow: 0 0 18px rgba(69, 240, 255, 0.5); }
.btn-primary:disabled { background: var(--surface-2); border-color: var(--line); color: var(--dim); opacity: 1; }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 11px; padding: 14px 18px; min-height: 48px; }
#btnDetonate:not(:disabled) { background: var(--red); border-color: var(--red); color: #05050d; }
#btnDetonate:not(:disabled):hover { box-shadow: 0 0 18px rgba(255, 85, 96, 0.55); }

/* ---------- aim bar (touch) ----------
   Shown on coarse pointers, or once a touch is seen (data-touch on .stage-col). */

.aim-bar { display: none; gap: 8px; margin-top: 10px; align-items: stretch; }
@media (hover: none) and (pointer: coarse) {
  .aim-bar { display: flex; }
}
.stage-col[data-touch="true"] .aim-bar { display: flex; }
.pad-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--cyan);
  font-size: 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s var(--ease-out), border-color 0.12s, background 0.12s;
}
.pad-btn:hover:not(:disabled) { border-color: var(--cyan); }
.pad-btn:active:not(:disabled) { transform: scale(0.94); background: rgba(69, 240, 255, 0.12); }
.pad-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.aim-go { flex: 1 1 auto; min-width: 0; min-height: 48px; padding: 8px; font-size: 12.5px; letter-spacing: 1px; }

/* ---------- notes ---------- */

.notes p { margin: 0; color: var(--dim); max-width: 75ch; }
.notes .fiction { color: var(--gold); font-family: var(--mono); font-size: 12px; }
.sources-title { margin: 6px 0 0; font-family: var(--pixel); font-size: 9px; color: var(--dim); letter-spacing: 1px; }
.sources { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-size: 13px; }
.sources a { color: var(--cyan); text-decoration: none; }
.sources a:hover { text-decoration: underline; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- footer ---------- */

.site-footer { border-top: 1px solid var(--line); padding: 22px var(--space-gutter); text-align: center; color: var(--dim); font-size: 13px; }
.site-footer p { margin: 4px 0; }
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */

@media (max-width: 360px) {
  .pad-btn { width: 44px; height: 44px; }
  .aim-bar { gap: 6px; }
}
@media (max-width: 900px) {
  .play-layout { grid-template-columns: 1fr; }
  .side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .side { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: 1fr; }
  .overlay { position: static; width: auto; border-radius: 0 0 10px 10px; border-width: 1px 0 0; animation: none; }
  .overlay::before { border-radius: 0; }
}
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .chip { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
}
