[hidden] { display: none !important; }

:root {
  --font-sans: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, "Cascadia Code", "Fira Code", Menlo, Consolas, monospace;
  --container: 1120px;
  --radius: 12px;
  --header-h: 60px;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --step-0: clamp(0.98rem, 0.95rem + 0.15vw, 1.06rem);
  --step-1: clamp(1.12rem, 1.05rem + 0.35vw, 1.3rem);
  --step-2: clamp(1.35rem, 1.2rem + 0.7vw, 1.75rem);
  --step-3: clamp(1.6rem, 1.35rem + 1.2vw, 2.3rem);
  --color-ink: #101f29;
  --color-navy: #142530;
  --color-dark-text: #f5f7f8;
  --accent-warm: #f5c518;
  color-scheme: dark;
  --bg: #0d1921;
  --bg-alt: #142530;
  --bg-elev: #142530;
  --bg-elev-2: #1a303e;
  --line: #263945;
  --line-strong: #324550;
  --text: #f5f7f8;
  --text-muted: #a5b1ba;
  --text-dim: #85939d;
  --accent: #79a7d0;
  --accent-hover: #a0c5e3;
  --accent-soft: rgba(121, 167, 208, 0.14);
  --accent-line: rgba(121, 167, 208, 0.4);
  --accent-ink: #0d1921;
  --danger: #e07a7a;
  --n1: #79a7d0;
  --n2: #6fbf98;
  --n3: #e07a7a;
  --n4: #c9a0ff;
  --n5: #e0a53c;
  --n6: #7ec8c3;
  --n7: #f5f7f8;
  --n8: #a5b1ba;
  --tile-2: #1a303e;
  --tile-2-ink: #f5f7f8;
  --tile-4: #243b4a;
  --tile-4-ink: #f5f7f8;
  --tile-8: #315c86;
  --tile-8-ink: #f5f7f8;
  --tile-16: #426f9b;
  --tile-16-ink: #ffffff;
  --tile-32: #79a7d0;
  --tile-32-ink: #0d1921;
  --tile-64: #c9a227;
  --tile-64-ink: #101f29;
  --tile-128: #f5c518;
  --tile-128-ink: #101f29;
  --tile-256: #f8d56a;
  --tile-256-ink: #101f29;
  --tile-512: #f5c518;
  --tile-512-ink: #101f29;
  --tile-1024: #e0a53c;
  --tile-1024-ink: #101f29;
  --tile-2048: #f5c518;
  --tile-2048-ink: #101f29;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fafaf9;
  --bg-alt: #f1f2f2;
  --bg-elev: #ffffff;
  --bg-elev-2: #f1f2f2;
  --line: #e8ecee;
  --line-strong: #d8dee2;
  --text: #101f29;
  --text-muted: #637381;
  --text-dim: #89959e;
  --accent: #426f9b;
  --accent-hover: #315c86;
  --accent-soft: rgba(66, 111, 155, 0.12);
  --accent-line: rgba(66, 111, 155, 0.4);
  --accent-ink: #ffffff;
  --danger: #b44545;
  --n1: #315c86;
  --n2: #2f7d57;
  --n3: #b44545;
  --n4: #6d4e99;
  --n5: #9a6b12;
  --n6: #2f7a76;
  --n7: #101f29;
  --n8: #637381;
  --tile-2: #ffffff;
  --tile-2-ink: #101f29;
  --tile-4: #e7eef3;
  --tile-4-ink: #101f29;
  --tile-8: #426f9b;
  --tile-8-ink: #ffffff;
  --tile-16: #315c86;
  --tile-16-ink: #ffffff;
  --tile-32: #1a303e;
  --tile-32-ink: #f5f7f8;
  --tile-64: #c9a227;
  --tile-64-ink: #101f29;
  --tile-128: #f5c518;
  --tile-128-ink: #101f29;
  --tile-256: #e0a53c;
  --tile-256-ink: #101f29;
  --tile-512: #f5c518;
  --tile-512-ink: #101f29;
  --tile-1024: #c9a227;
  --tile-1024-ink: #101f29;
  --tile-2048: #f5c518;
  --tile-2048-ink: #101f29;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--step-0);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; }
a { color: var(--text); text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
::selection { background: var(--accent-warm); color: var(--color-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.container { width: min(100% - 2.5rem, var(--container)); margin-inline: auto; }
main { flex: 1; }
.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;
}
.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 999;
  background: var(--accent); color: var(--accent-ink);
  padding: 0.55rem 0.95rem; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }

.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.site-header.scrolled { border-bottom-color: var(--line); }
.header-inner { height: var(--header-h); display: flex; align-items: center; gap: 1.25rem; }
.brand { display: inline-flex; align-items: center; gap: 0.6rem; margin-right: auto; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-name { font-weight: 550; letter-spacing: -0.015em; }
.brand-sub { color: var(--accent); font-weight: 550; }
.site-nav { display: flex; gap: 0.2rem; }
.site-nav a {
  padding: 0.42rem 0.75rem; border-radius: 8px; font-size: 0.9rem; color: var(--text-muted);
}
.site-nav a:hover { color: var(--text); background: var(--bg-elev); }
.site-nav a[aria-current="page"] { color: var(--text); }
.theme-toggle {
  display: grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--line-strong); border-radius: 10px;
  background: var(--bg-elev); color: var(--text-muted);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.7; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }

.hero { padding: clamp(2.4rem, 7vw, 4.5rem) 0 1.4rem; }
.hero h1 { font-size: var(--step-3); margin: 0.35rem 0 0.8rem; }
.lede { font-size: var(--step-1); color: var(--text-muted); max-width: 62ch; }
.eyebrow {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent); display: inline-flex; align-items: center; gap: 0.6rem;
}
.eyebrow::before { content: ""; width: 22px; height: 1px; background: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1.1rem; }
.library { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; padding-bottom: 2rem; }
.card {
  display: flex; flex-direction: column; gap: 0.55rem;
  padding: 0.85rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-elev);
  transition: border-color var(--transition), transform var(--transition);
}
.card:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.card h2 { font-size: 1.2rem; }
.card:hover h2 { color: var(--accent); }
.card p { color: var(--text-muted); font-size: 0.92rem; }
.preview {
  display: block; height: 88px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line); overflow: hidden;
}
.preview svg { width: 100%; height: 100%; }
.card-kicker {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--accent);
}
.card-best { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-dim); margin-top: auto; }
.noscript { margin: 0 0 1rem; color: var(--text-muted); }

