/* Sudoku tool. Every rule is scoped to .pv-sudoku (the site root) or its pv-sudoku__* parts and reads
   only the site's theme tokens (--text, --muted, --line, --panel, --accent, --accent-dark, --danger,
   --pv-*), so the light/dark switch restyles it without re-mounting.
   One workbench laid out as the board-first play deck (GAME_UIUX_IMPROVEMENT_SPEC §4, §6): the HUD
   (puzzle name and time; status with the one contextual action and New puzzle/Replay), the board, the
   result right after it and the side deck (input line, Notes/Erase, number pad, legend) — below the
   board, beside it from 60rem. Touch buttons and board cells are at least 44 CSS px (cells 48px from
   60rem, growing with enlarged digits as 1.9em of a 1.25rem cell, plus 6px halo padding) inside the
   only scroll region (overflow: auto, up to max(70vh, 100svh − 9rem) tall); below 30rem that region
   spans the page gutters. 320px screens and 200%/400% text scroll the board instead of shrinking the
   page or blocking pinch zoom. Spacing is capped by the viewport width (min(rem, vw)) so enlarged text
   keeps its usable width; text sizes are never reduced and nothing is clipped. No inline styles are
   needed (CSP style-src 'self'): the first calendar day uses a static offset class. [hidden] always
   wins; fixed cells, duplicates, selection and its peer/same-digit marks are shown by
   weight/borders/text and aria, not colour alone. */

.pv-sudoku {
  --su-gap-xs: min(0.25rem, 1vw);
  --su-gap-s: min(0.5rem, 2vw);
  --su-gap-m: min(0.75rem, 3vw);
  --su-gap-l: min(1rem, 3vw);
  --su-gap-xl: min(1.25rem, 4vw);
  --su-radius: min(0.75rem, 12px);
  min-width: 0;
  max-width: 100%;
  color: var(--text);
  overflow-wrap: anywhere;
}

.pv-sudoku [hidden],
.pv-sudoku__game [hidden] {
  display: none !important;
}

.pv-sudoku__game {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--su-gap-l);
  min-width: 0;
  max-width: 100%;
}

.pv-sudoku__game > * {
  min-width: 0;
}

.pv-sudoku__notes-block,
.pv-sudoku__storage {
  display: grid;
  gap: var(--su-gap-s);
  min-width: 0;
}

/* One wrapping bar: Daily puzzle → "Free play difficulty" → the three levels (GAME_UIUX_IMPROVEMENT_SPEC
   §6.5); the daily date line and the new-date offer take a full row of their own. */
.pv-sudoku__selectors {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  min-width: 0;
}

.pv-sudoku__selectors > .pv-sudoku__note--date,
.pv-sudoku__selectors > .pv-sudoku__restore {
  flex: 1 1 100%;
}

.pv-sudoku__note,
.pv-sudoku__storage-status,
.pv-sudoku__mode-line {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-sudoku__mode-line {
  font-size: 1.0625rem;
  font-weight: 700;
}

.pv-sudoku__storage-status {
  padding: var(--su-gap-s) var(--su-gap-m);
  border-left: 3px solid var(--pv-info-line);
  background: var(--pv-info-bg);
}

/* Loading/saving/saved: one quiet line; memory-only and failures keep the information box. */
.pv-sudoku__storage-status--quiet {
  padding: 0;
  border-left: 0;
  background: transparent;
  color: var(--muted);
}

.pv-sudoku__levels-label {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.pv-sudoku__note--muted {
  color: var(--muted);
}

.pv-sudoku__js {
  margin: 0;
  padding: var(--su-gap-s) var(--su-gap-m);
  border: 1px solid var(--pv-warning-line);
  border-radius: min(0.5rem, 8px);
  background: var(--pv-warning-bg);
  font-weight: 600;
}

/* The saved-game choice and the new-date offer are information, not warnings. */
.pv-sudoku__restore {
  display: grid;
  gap: var(--su-gap-s);
  padding: var(--su-gap-m) var(--su-gap-l);
  border: 1px solid var(--pv-info-line);
  border-radius: min(0.5rem, 8px);
  background: var(--pv-info-bg);
}

.pv-sudoku__restore-text {
  margin: 0;
  font-weight: 600;
}

.pv-sudoku__segmented,
.pv-sudoku__actions,
.pv-sudoku__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--su-gap-s);
  min-width: 0;
}

