/* ==========================================================================
   Kropki v2 — design system
   Warm paper light theme, deep ink dark theme, indigo accent, amber for help.
   ========================================================================== */

:root {
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-rounded, "SF Pro Rounded", "Nunito", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --thick: 2.5px;
  --thin: 1px;
}

:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3efe8;
  --bg-deco: rgba(27, 32, 48, 0.07);
  --surface: #ffffff;
  --surface-2: #f6f3ee;
  --surface-3: #e9e4dc;
  --ink: #1b2030;
  --ink-2: #585e6d;
  --ink-3: #8b8f9a;
  --line: #e4ded4;

  --board-bg: #ffffff;
  --grid-thin: #e3ddd3;
  --grid-thick: #262c3c;

  --accent: #4655d8;
  --accent-ink: #ffffff;
  --accent-soft: #e7e9fc;
  --accent-text: #3241c4;

  --cell-peer: #f2f0f8;
  --cell-same: #dbe0fd;
  --cell-sel: #c3cbfa;
  --given: #1b2030;
  --user: #3241c4;

  --good: #128a5b;
  --good-soft: #dcf4e8;
  --bad: #d93a40;
  --bad-soft: #fde3e3;
  --amber: #d98a00;
  --amber-soft: #fff1d4;
  --amber-ink: #6b4300;

  --dot-white: #ffffff;
  --dot-white-ring: #1b2030;
  --dot-black: #1b2030;
  --dot-black-ring: #1b2030;

  --shadow-1: 0 1px 2px rgba(27, 32, 48, 0.06), 0 1px 1px rgba(27, 32, 48, 0.03);
  --shadow-2: 0 12px 32px -14px rgba(27, 32, 48, 0.35), 0 2px 6px rgba(27, 32, 48, 0.06);
  --shadow-3: 0 24px 60px -20px rgba(16, 18, 28, 0.45);
  --scrim: rgba(18, 20, 28, 0.42);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1016;
  --bg-deco: rgba(236, 238, 243, 0.05);
  --surface: #181b24;
  --surface-2: #1e222c;
  --surface-3: #2a2f3b;
  --ink: #eceef3;
  --ink-2: #a4a9b7;
  --ink-3: #707687;
  --line: #2a2e3a;

  --board-bg: #1a1d27;
  --grid-thin: #2c313e;
  --grid-thick: #8890a6;

  --accent: #8293ff;
  --accent-ink: #0e1016;
  --accent-soft: #252c52;
  --accent-text: #aab5ff;

  --cell-peer: #20243a;
  --cell-same: #2d3672;
  --cell-sel: #3a4699;
  --given: #eceef3;
  --user: #aab5ff;

  --good: #3dd68c;
  --good-soft: #123827;
  --bad: #ff6b70;
  --bad-soft: #3d1719;
  --amber: #ffb547;
  --amber-soft: #3a2a0d;
  --amber-ink: #ffd99a;

  --dot-white: #f4f2ec;
  --dot-white-ring: #0e1016;
  --dot-black: #000000;
  --dot-black-ring: #6d7488;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 14px 36px -14px rgba(0, 0, 0, 0.8);
  --shadow-3: 0 24px 60px -16px rgba(0, 0, 0, 0.85);
  --scrim: rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button {
  font: inherit;
  color: inherit;
}

h1, h2, h3, p {
  margin: 0;
}

svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

svg .fill {
  fill: currentColor;
  stroke: none;
}

[hidden] {
  display: none !important;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font: 650 15px/1.15 var(--font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s ease, background-color 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-sm {
  padding: 9px 14px;
  font-size: 14px;
  border-radius: 12px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 16px -8px var(--accent);
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-amber {
  background: var(--amber);
  color: #1b1200;
}

.btn-amber:hover {
  filter: brightness(1.05);
}

.btn-danger {
  background: var(--bad-soft);
  color: var(--bad);
}

.btn-danger:hover {
  filter: brightness(0.97);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.icon-btn-sm {
  width: 34px;
  height: 34px;
  border-radius: 10px;
}

.icon-btn-sm svg {
  width: 18px;
  height: 18px;
}

.link-btn {
  border: 0;
  background: none;
  color: var(--ink-2);
  font: 600 14px var(--font);
  cursor: pointer;
  padding: 8px 4px;
}

.link-btn:hover {
  color: var(--ink);
}

/* ==========================================================================
   Home
   ========================================================================== */

.home {
  display: flex;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  background-image: radial-gradient(circle at 1px 1px, var(--bg-deco) 1.2px, transparent 0);
  background-size: 22px 22px;
}

.home-inner {
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.45s var(--ease-out) both;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 50px;
  height: 50px;
  stroke: none;
}

.bm-cell {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1.2;
}

.bm-accent {
  fill: var(--accent);
  stroke: none;
}

.bm-white {
  fill: var(--dot-white);
  stroke: var(--ink);
  stroke-width: 1.8;
}

.bm-black {
  fill: var(--ink);
}

.brand-name {
  font: 800 30px/1 var(--font);
  letter-spacing: -0.03em;
}

.brand-sub {
  margin-top: 4px;
  color: var(--ink-2);
  font-size: 14px;
}

:root[data-theme="light"] .i-moon,
:root[data-theme="dark"] .i-sun {
  display: none;
}

.continue-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 18px;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--accent);
  color: var(--accent-ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-2), 0 10px 24px -14px var(--accent);
  transition: transform 0.15s var(--ease), filter 0.15s ease;
}

.continue-card:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.continue-card:active {
  transform: scale(0.985);
}

.continue-play {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.2);
  flex: none;
}

:root[data-theme="dark"] .continue-play {
  background: rgba(14, 16, 22, 0.16);
}

.continue-play svg {
  fill: currentColor;
  stroke: none;
  width: 22px;
  height: 22px;
  margin-left: 2px;
}

.continue-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.continue-label {
  font: 700 17px/1.2 var(--font);
}

.continue-meta {
  font-size: 13px;
  opacity: 0.85;
}

.continue-track {
  margin-top: 6px;
  height: 5px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
}

:root[data-theme="dark"] .continue-track {
  background: rgba(14, 16, 22, 0.2);
}

.continue-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: currentColor;
  transition: width 0.4s var(--ease);
}

.learn-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: var(--amber-soft);
  color: var(--amber-ink);
}

