/* Sudoku. The grid is a square sized by app.js (--side) to the room .board-wrap is given.
   Wide screens: the grid with one column beside it (counters, number pad, tools).
   Upright screens: the counters in a row above the grid; under it the number pad on one side and the tools on the other. */
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: 22px; padding: 12px max(12px, var(--gk-safe-end)) max(12px, var(--gk-safe-bottom)) max(12px, var(--gk-safe-start)); }
.board-wrap { flex: 0 1 auto; min-width: 0; min-height: 0; height: 100%; max-height: 760px; aspect-ratio: 1; display: grid; place-items: center; }
/* The board's colours are custom properties on the frame. The values here are the Classic board (warm paper squares,
   navy lines, dark given numbers, blue ink for the player's numbers); a board skin (art.js BOARD_STYLES, put on by app.js)
   sets its own values on the frame instead. --board is what shows through the squares (they can be see-through, as on
   the wood), --cell-art a drawing on every square (the notebook's small squares), --ink-shadow and --given-shadow the
   shade of the numbers (carved on the wood, a glow at night). */
.frame { --side: 360px; --frame-bg: linear-gradient(145deg, var(--gk-raise), var(--gk-rim)); --frame-edge: var(--gk-gold-deep); --frame-rim: var(--gk-rim);
  --box-line: var(--gk-rim); --paper-line: #c9b88f; --board: var(--box-line); --paper: #f6ecd2; --cell-art: none;
  --ink: #1d58ad; --given: var(--gk-on-gold); --ink-shadow: none; --given-shadow: none; --note: #5d4a2c;
  --peer: #eadfbd; --same: #ecd08a; --pick: var(--gk-gold); --pick-ring: var(--gk-gold-deep); --wrong: #b3221a; --wrong-bg: #f3c2b4; --wrong-ring: var(--gk-leave);
  width: var(--side); height: var(--side); padding: calc(var(--side) * .02); border-radius: calc(var(--side) * .032);
  background: var(--frame-bg); border: 1px solid var(--frame-edge); box-shadow: 0 0 0 3px var(--frame-rim), var(--gk-shadow-2), var(--gk-inset); }
.grid { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); direction: ltr;
  background: var(--board); border: 2px solid var(--box-line); border-radius: calc(var(--side) * .012); overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.sq { position: relative; padding: 0; border: 0; border-right: 1px solid var(--paper-line); border-bottom: 1px solid var(--paper-line); border-radius: 0; background-color: var(--paper); background-image: var(--cell-art); color: var(--ink);
  text-shadow: var(--ink-shadow); font: var(--gk-medium) calc(var(--side) * .058)/1 var(--gk-font); display: grid; place-items: center; cursor: pointer; }
.sq:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--box-line); }
.sq:nth-child(9n) { border-right: 0; }
.sq:nth-child(n+19):nth-child(-n+27), .sq:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--box-line); }
.sq:nth-child(n+73) { border-bottom: 0; }
.sq.given { color: var(--given); text-shadow: var(--given-shadow); font-weight: var(--gk-number); }
.sq.peer { background-color: var(--peer); }
.sq.same { background-color: var(--same); }
.sq.selected { background-color: var(--pick); box-shadow: inset 0 0 0 2px var(--pick-ring); }
.sq.wrong { color: var(--wrong); background-color: var(--wrong-bg); text-shadow: none; }
.sq.wrong.selected { box-shadow: inset 0 0 0 2px var(--wrong-ring); }
.sq.pop { animation: pop-in .18s ease-out; }
/* The empty grid before the first game (html.gk-clear): no digits, notes or marks. */
html.gk-clear .sq { color: transparent; background-color: var(--paper); box-shadow: none; text-shadow: none; }
html.gk-clear .sq .notes-grid { visibility: hidden; }
html.gk-empty .digit small { visibility: hidden; }
@keyframes pop-in { from { font-size: calc(var(--side) * .085); } }
.sq:focus-visible { outline-offset: -3px; }
.notes-grid { position: absolute; inset: 6%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); font-size: max(calc(var(--side) * .024), 8px); font-weight: var(--gk-regular); color: var(--note); text-shadow: none; line-height: 1; }
.notes-grid i { font-style: normal; display: grid; place-items: center; }
.grid.done .sq { animation: wave .5s ease-out backwards; animation-delay: calc(var(--i) * 12ms); }
@keyframes wave { 40% { background-color: var(--pick); } }

