/* Sudoku on glazed tiles. The tiles are Blender renders (tools/render_tiles.py). */
@font-face { font-family: Fraunces; src: url(fonts/Fraunces.woff2) format('woff2'); font-weight: 300 800; font-style: normal; font-display: swap; }
@font-face { font-family: Fraunces; src: url(fonts/Fraunces-Italic.woff2) format('woff2'); font-weight: 300 800; font-style: italic; font-display: swap; }

:root {
  --wall: #17284f;
  --wall-lit: #24407c;
  --grout: #cfc9bc;
  --grout-deep: #a9a294;
  --cobalt: #1b3d92;
  --manganese: #5c2748;
  --ochre: #e2a724;
  --iron: #b3301a;
  --chalk: #e8edf6;
  --chalk-dim: #a9b6d3;
  --gap: 2px;
  --seam: 7px;
  --rim: 9px;
  --board: min(calc(100vw - 24px), calc(100dvh - 268px), 560px);
  --cell: calc((var(--board) - 2 * var(--rim) - 2 * var(--seam) - 6 * var(--gap)) / 9);
  font-family: Fraunces, Georgia, serif;
  font-variation-settings: 'SOFT' 100, 'opsz' 40;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120vmax 90vmax at 8% -10%, var(--wall-lit), var(--wall) 60%) fixed var(--wall);
  color: var(--chalk);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; padding: 0; background: none; cursor: pointer; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--ochre); outline-offset: 2px; }

.app { min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom)); }

.top { width: var(--board); display: grid; grid-template-columns: 1fr auto; align-items: baseline; row-gap: 6px; }
h1 { margin: 0; font-size: 1.9rem; font-weight: 560; font-style: italic; letter-spacing: -0.01em; line-height: 1; font-variation-settings: 'SOFT' 100, 'opsz' 144; }
.clock { grid-area: 1 / 2; margin: 0; font-size: 1.25rem; font-variant-numeric: tabular-nums; color: var(--chalk-dim); }
.levels { grid-area: 2 / 1 / 3 / -1; display: flex; gap: 4px; }
.levels button { flex: 1; padding: 7px 0; border-radius: 5px; font-size: 0.95rem; color: var(--chalk-dim); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.16); }
.levels button[aria-pressed='true'] { background: var(--chalk); color: var(--wall); font-weight: 620; box-shadow: none; }

