:root {
  --bg: #f7f8fa;
  --card: #ffffff;
  --ink: #202124;
  --muted: #5f6368;
  --line: #e3e6ea;
  --grid-line: #c3c8ce;
  --grid-bold: #202124;
  --accent: #2b6cb0;
  --cage: #c2570f;
  --accent-ink: #ffffff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  line-height: 1.5;
}

.wrap {
  max-width: 540px;
  margin: 0 auto;
  padding: 48px 20px 64px;
}

.header {
  text-align: center;
  margin-bottom: 28px;
  padding-bottom: 14px;
  border-bottom: 4px double var(--ink);
}

h1 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 38px;
  letter-spacing: 0.5px;
  margin: 0 0 6px;
}

/* The masthead itself gets the blackletter face; every other heading keeps
   the Georgia stack above. */
.masthead-title {
  font-family: "Manufacturing Consent", Georgia, "Times New Roman", Times, serif;
  font-weight: 400;
  font-size: 46px;
  letter-spacing: 0;
}

.subtitle {
  color: var(--muted);
  margin: 0;
}

.variant {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.var-btn {
  appearance: none;
  flex: 1;
  max-width: 160px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 9px 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.var-btn.active {
  background: var(--ink);
  color: var(--accent-ink);
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.diff-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 0;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s, box-shadow 0.15s;
  box-shadow: var(--shadow);
}

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

.diff-btn:active {
  transform: translateY(1px);
}

.diff-btn.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--accent-ink);
}

.result {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.badge {
  font-weight: 600;
  font-size: 14px;
  text-transform: capitalize;
}

.cached-note {
  font-size: 12px;
  color: var(--muted);
}

/* solve timer, in a small pill on the status row */
.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 5px 4px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.timer-pause {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--muted);
  font-size: 9px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.timer-pause:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* positioning context for the pause mask */
.board-wrap {
  position: relative;
}

/* opaque mask over the puzzle while paused — click anywhere on it to resume */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px solid var(--grid-bold);
  border-radius: 4px;
  background: var(--card);
  cursor: pointer;
}

.pause-overlay[hidden] {
  display: none;
}

.pause-title {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
}

.pause-sub {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.pause-hint {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

/* Pre-start mask: the grid loads blank underneath, and a click anywhere on
   the overlay (the whole board area) starts the puzzle. */
.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.start-overlay[hidden] {
  display: none;
}

.start-overlay .btn {
  flex: none;
  box-shadow: var(--shadow);
}

/* an unstarted killer board keeps its cage sums to itself too */
.board.unstarted .cage-sum {
  display: none;
}

/* 9x9 board */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  /* Rows must be declared too. Left implicit they size to their contents, so a
     row holding no digits collapses to a thin strip while its neighbours stay
     tall — and no row ends up square. minmax(0, 1fr) lets rows shrink below
     the digits' min-content height when the board is height-constrained. */
  grid-template-rows: repeat(9, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
  width: 100%;
  border: 2px solid var(--grid-bold);
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 5vw, 26px);
  font-variant-numeric: tabular-nums;
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  background: var(--card);
}

.board:focus {
  outline: none;
}

.cell.given {
  font-weight: 600;
  color: var(--ink);
}

.cell.editable {
  cursor: pointer;
}

/* user-entered digits */
.cell.user {
  color: var(--accent);
  font-weight: 500;
}

/* peers sharing the selected cell's value */
.cell.same {
  background: #eef3fb;
}

/* the currently selected cell */
.cell.selected {
  background: #d9e6fb;
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* duplicate in the same row / column / box */
.cell.conflict {
  color: #c5221f;
  background: #fdecea;
}

/* flagged as incorrect by the Check button */
.cell.wrong {
  color: #c5221f;
  background: #fbd5d1;
}

/* pencilled candidates, laid out 1-9 in a fixed 3x3 mini-grid */
.cell.noted {
  padding: 2px;
}

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  font-size: clamp(7px, 1.9vw, 11px);
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
}

.notes span {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* candidate matching the selected cell's digit */
.notes .hit {
  color: var(--accent);
}

/* revealed via Show solution */
.cell.revealed {
  color: #188038;
  font-weight: 500;
}

.board.solved {
  border-color: #188038;
  box-shadow: 0 0 0 3px rgba(24, 128, 56, 0.2);
}

.status {
  text-align: center;
  min-height: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.status.win {
  color: #188038;
  font-weight: 600;
}

/* One row under the board: timer pill left, fill status centred between,
   Notes toggle right. */
.pad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}

.pad-head .status {
  flex: 1;
}

.notes-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.notes-toggle:hover {
  border-color: var(--ink);
}

.notes-toggle.active {
  border-color: var(--ink);
  background: #eceef0;
  color: var(--ink);
}

.notes-state {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.4px;
  opacity: 0.75;
}

.notes-icon {
  font-size: 12px;
}

.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.pad-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  padding: 12px 0;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.12s, transform 0.05s;
}

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

.pad-btn:active {
  transform: translateY(1px);
}

.pad-btn:disabled {
  cursor: default;
  opacity: 0.35;
  box-shadow: none;
}

.pad-btn:disabled:hover {
  border-color: var(--line);
}

.pad-btn.erase {
  color: var(--muted);
}

/* the pad writes candidates while notes mode is on */
.pad.notes-on .pad-btn {
  border-color: #d8dbdf;
  color: var(--muted);
  font-size: 15px;
}

.pad.notes-on .pad-btn.erase {
  color: var(--muted);
}

/* remove the outermost right/bottom hairlines (board border handles it) */
.cell:nth-child(9n) {
  border-right: none;
}
.cell:nth-child(n + 73) {
  border-bottom: none;
}

/* thick 3x3 separators — classic boards only; jigsaw draws its own edges */
.board.classic .cell:nth-child(9n + 3),
.board.classic .cell:nth-child(9n + 6) {
  border-right: 2px solid var(--grid-bold);
}
.board.classic .cell:nth-child(n + 19):nth-child(-n + 27),
.board.classic .cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--grid-bold);
}