.site-footer {
  border-top: 1px solid var(--line); padding: 1.6rem 0; margin-top: auto;
  color: var(--text-dim); font-size: 0.84rem;
}
.footer-inner { display: flex; flex-wrap: wrap; gap: 0.6rem 1.5rem; align-items: center; justify-content: space-between; }
.footer-links { display: flex; gap: 1rem; }
.footer-links a:hover { color: var(--accent); }

.play { width: min(100% - 2.5rem, 880px); margin: 1.4rem auto 2.5rem; }
.play h1 { font-size: var(--step-2); margin-top: 0.35rem; }
.play-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 0.9rem 1.4rem; margin-bottom: 1rem;
}
.play-meta { display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; align-items: center; }
.stats { display: flex; flex-wrap: wrap; gap: 0.85rem 1.1rem; font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-dim); }
.stats strong { color: var(--text); font-weight: 600; margin-left: 0.3rem; }
.stats .is-best { color: var(--accent-warm); }
.actions, .seg { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.btn {
  border: 1px solid var(--line-strong); background: var(--bg-elev); color: var(--text);
  border-radius: 8px; padding: 0.42rem 0.75rem; line-height: 1.2;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn[aria-pressed="true"] { border-color: var(--accent-line); color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.help { margin: 0.85rem 0 0; text-align: center; color: var(--text-dim); font-size: 0.85rem; }
.miss { margin-top: 3rem; }
.miss h1 { font-size: var(--step-3); margin-bottom: 0.8rem; }
.miss a { color: var(--accent); }

.stage, .board-frame { position: relative; margin-inline: auto; }
.board-frame.fit { width: fit-content; max-width: 100%; }
.fuse-frame { width: min(100%, 420px); }
.fuse-frame .fuse-board { width: 100%; margin: 0; }
.mines-frame { width: 100%; }
.mines-frame .scroll { display: flex; justify-content: center; }
.stage.square { width: min(100%, 560px); aspect-ratio: 1; }
.stage.wide { width: min(100%, 720px); aspect-ratio: 16 / 10; }
.stage.freeze, .fuse-board, .dpad { touch-action: none; user-select: none; overscroll-behavior: contain; }
.stage canvas {
  width: 100%; height: 100%; display: block;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px;
}
.stage.hit canvas, .board-frame.hit { box-shadow: inset 0 0 0 2px var(--danger); }
.overlay {
  position: absolute; inset: 0; z-index: 2;
  display: grid; align-content: center; justify-items: center; gap: 0.65rem;
  padding: 1rem; text-align: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-radius: 12px;
}
.overlay-title { font-size: var(--step-2); font-weight: 650; }
.overlay-text { color: var(--text-muted); max-width: 36ch; }
.scroll { overflow-x: auto; }

.dpad {
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-areas: ". u ." "l d r";
  gap: 0.4rem; justify-content: center; margin-top: 0.85rem;
}
.dpad [data-dir="up"] { grid-area: u; }
.dpad [data-dir="left"] { grid-area: l; }
.dpad [data-dir="down"] { grid-area: d; }
.dpad [data-dir="right"] { grid-area: r; }
.dpad button { height: 48px; font-size: 1.05rem; }
@media (pointer: coarse), (max-width: 760px) { .dpad { display: grid; } }

.minefield {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  gap: 2px; width: max-content; margin-inline: auto;
}
.cell {
  width: var(--cell); height: var(--cell); padding: 0;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--bg-elev-2); color: var(--text);
  font-family: var(--font-mono); font-weight: 650; font-size: 0.85rem;
  display: grid; place-items: center;
}
.cell.open { background: var(--bg); }
.cell.boom { background: color-mix(in srgb, var(--danger) 35%, var(--bg)); }
.cell[data-n="1"] { color: var(--n1); }
.cell[data-n="2"] { color: var(--n2); }
.cell[data-n="3"] { color: var(--n3); }
.cell[data-n="4"] { color: var(--n4); }
.cell[data-n="5"] { color: var(--n5); }
.cell[data-n="6"] { color: var(--n6); }
.cell[data-n="7"] { color: var(--n7); }
.cell[data-n="8"] { color: var(--n8); }
.flag {
  width: 0; height: 0;
  border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  border-left: 9px solid var(--accent-warm);
}
.mine-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); }
.cell.boom .mine-dot { background: var(--accent-warm); }
.cross { color: var(--danger); font-size: 0.9rem; line-height: 1; }