.pv-sudoku__workbench {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--su-gap-l);
  min-width: 0;
  max-width: 100%;
  padding: var(--su-gap-l);
  border: 1px solid var(--line);
  border-radius: var(--su-radius);
  background: var(--panel);
}

.pv-sudoku__workbench > * {
  min-width: 0;
}

.pv-sudoku__button {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  padding: var(--su-gap-s) var(--su-gap-l);
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent-dark);
  font: inherit;
  font-weight: 600;
  word-break: keep-all;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}

.pv-sudoku__button[aria-pressed="true"],
.pv-sudoku__button--primary {
  background: var(--accent);
  color: var(--pv-on-primary);
}

/* The chosen level/mode is also underlined, so it is not shown by colour alone. */
.pv-sudoku__button[aria-pressed="true"] {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}

.pv-sudoku__button:disabled,
.pv-sudoku__button[aria-disabled="true"] {
  border-color: var(--pv-disabled-line);
  background: var(--pv-disabled-bg);
  color: var(--pv-disabled-text);
  cursor: not-allowed;
}

.pv-sudoku__button:focus-visible,
.pv-sudoku__day:focus-visible {
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

.pv-sudoku__hud {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--su-gap-s);
  min-width: 0;
}

/* Puzzle name at the start, time at the end; they wrap to two lines instead of overflowing. */
.pv-sudoku__hud-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--su-gap-xs) var(--su-gap-l);
  min-width: 0;
}

.pv-sudoku__state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--su-gap-s) min(1.5rem, 4vw);
  min-width: 0;
}

/* New puzzle / Replay sit at the row end, after the one contextual action. */
.pv-sudoku__state > .pv-sudoku__controls {
  margin-inline-start: auto;
}

.pv-sudoku__status {
  flex: 1 1 100%;
  min-height: 1.6em;
  margin: 0;
  font-weight: 700;
}

.pv-sudoku__alert {
  flex: 1 1 100%;
  margin: 0;
  padding: var(--su-gap-m) var(--su-gap-l);
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--pv-error-bg);
  color: var(--danger);
  font-weight: 600;
}

.pv-sudoku__notice {
  flex: 1 1 100%;
  margin: 0;
  padding: var(--su-gap-s) var(--su-gap-m);
  border-left: 3px solid var(--pv-warning-line);
  background: var(--pv-warning-bg);
}

/* Held lines (SCREEN_FIX_FOLLOWUP_SPEC C1): a routine line keeps one height. The view names the alternatives
   it may show next in data-su-hold / data-su-hold-2; both copies share the row of the live text at its full
   width and are invisible (not painted, read or selectable), so the line is as tall as the tallest of them.
   Inline-size containment keeps the copies out of the line's intrinsic width: only the live text sizes the
   desktop workbench column the HUD spans, as before. */
.pv-sudoku [data-su-hold] {
  display: flex;
}

.pv-sudoku [data-su-hold]::before,
.pv-sudoku [data-su-hold]::after {
  flex: none;
  order: -1;
  width: 100%;
  margin-inline-end: -100%;
  contain: inline-size;
  visibility: hidden;
  content: attr(data-su-hold);
}

.pv-sudoku [data-su-hold]::after {
  content: attr(data-su-hold-2);
}