/* ----- jigsaw ------------------------------------------------------------- */
/* Region edges are per-cell, since the shapes are irregular. Each edge is an
   absolutely-positioned 2px bar laid over the hairline grid (never a border,
   which would change the cell's size and throw the 9x9 layout out). The bars
   overrun the cell by 1px at each end so that where a boundary turns a corner,
   the meeting segments overlap instead of leaving a notch. */
.board.jigsaw .cell {
  position: relative;
}
.board.jigsaw .cell.edge-right::before,
.board.jigsaw .cell.edge-bottom::after {
  content: "";
  position: absolute;
  z-index: 1;
  background: var(--grid-bold);
  pointer-events: none;
}
.board.jigsaw .cell.edge-right::before {
  top: -1px;
  bottom: -1px;
  right: -1px;
  width: 2px;
}
.board.jigsaw .cell.edge-bottom::after {
  left: -1px;
  right: -1px;
  bottom: -1px;
  height: 2px;
}

/* Four map-style washes — distinct hues, assigned so no two touching regions
   match, the way countries are coloured on an atlas. Only applied while the
   "jigsaw region shading" preference is on (.shaded); pale enough that the
   selection and conflict states stay louder than the shapes. */
.board.jigsaw:where(.shaded) .cell.tint-0 {
  background: #fdf6dd; /* parchment yellow */
}
.board.jigsaw:where(.shaded) .cell.tint-1 {
  background: #e4f1e4; /* map green */
}
.board.jigsaw:where(.shaded) .cell.tint-2 {
  background: #e2ecf8; /* sea blue */
}
.board.jigsaw:where(.shaded) .cell.tint-3 {
  background: #fbe9e2; /* terracotta rose */
}

/* state colours must win over the region wash */
.board.jigsaw .cell.same {
  background: #dfe9f9;
}
/* The selection ring is an outline so it composes with the region-edge bars
   instead of replacing them. */