.learn-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--amber);
  color: #1b1200;
  flex: none;
}

.learn-icon svg {
  width: 22px;
  height: 22px;
}

.learn-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 13.5px;
  line-height: 1.35;
}

.learn-text strong {
  font-size: 15px;
}

.section-label {
  margin: 8px 4px 0;
  font: 700 12px/1 var(--font);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.level {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  transition: transform 0.15s var(--ease), box-shadow 0.15s ease;
}

.level:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2), inset 0 0 0 1.5px var(--lv);
}

.level:active {
  transform: scale(0.99);
}

.level-badge {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--lv-soft);
  display: grid;
  place-items: center;
}

.pips {
  display: inline-flex;
  gap: 3px;
  align-items: flex-end;
}

.pips i {
  width: 4px;
  border-radius: 2px;
  background: var(--lv, var(--accent));
  opacity: 0.25;
}

.pips i.on {
  opacity: 1;
}

.level-badge .pips i:nth-child(1) { height: 8px; }
.level-badge .pips i:nth-child(2) { height: 11px; }
.level-badge .pips i:nth-child(3) { height: 14px; }
.level-badge .pips i:nth-child(4) { height: 17px; }
.level-badge .pips i:nth-child(5) { height: 20px; }

.level-name {
  display: block;
  font: 700 16px/1.25 var(--font);
}

.level-desc {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink-2);
}

.level-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  color: var(--ink-3);
  font-size: 12px;
  white-space: nowrap;
}

.level-meta b {
  color: var(--ink-2);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.level-meta svg {
  width: 18px;
  height: 18px;
}

.home-nav {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.nav-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 13px 4px 11px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  font: 600 12.5px/1.2 var(--font);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--line);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-tile:hover {
  color: var(--ink);
  background: var(--surface-2);
}

.nav-tile svg {
  width: 22px;
  height: 22px;
}

/* ==========================================================================
   Game layout
   ========================================================================== */

/* Registered so the board can smoothly shrink while a hint is open */
@property --board {
  syntax: '<length>';
  inherits: true;
  initial-value: 0px;
}

.game {
  --board: min(calc(100vw - 28px), 600px, calc(100vh - 330px));
  --board: min(calc(100vw - 28px), 600px, calc(100dvh - 330px));
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  transition: --board 0.3s var(--ease-out);
}

/*
 * Phones: while a hint is open the board shrinks (by up to ~40% on short
 * screens) and the hint card below it gets room for the explanation
 */
@media not all and (orientation: landscape) and (min-width: 700px) {
  .game.hinting {
    --board: min(calc(100vw - 28px), 600px, calc(100dvh - 312px), max(calc((100vw - 28px) * 0.62), calc(100dvh - 440px)));
  }

  /* …while the card itself keeps the full width */
  .panel.hinting {
    width: min(calc(100vw - 28px), 600px);
  }

  .hint-card {
    gap: 6px;
    padding: 12px 14px;
  }

  .hint-title {
    font-size: 16px;
  }

  .hint-text {
    font-size: 13.5px;
  }

  .hint-foot .btn {
    padding: 10px 16px;
    font-size: 14.5px;
  }
}

.topbar {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(42px, 1fr) auto minmax(42px, 1fr);
  gap: 8px;
  align-items: center;
  padding: max(6px, env(safe-area-inset-top)) 10px 2px;
  flex: none;
}

.topbar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

/* Level pill: tap to change level / start a new game */
.level-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px 6px 12px;
  border: 0;
  border-radius: 99px;
  background: var(--surface);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 700 15px/1.2 var(--font);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease;
}

.level-btn:hover {
  background: var(--surface-2);
}

.level-btn:active {
  transform: scale(0.97);
}

.level-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.4;
  color: var(--ink-3);
}

.level-btn .pips i {
  height: 10px;
  width: 3px;
}

.topbar > :first-child {
  justify-self: start;
}

.topbar > :last-child {
  justify-self: end;
}

/* Labelled menu button: discoverable, unlike a bare "⋯" */
.menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 11px;
  border: 0;
  border-radius: 13px;
  background: var(--surface);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 650 14px/1 var(--font);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease;
}

.menu-btn:hover {
  background: var(--surface-2);
}

.menu-btn:active {
  transform: scale(0.97);
}

.menu-btn svg {
  width: 19px;
  height: 19px;
}

@media (max-width: 340px) {
  .tool {
    font-size: 10px;
    padding-left: 0;
    padding-right: 0;
  }

  .tool svg {
    width: 22px;
    height: 22px;
  }

  .menu-btn span {
    display: none;
  }

  .menu-btn {
    padding: 0 10px;
  }
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--ink-2);
  font: 600 13px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.timer:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.timer svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.6;
}

.timer.no-time #timer-text {
  display: none;
}

.timer.no-time {
  padding: 3px 8px;
}

.game-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 4px 14px 12px;
}

.board-col {
  width: var(--board);
  flex: none;
  margin-top: clamp(4px, 2.5vh, 28px);
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px;
  font-size: 13px;
  color: var(--ink-2);
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.stat-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.stat b {
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat b.warn {
  color: var(--bad);
}

.stat b.bump {
  animation: bump 0.4s var(--ease);
}

.panel {
  width: var(--board);
  flex: 1 1 auto; /* fills the space under the board; controls sit at the bottom, in thumb reach */
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
}

/* ==========================================================================
   Board
   ========================================================================== */

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  container-type: inline-size;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--thick);
  padding: var(--thick);
  background: var(--grid-thick);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  touch-action: manipulation;
}

.box {
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--thin);
  background: var(--grid-thin);
}

/* Corner boxes follow the board's rounding, inset by the frame width */
.box:nth-child(1) {
  border-top-left-radius: calc(var(--r-md) - var(--thick));
}

.box:nth-child(3) {
  border-top-right-radius: calc(var(--r-md) - var(--thick));
}

.box:nth-child(7) {
  border-bottom-left-radius: calc(var(--r-md) - var(--thick));
}

.box:nth-child(9) {
  border-bottom-right-radius: calc(var(--r-md) - var(--thick));
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--board-bg);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 0.12s ease;
}

/* Corner cells: same inner rounding, so selection / hint rings follow the corner */
.cell[data-r="0"][data-c="0"] {
  border-top-left-radius: calc(var(--r-md) - var(--thick));
}