.pairs {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 8px;
  width: min(100%, 460px); margin-inline: auto;
}
.pair-card {
  aspect-ratio: 3 / 4; padding: 0; border: 0; background: transparent; perspective: 700px;
}
.pair-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform 240ms ease;
}
.pair-card.up .pair-inner, .pair-card.matched .pair-inner { transform: rotateY(180deg); }
.pair-card.matched { opacity: 0.55; }
.pair-face {
  position: absolute; inset: 0; display: grid; place-items: center;
  backface-visibility: hidden; border-radius: 8px; border: 1px solid var(--line);
}
.pair-back { background: var(--color-navy); }
.pair-front { background: var(--bg-elev); transform: rotateY(180deg); }
.pair-front svg { width: 54%; height: 54%; }
.pair-back svg { width: 42%; height: 42%; }

.lights {
  display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 8px;
  width: min(100%, 420px); margin-inline: auto;
}
.lights button {
  aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-elev-2);
}
.lights button.on { background: var(--accent-warm); border-color: var(--accent-warm); }

.fuse-board {
  position: relative; width: min(100%, 420px); aspect-ratio: 1; margin-inline: auto;
  background: var(--bg-alt); border: 1px solid var(--line); border-radius: 12px;
}
.fuse-board.shake { animation: shake 140ms linear; }
.tile {
  position: absolute; display: grid; place-items: center; border-radius: 8px;
  font-weight: 650; letter-spacing: -0.03em;
  font-size: clamp(1.05rem, 4.2vw, 1.7rem);
  background: var(--tile-2); color: var(--tile-2-ink);
  transform: translate(var(--x), var(--y));
  transition: transform 120ms ease;
}
.tile.dense { font-size: clamp(0.8rem, 3vw, 1.15rem); }
.tile.pop { animation: pop 140ms ease; }
.tile[data-v="2"] { background: var(--tile-2); color: var(--tile-2-ink); }
.tile[data-v="4"] { background: var(--tile-4); color: var(--tile-4-ink); }
.tile[data-v="8"] { background: var(--tile-8); color: var(--tile-8-ink); }
.tile[data-v="16"] { background: var(--tile-16); color: var(--tile-16-ink); }
.tile[data-v="32"] { background: var(--tile-32); color: var(--tile-32-ink); }
.tile[data-v="64"] { background: var(--tile-64); color: var(--tile-64-ink); }
.tile[data-v="128"] { background: var(--tile-128); color: var(--tile-128-ink); }
.tile[data-v="256"] { background: var(--tile-256); color: var(--tile-256-ink); }
.tile[data-v="512"] { background: var(--tile-512); color: var(--tile-512-ink); }
.tile[data-v="1024"] { background: var(--tile-1024); color: var(--tile-1024-ink); }
.tile[data-v="2048"], .tile.hi { background: var(--tile-2048); color: var(--tile-2048-ink); }