.pv-sudoku__time {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pv-sudoku__visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* The one intentional 2D scroll region: the board only. */
.pv-sudoku__scroll {
  position: relative;
  box-sizing: border-box;
  width: max-content;
  max-width: 100%;
  min-width: 0;
  max-height: 70vh;
  overflow: auto;
  border: 1px solid var(--pv-control);
  border-radius: min(0.5rem, 8px);
  background: var(--pv-sunken);
}

/* The small viewport height leaves room for the HUD line above the board when browser bars show. */
@supports (height: 1svh) {
  .pv-sudoku__scroll {
    max-height: max(70vh, calc(100svh - 9rem));
  }
}

/* 9 cells of max(44px, 1.9em) plus the 6px halo; enlarged digits widen the board inside its region. */
.pv-sudoku__board {
  box-sizing: border-box;
  display: grid;
  width: max-content;
  padding: 6px;
}

.pv-sudoku__row {
  display: grid;
  grid-template-columns: repeat(9, max-content);
  gap: 0;
}

.pv-sudoku__gridcell {
  display: flex;
  min-width: 0;
}

/* scroll-margin: the board's 6px halo (view.js HALO), so the nearest page scroll of a keyboard move also keeps
   the focus indicator inside the viewport. */
.pv-sudoku__cell {
  position: relative;
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: max(44px, 1.9em);
  height: max(44px, 1.9em);
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--pv-rule);
  border-radius: 0;
  background: var(--panel);
  color: var(--accent-dark);
  font: inherit;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  scroll-margin: 6px;
}

/* The outer frame and the 3×3 box lines. */
.pv-sudoku__cell--box-top {
  border-top: 3px solid var(--text);
}

.pv-sudoku__cell--box-left {
  border-left: 3px solid var(--text);
}

.pv-sudoku__cell--box-right {
  border-right: 3px solid var(--text);
}

.pv-sudoku__cell--box-bottom {
  border-bottom: 3px solid var(--text);
}

.pv-sudoku__cell--given {
  background: var(--pv-soft);
  color: var(--text);
  font-weight: 800;
}

/* Selection marks in source order peer < same digit < selected < duplicate, all single-class rules of
   the same specificity, so a duplicate always keeps its own background (the view never marks a fixed
   cell as a peer). They change backgrounds only: the digit weight stays the fixed/entered cue. */
.pv-sudoku__cell--peer {
  background: var(--pv-selected);
}

.pv-sudoku__cell--same {
  background: var(--pv-selection);
}

.pv-sudoku__cell--selected {
  background: var(--pv-soft);
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

/* Duplicates: colour plus a dashed inner frame and an underline on the digit. */
.pv-sudoku__cell--conflict {
  background: var(--pv-error-bg);
  color: var(--danger);
  box-shadow: inset 0 0 0 2px var(--danger);
}

.pv-sudoku__cell--conflict .pv-sudoku__value {
  text-decoration: underline wavy;
  text-underline-offset: 0.15em;
}

.pv-sudoku__cell[aria-disabled="true"] {
  cursor: default;
}

.pv-sudoku__cell:focus-visible {
  z-index: 1;
  outline: 3px solid var(--pv-focus);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px var(--pv-halo);
}

/* The value and the notes share the cell's single grid area; an empty one takes no visible space. */
.pv-sudoku__value {
  grid-area: 1 / 1;
  font-size: 1.1em;
  font-weight: inherit;
}

/* Nine fixed note positions: digit d in slot d of a 3×3 grid. */
.pv-sudoku__notes {
  display: grid;
  grid-area: 1 / 1;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-self: stretch;
  justify-self: stretch;
  padding: 2px;
  color: var(--muted);
  font-size: 0.55em;
  font-weight: 600;
  line-height: 1;
}

.pv-sudoku__note-slot {
  display: grid;
  place-items: center;
}

/* Side deck: the input line, Notes/Erase and the number pad, then the legend. One shrinkable column:
   an auto track would grow to the pad's and buttons' min-content and push the page wider. */
.pv-sudoku__side,
.pv-sudoku__deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--su-gap-m);
  min-width: 0;
  align-content: start;
}

.pv-sudoku__side > *,
.pv-sudoku__deck > *,
.pv-sudoku__hud > * {
  min-width: 0;
}

.pv-sudoku__input-status {
  min-height: 1.6em;
  margin: 0;
  font-weight: 700;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.pv-sudoku__tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--su-gap-s);
  min-width: 0;
}

.pv-sudoku__tools .pv-sudoku__button {
  flex: 1 1 6rem;
}