.board.jigsaw .cell.selected {
  background: #d9e6fb;
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* While regions are washed, the blue selection fill would clash with (or
   vanish into) the region colours — so the selected cell instead brightens
   to a much lighter shade of its own region's hue, with the accent ring
   still marking it. The extra tint class outranks the plain rule above. */
.board.jigsaw:where(.shaded) .cell.tint-0.selected {
  background: #fffcf0;
}
.board.jigsaw:where(.shaded) .cell.tint-1.selected {
  background: #f5fbf5;
}
.board.jigsaw:where(.shaded) .cell.tint-2.selected {
  background: #f3f8fd;
}
.board.jigsaw:where(.shaded) .cell.tint-3.selected {
  background: #fef6f2;
}
.board.jigsaw .cell.conflict {
  background: #fdecea;
}
.board.jigsaw .cell.wrong {
  background: #fbd5d1;
}

/* Symbols edition: glyphs run wider than digits, so ease the size down a
   touch. The default set is monochrome glyphs, so entered symbols still
   take the accent colour like ordinary text. */
.board.symbols .cell {
  font-size: clamp(14px, 4.2vw, 22px);
}

.actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.btn {
  flex: 1;
  text-align: center;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--accent-ink);
}

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

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

.loading,
.error {
  text-align: center;
  margin-top: 24px;
  color: var(--muted);
}

.error {
  color: #c5221f;
}

.footer {
  text-align: center;
  margin-top: 32px;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  margin: 0 10px;
}

.footer a:hover {
  text-decoration: underline;
}

/* Archive page */
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.archive-day {
  background: var(--card);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.archive-date {
  font-weight: 600;
}

.archive-sets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}

.archive-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.archive-variant {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
}

.pill {
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  text-transform: capitalize;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent);
  background: var(--card);
}

.pill:hover {
  border-color: var(--accent);
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

/* Sensei page */
.lesson {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.lesson h2 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 21px;
  margin: 0 0 10px;
}

.lesson p,
.lesson li {
  color: var(--ink);
  margin: 0 0 10px;
}

.lesson ol,
.lesson ul {
  padding-left: 22px;
  margin: 0 0 10px;
}

.lesson :last-child {
  margin-bottom: 0;
}

.lesson kbd {
  background: var(--bg);
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
}

/* ----- phones: fold the masthead and options away while solving ----------- */
/* Selecting a cell on a phone-sized screen adds .folded to .wrap (app.js),
   collapsing the header and option rows so the board gets the whole screen.
   The fixed handle bar at the top brings them back. */
.unfold-bar {
  display: none;
}

@media (max-width: 600px), (orientation: landscape) and (max-height: 520px) {
  .header,
  .variant,
  .difficulty {
    overflow: hidden;
    max-height: 480px;
    transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease,
      padding 0.25s ease;
  }

  .wrap.folded .header,
  .wrap.folded .variant,
  .wrap.folded .difficulty {
    max-height: 0;
    opacity: 0;
    margin: 0;
    padding: 0;
    border-width: 0;
    pointer-events: none;
  }

  .wrap.folded {
    padding: 32px 4px 24px;
  }

  /* While folded the board is the whole point: drop the type/givens line and
     the action buttons, and pull the card padding in so the grid runs nearly
     edge to edge. Everything hidden comes back via the unfold bar. */
  .wrap.folded .result-head,
  .wrap.folded .actions,
  .wrap.folded .footer {
    display: none;
  }

  .wrap.folded .result {
    padding: 8px 6px;
    border-radius: 10px;
  }

  /* Styled after the masthead's double rule so it reads as the folded-away
     header, with "Menu" naming what tapping it brings back. */
  .unfold-bar:not([hidden]) {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 28px;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--bg);
    border: none;
    border-bottom: 4px double var(--ink);
    font-family: Georgia, "Times New Roman", Times, serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: var(--ink);
    cursor: pointer;
    z-index: 10;
  }
}

/* ----- phone landscape: board left, controls right ------------------------ */
/* On short landscape screens the square board is height-limited, leaving the
   right half of the screen empty — so the status/notes row, number pad, and
   action buttons move into a column beside it. Rows are pinned explicitly:
   row 1 is the type/givens line (collapses to nothing when folded hides it),
   the board spans rows 2-5 on the left, the controls fill the right column. */
