/* Sudoku. Functional layout before the design pass; existing tokens only (audit S2).
   Mobile: bar (level, mistakes, time, pause), board, actions, numpad row.
   900 px and up: board left; bar, actions, 3×3 numpad and New game right.
   Derived colors (color-mix of tokens) are listed for design review in docs/follow-ups.md. */

.g-sudoku { padding-block: var(--s3) var(--s7); }
/* On the card: it carries .sw-cobalt, so --field and --light resolve here */
.g-sudoku__game {
  --sd-user: var(--field);                                   /* digits the player placed */
  --sd-wrong: var(--state-wrong);
  --sd-same: color-mix(in srgb, var(--field) 22%, var(--surface));
  --sd-select: color-mix(in srgb, var(--field) 30%, var(--surface));
  --sd-conflict: color-mix(in srgb, var(--state-wrong) 18%, var(--surface));
  --sd-hint: color-mix(in srgb, var(--state-correct) 16%, var(--surface));
}
/* Dark: cobalt and the wrong red fall under 3:1 on the dark highlights, so lighter variants */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .g-sudoku__game {
    --sd-user: var(--light);
    --sd-wrong: color-mix(in srgb, var(--state-wrong) 65%, var(--ink));
  }
}
:root[data-theme="dark"] .g-sudoku__game {
  --sd-user: var(--light);
  --sd-wrong: color-mix(in srgb, var(--state-wrong) 65%, var(--ink));
}

.g-sudoku__intro { margin-bottom: var(--s3); }
.g-sudoku__intro h1 { font-size: 24px; }
.g-sudoku__intro p { margin-top: var(--s1); max-width: 60ch; }
.g-sudoku__note { margin-bottom: var(--s3); }

/* ---------- game card ---------- */
.g-sudoku__game {
  position: relative; max-width: 560px; padding: var(--s2);
  display: grid; gap: var(--s3);
  grid-template-areas: "bar" "board" "actions" "pad" "tools";
}
.g-sudoku__game:focus { outline: none; }
.g-sudoku__bar { grid-area: bar; display: flex; align-items: center; gap: var(--s2); min-height: 44px; }
.g-sudoku__bar .stat { text-align: center; }
.g-sudoku__bar .stat[hidden] { display: none; }
.g-sudoku__bar .stat__label { font-size: 11px; }
.g-sudoku__bar .stat__value { font-size: 16px; }
.g-sudoku__level, .g-sudoku__pause-btn { padding-inline: 12px; }
.g-sudoku__level { margin-right: auto; }
.g-sudoku__pause-btn { margin-left: auto; min-width: 76px; } /* Pause and Resume keep one width */

/* ---------- board ---------- */
.g-sudoku__board {
  grid-area: board; position: relative; container-type: inline-size;
  width: 100%; aspect-ratio: 1; display: flex; flex-direction: column;
  border: 2px solid var(--ink); background: var(--surface);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
/* Thick box lines drawn over the cells, so every cell keeps the same size */
.g-sudoku__board::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(var(--ink) 0 0) 33.333% 0 / 2px 100% no-repeat,
    linear-gradient(var(--ink) 0 0) 66.667% 0 / 2px 100% no-repeat,
    linear-gradient(var(--ink) 0 0) 0 33.333% / 100% 2px no-repeat,
    linear-gradient(var(--ink) 0 0) 0 66.667% / 100% 2px no-repeat;
}
.g-sudoku__row { flex: 1; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); min-height: 0; }
.g-sudoku__cell {
  position: relative; display: grid; place-items: center; min-width: 0;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--surface); cursor: pointer;
}
.g-sudoku__cell:focus { outline: none; }
.g-sudoku__cell:focus-visible { outline: none; } /* the selected-cell ring is the focus indicator */
.g-sudoku__digit { font-size: calc(100cqi / 9 * .6); line-height: 1; font-weight: 700; color: var(--sd-user); font-variant-numeric: tabular-nums; }
.g-sudoku__cell.is-given .g-sudoku__digit { color: var(--ink); font-weight: 800; }
.g-sudoku__cell.is-wrong .g-sudoku__digit {
  color: var(--sd-wrong);
  text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .12em; /* non-color cue */
}
.g-sudoku__notes {
  position: absolute; inset: 1px; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); place-items: center;
  font-size: calc(100cqi / 9 * .27); line-height: 1; color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.g-sudoku__notes .is-match { color: var(--ink); font-weight: 800; }
/* Highlight tiers, weakest first: area, identical digit, duplicate, selected */
.g-sudoku__cell.is-area { background: var(--surface-2); }
.g-sudoku__cell.is-same { background: var(--sd-same); }
.g-sudoku__cell.is-conflict { background: var(--sd-conflict); }
.g-sudoku__cell.is-selected { background: var(--sd-select); box-shadow: inset 0 0 0 2px var(--ink); }
/* Smart hint: the step's cells tinted, the cell to fill ringed, removed candidates struck out */
.g-sudoku__cell.is-hint { background: var(--sd-hint); }
.g-sudoku__cell.is-hint-target { box-shadow: inset 0 0 0 3px var(--state-correct); }
.g-sudoku__notes .is-gone { color: var(--sd-wrong); text-decoration: line-through; text-decoration-thickness: 2px; }
.g-sudoku__loading { margin: auto; color: var(--ink-2); padding: var(--s4); text-align: center; }