.table { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ---------- the board ---------- */
.board {
  width: var(--board); height: var(--board); padding: var(--rim);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: var(--seam);
  background: var(--grout);
  background-image: radial-gradient(rgb(0 0 0 / 0.07) 0.6px, transparent 0.9px); background-size: 4px 4px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px var(--grout-deep), 0 1px 0 rgb(255 255 255 / 0.12), 0 22px 40px -18px rgb(3 8 25 / 0.75);
}
.box { display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); gap: var(--gap); }
.cell {
  position: relative; display: grid; place-items: center;
  width: var(--cell); height: var(--cell);
  background: center / 100% 100% no-repeat;
  font-size: calc(var(--cell) * 0.64); line-height: 1; font-weight: 600; color: var(--cobalt);
  font-variation-settings: 'SOFT' 100, 'opsz' 144;
  user-select: none; -webkit-user-select: none;
}
.cell:focus-visible { outline-offset: -3px; z-index: 2; }
.cell.mine { color: var(--manganese); font-style: italic; font-weight: 480; }
.cell.peer::after { content: ''; position: absolute; inset: 0; border-radius: 9%; background: rgb(27 61 146 / 0.15); pointer-events: none; }
.cell.same { background-image: url(img/tile-cobalt.webp) !important; color: #fff; }
.cell.sel { background-image: url(img/tile-ochre.webp) !important; color: #2a1608; }
.cell.sel::after { display: none; }
.cell.clash { color: var(--iron); }
.cell.clash.same { color: #ffc9bd; }
.cell.clash::before { content: ''; position: absolute; top: 12%; right: 12%; width: 13%; height: 13%; border-radius: 50%; background: currentColor; }
.cell .d { display: block; transform: translateY(-3%); }
.cell.pop .d { animation: paint 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
@keyframes paint { from { transform: translateY(-3%) scale(1.5); opacity: 0; } }
.pencil { position: absolute; inset: 9%; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); place-items: center; font-size: calc(var(--cell) * 0.27); font-style: normal; font-weight: 500; color: #4a5878; }
.cell.sel .pencil { color: #4d3306; }
.pencil .on { color: var(--cobalt); font-weight: 760; }
.board.won .cell { animation: lift 0.6s ease calc(var(--far) * 55ms) both; }
@keyframes lift { 40% { transform: translateY(-9%) scale(1.06); filter: brightness(1.12); } }

/* ---------- pad and tools ---------- */
.side { width: var(--board); display: grid; gap: 10px; }
.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.pad button {
  aspect-ratio: 1 / 1.16; display: grid; align-content: center; justify-items: center; gap: 1px;
  background: url(img/tile-1.webp) center / 100% 100% no-repeat;
  color: var(--cobalt); font-size: clamp(1.3rem, 6.4vw, 2rem); font-weight: 600; line-height: 1;
  font-variation-settings: 'SOFT' 100, 'opsz' 144;
  transition: transform 0.08s;
}
.pad button:active, .tools button:active, .new:active { transform: translateY(1px) scale(0.97); }
.pad small { font-size: 0.68rem; font-weight: 500; color: #5c6a8c; font-variant-numeric: tabular-nums; }
.pad button[disabled] { opacity: 0.38; cursor: default; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tools button, .new, dialog button {
  padding: 11px 4px; border-radius: 6px; font-size: 1rem; font-weight: 520;
  background: linear-gradient(160deg, #3257b4, #1c3c8e 55%, #17357f);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.28), inset 0 -2px 0 rgb(0 0 0 / 0.22), 0 2px 5px rgb(3 8 25 / 0.4);
  color: #fff; transition: transform 0.08s;
}
.tools button[aria-pressed='true'], dialog button.primary {
  background: linear-gradient(160deg, #f2c04a, #dfa420 55%, #cc931a); color: #2a1608; font-weight: 640;
}
.tools button[disabled] { opacity: 0.45; cursor: default; }
.new { background: none; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.3); color: var(--chalk); }
.keys { display: none; margin: 0; font-size: 0.9rem; line-height: 1.5; color: var(--chalk-dim); }
.foot { margin-top: auto; font-size: 0.85rem; }
.foot a { color: var(--chalk-dim); text-underline-offset: 3px; }

/* ---------- dialog ---------- */
dialog { width: min(420px, calc(100vw - 32px)); border: 0; border-radius: 10px; padding: 26px 24px 22px; background: #f1f3f2; color: #17284f; box-shadow: 0 30px 70px rgb(3 8 25 / 0.6); font-family: inherit; }
dialog::backdrop { background: rgb(12 22 48 / 0.62); }
dialog h2 { margin: 0 0 8px; font-size: 1.7rem; font-style: italic; font-weight: 560; line-height: 1.1; font-variation-settings: 'SOFT' 100, 'opsz' 144; }
dialog p { margin: 0 0 20px; font-size: 1.05rem; line-height: 1.5; }
.choices { display: flex; gap: 8px; }
.choices button { flex: 1; padding: 12px 8px; }

/* ---------- wide screens: pad beside the board ---------- */
@media (min-width: 860px) and (min-height: 560px) {
  :root { --board: min(calc(100dvh - 150px), calc(100vw - 400px), 660px); --seam: 9px; --rim: 12px; --gap: 3px; }
  .app { justify-content: center; gap: 18px; }
  .top { width: calc(var(--board) + 36px + 300px); grid-template-columns: auto 1fr auto; column-gap: 28px; align-items: center; }
  h1 { font-size: 2.6rem; }
  .levels { grid-area: 1 / 2; max-width: 400px; }
  .clock { grid-area: 1 / 3; font-size: 1.5rem; }
  .table { flex-direction: row; align-items: stretch; gap: 36px; }
  .side { width: 300px; align-content: start; gap: 14px; }
  .pad { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .pad button { aspect-ratio: 1; font-size: 2.7rem; }
  .pad small { font-size: 0.8rem; }
  .tools { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .keys { display: block; margin-top: 4px; }
  .foot { margin-top: 0; }
}
@media (hover: hover) {
  .cell:hover:not(.sel) { filter: brightness(1.05); }
  .levels button:hover:not([aria-pressed='true']) { color: var(--chalk); }
  .tools button:hover:not([disabled]), dialog button:hover { filter: brightness(1.1); }
}
@media (prefers-reduced-motion: reduce) {
  .cell.pop .d, .board.won .cell { animation: none; }
  .pad button, .tools button, .new { transition: none; }
}