@media (orientation: landscape) and (max-height: 520px) {
  .wrap {
    max-width: 820px;
  }

  .result {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 18px;
    align-items: start;
  }

  .result-head {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .wrap.folded {
    padding-bottom: 10px;
  }

  /* Sized by the screen's height (the query caps it at 520px, so this can't
     outgrow the wrap) — a percentage here would resolve against the auto grid
     track and collapse. */
  .board-wrap {
    grid-column: 1;
    grid-row: 2 / span 4;
    width: calc(100vh - 130px);
  }

  .wrap.folded .board-wrap {
    width: calc(100vh - 92px);
  }

  /* The board is height-bound here, so cell digits scale with the viewport's
     height — the portrait clamp bottoms out at 16px, which would force rows
     taller than the board and clip its last rows. */
  .cell {
    font-size: clamp(12px, 6vh, 26px);
  }

  .notes {
    font-size: clamp(6px, 2.4vh, 11px);
  }

  /* Keypad first, with the timer/status/notes row tucked under it. */
  .pad {
    grid-column: 2;
    grid-row: 2;
    margin-top: 0;
    grid-template-columns: repeat(2, 1fr);
    max-width: 300px;
  }

  .pad-head {
    grid-column: 2;
    grid-row: 3;
    margin-top: 10px;
  }

  .result > .actions {
    grid-column: 2;
    margin-top: 0;
  }

  .result > .actions:nth-of-type(1) {
    grid-row: 4;
  }

  .result > .actions:nth-of-type(2) {
    grid-row: 5;
  }
}

/* ----- install-as-app tip -------------------------------------------------- */
.install-tip {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(32, 33, 36, 0.45);
}

.install-tip[hidden] {
  display: none;
}

.install-card {
  max-width: 340px;
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 22px 24px;
}

.install-card h2 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 22px;
  margin: 0 0 8px;
}

.install-card p,
.install-card ol {
  font-size: 14px;
  margin: 0 0 10px;
}

.install-card ol {
  padding-left: 20px;
}

.install-card li {
  margin-bottom: 4px;
}

.install-alt {
  color: var(--muted);
  font-size: 13px;
}

.install-card .btn {
  display: block;
  width: 100%;
  margin-top: 6px;
}

/* ----- notch safe areas (viewport-fit=cover) ------------------------------- */
/* Zero everywhere except installed/landscape on notched phones, where the
   layout would otherwise sit under the notch or home indicator. */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.unfold-bar:not([hidden]) {
  padding-top: env(safe-area-inset-top);
  height: calc(28px + env(safe-area-inset-top));
}

.wrap.folded {
  padding-top: calc(32px + env(safe-area-inset-top));
}

/* ----- killer cages -------------------------------------------------------- */
/* Each cell draws an inset dashed border on the sides where its cage ends
   (kt/kr/kb/kl from app.js), so every cage reads as one dashed rectangle
   sitting inside the grid lines, with its sum in the top-left corner. */
.board.killer .cell {
  position: relative;
}

.board.killer .cell::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px dashed transparent;
  pointer-events: none;
}

.board.killer .cell.kt::before {
  border-top-color: var(--cage);
}
.board.killer .cell.kr::before {
  border-right-color: var(--cage);
}
.board.killer .cell.kb::before {
  border-bottom-color: var(--cage);
}
.board.killer .cell.kl::before {
  border-left-color: var(--cage);
}

.cage-sum {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: clamp(8px, 1.9vw, 11px);
  font-weight: 600;
  line-height: 1;
  color: var(--cage);
  pointer-events: none;
}

/* In a cell that carries the cage sum, pencil marks start below it — the
   top-left notes slot (where "1" lives) sits exactly under the label
   otherwise. */
.board.killer .cell.sum-cell.noted {
  padding-top: clamp(11px, 2.8vw, 14px);
}

/* Selecting or hovering a cell washes its whole cage, so the grouping reads
   at a glance. Louder states re-asserted below so they still win. */
.board.killer .cell.cage-mate {
  background: #f9eede;
}

.board.killer .cell.same {
  background: #eef3fb;
}
.board.killer .cell.selected {
  background: #d9e6fb;
}
.board.killer .cell.conflict {
  background: #fdecea;
}
.board.killer .cell.wrong {
  background: #fbd5d1;
}