/* Tracks of at least 44px (or 2.25 digit widths when enlarged), never wider than the pad itself. */
.pv-sudoku__pad {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(44px, 2.25em)), 1fr));
  gap: var(--su-gap-s);
  max-width: 34rem;
}

.pv-sudoku__digit {
  padding: var(--su-gap-s);
  font-size: 1.25rem;
}

/* Notes mode: the pad keys change shape (dashed frame), not only the input line; the thicker frame takes its
   1px from the padding, so no key moves. */
.pv-sudoku__pad--notes .pv-sudoku__digit {
  border-style: dashed;
  border-width: 2px;
  padding: calc(var(--su-gap-s) - 1px);
}

.pv-sudoku__result {
  display: grid;
  gap: var(--su-gap-s);
  padding: var(--su-gap-m) var(--su-gap-l);
  border: 1px solid var(--pv-info-line);
  border-radius: min(0.5rem, 8px);
  background: var(--pv-info-bg);
}

.pv-sudoku__result-line {
  margin: 0;
  font-weight: 600;
}

.pv-sudoku__panel {
  display: grid;
  gap: var(--su-gap-s);
  padding: var(--su-gap-l);
  border: 1px solid var(--line);
  border-radius: var(--su-radius);
  background: var(--panel);
}

.pv-sudoku__panel-title {
  margin: 0;
  font-size: 1.125rem;
}

.pv-sudoku__subhead {
  margin: var(--su-gap-s) 0 0;
  font-size: 1rem;
}

.pv-sudoku__list {
  display: grid;
  gap: var(--su-gap-xs);
  margin: 0;
  padding-left: min(1.25rem, 6vw);
}

.pv-sudoku__item {
  line-height: 1.5;
}

.pv-sudoku__month-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--su-gap-s);
}

.pv-sudoku__month {
  margin: 0;
  font-weight: 700;
}