.cell[data-r="0"][data-c="8"] {
  border-top-right-radius: calc(var(--r-md) - var(--thick));
}

.cell[data-r="8"][data-c="0"] {
  border-bottom-left-radius: calc(var(--r-md) - var(--thick));
}

.cell[data-r="8"][data-c="8"] {
  border-bottom-right-radius: calc(var(--r-md) - var(--thick));
}

.cell .v {
  font: 600 22px/1 var(--font-num);
  font-size: 6.3cqw;
  font-variant-numeric: tabular-nums;
}

.cell.given .v {
  color: var(--given);
  font-weight: 700;
}

.cell.user .v {
  color: var(--user);
}

.cell .notes {
  position: absolute;
  inset: 11%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.cell .notes span {
  display: grid;
  place-items: center;
  font: 650 9px/1 var(--font-num);
  font-size: 2.35cqw;
  color: var(--ink-2);
}

.cell .notes span.hl {
  color: var(--accent-text);
  font-weight: 800;
  background: var(--accent-soft);
  border-radius: 4px;
}

.cell.peer {
  background: var(--cell-peer);
}

.cell.same {
  background: var(--cell-same);
}

.cell.sel {
  background: var(--cell-sel);
}

.cell.sel::after,
.cell.hint-t::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

.cell.sel::after {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.hint-t {
  background: var(--amber-soft);
}

.cell.hint-t::after {
  box-shadow: inset 0 0 0 2.5px var(--amber);
  animation: glow 1.6s ease-in-out infinite;
}

.cell.hint-s::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1.5px dashed var(--amber);
  border-radius: 6px;
  pointer-events: none;
}

.cell.err {
  background: var(--bad-soft);
  animation: shake 0.34s ease;
}

.cell.err .v {
  color: var(--bad);
}

.cell.conflict {
  animation: conflict 1.6s ease;
}

.cell.pop .v {
  animation: pop 0.28s var(--ease-out);
}

.cell.wave {
  animation: wave 0.7s ease;
  animation-delay: var(--d, 0ms);
}

/* Dots layer: positioned in JS from the real cell geometry */
.dots {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.dot {
  position: absolute;
  width: 11px;
  height: 11px;
  width: clamp(9px, 2.75cqw, 16px);
  height: clamp(9px, 2.75cqw, 16px);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform 0.2s var(--ease), box-shadow 0.2s ease;
}

.dot.white {
  background: var(--dot-white);
  border: 1.7px solid var(--dot-white-ring);
}

.dot.black {
  background: var(--dot-black);
  border: 1.7px solid var(--dot-black-ring);
}

.dot.near {
  transform: translate(-50%, -50%) scale(1.3);
  box-shadow: 0 0 0 2.5px var(--accent);
}

/* Pause / generation cover */
.cover {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
  cursor: pointer;
  animation: fade 0.2s ease both;
}

.cover.busy {
  cursor: progress;
}

.cover-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 20px;
}

.cover-inner strong {
  font: 750 20px/1.2 var(--font);
}

.cover-inner span:last-child {
  color: var(--ink-2);
  font-size: 14px;
}

.cover-play {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  margin-bottom: 6px;
  box-shadow: 0 10px 24px -10px var(--accent);
}

.cover-play svg {
  fill: currentColor;
  stroke: none;
  width: 28px;
  height: 28px;
  margin-left: 3px;
}

.spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3.5px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  margin-bottom: 6px;
}

/* ==========================================================================
   Context strip (explains the selected cell)
   ========================================================================== */

.context {
  flex: 1 0 58px;
  min-height: 58px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.3;
  color: var(--ink-2);
  text-align: center;
}

.context .tip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.context .tip svg {
  width: 18px;
  height: 18px;
  color: var(--ink-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-2);
  white-space: nowrap;
  font-size: 12.5px;
  animation: fade 0.18s ease both;
}

.chip b {
  color: var(--ink);
  font-weight: 700;
}

.chip-accent {
  background: var(--accent-soft);
  box-shadow: none;
  color: var(--accent-text);
}

.chip-accent b {
  color: var(--accent-text);
}

.chip-good {
  background: var(--good-soft);
  box-shadow: none;
  color: var(--good);
}

.msg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  animation: fade 0.18s ease both;
}

.msg svg {
  width: 18px;
  height: 18px;
}

.msg-error {
  background: var(--bad-soft);
  color: var(--bad);
}

.msg-good {
  background: var(--good-soft);
  color: var(--good);
}

.msg-info {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.mini-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  vertical-align: -1px;
}

.mini-dot.white {
  background: var(--dot-white);
  border: 1.6px solid var(--dot-white-ring);
}

.mini-dot.black {
  background: var(--dot-black);
  border: 1.6px solid var(--dot-black-ring);
}

/* ==========================================================================
   Tools & number pad
   ========================================================================== */

.play-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tools {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 7px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font: 600 12px/1.1 var(--font);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.08s ease;
}

.tool:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.tool:active {
  transform: scale(0.95);
}

.tool svg {
  width: 24px;
  height: 24px;
}

.tool:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.tool-flag {
  position: absolute;
  top: 3px;
  left: calc(50% + 4px);
  padding: 1px 4px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--ink-2);
  font: 700 8.5px/1.3 var(--font);
  font-style: normal;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tool[aria-pressed="true"] .tool-flag {
  background: var(--accent);
  color: var(--accent-ink);
}

#hint-btn svg {
  color: var(--amber);
}

.tool-beginner[aria-checked="true"],
.tool-beginner[aria-checked="true"]:hover {
  background: var(--amber);
  color: #1b1200;
  box-shadow: 0 0 0 3px var(--amber-soft), 0 6px 18px -6px var(--amber);
}

.tool-beginner[aria-checked="true"] .tool-flag {
  background: #1b1200;
  color: var(--amber);
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
}

.key {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 0.72;
  max-height: 68px;
  width: 100%;
  border: 0;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease, color 0.15s ease;
}

.key:hover {
  background: var(--surface-2);
}

.key:active {
  transform: scale(0.93);
}

.key .k-n {
  font: 600 24px/1 var(--font-num);
  font-size: clamp(19px, 5.6vw, 27px);
  transition: font-size 0.15s ease;
}