/* ----- radial input wheel -------------------------------------------------- */
/* A fixed-position popup centred (viewport permitting) on the selected cell.
   The svg carries a 200x200 viewBox; the element's width/height set by script
   scale the whole dial to the board's cell size. */
.wheel {
  position: fixed;
  z-index: 60;
  transform: translate(-50%, -50%);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.wheel svg {
  display: block;
  width: 100%;
  height: 100%;
  /* svg itself lets taps through; only the slices catch them, so the open
     centre and the corners of the bounding box still reach the cells under */
  pointer-events: none;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.18));
  animation: wheel-pop 0.14s ease-out;
}

@keyframes wheel-pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.wheel .slice {
  pointer-events: auto;
  cursor: pointer;
}

/* Translucent so the board stays readable behind the dial; the open centre
   keeps the focused cell itself fully visible. */
.wheel .slice-bg {
  fill: rgba(255, 255, 255, 0.7);
  stroke: var(--grid-line);
  stroke-width: 0.75;
  transition: fill 0.1s;
}

.wheel text {
  fill: var(--muted);
  font-family: inherit;
  font-size: 22px;
  font-weight: 600;
  text-anchor: middle;
  dominant-baseline: central;
}

.wheel .slice:hover .slice-bg {
  fill: #eef3fb;
}

.wheel .slice:active .slice-bg {
  fill: var(--accent);
}

.wheel .slice:active text {
  fill: var(--accent-ink);
}

/* slice matching the cell's current answer */
.wheel .slice.is-value .slice-bg {
  fill: var(--accent);
}

.wheel .slice.is-value text {
  fill: var(--accent-ink);
}

/* slices already pencilled into the cell */
.wheel .slice.is-noted .slice-bg {
  fill: rgba(217, 230, 251, 0.85);
}

/* the notes / erase slots read as controls, not digits */
.wheel .slice-action .slice-bg {
  fill: rgba(241, 243, 246, 0.75);
}

.wheel .slice-action text,
.wheel.notes-on .slice-action text {
  font-size: 15px;
}

.wheel .slice-erase text,
.wheel.notes-on .slice-erase text {
  fill: var(--muted);
  font-size: 17px;
}

.wheel .slice-action:active .slice-bg {
  fill: rgba(217, 230, 251, 0.95);
}

.wheel.notes-on .slice-notes .slice-bg {
  fill: rgba(217, 230, 251, 0.95);
  stroke: var(--accent);
}

/* notes mode: the dial writes candidates, so it dresses like the pad does */
.wheel.notes-on .slice text {
  font-size: 18px;
  fill: var(--accent);
}

.wheel.notes-on .slice.is-value text,
.wheel.notes-on .slice:active text {
  fill: var(--accent-ink);
}

/* action glyphs keep their own colour through presses (the digit :active
   rules above would wash them out against the pale active fill) */
.wheel .slice-action:active text,
.wheel.notes-on .slice-action:active text,
.wheel.notes-on .slice-erase text {
  fill: var(--muted);
}

/* Edge and corner layouts pack the labels tighter; smaller type keeps every
   glyph inside its slimmer slice. */
.wheel.mode-fan text,
.wheel.mode-fan.notes-on .slice text {
  font-size: 16px;
}

.wheel.mode-corner text,
.wheel.mode-corner.notes-on .slice text {
  font-size: 14px;
}

.wheel.mode-fan .slice-action text,
.wheel.mode-fan.notes-on .slice-action text {
  font-size: 11px;
}

.wheel.mode-corner .slice-action text,
.wheel.mode-corner.notes-on .slice-action text {
  font-size: 10px;
}

.wheel.mode-fan .slice-erase text,
.wheel.mode-fan.notes-on .slice-erase text {
  font-size: 12px;
}

.wheel.mode-corner .slice-erase text,
.wheel.mode-corner.notes-on .slice-erase text {
  font-size: 11px;
}

/* ----- account bar --------------------------------------------------------- */
.account-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: -24px 0 4px;
  min-height: 34px;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 15px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.05s;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn:active {
  transform: translateY(1px);
}

.signin-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.signin-btn:hover {
  border-color: var(--accent);
}