/* Sunday-first month: seven weekday columns of 44px touch targets (wide screens, see the 30em query). */
.pv-sudoku__days {
  display: none;
  grid-template-columns: repeat(7, minmax(44px, 1fr));
  gap: var(--su-gap-xs);
  max-width: 28rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pv-sudoku__day-slot {
  min-width: 0;
}

/* Column of day 1 by its weekday (0 = Sunday). */
.pv-sudoku__day-slot--offset-0 {
  grid-column-start: 1;
}

.pv-sudoku__day-slot--offset-1 {
  grid-column-start: 2;
}

.pv-sudoku__day-slot--offset-2 {
  grid-column-start: 3;
}

.pv-sudoku__day-slot--offset-3 {
  grid-column-start: 4;
}

.pv-sudoku__day-slot--offset-4 {
  grid-column-start: 5;
}

.pv-sudoku__day-slot--offset-5 {
  grid-column-start: 6;
}

.pv-sudoku__day-slot--offset-6 {
  grid-column-start: 7;
}

.pv-sudoku__day {
  box-sizing: border-box;
  width: 100%;
  min-width: 44px;
  min-height: 44px;
  padding: var(--su-gap-xs);
  border: 1px solid var(--pv-rule);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.pv-sudoku__day--attempted {
  border-style: dashed;
}

.pv-sudoku__day--completed {
  border-color: var(--accent);
  font-weight: 700;
}

.pv-sudoku__day--today {
  box-shadow: inset 0 0 0 2px var(--text);
}

.pv-sudoku__day[aria-pressed="true"] {
  background: var(--accent);
  color: var(--pv-on-primary);
}

/* Narrow screens: the same Sunday-first month as a noninteractive seven-column display (cells may be
   smaller than 44px because they are not controls) and one native date select as the 44px target. */
.pv-sudoku__calendar-narrow {
  display: grid;
  gap: var(--su-gap-s);
  min-width: 0;
}

/* Seven equal columns that never exceed the container (B7-C1: min-content columns of enlarged weekday
   text pushed the page 5px wider at 320px / 32px text); a too-long mark wraps inside its slot. */
.pv-sudoku__display-days {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--su-gap-xs);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pv-sudoku__display-slot {
  min-width: 0;
  padding: var(--su-gap-xs) 0;
  border: 1px solid var(--pv-rule);
  border-radius: 4px;
  font-size: 0.875rem;
  line-height: 1.3;
  text-align: center;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.pv-sudoku__display-slot--attempted {
  border-style: dashed;
}

.pv-sudoku__display-slot--completed {
  border-color: var(--accent);
  font-weight: 700;
}

.pv-sudoku__display-slot--today {
  box-shadow: inset 0 0 0 2px var(--text);
}

.pv-sudoku__display-slot--selected {
  background: var(--accent);
  color: var(--pv-on-primary);
  text-decoration: underline;
}

.pv-sudoku__select-label {
  font-weight: 600;
}

.pv-sudoku__select {
  box-sizing: border-box;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  padding: var(--su-gap-s) var(--su-gap-m);
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.pv-sudoku__select:focus-visible {
  outline: 3px solid var(--pv-focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--pv-halo);
}

/* Exactly one presentation: the interactive 44px day grid only where seven of them fit. */
@media (min-width: 30em) {
  .pv-sudoku__days {
    display: grid;
  }

  .pv-sudoku__calendar-narrow {
    display: none;
  }
}

/* The modal uses the viewport (not the UA's font-relative margin), scrolls inside itself when its
   enlarged text is taller than the screen, and keeps its spacing small so labels have width. */
.pv-sudoku__dialog {
  box-sizing: border-box;
  width: min(28rem, calc(100% - 16px));
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  overflow: auto;
  padding: var(--su-gap-xl);
  border: 1px solid var(--line);
  border-radius: var(--su-radius);
  background: var(--panel);
  color: var(--text);
}

.pv-sudoku__dialog::backdrop {
  background: var(--pv-backdrop, rgb(0 0 0 / 0.45));
}

.pv-sudoku__dialog-message {
  margin: 0 0 var(--su-gap-l);
  line-height: 1.6;
}

/* What the confirmed action starts ("Next: …"), between the canonical message and the buttons. */
.pv-sudoku__dialog-target {
  margin: 0 0 var(--su-gap-l);
  font-weight: 700;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

@media (min-width: 48rem) {
  .pv-sudoku__workbench {
    gap: 1.25rem;
    padding: 1.25rem;
  }
}

/* Under 30rem: the workbench card gives its side padding and frame back to the board, and the board
   region spans the page gutters (its outer width is exactly the document width, so the page never
   overflows); a board wider than that scrolls inside the region. */
@media not all and (min-width: 30rem) {
  .pv-sudoku__workbench {
    padding-inline: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
  }

  .pv-sudoku__scroll {
    width: calc(100% + 2 * var(--pv-gutter));
    max-width: none;
    margin-inline: calc(-1 * var(--pv-gutter));
    border-inline-width: 0;
    border-radius: 0;
  }

  .pv-sudoku__board {
    margin-inline: auto;
  }
}

/* From 60rem the side deck sits beside the board (DOM order: HUD, board, result, side); cells grow to
   48px and the pad becomes a 3×3 keypad. */
@media (min-width: 60rem) {
  .pv-sudoku__workbench {
    grid-template-columns: minmax(0, max-content) minmax(14rem, 20rem);
    grid-template-areas: "hud hud" "board side" "result side";
    column-gap: 2rem;
    justify-content: start;
    align-items: start;
  }

  .pv-sudoku__hud {
    grid-area: hud;
  }

  .pv-sudoku__scroll {
    grid-area: board;
  }

  .pv-sudoku__result {
    grid-area: result;
  }

  .pv-sudoku__side {
    grid-area: side;
  }

  .pv-sudoku__cell {
    width: max(48px, 1.9em);
    height: max(48px, 1.9em);
  }

  .pv-sudoku__value {
    font-size: 1.2em;
  }

  .pv-sudoku__notes {
    font-size: 0.6em;
  }

  .pv-sudoku__pad {
    grid-template-columns: repeat(3, minmax(44px, 1fr));
  }
}