/* ---------- actions and numpad ---------- */
.g-sudoku__actions { grid-area: actions; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.g-sudoku__actions .btn, .g-sudoku__num { touch-action: manipulation; padding-inline: 4px; min-width: 0; }
.g-sudoku__actions .btn { font-size: 15px; line-height: 1.1; }
/* Notes shows its state on a second line so it fits a quarter of 328 px */
.g-sudoku__actions [data-action="notes"] { flex-direction: column; gap: 0; }
.g-sudoku__actions .btn[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.g-sudoku__onoff { font-size: 12px; font-weight: 800; }
.g-sudoku__pad { grid-area: pad; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.g-sudoku__num {
  min-height: 56px; font-size: 28px; font-weight: 700; font-stretch: 100%;
  background: var(--surface-2); color: var(--ink); border-radius: 8px;
}
.g-sudoku__num:hover { background: color-mix(in srgb, var(--ink) 10%, var(--surface-2)); }
.g-sudoku__num.is-done { visibility: hidden; }
.g-sudoku__newgame { grid-area: new; display: none; }
.g-sudoku__hint { grid-area: tools; display: grid; gap: var(--s2); padding: var(--s3); border-radius: 12px; background: var(--surface-2); }
.g-sudoku__hint[hidden] { display: none; }
.g-sudoku__hint p { font-size: 15px; line-height: 1.4; }
.g-sudoku__hint-actions { display: flex; gap: var(--s2); }
.g-sudoku__game.has-hint .g-sudoku__tools { display: none; }
.g-sudoku__game.is-paused .g-sudoku__hint { visibility: hidden; }
.g-sudoku__tools { grid-area: tools; display: flex; justify-content: center; gap: var(--s2); margin-top: calc(-1 * var(--s2)); }

/* ---------- pause: hides board, actions and numpad (§7.7) ---------- */
.g-sudoku__game.is-paused .g-sudoku__board,
.g-sudoku__game.is-paused .g-sudoku__actions,
.g-sudoku__game.is-paused .g-sudoku__pad { visibility: hidden; }
.g-sudoku__pause { grid-area: board; position: relative; inset: auto; border-radius: 0; align-content: center; padding: var(--s5); }

/* ---------- dialogs ---------- */
.g-sudoku__levels { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
.g-sudoku__lvl { width: 100%; justify-content: space-between; }
.g-sudoku__lvl-note { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.g-sudoku__warn { margin-bottom: var(--s4); font-weight: 600; }
.g-sudoku__dlg .figs { margin-bottom: var(--s2); }
.g-sudoku__dlg .fig dd { font-size: 28px; }
.g-sudoku__won-note { margin-top: var(--s3); }
.g-sudoku__dlg .fig dt .chip { vertical-align: 1px; margin-left: 4px; }
.g-sudoku__seg { margin-bottom: var(--s4); flex-wrap: wrap; border-radius: 22px; } /* six levels wrap at 360 px */
.g-sudoku__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 480px) { .g-sudoku__stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.g-sudoku__stats .fig dd { font-size: 22px; }
.g-sudoku__reset { margin-top: var(--s5); }
.g-sudoku__reset p { font-weight: 600; }
.g-sudoku__settings fieldset { border: 0; margin: 0; padding: 0; display: grid; }
.g-sudoku__settings fieldset + fieldset { margin-top: var(--s5); }
.g-sudoku__settings legend { padding: 0; margin-bottom: var(--s1); }
.g-sudoku__settings label { display: flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; }
.g-sudoku__settings input { width: 20px; height: 20px; accent-color: var(--ink); margin: 0; }
.g-sudoku__settings label:has(input:disabled) { color: var(--ink-2); cursor: not-allowed; }

/* ---------- text below the game ---------- */
.g-sudoku__about { max-width: 62ch; margin-top: var(--s6); }
.g-sudoku__about h2 { margin: var(--s6) 0 var(--s3); }
.g-sudoku__about h2:first-child { margin-top: 0; }
.g-sudoku__about h3 { margin: var(--s4) 0 var(--s2); }
.g-sudoku__about ol { padding-left: 1.25em; margin: var(--s3) 0 0; }
.g-sudoku__about li + li { margin-top: 6px; }
.g-sudoku__keys { border-collapse: collapse; font-size: 15px; }
.g-sudoku__keys th, .g-sudoku__keys td { text-align: left; padding: 6px var(--s4) 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.g-sudoku__keys th { font-weight: 600; white-space: nowrap; }

/* ---------- wide: board left, controls right ---------- */
@media (min-width: 900px) {
  .g-sudoku__game {
    max-width: 920px; padding: var(--s5); column-gap: var(--s6); row-gap: var(--s4); align-items: start;
    grid-template-columns: minmax(0, 560px) minmax(260px, 1fr);
    grid-template-rows: auto auto auto auto 1fr;
    grid-template-areas: "board bar" "board actions" "board pad" "board new" "board tools";
  }
  .g-sudoku__bar { flex-wrap: wrap; }
  .g-sudoku__level { margin-right: 0; }
  .g-sudoku__pad { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
  .g-sudoku__num { min-height: 72px; font-size: 32px; }
  .g-sudoku__newgame { display: inline-flex; width: 100%; }
  .g-sudoku__tools { margin-top: 0; }
}