/* Clerk's mounted avatar button */
#userButton {
  display: flex;
  align-items: center;
}

/* ----- dialogs ------------------------------------------------------------- */
.dialog {
  border: none;
  border-radius: 16px;
  padding: 24px;
  width: min(92vw, 380px);
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(32, 33, 36, 0.4);
}

.dialog h2 {
  font-family: Georgia, "Times New Roman", Times, serif;
  font-size: 22px;
  margin: 0 0 16px;
}

.dialog form {
  margin: 16px 0 0;
}

.dialog-note {
  font-size: 12px;
  color: var(--muted);
  margin: 14px 0 0;
}

/* ---------- plan chooser (SudokuBilling in masthead.js) ---------- */

.plan-dialog {
  width: min(92vw, 440px);
  /* fits short screens: the dialog scrolls and the buttons stay in reach */
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.plan-intro {
  margin: -6px 0 4px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.plan-options {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  border: 0;
}

.plan-legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.plan-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.plan-option:hover {
  border-color: var(--ink);
}

.plan-option.selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.plan-option input {
  flex: none;
  margin: 3px 0 0;
  accent-color: var(--ink);
}

.plan-body {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.plan-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.plan-name {
  font-size: 15px;
  font-weight: 700;
}

.plan-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--ink);
  color: var(--accent-ink);
}

.plan-price {
  font-size: 14px;
}

.plan-meta {
  font-size: 12.5px;
  color: var(--muted);
}

/* the buttons and the status line, kept in reach while the dialog scrolls */
.plan-footer {
  position: sticky;
  bottom: -24px; /* sit over the dialog's bottom padding while scrolling */
  margin: 16px 0 -24px;
  padding: 12px 0 24px;
  background: var(--card);
}

.plan-actions {
  display: flex;
  gap: 10px;
}

.plan-actions .btn {
  min-width: 0;
  white-space: normal;
}

/* phones: stack the buttons, the way forward on top */
@media (max-width: 420px) {
  .plan-actions {
    flex-direction: column-reverse;
  }
}

.plan-status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.plan-status:empty {
  display: none;
}

.setting {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.setting:last-of-type {
  border-bottom: none;
}

.setting input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.setting-name {
  display: block;
  font-weight: 600;
  font-size: 14px;
}

.setting-desc {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

/* ----- stats --------------------------------------------------------------- */
.stats-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stats-tile {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 6px;
  text-align: center;
}

.stats-num {
  display: block;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stats-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.stats-table th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  font-weight: 600;
  text-align: right;
  padding: 6px 4px;
}

.stats-table td {
  padding: 6px 4px;
  text-align: right;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.stats-diff,
.stats-table th:first-child {
  text-align: left;
  text-transform: capitalize;
  font-weight: 600;
}

.stats-pitch {
  font-size: 14px;
  color: var(--muted);
  margin: 0 0 14px;
}

/* ----- puzzle coach -------------------------------------------------------- */
.coach {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  font-size: 14px;
  line-height: 1.45;
}

.coach-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
}

.coach-text {
  flex: 1 1 240px;
}

.coach-why {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  white-space: nowrap;
}

.coach-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  white-space: nowrap;
}

/* praise for a placement that followed the tip — same green as the win line */
.coach-ack {
  color: #188038;
  font-weight: 600;
}

/* A fresh tip announces itself: the bar's accent edge flashes and the new
   text slides in. The class is re-applied per change (see setCoachMessage),
   so the animation runs once each time the advice actually changes. */
.coach-fresh {
  animation: coach-flash 0.8s ease-out;
}

.coach-fresh .coach-text {
  animation: coach-slide 0.35s ease-out;
}

@keyframes coach-flash {
  0% {
    background: rgba(43, 108, 176, 0.14);
    border-left-color: #188038;
  }
  100% {
    background: var(--card);
    border-left-color: var(--accent);
  }
}

@keyframes coach-slide {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .coach-fresh,
  .coach-fresh .coach-text {
    animation: none;
  }
}

.coach-dialog p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.55;
}

.coach-dialog-actions {
  margin-top: 4px;
}

.coach-lesson-link {
  display: inline-block;
  font-size: 14px;
  color: var(--accent);
}
