/* SudoTutor – mobile-first styles. Colors are tokens so a dark theme can be added later (D5). */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ink: #1f2933;          /* givens */
  --ink-muted: #52606d;
  --ink-player: #1e40af;   /* player digits: >= 4.5:1 on every fill (S-4) */
  --ink-note: #3e4c59;     /* pencil notes: >= 4.5:1 on every fill, since they are small (P-3) */
  --line-cell-color: #66707c; /* >= 3:1 on white and every fill below (B-1) */
  --line-box-color: #1f2933;
  --line-cell: 1px;
  --line-box: 3px;
  --fill-peer: #e9eef5;
  --fill-same: #ccd9ee;
  --fill-selected: #b9cdf0;
  --ring: #1d4ed8;
  --focus: #1d4ed8;
  --control-border: #c3cad3;
  --control-press: #e9eef5;

  --gap: 8px;
  --control: 44px;         /* K-4 minimum touch target */
  --tip-height: calc(var(--control) + 2px); /* 44px close button + 1px top and bottom border */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* L-2 fit rule. --chrome-height reserves room for everything stacked with the board:
   top bar + action row + two keypad rows (with their 6px gap) + three gaps between sections.
   The tip line adds its full rendered height plus one more gap while it shows. Below --board-min the board stops
   shrinking and the stacked page scrolls vertically instead (L-4). */
.game {
  --chrome-height: calc(4 * var(--control) + 6px + 3 * var(--gap));
  --board-min: 252px;
  --board-size: min(
    100vw - 16px,
    max(100vh - var(--chrome-height) - var(--safe-top) - var(--safe-bottom), var(--board-min)),
    720px
  );
}
.game:has(.tip:not([hidden])) { --chrome-height: calc(4 * var(--control) + var(--tip-height) + 6px + 4 * var(--gap)); }
@supports (height: 100dvh) {
  .game {
    --board-size: min(
      100vw - 16px,
      max(100dvh - var(--chrome-height) - var(--safe-top) - var(--safe-bottom), var(--board-min)),
      720px
    );
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden; /* L-3 */
}

.game {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
  min-height: 100vh;
  padding: var(--safe-top) max(8px, env(safe-area-inset-right, 0px)) var(--safe-bottom) max(8px, env(safe-area-inset-left, 0px));
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: var(--board-size);
  min-height: var(--control);
}
.brand { margin: 0; font-size: 1.125rem; font-weight: 700; letter-spacing: 0.01em; }
.tier { font-size: 0.9375rem; color: var(--ink-muted); }

/* Board */
.board {
  display: grid;
  grid-template-rows: repeat(9, 1fr);
  width: var(--board-size);
  height: var(--board-size);
  background: var(--surface);
  border: var(--line-box) solid var(--line-box-color);
  touch-action: manipulation; /* K-5 */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.board:focus { outline: none; }
.board:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; } /* K-2 */

.row { display: grid; grid-template-columns: repeat(9, 1fr); min-height: 0; }

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-right: var(--line-cell) solid var(--line-cell-color);
  border-bottom: var(--line-cell) solid var(--line-cell-color);
  font-size: calc(var(--board-size) / 9 * 0.56);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.cell:nth-child(9) { border-right: 0; }
.row:last-child .cell { border-bottom: 0; }
.cell.box-edge-right { border-right: var(--line-box) solid var(--line-box-color); }
.cell.box-edge-bottom { border-bottom: var(--line-box) solid var(--line-box-color); }

.cell.given { font-weight: 700; color: var(--ink); }      /* B-3 */
.cell.editable { font-weight: 400; color: var(--ink-player); }

/* S-2 / S-3: peer < same digit < selected. The ring carries meaning without color (S-4). */
.cell.peer { background: var(--fill-peer); }
.cell.same-digit { background: var(--fill-same); }
.cell.selected { background: var(--fill-selected); box-shadow: inset 0 0 0 2px var(--ring); }

/* P-3 pencil notes: a positional 3x3 grid, digit n always in slot n. At a 39 px cell (L-2, 375 px wide)
   each slot is about 13 px and the digit about 11.5 px. */
.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
  font-size: calc(var(--board-size) / 9 * 0.3);
  font-weight: 500;
  color: var(--ink-note);
}
.notes span { display: flex; align-items: center; justify-content: center; }

@media (hover: hover) {
  .cell:not(.selected):hover { box-shadow: inset 0 0 0 1px var(--line-cell-color); }
}

/* G-5 / K-3 tip line */
.tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  width: var(--board-size);
  min-height: var(--tip-height);
  margin: 0;
  padding-left: 12px;
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  font-size: 0.9375rem;
  color: var(--ink-muted);
}
.tip[hidden] { display: none; }
.tip-close {
  width: var(--control);
  height: var(--control);
  flex: none;
  border: 0;
  background: none;
  color: var(--ink-muted);
  font: inherit;
  font-size: 1.375rem;
  cursor: pointer;
  touch-action: manipulation; /* K-5 */
  -webkit-tap-highlight-color: transparent;
}

/* L-1 action row and two-row keypad, all at least 44 x 44 (K-4) */
.actions, .keypad-row {
  display: flex;
  gap: 6px;
  width: var(--board-size);
}
.keypad { display: flex; flex-direction: column; gap: 6px; }
.keypad-row { justify-content: center; }

.action, .key {
  flex: 1 1 0;
  min-width: var(--control);
  min-height: var(--control);
  max-width: calc((var(--board-size) - 24px) / 5); /* keeps the 4-key row the same key width */
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation; /* K-5 */
  -webkit-tap-highlight-color: transparent;
}
.action { max-width: none; font-size: 1rem; font-weight: 600; }
.key { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.action:active:not(:disabled), .key:active { background: var(--control-press); }
.action:disabled { color: var(--ink-muted); opacity: 0.55; cursor: default; }
/* P-1: Notes mode on. The label says so in text; the fill and ring echo it. */
.action.on { background: var(--fill-selected); border-color: var(--ring); color: var(--ink); }

button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } /* K-2 */

/* Read by screen readers, not shown (Undo announcements). */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