.key .k-left {
  position: absolute;
  top: 4px;
  right: 6px;
  font: 650 10px/1 var(--font);
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.key.dim .k-n {
  opacity: 0.3;
}

.key.done {
  opacity: 0.35;
  cursor: default;
}

.key.done .k-left {
  color: var(--good);
}

.key.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 8px 18px -10px var(--accent);
}

.key.active .k-left {
  color: var(--accent-ink);
  opacity: 0.8;
}

/* Notes mode: keys look like pencil marks sitting in their note position */
.numpad.notes-mode .key {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1.5px var(--accent);
  color: var(--accent-text);
}

.numpad.notes-mode .key .k-n {
  font-size: clamp(13px, 3.6vw, 17px);
  justify-self: var(--jx);
  align-self: var(--jy);
  margin: 7px;
}

.numpad.notes-mode .key .k-left {
  display: none;
}

/* ==========================================================================
   Hint card (replaces the controls, so the board stays visible)
   ========================================================================== */

.hint-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 14px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2), inset 0 0 0 1.5px var(--amber);
  animation: rise 0.25s var(--ease-out) both;
  flex: 0 1 auto;
  min-height: 0;
}

.hint-card > * {
  flex: none;
}

.hint-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hint-steps {
  display: inline-flex;
  gap: 4px;
}

.hint-steps i {
  width: 18px;
  height: 5px;
  border-radius: 9px;
  background: var(--surface-3);
}

.hint-steps i.on {
  background: var(--amber);
}

.hint-kicker {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font: 700 11px/1 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--amber);
}

.hint-title {
  font: 750 17px/1.25 var(--font);
}

.hint-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-2);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
}

.hint-card > .hint-text {
  flex: 0 1 auto;
}

/* More text below: the last line fades out instead of being cut */
.hint-text.more {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent);
}

.hint-text b,
.hint-text strong {
  color: var(--ink);
}

.hint-text em {
  font-size: 12.5px;
  color: var(--ink-3);
}

.hint-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.hint-cost {
  font-size: 12px;
  color: var(--ink-3);
}

.hint-foot .btn {
  flex: none;
  white-space: nowrap;
}

.hint-cost b {
  color: var(--bad);
}

/* ==========================================================================
   Overlays: bottom sheets on phones, dialogs on larger screens
   ========================================================================== */

/* The page behind an open overlay stays put (see syncScrollLock) */
html.scroll-lock {
  overflow: hidden;
  overscroll-behavior: none;
}

html.scroll-lock body {
  position: fixed;
  left: 0;
  right: 0;
  overflow: hidden;
}

/* Scrolling inside a sheet never hands the gesture over to the page */
.overlay .sheet,
.overlay .sheet-body,
.overlay .tut-stage,
.overlay .dialog-body,
.overlay .result {
  overscroll-behavior: contain;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%);
  transition: transform 0.32s var(--ease-out), opacity 0.25s ease;
}

.sheet-tall {
  height: 88vh;
  height: 88dvh;
}

.overlay.open .scrim {
  opacity: 1;
}

.overlay.open .sheet {
  transform: none;
}

.sheet-grip {
  width: 42px;
  height: 5px;
  border-radius: 9px;
  background: var(--surface-3);
  margin: 9px auto 0;
  flex: none;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 6px 22px;
  flex: none;
}

.sheet-head h2 {
  font: 750 21px/1.2 var(--font);
  letter-spacing: -0.01em;
}

.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 22px 22px;
  overscroll-behavior: contain;
}

.overlay-center {
  align-items: center;
  padding: 16px;
}

.overlay-center .sheet {
  max-width: 400px;
  border-radius: var(--r-xl);
  transform: translateY(14px) scale(0.96);
  opacity: 0;
}

.overlay-center.open .sheet {
  transform: none;
  opacity: 1;
}

@media (min-width: 720px) and (min-height: 560px) {
  .overlay {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    border-radius: var(--r-xl);
    transform: translateY(14px) scale(0.98);
    opacity: 0;
    max-height: min(760px, 90dvh);
  }

  .sheet-tall {
    height: min(760px, 90dvh);
  }

  .overlay.open .sheet {
    transform: none;
    opacity: 1;
  }

  .sheet-grip {
    display: none;
  }

  .sheet-head {
    padding-top: 16px;
  }
}

/* Menu */
.menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-list button {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 11px 8px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.menu-list button:hover {
  background: var(--surface-2);
}

.menu-list b {
  display: block;
  font: 650 15px/1.3 var(--font);
}

.menu-list small {
  display: block;
  font-size: 12.5px;
  color: var(--ink-2);
}

.menu-ic {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink-2);
  flex: none;
}

.menu-ic svg {
  width: 20px;
  height: 20px;
}

.ic-accent {
  background: var(--accent-soft);
  color: var(--accent-text);
}

/* Prose (rules) */
.prose section + section {
  margin-top: 22px;
}

.prose h3 {
  font: 750 15px/1.3 var(--font);
  margin-bottom: 8px;
}

.prose p,
.prose li {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.prose b {
  color: var(--ink);
}

.prose ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rule {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  font-size: 14.5px;
  line-height: 1.45;
  color: var(--ink-2);
}

.rule + .rule {
  border-top: 1px solid var(--line);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.table th,
.table td {
  padding: 7px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.table th {
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-3);
}

.table td:first-child {
  font-weight: 700;
  color: var(--ink);
}

.table-keys td:first-child {
  white-space: nowrap;
  width: 1%;
  padding-right: 16px;
}

kbd {
  display: inline-block;
  min-width: 22px;
  margin: 0 1px;
  padding: 2px 6px;
  border-radius: 7px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line), 0 1.5px 0 var(--line);
  font: 650 12px/1.3 var(--font);
  text-align: center;
  color: var(--ink);
}

@media (hover: none) and (pointer: coarse) {
  .only-keyboard {
    display: none;
  }
}

/* Dot pair illustration (rules & tutorial).
   The frame is the container background showing through padding/gaps, and
   corner cells are rounded by (outer radius - frame), so the line keeps the
   same thickness around the corners. */
.pair {
  --frame: 2px;
  --radius: 15px;
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  gap: var(--frame);
  padding: var(--frame);
  border-radius: var(--radius);
  background: var(--grid-thick);
}

.pc {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  background: var(--board-bg);
  font: 650 26px/1 var(--font-num);
  color: var(--given);
}

.pair .pc:first-child {
  border-radius: calc(var(--radius) - var(--frame)) 0 0 calc(var(--radius) - var(--frame));
}

.pair .pc:last-child {
  border-radius: 0 calc(var(--radius) - var(--frame)) calc(var(--radius) - var(--frame)) 0;
}

.pc.q {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.pc.q.ok {
  background: var(--good-soft);
  color: var(--good);
}

.pdot {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.pdot.white {
  background: var(--dot-white);
  border: 2px solid var(--dot-white-ring);
}

.pdot.black {
  background: var(--dot-black);
  border: 2px solid var(--dot-black-ring);
}

.pdot.none {
  display: none;
}

.pair-sm {
  --frame: 1.5px;
  --radius: 11px;
}

.pair-sm .pc {
  width: 38px;
  height: 38px;
  font-size: 18px;
}

.pair-sm .pdot {
  width: 13px;
  height: 13px;
  border-width: 1.6px;
}

/* Row of nine cells (tutorial): frame -> 3 groups (thick gaps) -> cells (thin gaps) */
.row9 {
  --frame: 2px;
  --radius: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--frame);
  width: min(100%, 380px);
  padding: var(--frame);
  border-radius: var(--radius);
  background: var(--grid-thick);
}

.row9-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--grid-thin);
  overflow: hidden;
}

