/* Minesweeper — matches the games hub palette. Dark by default, light via prefers-color-scheme. */

:root {
  color-scheme: dark;
  --font-display: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  --bg: #0d0d10;
  --surface: #17171c;
  --surface-2: #222229;
  --text: #f5f5f7;
  --muted: #a1a1aa;
  --line: #2a2a31;
  --accent: #2fbf71;
  --warn: #ffd23f;
  --danger: #ff5d5d;
  --focus: #ffd23f;

  --tile: #34343d;
  --tile-hi: #44444f;
  --tile-edge: #24242b;
  --open: #18181d;
  --open-line: #26262d;

  --n1: #5aa9ff;
  --n2: #2fbf71;
  --n3: #ff6b6b;
  --n4: #b18cff;
  --n5: #ffa94d;
  --n6: #3dd6d0;
  --n7: #f5f5f7;
  --n8: #a1a1aa;

  --cell: 34px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6f3;
    --surface: #ffffff;
    --surface-2: #ececea;
    --text: #141416;
    --muted: #55555e;
    --line: #dcdcd6;
    --focus: #141416;
    --tile: #cfcfc8;
    --tile-hi: #deded8;
    --tile-edge: #b4b4ac;
    --open: #fbfbf9;
    --open-line: #e3e3dd;
    --n1: #1f6fd1;
    --n2: #1d8a50;
    --n3: #d63c3c;
    --n4: #6b46c1;
    --n5: #b8620e;
    --n6: #0f8b86;
    --n7: #141416;
    --n8: #6b6b74;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(60rem 30rem at 15% -10%, rgba(255, 93, 93, 0.12), transparent 60%),
    radial-gradient(50rem 28rem at 110% 0%, rgba(90, 169, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.topbar {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
}
.back {
  justify-self: start;
  display: inline-flex; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 6px 8px 6px 2px; border-radius: 10px;
}
.back:hover { color: var(--text); }
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -0.03em;
  margin: 0;
}

.levels {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.levels button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; border-radius: 999px;
  font-weight: 700; font-size: 0.92rem; color: var(--muted);
}
.levels button:hover { color: var(--text); }
.levels button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  width: min(100%, 360px);
}
.stat {
  display: inline-flex; align-items: center; gap: 8px;
  min-width: 92px;
  padding: 8px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  font: 800 1.15rem var(--font-display);
  font-variant-numeric: tabular-nums;
}
.stat:last-child { justify-content: flex-end; }
.stat svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.reset {
  width: 52px; height: 52px; border-radius: 16px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 1.6rem; line-height: 1;
  display: grid; place-items: center;
  transition: transform 120ms ease;
}
.reset:hover { border-color: var(--muted); }
.reset:active { transform: scale(0.94); }

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: safe center;
  overflow-x: auto;
  padding: 4px 0;
}
.board {
  display: grid;
  gap: var(--gap, 3px);
  padding: var(--board-pad, 8px);
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.cell {
  width: var(--cell); height: var(--cell);
  padding: 0; border: 0; margin: 0;
  border-radius: calc(var(--cell) * 0.2);
  display: grid; place-items: center;
  font: 800 calc(var(--cell) * 0.56) / 1 var(--font-display);
  cursor: pointer;
  background: var(--tile);
  box-shadow: inset 0 -3px 0 var(--tile-edge);
  -webkit-tap-highlight-color: transparent;
}
.cell:hover { background: var(--tile-hi); }
.cell.open {
  background: var(--open);
  box-shadow: inset 0 0 0 1px var(--open-line);
  cursor: default;
}
.cell.open.num { cursor: pointer; }
.cell svg { width: 62%; height: 62%; }
.cell.flag svg path { fill: var(--danger); }
.cell.flag svg line { stroke: var(--text); }
.cell.hit { background: var(--danger); box-shadow: none; }
.cell.wrong { background: var(--surface-2); }
.cell.wrong svg { opacity: 0.45; }
.cell.wrong::after { content: ''; }
.cell.mine svg circle, .cell.mine svg path { fill: var(--text); stroke: var(--text); }
.cell.hit svg circle, .cell.hit svg path { fill: #160606; stroke: #160606; }

.n1 { color: var(--n1); } .n2 { color: var(--n2); } .n3 { color: var(--n3); } .n4 { color: var(--n4); }
.n5 { color: var(--n5); } .n6 { color: var(--n6); } .n7 { color: var(--n7); } .n8 { color: var(--n8); }

.board.done .cell:not(.open) { cursor: default; }
.board.won .cell.flag { background: color-mix(in srgb, var(--accent) 30%, var(--tile)); }

.controls {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 420px; text-align: center;
}
.mode {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  font-weight: 700;
}
.mode[aria-pressed="true"] { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 16%, var(--surface)); }
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }

.status {
  margin: 0; min-height: 1.6em;
  font: 800 1.25rem var(--font-display); letter-spacing: -0.01em;
}
.status.win { color: var(--accent); }
.status.lose { color: var(--danger); }
.best { margin: -10px 0 0; color: var(--muted); font-size: 0.9rem; min-height: 1.4em; }

@media (hover: none) { .cell:hover { background: var(--tile); } .cell.open:hover { background: var(--open); } }
@media (prefers-reduced-motion: reduce) { .reset { transition: none; } }
