:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --cell: #e6e2db;
  --cell-hover: #dcd7ce;
  --revealed: #faf9f7;
  --text: #2d2a26;
  --muted: #8f8a81;
  --text-muted: #68635d;
  --accent: #f5a9ae;
  --accent-ink: #d9545e;
  --accent-soft: #fbe1e3;
  --mine: #2d2a26;
  /* Radius tiers: sm = cells, chips, inner segments; md = buttons, controls, board; lg = panels, modal */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --cell-size: 32px;
  --corner: var(--radius-sm);
  --gap: 2px;
  --danger: #e5484d;
  --gold: #e8b931;
  --line: color-mix(in srgb, var(--muted) 60%, transparent);
  --n1: #6a9fd8; --n2: #6fb58a; --n3: #e8836b; --n4: #9b7fd1;
  --n5: #d4a24c; --n6: #4fb3b3; --n7: #2d2a26; --n8: #9a948b;
  --overlay: rgba(45, 42, 38, 0.3);
  /* The one drop shadow used everywhere: small and subtle */
  --shadow-sm: 0 1px 3px rgba(45, 42, 38, 0.10);
}

/* ---------- Dark theme base ---------- */
:root[data-theme="dark"] {
  --overlay: rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --n1: #7fb4ee; --n2: #84cc9c; --n3: #f09a84; --n4: #b59cf0;
  --n5: #e6bb66; --n6: #6cc9c9; --n7: #ededed; --n8: #8c857d;
  color-scheme: dark;
}

/* ---------- Palettes: light ---------- */
:root[data-theme="light"][data-palette="sage"] {
  --bg: #eef2ec; --cell: #dde5d8; --cell-hover: #cfdac8; --revealed: #f7f9f5;
  --text: #26302a; --muted: #808d82; --text-muted: #5a665e; --accent: #b4d6bc; --accent-soft: #e4f0e6; --accent-ink: #678f72; --mine: #26302a;
}
:root[data-theme="light"][data-palette="lavender"] {
  --bg: #f1eff6; --cell: #e2deec; --cell-hover: #d6d0e4; --revealed: #f9f8fc;
  --text: #2b2836; --muted: #8b869a; --text-muted: #646071; --accent: #cbbff2; --accent-soft: #eee9fb; --accent-ink: #8b78ca; --mine: #2b2836;
}
:root[data-theme="light"][data-palette="ocean"] {
  --bg: #edf2f6; --cell: #dbe4ec; --cell-hover: #ccd8e3; --revealed: #f7fafc;
  --text: #23303a; --muted: #7d8c99; --text-muted: #576571; --accent: #abd0ee; --accent-soft: #e2eef8; --accent-ink: #4d8bbb; --mine: #23303a;
}
:root[data-theme="light"][data-palette="mono"] {
  --bg: #f2f2f2; --cell: #e3e3e3; --cell-hover: #d6d6d6; --revealed: #fafafa;
  --text: #1f1f1f; --muted: #8a8a8a; --text-muted: #646464; --accent: #cdcdcd; --accent-soft: #e8e8e8; --accent-ink: #3a3a3a; --mine: #1f1f1f;
}

/* ---------- Palettes: dark ---------- */
:root[data-theme="dark"] {
  --bg: #1c1a19; --surface: #262321; --cell: #34302d; --cell-hover: #403b37; --revealed: #1f1d1b;
  --text: #f0ebe5; --muted: #8c857d; --text-muted: #a09991; --accent: #ff3d55; --accent-soft: #3d1419; --accent-ink: #ff3d55; --mine: #f0ebe5;
}
:root[data-theme="dark"][data-palette="sage"] {
  --bg: #161b18; --surface: #1f2621; --cell: #2b342e; --cell-hover: #35403a; --revealed: #1a201c;
  --text: #e6efe8; --muted: #82917f; --text-muted: #919f8f; --accent: #3dff9a; --accent-soft: #12331f; --accent-ink: #3dff9a; --mine: #e6efe8;
}
:root[data-theme="dark"][data-palette="lavender"] {
  --bg: #19171f; --surface: #221f2b; --cell: #2f2b3b; --cell-hover: #3a3549; --revealed: #1c1a23;
  --text: #ece8f5; --muted: #8c869c; --text-muted: #9893a8; --accent: #b67dff; --accent-soft: #2b1c47; --accent-ink: #b67dff; --mine: #ece8f5;
}
:root[data-theme="dark"][data-palette="ocean"] {
  --bg: #141a20; --surface: #1c242c; --cell: #27323d; --cell-hover: #313e4b; --revealed: #171e25;
  --text: #e4edf4; --muted: #7f8f9c; --text-muted: #8d9ca8; --accent: #26d6ff; --accent-soft: #0e3242; --accent-ink: #26d6ff; --mine: #e4edf4;
}
:root[data-theme="dark"][data-palette="mono"] {
  --bg: #141414; --surface: #1e1e1e; --cell: #2c2c2c; --cell-hover: #373737; --revealed: #181818;
  --text: #ededed; --muted: #858585; --text-muted: #949494; --accent: #ffffff; --accent-soft: #363636; --accent-ink: #ffffff; --mine: #ededed;
}