.row9-group:first-child {
  border-radius: calc(var(--radius) - var(--frame)) 0 0 calc(var(--radius) - var(--frame));
}

.row9-group:last-child {
  border-radius: 0 calc(var(--radius) - var(--frame)) calc(var(--radius) - var(--frame)) 0;
}

.row9 .pc {
  width: auto;
  height: auto;
  aspect-ratio: 1;
  font-size: clamp(16px, 5vw, 22px);
}

/* One 3x3 box (tutorial): same frame technique as the board */
.box3 {
  --frame: 2.5px;
  --radius: 14px;
  padding: var(--frame);
  border-radius: var(--radius);
  background: var(--grid-thick);
}

.box3-in {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--grid-thin);
  border-radius: calc(var(--radius) - var(--frame));
  overflow: hidden;
}

.box3 .pc {
  width: 54px;
  height: 54px;
  font-size: 24px;
}

/* Beginner mode: home card, menu row, explanation dialog */
.beginner-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.beginner-card[aria-checked="true"] {
  background: var(--amber);
  color: #1b1200;
  box-shadow: 0 0 0 4px var(--amber-soft), 0 10px 26px -10px var(--amber);
}

.beginner-card[aria-checked="true"] .beginner-text small {
  color: rgba(27, 18, 0, 0.78);
}

.beginner-card[data-beginner][aria-checked="true"] .switch {
  background: #1b1200;
}

.beginner-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink-3);
  flex: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.beginner-card[aria-checked="true"] .beginner-icon {
  background: #1b1200;
  color: var(--amber);
}

.beginner-icon svg {
  width: 22px;
  height: 22px;
}

.beginner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.beginner-text b {
  font: 700 15.5px/1.25 var(--font);
}

.beginner-text small {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-2);
}

[data-beginner][aria-checked="true"] .switch {
  background: var(--amber);
}

.menu-switch[data-beginner][aria-checked="true"] {
  background: var(--amber-soft);
  box-shadow: inset 0 0 0 1.5px var(--amber);
}

.menu-switch[data-beginner][aria-checked="true"] .menu-ic {
  background: var(--amber);
  color: #1b1200;
}

[data-beginner][aria-checked="true"] .switch::after {
  transform: translateX(18px);
}

.menu-caption {
  display: block;
  margin: 14px 8px 4px;
  font: 700 11.5px/1 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.menu-caption:first-child {
  margin-top: 2px;
}

.menu-list .menu-switch > span:nth-child(2) {
  flex: 1;
}

.ic-amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.sheet-note {
  margin: 0 4px 12px;
  font-size: 13px;
  color: var(--ink-2);
}

.level.current {
  box-shadow: var(--shadow-1), inset 0 0 0 1.5px var(--lv);
}

.level-now {
  padding: 4px 9px;
  border-radius: 99px;
  background: var(--lv-soft);
  color: var(--lv);
  font: 700 11.5px/1 var(--font);
}

.beginner-dialog {
  max-width: 420px;
}

.overlay-center .beginner-dialog {
  max-width: 420px;
}

.beginner-emblem {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--amber-soft);
  color: var(--amber);
  margin-bottom: 4px;
}

.beginner-emblem.off {
  background: var(--surface-2);
  color: var(--ink-3);
}

.beginner-emblem svg {
  width: 26px;
  height: 26px;
}

.beginner-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.beginner-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
}

.beginner-item b {
  display: block;
  font: 650 14.5px/1.3 var(--font);
}

.beginner-item p {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-2);
}

.beginner-demo {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 9px;
}

.beginner-list.off .beginner-item {
  opacity: 0.55;
}

.beginner-list.off .beginner-item b {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.mini-key {
  width: 26px;
  height: 32px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
  font: 600 15px/1 var(--font-num);
}

.mini-key.dim {
  color: var(--ink-3);
  opacity: 0.45;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(6, 12px);
  gap: 2px;
}

.mini-grid i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.mini-grid i.z {
  background: var(--accent-soft);
  box-shadow: none;
}

.mini-grid i.d {
  background: var(--accent);
  box-shadow: none;
}

.dialog-note {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--ink-3);
}

/* First-game beginner notice */
.notice-list {
  margin: 4px 0 6px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notice-list li {
  position: relative;
  padding-left: 18px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}

.notice-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.55em;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.notice-list b {
  color: var(--ink);
}

.inline-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px 1px 6px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--amber-ink);
  font-weight: 650;
  white-space: nowrap;
}

.inline-ic {
  width: 15px;
  height: 15px;
  color: var(--amber);
}

.notice-ok {
  min-width: 110px;
}

/* Draws attention to the beginner switch after the notice */
.tool.attention {
  animation: attention 1.2s ease-in-out 2;
}

@keyframes attention {
  0%, 100% { box-shadow: 0 0 0 0 transparent; transform: scale(1); }
  40% { box-shadow: 0 0 0 4px var(--amber); transform: scale(1.06); }
}

/* Stats */
.stats-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 14px 16px;
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.stat-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stat-card-head b {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: 700 15px/1.2 var(--font);
}

