:root {
  color-scheme: dark;
  --bg: #050308;
  --panel: #0f0a14;
  --line: #2b143c;
  --muted: #684675;
  --text: #dff9fb;
  --silver: #f1f2f5;
  --red: #ff3e55;
  --cyan: #00ffff;
  --magenta: #ff007f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-height: 100svh;
  color: var(--text);
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 3%, rgba(255, 62, 85, 0.12), transparent 36%),
    linear-gradient(180deg, #100615 0%, var(--bg) 65%);
}
button { color: inherit; font: inherit; }
.shell {
  width: min(100%, 540px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 20px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}
.top-nav { padding: 0 2px 12px; display: flex; }
.back-link {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .15em;
  text-decoration: none;
  transition: color .2s, transform .2s;
}
.back-link:hover, .back-link:focus { color: var(--cyan); transform: translateX(-2px); outline: none; }
.masthead { display: flex; align-items: flex-start; justify-content: space-between; padding: 4px 2px 18px; }
.masthead-buttons { display: flex; gap: 8px; }
.eyebrow { margin: 0 0 8px; color: var(--cyan); font-size: .67rem; font-weight: 800; letter-spacing: .22em; }
h1, h2 { margin: 0; font-weight: 900; letter-spacing: -.055em; line-height: .9; }
h1 { font-size: clamp(2rem, 10vw, 3.15rem); text-transform: uppercase; }
h2 { font-size: 2.2rem; line-height: .96; }
.icon-button, .dialog-close {
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%;
  background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: border-color .2s, background-color .2s;
}
.icon-button:hover, .dialog-close:hover { border-color: var(--red); background: rgba(224, 48, 74, .07); }
.hud { display: grid; grid-template-columns: 1fr 1fr; border-block: 1px solid var(--line); padding: 12px 2px 11px; }
.metric { display: flex; flex-direction: column; gap: 3px; }
.metric-right { align-items: flex-end; }
.metric-label { color: var(--muted); font-size: .58rem; font-weight: 800; letter-spacing: .16em; }
.metric strong { font: 700 1.2rem "SFMono-Regular", Consolas, monospace; letter-spacing: .06em; color: var(--silver); }
.metric-right strong { color: var(--red); }
.board-wrap {
  position: relative; flex: 1; min-height: 420px; margin: 16px 0 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 1px solid var(--line); background: var(--bg); touch-action: none;
}
canvas#game-canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: none; background: var(--bg); }
.start-overlay {
  position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  text-align: center; cursor: pointer; background: rgba(11, 11, 16, .77); backdrop-filter: blur(3px);
  pointer-events: auto !important;
}
.start-overlay.hidden { display: none; }
.start-inner { padding: 0 28px; max-width: 360px; }
.start-kicker { margin: 0 0 12px; color: var(--red); font-size: 1.25rem; font-weight: 900; letter-spacing: .06em; }
.start-sub { margin: 0 0 22px; color: #a9adba; font-size: .85rem; line-height: 1.55; }
.start-cta { margin: 0; color: var(--cyan); font-size: .7rem; font-weight: 800; letter-spacing: .2em; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }
.footer { display: flex; justify-content: center; color: var(--muted); font-size: .68rem; line-height: 1.4; }
.footer p { margin: 0; }
.pulse-dot { display: inline-block; width: 6px; height: 6px; margin-right: 5px; border-radius: 50%; background: var(--red); box-shadow: 0 0 9px var(--red); }
dialog {
  width: min(calc(100% - 36px), 480px); padding: 0; color: var(--text);
  border: 1px solid #3a3a48; background: #111118; box-shadow: 0 25px 90px rgba(0,0,0,.75);
}
dialog::backdrop { background: rgba(7,7,11,.88); backdrop-filter: blur(7px); }
.dialog-inner { position: relative; padding: 32px; }
.dialog-close { position: absolute; top: 18px; right: 18px; color: #a9adba; font-size: 1.35rem; border: 0; }
.dialog-inner ol { margin: 24px 0; padding-left: 20px; color: #adb1be; line-height: 1.58; font-size: .86rem; }
.dialog-inner li { padding-left: 7px; margin-bottom: 9px; }
.toggle-row, .range-row { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; color: #b6bac6; font-size: .85rem; cursor: pointer; }
.toggle-row input { accent-color: var(--red); width: 18px; height: 18px; }
.range-row { justify-content: space-between; }
.range-row input { width: 52%; accent-color: var(--red); }
.primary-button, .secondary-button {
  min-height: 48px; padding: 0 18px; border: 1px solid var(--red); font-size: .7rem;
  font-weight: 900; letter-spacing: .13em; cursor: pointer; transition: background-color .2s, border-color .2s;
}
.primary-button { color: #fff; background: var(--red); }
.primary-button:hover { background: #f04b63; border-color: #f04b63; }
.secondary-button { color: var(--text); border-color: #454554; background: transparent; }
.secondary-button:hover { border-color: var(--cyan); }
.share-card { display: block; width: 100%; height: auto; margin: 20px 0 0; border: 1px solid #3a3a48; image-rendering: pixelated; }
.result-inner pre { margin: 16px 0 24px; padding: 18px; overflow: auto; color: #d5d8e1; border: 1px solid #343441; background: #09090e; font: .72rem/1.65 "SFMono-Regular", Consolas, monospace; white-space: pre-wrap; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast {
  position: fixed; z-index: 20; left: 50%; bottom: max(22px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); padding: 10px 14px; color: var(--text); border: 1px solid #454554;
  background: #171722; font-size: .7rem; opacity: 0; pointer-events: none; transition: opacity 180ms, transform 180ms;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
@media (max-height: 720px) {
  .shell { padding-top: 12px; }
  .masthead { padding-bottom: 10px; }
  h1 { font-size: 1.9rem; }
  .board-wrap { min-height: 340px; margin-top: 10px; }
}