.sudoku {
  display: grid; grid-template-columns: repeat(9, 1fr);
  width: min(100%, 480px); aspect-ratio: 1; margin-inline: auto;
  border: 2px solid var(--line-strong); background: var(--bg-elev);
}
.sudoku button {
  border: 1px solid var(--line); background: transparent; padding: 0;
  font-family: var(--font-mono); font-size: clamp(0.85rem, 2.6vw, 1.15rem); font-weight: 550;
  display: grid; place-items: center; position: relative;
}
.sudoku button.box-r { border-right-width: 2px; border-right-color: var(--line-strong); }
.sudoku button.box-b { border-bottom-width: 2px; border-bottom-color: var(--line-strong); }
.sudoku button.given { font-weight: 700; }
.sudoku button.peer { background: var(--accent-soft); }
.sudoku button.same { background: color-mix(in srgb, var(--accent) 24%, var(--bg-elev)); }
.sudoku button.selected { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.sudoku button.conflict { color: var(--danger); }
.sudoku button.entered { color: var(--accent); }
.notes {
  display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%;
  font-size: clamp(0.45rem, 1.5vw, 0.62rem); color: var(--text-muted); font-weight: 500;
}
.notes span { display: grid; place-items: center; }
.numpad {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 0.35rem;
  width: min(100%, 480px); margin: 0.8rem auto 0;
}
.numpad .btn { aspect-ratio: 1; padding: 0; }
.pad-tools { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-top: 0.55rem; }

@keyframes pop { from { scale: 0.62; } to { scale: 1; } }
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card, .pair-inner, .tile { transition: none; }
  .tile.pop, .fuse-board.shake { animation: none; }
}
@media (max-width: 640px) {
  .header-inner { gap: 0.6rem; }
  .site-nav a { padding: 0.42rem 0.55rem; }
  .numpad { grid-template-columns: repeat(5, 1fr); }
}