.stat-card-head span {
  font-size: 12.5px;
  color: var(--ink-3);
}

.stat-card-head .pips i {
  height: 10px;
}

.stat-nums {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-nums div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-nums span {
  font-size: 11px;
  color: var(--ink-3);
}

.stat-nums b {
  font: 700 16px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
}

.empty-note {
  padding: 18px;
  text-align: center;
  color: var(--ink-2);
  font-size: 14px;
}

/* Settings */
.setting-group + .setting-group {
  margin-top: 18px;
}

.setting-caption {
  display: block;
  margin-bottom: 8px;
  font: 700 12px/1 var(--font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.seg button {
  padding: 9px 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-2);
  font: 600 13px/1.2 var(--font);
  cursor: pointer;
}

.seg button[aria-checked="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  padding: 13px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}

.switch-row:last-child {
  border-bottom: 0;
}

.switch-text b {
  display: block;
  font: 650 15px/1.3 var(--font);
  color: var(--ink);
}

.switch-text small {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-2);
}

.switch {
  position: relative;
  width: 46px;
  height: 28px;
  border-radius: 99px;
  background: var(--surface-3);
  flex: none;
  transition: background-color 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.22s var(--ease);
}

.switch-row[aria-checked="true"] .switch {
  background: var(--accent);
}

.switch-row[aria-checked="true"] .switch::after {
  transform: translateX(18px);
}

/* Tutorial */
.overlay-full .sheet.tutorial {
  height: 100vh;
  height: 100dvh;
  max-height: none;
  max-width: 560px;
  border-radius: 0;
  padding: max(10px, env(safe-area-inset-top)) 0 max(14px, env(safe-area-inset-bottom));
}

@media (min-width: 720px) and (min-height: 600px) {
  .overlay-full .sheet.tutorial {
    height: min(720px, 92dvh);
    border-radius: var(--r-xl);
    padding: 12px 0 18px;
  }
}

.tut-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 18px 6px 24px;
}

.tut-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tut-name {
  font: 750 19px/1.2 var(--font);
  letter-spacing: -0.01em;
}

.tut-progress {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 10px 24px 0;
}

.tut-progress i {
  width: 8px;
  height: 8px;
  border-radius: 9px;
  background: var(--surface-3);
  transition: width 0.25s var(--ease), background-color 0.25s ease;
}

.tut-progress i.on {
  width: 24px;
  background: var(--accent);
}

.tut-progress i.done {
  background: var(--accent);
  opacity: 0.45;
}

.tut-stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 24px;
  display: flex;
}

.tut-slide {
  margin: auto 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  animation: slide-in 0.35s var(--ease-out) both;
}

.tut-slide.back {
  animation-name: slide-in-back;
}

.tut-kicker {
  font: 700 12px/1 var(--font);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent-text);
}

.tut-title {
  font: 800 26px/1.15 var(--font);
  letter-spacing: -0.02em;
}

.tut-text {
  max-width: 400px;
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--ink-2);
}

.tut-text b {
  color: var(--ink);
}

.tut-demo {
  padding: 22px 16px;
  width: 100%;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.tut-question {
  font: 650 15px/1.35 var(--font);
}

.quiz {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.opt {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-1), inset 0 0 0 1.5px var(--line);
  font: 650 26px/1 var(--font-num);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}

.opt:hover {
  background: var(--surface-3);
}

.opt:active {
  transform: scale(0.94);
}

.opt.right {
  background: var(--good-soft);
  color: var(--good);
  box-shadow: inset 0 0 0 2px var(--good);
}

.opt.wrong {
  background: var(--bad-soft);
  color: var(--bad);
  box-shadow: inset 0 0 0 2px var(--bad);
}

/* One-shot animations: added by JS only at the moment of the answer */
.opt.shake {
  animation: shake 0.34s ease;
}

.opt.celebrate {
  animation: correct-pop 0.5s var(--ease-out);
}

.opt.celebrate::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 2px var(--good);
  animation: ring-out 0.7s ease-out forwards;
  pointer-events: none;
}

.quiz.solved .opt:not(.right) {
  opacity: 0.4;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.quiz.solved .opt.right {
  pointer-events: none;
}

.pc.q.ok.celebrate {
  animation: correct-pop 0.5s var(--ease-out) 0.08s both;
}

.quiz-feedback.good {
  font-weight: 600;
}

.quiz-feedback.good svg {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 4px;
  vertical-align: -4px;
  stroke-width: 2.6;
}

.quiz-feedback.appear {
  animation: fade-up 0.28s var(--ease-out);
}

.btn.nudge {
  animation: nudge 0.6s var(--ease-out) 0.35s;
}

.quiz-feedback {
  min-height: 42px;
  max-width: 380px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}

.quiz-feedback.good {
  color: var(--good);
}

.quiz-feedback.bad {
  color: var(--bad);
}

.facts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 420px;
  text-align: left;
}

.fact {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
}

.fact b {
  color: var(--ink);
}

.fact-ic {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--accent-text);
}

.fact-ic svg {
  width: 21px;
  height: 21px;
}

.tut-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px 0;
}

.tut-foot .btn-primary {
  min-width: 150px;
}

/* Result */
.result {
  padding: 28px 24px 22px;
  align-items: center;
  text-align: center;
  gap: 6px;
  overflow-y: auto;
}

.result-emblem {
  width: 76px;
  height: 76px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  background: var(--amber-soft);
  color: var(--amber);
  margin-bottom: 8px;
  animation: pop-in 0.5s var(--ease-out) both 0.1s;
}

.result-emblem.lose {
  background: var(--bad-soft);
  color: var(--bad);
}

.result-emblem svg {
  width: 40px;
  height: 40px;
}

.result-title {
  font: 800 26px/1.2 var(--font);
  letter-spacing: -0.02em;
}

.result-sub {
  font-size: 14.5px;
  color: var(--ink-2);
  max-width: 320px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  margin: 16px 0 6px;
}

.result-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.result-stats span {
  font-size: 12px;
  color: var(--ink-3);
}

.result-stats b {
  font: 800 24px/1.2 var(--font);
  font-variant-numeric: tabular-nums;
}

.result-note {
  font-size: 12.5px;
  color: var(--ink-3);
}

.result-records {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  width: 100%;
}