body, .board, .panel, .stats, .cell, .modal-card { transition: background-color 0.3s ease, color 0.3s ease; }

.icon {
  width: 1em; height: 1em; fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}
/* Solid parts of filled symbols (trophy, flag, moon) */
.icon .f { fill: currentColor; stroke: none; }
/* Filled shapes with soft (rounded) points, e.g. the moon's tips */
.icon .f.soft { stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
/* Gap cut around a slash (flag.slash) in the colour of the tile behind it */
.icon .knock { stroke: var(--revealed); stroke-width: 4.5; }
.icon-mine { fill: currentColor; stroke: none; }

/* PP Fraktion Mono is a licensed font: drop its files into fonts/ and they load automatically.
   Until then the page falls back to JetBrains Mono. */
@font-face {
  font-family: "PP Fraktion Mono";
  src: local("PP Fraktion Mono"), url("fonts/PPFraktionMono-Regular.woff2") format("woff2");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: "PP Fraktion Mono";
  src: local("PP Fraktion Mono Bold"), url("fonts/PPFraktionMono-Bold.woff2") format("woff2");
  font-weight: 600 700; font-display: swap;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "PP Fraktion Mono", "JetBrains Mono", ui-monospace, monospace;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  padding: 32px 16px;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.cell:focus-visible { outline-offset: -2px; z-index: 2; }

/* ---------- Game area ---------- */
.app { display: flex; flex-direction: column; align-items: center; gap: 20px; min-width: 0; }

.topbar { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.logo { font-weight: 700; font-size: 28px; letter-spacing: -1px; }
.logo span { color: var(--accent-ink); }

.stats {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); padding: 8px 12px;
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
}
.stat { display: flex; align-items: center; gap: 6px; min-width: 64px; justify-content: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-icon { color: var(--text-muted); font-size: 16px; }
.stat.timer { min-width: 108px; justify-content: flex-start; }
.reset {
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent-ink); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
/* Arrow buttons: only the arrow spins, in the direction it points (counter-clockwise) */
.reset .icon, .btn.icon-only .icon { transition: transform 0.4s ease; }

.settings { display: flex; flex-direction: column; gap: var(--panel-gap); }
.settings-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.theme-toggle { display: grid; grid-template-columns: 1fr 1fr; background: var(--cell); padding: 4px; border-radius: var(--radius-md); }
.theme-opt {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 0; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500; color: var(--text-muted);
}
.theme-opt.active { background: var(--surface); color: var(--text); }
.swatches { display: flex; justify-content: space-between; }
.swatch {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.3);
  transition: transform 0.15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch .icon { width: 62%; height: 62%; }
.swatch.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-ink); }
.reset:hover .icon, .btn.icon-only:hover .icon { transform: rotate(-360deg); }

.difficulty { display: flex; background: var(--cell); padding: 4px; border-radius: var(--radius-md); }
.diff { padding: 6px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; color: var(--text-muted); transition: all 0.2s; }
.diff.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.board-wrap { max-width: 100%; overflow-x: auto; padding: 4px; }
.board {
  display: grid; gap: 0;
  /* Opened cells use the page colour, so the board has no visible edge, frame or shadow */
  --revealed: var(--bg);
  background: var(--revealed); padding: 0; overflow: hidden;
  border-radius: var(--corner);
  user-select: none; -webkit-user-select: none;
  width: max-content; margin: 0 auto;
}
.board.shake { animation: shake 0.4s; }

/* Cell shape comes from classes set in app.js (shapeCells):
   r-*  round that outer corner, g-*  inset that side to leave a gap, line-*  draw a grid segment.
   Every cell's base is the opened colour; unopened and flagged tiles are drawn on top (::before),
   so gaps and rounded corners always reveal the opened colour and inner corners curve cleanly. */
.cell {
  --it: 0px; --ir: 0px; --ib: 0px; --il: 0px;
  --rtl: 0px; --rtr: 0px; --rbr: 0px; --rbl: 0px;
  --ntl: -1px; --ntr: -1px; --nbr: -1px; --nbl: -1px;
  --lr: transparent; --lb: transparent;
  --tile: var(--accent);
  --line-gap: calc(var(--cell-size) * 0.18);
  width: var(--cell-size); height: var(--cell-size);
  background: var(--revealed);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: calc(var(--cell-size) * 0.42);
  color: var(--text);
  position: relative;
}
.cell.r-tl { --rtl: var(--corner); }
.cell.r-tr { --rtr: var(--corner); }
.cell.r-br { --rbr: var(--corner); }
.cell.r-bl { --rbl: var(--corner); }
.cell.g-t { --it: var(--gap); }
.cell.g-r { --ir: var(--gap); }
.cell.g-b { --ib: var(--gap); }
.cell.g-l { --il: var(--gap); }
.cell.n-tl { --ntl: var(--gap); }
.cell.n-tr { --ntr: var(--gap); }
.cell.n-br { --nbr: var(--gap); }
.cell.n-bl { --nbl: var(--gap); }

/* Unopened / flagged tile */
.cell::before {
  content: ""; position: absolute; pointer-events: none;
  top: var(--it); right: var(--ir); bottom: var(--ib); left: var(--il);
  border-radius: var(--rtl) var(--rtr) var(--rbr) var(--rbl);
  background:
    linear-gradient(var(--lr), var(--lr)) right center / 1px calc(100% - 2 * var(--line-gap)) no-repeat,
    linear-gradient(var(--lb), var(--lb)) center bottom / calc(100% - 2 * var(--line-gap)) 1px no-repeat,
    var(--tile);
  -webkit-mask:
    radial-gradient(circle at 0 0, transparent var(--ntl), #000 calc(var(--ntl) + 0.5px)),
    radial-gradient(circle at 100% 0, transparent var(--ntr), #000 calc(var(--ntr) + 0.5px)),
    radial-gradient(circle at 100% 100%, transparent var(--nbr), #000 calc(var(--nbr) + 0.5px)),
    radial-gradient(circle at 0 100%, transparent var(--nbl), #000 calc(var(--nbl) + 0.5px));
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(circle at 0 0, transparent var(--ntl), #000 calc(var(--ntl) + 0.5px)),
    radial-gradient(circle at 100% 0, transparent var(--ntr), #000 calc(var(--ntr) + 0.5px)),
    radial-gradient(circle at 100% 100%, transparent var(--nbr), #000 calc(var(--nbr) + 0.5px)),
    radial-gradient(circle at 0 100%, transparent var(--nbl), #000 calc(var(--nbl) + 0.5px));
  mask-composite: intersect;
  transition: top 0.25s, right 0.25s, bottom 0.25s, left 0.25s, border-radius 0.25s, filter 0.15s, opacity 0.8s;
}
/* New game: tiles grow in from small rounded squares in a diagonal wave */
.cell.enter::before { animation: grow 0.38s cubic-bezier(.3, 1.3, .5, 1) backwards; animation-delay: var(--enter-delay); }
/* Hover: a rounded square highlight on the single cell, whatever the region's shape */
.cell:not(.revealed):not(.flagged):not(.mine)::after {
  content: ""; position: absolute; inset: var(--gap); pointer-events: none;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 28%, transparent);
  opacity: 0; transition: opacity 0.15s;
}
.cell:not(.revealed):not(.flagged):not(.mine):hover::after { opacity: 1; }
.cell:not(.revealed):active { transform: scale(0.9); }

/* Opened: grid segments on the right and bottom edges, shortened so they never meet at a vertex.
   They fade in just after the tile above has shrunk away. */
.cell.revealed { --tile: transparent; cursor: default; }
.cell.revealed::before {
  inset: 0; border-radius: 0; -webkit-mask: none; mask: none;
  animation: fadeIn 0.4s ease-out backwards; animation-delay: calc(var(--reveal-delay, 0ms) + 220ms);
}

/* Reveal: a copy of the tile shrinks away as a rounded square */
.vanish {
  position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: var(--accent);
  animation: vanish 0.34s cubic-bezier(.55, 0, .7, .4) both;
}
.cell.line-r { --lr: var(--line); }
.cell.line-b { --lb: var(--line); }

/* Flag: separate rounded gray tile */
.cell.flagged { --tile: var(--muted); --line: color-mix(in srgb, var(--revealed) 30%, transparent); color: var(--surface); }
.cell.flagged::before { animation: flag 0.25s ease-out; }
.cell.flagged .icon { position: relative; width: 72%; height: 72%; stroke-width: 2; }
.cell.wrong-flag { --tile: transparent; color: var(--text-muted); }

/* Mine: pixel block on an opened-style tile */
.cell.mine { --tile: transparent; }
.cell.mine .icon {
  position: relative; width: 72%; height: 72%; color: var(--mine);
  animation: drop 0.3s ease-out backwards; animation-delay: calc(var(--reveal-delay, 0ms) + 120ms);
}
/* The mine that was hit blinks red: its icon cycles every 1.2s, well under the 3 flashes/s WCAG limit */
.cell.mine.exploded .icon { animation: mine-red 1.2s ease-in-out infinite; }

/* Win: numbers, grid lines and flag icons fade out, leaving the mine blocks */
.board.won .cell { color: transparent; transition: color 0.8s; }
.board.won .cell.revealed::before { opacity: 0; }
.board.won .cell .icon { opacity: 0; transition: opacity 0.8s; }
.board.won .cell.flagged { --lr: transparent; --lb: transparent; }

.hint { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 12px; }
.review-bar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 8px; font-size: 13px; color: var(--text-muted);
}
.review-bar .btn { padding: 8px 16px; }

/* Review: board is read-only */
.board.review .cell { cursor: default; }
.board.review .cell::after { display: none; }
/* Grid lines blink off and back on in a diagonal sweep; nothing moves */
.cell.cascade:is(.revealed, .mine)::before { animation: line-blink 1.4s ease-in-out backwards; animation-delay: var(--cascade-delay); }
/* Won: mines glint between their normal colour and gold, each out of phase */
.board.review-won .cell.mine .icon { animation: mine-gold 1.6s ease-in-out infinite; animation-delay: var(--glint-delay, 0s); }

@keyframes pop { 0% { transform: scale(0.7); } 70% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes flag { 0% { transform: scale(0.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes drop { 0% { transform: scale(1.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes vanish { 0% { transform: scale(1); border-radius: 0; } 100% { transform: scale(0); border-radius: 25%; } }
@keyframes grow { 0% { transform: scale(0); border-radius: 25%; } }
@keyframes line-blink { 50% { opacity: 0; } }
@keyframes mine-gold { 50% { color: var(--gold); } }
@keyframes mine-red { 50% { color: var(--danger); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { transform: translateY(20px) scale(0.95); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Panel ---------- */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(320px, 88vw); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  /* One spacing value between every block in the menu */
  --panel-gap: 16px;
  box-shadow: var(--shadow-sm); padding: 72px 20px 24px;
  display: flex; flex-direction: column; gap: var(--panel-gap);
  transform: translateX(105%); transition: transform 0.35s cubic-bezier(.2,.8,.2,1);
}
.panel.open { transform: none; }
.scrim {
  position: fixed; inset: 0; z-index: 25; background: var(--overlay);
  opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.scrim.open { opacity: 1; pointer-events: auto; }
.profile { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; aspect-ratio: 1; padding: 0;
  background: var(--accent-soft); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar .icon { width: 58%; height: 58%; }
.avatar .icon .hole { fill: var(--accent-soft); stroke: none; }
.avatar-option { cursor: pointer; transition: transform 0.15s; }
.avatar-option:hover { transform: scale(1.06); }

/* Guest profile picture choices */
.avatar-picker { display: flex; justify-content: space-between; gap: 8px; animation: fadeIn 0.2s; }
.avatar-option { width: 40px; height: 40px; background: var(--cell); color: var(--text-muted); }
.avatar-option.active { background: var(--accent-soft); color: var(--accent-ink); box-shadow: 0 0 0 2px var(--accent-ink); }
.avatar-option .icon .hole { fill: var(--cell); }
.avatar-option.active .icon .hole { fill: var(--accent-soft); }
.profile-info { display: flex; flex-direction: column; min-width: 0; }
.profile-info small { color: var(--text-muted); font-size: 12px; }

.auth { display: flex; flex-direction: column; gap: 8px; }
.auth-hint { font-size: 13px; line-height: 1.5; color: var(--text-muted); }
.auth .btn { display: flex; align-items: center; justify-content: flex-start; gap: 12px; text-align: left; }
.auth .icon { font-size: 18px; }
/* Play as Guest: a light tint of the palette colour, quiet like an unselected segment */
.btn.accent { background: var(--accent-soft); color: var(--text); }
.btn.accent:hover { background: var(--accent-soft); filter: brightness(1.08); }
/* Brand marks: flat, single-colour (text colour) */
.icon.brand { fill: currentColor; stroke: none; }
.btn {
  padding: 12px 16px; border-radius: var(--radius-md); font-size: 14px; font-weight: 500;
  background: var(--cell); transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: var(--cell-hover); }
.btn:active { transform: scale(0.97); }
.btn.ghost { background: transparent; border: 1px solid var(--cell); }
.btn.primary { background: var(--text); color: var(--surface); }
.btn.primary:hover { background: var(--text); filter: brightness(1.15); }

.panel-title { font-size: 16px; font-weight: 600; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--cell); padding: 4px; border-radius: var(--radius-md); }
.tab { padding: 6px 0; font-size: 12px; font-weight: 500; border-radius: var(--radius-sm); color: var(--text-muted); }
.tab.active { background: var(--surface); color: var(--text); }
.lb-diff { display: flex; gap: 6px; }
.chip { padding: 4px 12px; border-radius: var(--radius-sm); font-size: 12px; color: var(--text-muted); border: 1px solid var(--cell); }
.chip.active { background: var(--accent-soft); color: var(--text); border-color: transparent; }

.leaderboard { list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 340px; overflow-y: auto; }
.leaderboard li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm); font-size: 14px;
  animation: fadeIn 0.3s;
}
.leaderboard li:nth-child(odd) { background: var(--revealed); }
.leaderboard .rank { width: 22px; color: var(--text-muted); font-weight: 600; font-size: 12px; }
.leaderboard .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .time { font-weight: 600; font-variant-numeric: tabular-nums; }
.leaderboard .empty { color: var(--text-muted); justify-content: center; background: none !important; }

.panel-toggle {
  position: fixed; top: 20px; right: 20px; z-index: 35;
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); font-size: 22px; box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}
.panel-toggle:hover { transform: scale(1.06); }
.panel-toggle .icon path { transition: d 0.3s; }
.panel-toggle[aria-expanded="true"] .icon path { d: path("M6 6l12 12M12 12h0M6 18L18 6"); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: var(--overlay); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.25s;
}
.modal-card {
  background: var(--surface); border-radius: var(--radius-lg); padding: 32px 40px;
  text-align: center; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  animation: rise 0.35s ease-out; max-width: 90vw;
}
.modal-icon { font-size: 44px; color: var(--accent-ink); display: flex; }
.modal-card p { color: var(--text-muted); margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.btn.icon-only { display: inline-flex; align-items: center; justify-content: center; padding: 12px 20px; }
/* Icon sized to the label text it stands in for, so both buttons read the same height */
.btn.icon-only .icon { width: 1.15em; height: 1.15em; stroke-width: 2; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
}

/* Respect the OS "reduce motion" setting: drop decorative motion, keep state changes instant */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-delay: 0ms !important;
    transition-duration: 0.01ms !important; transition-delay: 0ms !important;
  }
}

/* ---------- Home screen ---------- */
body.on-home .app { display: none; }
body:not(.on-home) .home { display: none; }

.home {
  width: 100%; max-width: 360px; flex: 1 0 auto;
  /* One spacing value between every item from the difficulty picker down */
  --home-gap: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--home-gap);
  text-align: center;
}
.home-mine {
  width: 152px; height: 152px; color: var(--accent);
  margin-bottom: 32px; animation: home-mine-in 0.7s cubic-bezier(.2, .9, .3, 1.2) backwards;
  transition: transform 0.6s cubic-bezier(.2, .9, .3, 1);
}
.home-mine:hover { transform: rotate(45deg); }

.level-picker { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.level-step {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 20px; transition: color 0.15s, background 0.15s;
}
.level-step:hover:not(:disabled) { color: var(--text); background: var(--cell); }
.level-step:disabled { opacity: 0.3; cursor: default; }
.level-info { display: flex; flex-direction: column; gap: 4px; }
.level-name { font-size: 20px; font-weight: 600; }
.level-meta { font-size: 12px; color: var(--text-muted); }

.btn.outline {
  width: 100%; padding: 16px; font-size: 15px;
  background: transparent; border: 1px solid var(--muted); color: var(--text);
}
.btn.outline:hover { background: var(--cell); }

.home-auth { width: 100%; gap: var(--home-gap); }
.divider { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-muted); }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--cell); }
.home-user { font-size: 13px; color: var(--text-muted); margin-top: 8px; }

.logo-btn { font: inherit; letter-spacing: inherit; }
.logo-btn:hover { opacity: 0.8; }

/* New game: a copy of the big mine flies into the logo's period */
.mine-flight { position: fixed; z-index: 60; pointer-events: none; color: var(--accent); transform-origin: 50% 50%; }
.logo span.landing { animation: dot-land 0.35s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes dot-land { from { opacity: 0; transform: scale(2.2); } }
@keyframes home-mine-in { from { transform: scale(0.6) rotate(-90deg); opacity: 0; } }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 12px; text-align: center;
}
/* Studio wordmark in the main text colour, drawn via a mask */
.brand-logo {
  display: block; width: 104px; aspect-ratio: 810 / 245;
  background: var(--text);
  -webkit-mask: url("om-logo.svg") center / contain no-repeat;
  mask: url("om-logo.svg") center / contain no-repeat;
}

/* ---------- How to play ---------- */
/* Top-left, mirroring the menu button in the top-right */
.help-toggle {
  position: fixed; top: 20px; left: 20px; z-index: 35;
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--text); font-size: 22px; box-shadow: var(--shadow-sm);
  transition: transform 0.2s;
}
.help-toggle:hover { scale: 1.06; }
body:not(.on-home) .help-toggle { display: none; }

.help {
  position: fixed; inset: 0; z-index: 50; padding: 16px;
  background: var(--overlay); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.25s;
}
.help-card {
  position: relative; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-lg); padding: 32px 28px 28px;
  display: flex; flex-direction: column; gap: 24px;
  animation: rise 0.35s ease-out;
}
.help-close {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 18px;
}
.help-close:hover { background: var(--cell); color: var(--text); }
.help-title { font-size: 20px; font-weight: 600; }
.help-lead { color: var(--text-muted); font-size: 14px; line-height: 1.5; margin-top: -12px; text-wrap: pretty; }

/* Every demo is the same 4x4 size, so the text column lines up for all steps */
.help-step { --demo-cell: 28px; display: grid; grid-template-columns: calc(var(--demo-cell) * 4) 1fr; gap: 20px; align-items: start; }
.help-text h3 { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
/* Justified, with balanced line breaks so a paragraph never ends on a lone word */
.help-text p { font-size: 13px; line-height: 1.55; color: var(--text-muted); text-align: justify; text-align-last: left; text-wrap: pretty; hyphens: none; }
/* Key words: just the palette colour, no background */
.help-text mark { background: none; color: var(--accent-ink); }
.help-num {
  width: 20px; height: 20px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-ink); font-size: 11px; font-weight: 700;
}

/* Demo boards: the real tiles, smaller and not interactive */
.demo { justify-self: start; }
.demo-board { --cell-size: var(--demo-cell); pointer-events: none; box-shadow: none; margin: 0; }
.demo-board .cell.focus { outline: 2px solid var(--accent-ink); outline-offset: -3px; border-radius: var(--radius-sm); z-index: 1; }
.demo-board .cell.revealed::before, .demo-board .cell.mine .icon { animation: none; }
/* The tile being clicked in an animated demo */
.demo-board .cell.press { animation: demo-press 0.35s ease-in-out; }
@keyframes demo-press { 50% { transform: scale(0.82); } }

@media (max-width: 480px) {
  .help-step { grid-template-columns: 1fr; gap: 12px; }
}