/* The column beside the grid. */
.side { flex: none; width: 264px; display: flex; flex-direction: column; gap: 14px; }
.stats { display: flex; justify-content: center; gap: 8px; }
.stats .gk-stat { flex: 1; min-width: 0; padding: 5px 8px; }
.stats .word { direction: inherit; font-size: var(--gk-text-md); line-height: 1.4; }
/* The number pad: gold keys, as every in-game action. The small number on a key is how many of it are still missing. */
.digits { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; direction: ltr; }
.digit { position: relative; min-height: 58px; padding: 0; border-radius: 13px; border: 1px solid var(--gk-gold-edge); cursor: pointer;
  background: linear-gradient(var(--gk-gold-pale), var(--gk-gold-warm)); color: var(--gk-on-gold); font: var(--gk-number) 25px/1 var(--gk-font); box-shadow: 0 3px 0 var(--gk-gold-deep), var(--gk-shadow-1); }
.digit:hover:not(:disabled) { filter: brightness(1.08); }
.digit:active:not(:disabled) { translate: 0 2px; box-shadow: 0 1px 0 var(--gk-gold-deep); }
.digit:disabled { filter: grayscale(.7) brightness(.6); cursor: default; }
.digit:focus-visible { outline: var(--gk-focus); outline-offset: var(--gk-focus-gap); }
.digit small { position: absolute; top: 4px; right: 7px; font-size: var(--gk-text-xs); font-weight: var(--gk-medium); line-height: 1; opacity: .75; }
.digit.noting { background: linear-gradient(var(--gk-white), var(--gk-gold-pale)); }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool { min-height: 54px; padding: 6px 2px; flex-direction: column; gap: 2px; white-space: nowrap; }
.tool span { font-size: 19px; line-height: 1; }
.tool small { font-size: var(--gk-text-xs); font-weight: var(--gk-medium); }

/* Desktop: room for a larger column (the upright and sideways-phone rules below come after it and win). */
@media (min-width: 1024px) {
  .side { width: 300px; gap: 16px; }
  .digits, .tools { gap: 10px; }
  .digit { min-height: 68px; font-size: 29px; }
  .tool { min-height: 60px; }
  .tool span { font-size: 21px; }
}
/* Upright: counters, then the grid, then the pad and the tools side by side. */
@media (orientation: portrait) {
  .stage { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); grid-template-rows: auto minmax(0, 1fr) auto; gap: 10px; padding-top: 10px; }
  .side { display: contents; }
  .stats { grid-area: 1 / 1 / 2 / -1; justify-self: center; width: min(100%, 420px); }
  .board-wrap { grid-area: 2 / 1 / 3 / -1; width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }
  .digits { grid-area: 3 / 1; justify-self: end; width: min(100%, 250px); }
  .tools { grid-area: 3 / 2; justify-self: start; width: min(100%, 190px); grid-template-columns: repeat(2, 1fr); align-content: stretch; }
  .digit { min-height: clamp(48px, 8.5dvh, 76px); }
  .tool { min-height: 0; }
}
@media (max-width: 599px) {
  .digit { font-size: 22px; border-radius: 11px; }
  .stats .gk-stat b { font-size: var(--gk-text-md); }
}
@media (min-width: 600px) and (max-width: 1023px) and (orientation: portrait) {
  .stage { gap: 16px; padding-top: 16px; padding-bottom: max(20px, var(--gk-safe-bottom)); }
  .digits { width: 280px; gap: 10px; }
  .tools { width: 220px; gap: 10px; }
  .digit { min-height: 66px; font-size: 30px; }
  .tool span { font-size: 24px; }
  .tool small { font-size: var(--gk-text-sm); }
}
/* A sideways phone: the column is kept, with smaller keys. */
@media (orientation: landscape) and (max-height: 560px) {
  .stage { gap: 12px; padding-top: 6px; padding-bottom: max(6px, var(--gk-safe-bottom)); }
  .side { width: 236px; gap: 6px; }
  .stats .gk-stat { padding: 2px 6px; }
  .stats .gk-stat b, .stats .word { font-size: var(--gk-text-sm); }
  .digits { gap: 5px; }
  .digit { min-height: 44px; font-size: 20px; }
  .tool { min-height: 44px; }
  .tool small { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sq.pop, .grid.done .sq { animation: none; } }