.record-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 99px;
  background: var(--good-soft);
  color: var(--good);
  font: 700 13.5px/1.2 var(--font);
  animation: pop-in 0.45s var(--ease-out) both;
}

.record-badge svg {
  width: 16px;
  height: 16px;
}

.record-line {
  font-size: 13px;
  color: var(--ink-2);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  margin-top: 18px;
}

/* Confirm dialog */
.dialog {
  padding: 22px 22px 16px;
  gap: 8px;
}

.dialog-title {
  font: 750 19px/1.25 var(--font);
}

.dialog-text {
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink-2);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Long dialogs: the text scrolls, the buttons stay on screen */
.dialog-split {
  padding: 0;
  gap: 0;
}

.dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 22px 4px;
}

.dialog-split .dialog-actions {
  flex: none;
  margin-top: 0;
  padding: 12px 22px 16px;
  border-top: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.dialog-split.overflowing .dialog-actions {
  border-top-color: var(--line);
}

/* Toast & confetti */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: min(92vw, 420px);
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow-3);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s var(--ease-out), opacity 0.2s ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ==========================================================================
   Responsive: side-by-side layout for landscape tablets, laptops, desktops
   ========================================================================== */

@media (orientation: landscape) and (min-width: 700px) {
  .game {
    --board: min(calc(100vh - 110px), 660px, calc(100vw - 440px));
    --board: min(calc(100dvh - 110px), 660px, calc(100vw - 440px));
  }

  .game-body {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(24px, 4vw, 56px);
    padding: 4px 24px 20px;
  }

  .board-col {
    margin: auto 0;
  }

  .panel {
    width: clamp(290px, 30vw, 360px);
    gap: 14px;
    margin: auto 0;
  }

  .panel {
    flex: none;
  }

  .context {
    flex: none;
    height: 76px;
    min-height: 0;
  }

  .numpad {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .key {
    aspect-ratio: 1.5 / 1;
    max-height: none;
    border-radius: var(--r-md);
  }

  .key .k-n {
    font-size: 28px;
  }

  .key .k-left {
    top: 7px;
    right: 9px;
    font-size: 11px;
  }

  .numpad.notes-mode .key .k-n {
    font-size: 17px;
    margin: 8px 12px;
  }

  .hint-card {
    max-height: calc(100dvh - 140px);
  }
}

/* Tablets & desktops: the context strip sits under the board (moved there by app.js) */
@media (orientation: landscape) and (min-width: 700px) and (min-height: 521px) {
  .game {
    --board: min(calc(100vh - 176px), 660px, calc(100vw - 440px));
    --board: min(calc(100dvh - 176px), 660px, calc(100vw - 440px));
  }

  .board-col > .context {
    height: 56px;
    margin-top: 10px;
  }

  /* While a hint is open the strip keeps its place, so the board does not jump */
  .board-col > .context[hidden] {
    display: flex !important;
    visibility: hidden;
  }
}

/* Short landscape screens (phones turned sideways) */
@media (orientation: landscape) and (min-width: 700px) and (max-height: 520px) {
  .game {
    --board: min(calc(100dvh - 78px), calc(100vw - 420px));
  }

  .topbar {
    padding-top: max(2px, env(safe-area-inset-top));
  }

  .status {
    padding-bottom: 4px;
  }

  .panel {
    gap: 8px;
  }

  .context {
    height: 44px;
    min-height: 0;
    font-size: 12px;
  }

  .key {
    aspect-ratio: 2.3 / 1;
  }

  .key .k-n {
    font-size: 22px;
  }

  .tool {
    padding: 5px 2px;
  }

  .tool span {
    display: none;
  }
}

/* Very small phones */
@media (max-width: 359px) {
  .tut-head {
    padding: 6px 10px 6px 18px;
  }

  .tut-label {
    gap: 8px;
  }

  .tut-name {
    font-size: 18px;
  }

  .tut-head .rules-tag svg {
    display: none;
  }

  .tut-head .rules-tag {
    padding: 3px 9px;
  }
}

@media (max-width: 360px) {
  .numpad {
    gap: 4px;
  }

  .key .k-left {
    top: 3px;
    right: 4px;
    font-size: 9px;
  }

  .tool {
    font-size: 11px;
  }

  .home-nav {
    gap: 6px;
  }

  .nav-tile {
    font-size: 11px;
  }

  .level-desc {
    font-size: 12.5px;
  }
}

/* Short portrait screens: give the board every pixel */
@media (orientation: portrait) and (max-height: 700px) {
  .game {
    --board: min(calc(100vw - 28px), 600px, calc(100dvh - 312px));
  }

  .game-body {
    gap: 6px;
  }

  .play-controls {
    gap: 6px;
  }
}

/* ==========================================================================
   Motion
   ========================================================================== */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes pop-in {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); }
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* Only the peak is defined: the cell starts from and returns to its own
   current colour (peer / same / selected), so nothing "re-runs" afterwards */
@keyframes wave {
  35% { background-color: var(--cell-same); }
}

@keyframes conflict {
  0%, 60% { background-color: var(--bad-soft); box-shadow: inset 0 0 0 2px var(--bad); }
  100% { box-shadow: inset 0 0 0 2px transparent; }
}

@keyframes correct-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.18); }
  65% { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes ring-out {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.45); }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes nudge {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.06); }
  70% { transform: scale(0.98); }
}

@keyframes glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: none; }
}

@keyframes slide-in-back {
  from { opacity: 0; transform: translateX(-24px); }
  to { opacity: 1; transform: none; }
}

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

.sheet:focus,
.sheet:focus-visible {
  outline: none;
}

/* ==========================================================================
   v3: rules modes (classic / dots)
   ========================================================================== */

svg .fill-paper {
  fill: var(--surface);
  stroke: currentColor;
  stroke-width: 1.6;
}

.bm-white,
.bm-black {
  transition: opacity 0.3s ease, transform 0.3s var(--ease);
  transform-box: fill-box;
  transform-origin: center;
}

/* The home logo loses its dots under classic rules */
:root[data-rules="classic"] .home .bm-white,
:root[data-rules="classic"] .home .bm-black {
  opacity: 0;
  transform: scale(0.3);
}

/* Rules switch on the home screen */
.rules-seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: var(--surface-3);
  margin-top: -4px;
}

.rules-seg button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-2);
  font: 650 14.5px/1.2 var(--font);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.rules-seg button:hover {
  color: var(--ink);
}

