/* Sudoku. */

.su { container-type: inline-size; display: grid; justify-content: center; }

/* The grid is square. It is as wide as its column, but never so tall that the key pad under it
   is pushed off the screen: the bars above it and the pad below take about 296px at the usual
   text size. That room is kept in fixed units, as is the 240px floor: a visitor who sets larger
   text must not get a smaller grid for it (the page then scrolls a little to reach the pad). */
.su-grid {
  --side: max(min(100cqw, 240px), min(100cqw, calc(100vh - 296px), 31.5rem));
  --side: max(min(100cqw, 240px), min(100cqw, calc(100svh - 296px), 31.5rem));
  width: var(--side); height: var(--side);
  display: grid; grid-template-rows: repeat(9, 1fr);
  border: 2px solid var(--ink); border-radius: 3px; background: var(--sheet); overflow: hidden;
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.su-row { display: grid; grid-template-columns: repeat(9, 1fr); min-height: 0; }
.su-gc { display: block; min-width: 0; min-height: 0; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.su-gc:nth-child(3n) { border-right: 2px solid var(--ink); }
.su-gc:nth-child(9) { border-right: 0; }
.su-row:nth-child(3n) > .su-gc { border-bottom: 2px solid var(--ink); }
.su-row:nth-child(9) > .su-gc { border-bottom: 0; }

.su-sq {
  position: relative; width: 100%; height: 100%; padding: 0; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center; color: var(--c);
  font: 500 calc(var(--side) / 9 * 0.58)/1 var(--sans); font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
.su-sq:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; z-index: 1; }

/* the digits that came with the puzzle are heavier and in ink; the visitor's are in the game's colour */
.su-sq.given { color: var(--ink); font-weight: 700; }
/* a digit from a hint is underlined, so it can be told from the visitor's own */
.su-sq.hinted .su-val { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.18em; }

/* the chosen square, the squares it shares a row, column or box with, and the squares holding its digit */
.su-sq.peer { background: color-mix(in srgb, var(--c) 8%, transparent); }
.su-sq.same { background: color-mix(in srgb, var(--c) 18%, transparent); }
.su-sq.sel { background: color-mix(in srgb, var(--c) 30%, transparent); box-shadow: inset 0 0 0 2px var(--c); }

/* a clash is marked with a dot as well as by colour */
.su-sq.clash { color: #A3261D; }
.su-sq.clash::after {
  content: ""; position: absolute; top: 8%; right: 8%; width: 18%; height: 18%; border-radius: 50%; background: #A3261D;
}

/* pencil marks: nine places, each digit always in its own */
.su-notes {
  position: absolute; inset: 6%; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); place-items: center;
  color: var(--stone); font: 500 calc(var(--side) / 9 * 0.27)/1 var(--sans);
}

.su-pad .keys { max-width: 31.5rem; margin: 0 auto; }

/* Where the system sets the colours, tints are dropped: the chosen square and a clash keep a sign. */
@media (forced-colors: active) {
  .su-sq.sel { outline: 3px solid Highlight; outline-offset: -3px; }
  .su-sq.clash::after { background: Highlight; }
  .su-sq.given { text-decoration: none; font-weight: 800; }
}

/* The board's gutters stay at their usual size in pixels: at 200% text the page's would take 36px
   a side, and a visitor who sets larger text must not get a narrower grid for it. */
.board:has(> .su) { padding: 0 min(var(--gutter), 18px); }
@media (max-width: 22.5rem) {
  .board:has(> .su) { padding: 0 min(0.625rem, 10px); }
}

/* the pad sits inside the board's own gutters, so its keys line up with the grid's edges */
.su-pad .keys { padding-left: 0; padding-right: 0; margin-left: 0; margin-right: 0; }

/* the finished grid on the answers page: a real table, read row by row */
.su-answer {
  width: 100%; max-width: 24rem; margin: 1rem 0 1.5rem; border-collapse: collapse; table-layout: fixed;
  background: var(--sheet); border: 2px solid var(--ink);
}
.su-answer caption { caption-side: bottom; padding-top: 0.5rem; text-align: left; color: var(--stone); font-size: 0.9375rem; }
.su-answer td {
  position: relative; padding: 0; border: 1px solid var(--rule);
  color: var(--c); font: 500 1.25rem/1 var(--sans); font-variant-numeric: tabular-nums;
}
/* a table cell takes its height from its content: this makes each one as tall as it is wide */
.su-answer td::before { content: ""; display: block; padding-top: 100%; }
.su-answer td > :first-child { position: absolute; inset: 0; display: grid; place-items: center; }
.su-answer td.given { color: var(--ink); }
.su-answer td b { font-weight: 700; }
.su-answer td:nth-child(3n) { border-right: 2px solid var(--ink); }
.su-answer tr:nth-child(3n) td { border-bottom: 2px solid var(--ink); }


/* While the board loads, about the room it will take (game.css): the drawn board measured 445px at 320 wide, 527 at 412,
   670 from 600. */
#board { --board-wait: min(calc(89vw + 160px), 670px); }