.rules-seg button svg {
  width: 20px;
  height: 20px;
}

.rules-seg button[aria-checked="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
}

.rules-seg button[aria-checked="true"] svg {
  color: var(--accent);
}

.game-mark {
  display: none;
  position: absolute;
  top: 7px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.rules-seg button.has-game .game-mark {
  display: block;
}

/* The same switch in the "New game" sheet: tabs that swap the level list */
.levels-seg {
  margin: 0 0 12px;
}

/* Rules name above the level in the game top bar */
.level-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}

.level-btn-text small {
  font: 600 10.5px/1.15 var(--font);
  color: var(--ink-3);
}

.rules-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 6px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font: 650 12px/1.2 var(--font);
  white-space: nowrap;
  vertical-align: middle;
}

.rules-tag svg {
  width: 15px;
  height: 15px;
}

.sheet-note .rules-tag {
  margin-right: 8px;
}

.tut-head .rules-tag {
  flex: none;
}

.tut-head .link-btn {
  flex: none;
}

.seg.seg-2 {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 14px;
}

/* ---- First run: choose the rules ---------------------------------------- */

.overlay.overlay-choose {
  align-items: stretch;
  padding: 0;
  z-index: 60;
}

.overlay-choose .scrim {
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, var(--bg-deco) 1.2px, transparent 0);
  background-size: 22px 22px;
}

.overlay-choose .sheet.choose {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  padding: max(28px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  transform: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.overlay-choose.open .sheet.choose {
  opacity: 1;
}

.choose-head {
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  animation: rise 0.5s var(--ease-out) both;
}

.choose-mark {
  width: 58px;
  height: 58px;
}

.choose-title {
  font: 800 30px/1.1 var(--font);
  letter-spacing: -0.02em;
}

.choose-lead {
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.45;
}

.choose-grid {
  width: 100%;
  max-width: 620px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.choose-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 14px 16px;
  border: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
  transition: transform 0.18s var(--ease), box-shadow 0.2s ease;
  animation: rise 0.5s var(--ease-out) 0.05s both;
}

.choose-card + .choose-card {
  animation-delay: 0.12s;
}

.choose-card:hover {
  transform: translateY(-3px);
}

.choose-card:active {
  transform: scale(0.98);
}

/* The recommended card: amber ring + badge, but nothing is preselected */
.choose-rec {
  box-shadow: var(--shadow-2), inset 0 0 0 2px var(--amber), 0 0 0 5px var(--amber-soft);
}

.rec-badge {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px 6px 9px;
  border-radius: 99px;
  background: linear-gradient(135deg, #ffcb6b, #f59e0b);
  color: #3a2400;
  font: 800 12px/1 var(--font);
  letter-spacing: 0.02em;
  white-space: nowrap;
  box-shadow: 0 8px 18px -8px rgba(217, 138, 0, 0.8);
}

.rec-badge svg {
  width: 14px;
  height: 14px;
}

.choose-art {
  width: min(100%, 132px);
  margin-bottom: 6px;
}

.mini-board {
  --frame: 2.5px;
  --radius: 14px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5px;
  padding: var(--frame);
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--grid-thick);
}

.mini-board i {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  background: var(--board-bg);
  color: var(--given);
  font: 700 22px/1 var(--font-num);
  font-style: normal;
}

.mini-board i:nth-child(1) { border-top-left-radius: calc(var(--radius) - var(--frame)); }
.mini-board i:nth-child(3) { border-top-right-radius: calc(var(--radius) - var(--frame)); }
.mini-board i:nth-child(7) { border-bottom-left-radius: calc(var(--radius) - var(--frame)); }
.mini-board i:nth-child(9) { border-bottom-right-radius: calc(var(--radius) - var(--frame)); }

.mini-board .md {
  position: absolute;
  left: calc(var(--frame) + (100% - 2 * var(--frame)) * var(--x) / 3);
  top: calc(var(--frame) + (100% - 2 * var(--frame)) * var(--y) / 3);
  width: 13px;
  height: 13px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.mini-board .md.white {
  background: var(--dot-white);
  border: 2px solid var(--dot-white-ring);
}

.mini-board .md.black {
  background: var(--dot-black);
  border: 2px solid var(--dot-black-ring);
}

.choose-name {
  font: 800 19px/1.2 var(--font);
}

.choose-desc {
  flex: 1;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.4;
}

.choose-cta {
  margin-top: 6px;
  padding: 10px 20px;
  border-radius: 99px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font: 700 14px/1 var(--font);
}

.choose-rec .choose-cta {
  background: var(--accent);
  box-shadow: none;
  color: var(--accent-ink);
}

@media (max-width: 380px) {
  .choose-card {
    padding: 26px 10px 14px;
    gap: 6px;
  }

  .choose-name {
    font-size: 17px;
  }

  .choose-desc {
    font-size: 12.5px;
  }

  .choose-title {
    font-size: 26px;
  }

  .mini-board i {
    font-size: 19px;
  }
}

/* ---- Hints: step-by-step reasoning -------------------------------------- */

.hint-text p + p,
.hint-text ul + p,
.hint-text .digit-strip + p {
  margin-top: 6px;
}

.hint-list {
  list-style: none;
  margin: 8px 0 10px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-list li {
  position: relative;
  padding-left: 16px;
  line-height: 1.4;
}

.hint-list li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 0.6em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
}

.digit-strip {
  display: flex;
  gap: 4px;
  margin: 2px 0 8px;
}

.digit-strip i {
  flex: 1;
  max-width: 32px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font: 700 14px/1 var(--font-num);
  font-style: normal;
}

.digit-strip i.x {
  background: var(--surface-2);
  color: var(--ink-3);
  text-decoration: line-through;
}

.digit-strip i.left {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink-3);
}

.digit-strip i.answer {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
  animation: pop 0.3s var(--ease);
}

.hint-note {
  font-size: 12.5px;
  color: var(--ink-3);
}

.chip-result {
  font-weight: 600;
}

/* Compact chips when the explanation does not fit (small phones) */
.context.compact {
  gap: 4px;
}

.context.compact .chip {
  padding: 3px 8px;
  gap: 4px;
  font-size: 11.5px;
}

.context.compact .mini-dot {
  width: 9px;
  height: 9px;
}
