body { background: #f6f1e7; }
.sudoku-stage { width: min(100%, 31rem); max-height: 100%; display: grid; gap: clamp(.45rem, 1.4cqh, .8rem); place-items: center; }
.sudoku-board { width: min(100%, 28rem, calc(100cqh - 8.1rem)); aspect-ratio: 1; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); grid-template-rows: repeat(9, minmax(0, 1fr)); overflow: hidden; container-type: inline-size; border: 3px solid #17324d; border-radius: .45rem; background: #fffdf8; box-shadow: 5px 5px 0 rgba(23,50,77,.14); touch-action: manipulation; }
.sudoku-cell { position: relative; min-width: 0; min-height: 0; padding: 0; display: grid; place-items: center; border: 0; border-right: 1px solid #aab3b5; border-bottom: 1px solid #aab3b5; border-radius: 0; background: #fffdf8; color: #267875; font-size: clamp(.55rem, 7cqw, 1.65rem); font-weight: 850; line-height: 1; cursor: pointer; transition: background .12s ease, color .12s ease, transform .12s ease; }
.sudoku-cell:nth-child(9n) { border-right: 0; }
.sudoku-cell:nth-child(n+73) { border-bottom: 0; }
.sudoku-cell:nth-child(9n+3), .sudoku-cell:nth-child(9n+6) { border-right: 3px solid #17324d; }
.sudoku-cell:nth-child(n+19):nth-child(-n+27), .sudoku-cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 3px solid #17324d; }
.sudoku-cell.given { color: #17324d; font-weight: 950; }
.sudoku-cell.related { background: #f1eadb; }
.sudoku-cell.matching { background: #dcefeb; }
.sudoku-cell.selected { z-index: 1; background: #f7d978; box-shadow: inset 0 0 0 3px #b47b16; }
.sudoku-cell.conflict { background: #f8c5bc; }
.sudoku-cell.hint-error { color: #c24030; }
.sudoku-cell.hinted { animation: hint-pop .45s ease; }
.sudoku-cell:focus-visible { z-index: 2; outline: 3px solid var(--danger); outline-offset: -3px; }
.notes-grid { position: absolute; inset: 1px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); color: #44616b; font-size: clamp(.25rem, 2.8cqw, .66rem); font-weight: 800; line-height: 1; }
.notes-grid span { display: grid; place-items: center; }
.number-pad { width: min(100%, 28rem); display: grid; grid-template-columns: repeat(9, 1fr); gap: .28rem; }
.number-pad button, .tool-button { min-width: 0; min-height: 2.75rem; padding: 0; border: 2px solid #17324d; border-radius: .48rem; background: #fffdf8; color: #17324d; box-shadow: 2px 2px 0 rgba(23,50,77,.14); cursor: pointer; font-weight: 900; }
.number-pad button { font-size: 1.15rem; }
.number-pad button:hover, .tool-button:hover { background: #e8f3f0; transform: translateY(-1px); }
.number-pad button:active, .tool-button:active { transform: translate(1px, 2px); box-shadow: none; }
.number-pad button:focus-visible, .tool-button:focus-visible { outline: 3px solid var(--danger); outline-offset: 2px; }
.number-pad button.complete { opacity: .32; }
.tool-row { width: min(100%, 23rem); display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.tool-button { min-height: 2.4rem; padding: .35rem; font-size: .76rem; }
.tool-button span { margin-right: .18rem; }
.tool-button[aria-pressed="true"] { background: #2b7a78; color: white; }
.setup-dialog, .guide-dialog { width: min(calc(100% - 2rem), 30rem); max-height: calc(100dvh - 2rem); padding: 0; border: 2px solid #17324d; border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: 8px 9px 0 rgba(0,0,0,.2); }
.setup-dialog::backdrop, .guide-dialog::backdrop { background: rgba(16,38,58,.72); backdrop-filter: blur(5px); }
.setup-dialog form, .guide-dialog article { display: grid; gap: 1rem; padding: 1.5rem; }
.setup-dialog h2, .guide-dialog h2 { margin: -.25rem 0 .1rem; color: #17324d; font: 750 2rem/1 Georgia, "Times New Roman", serif; }
.setup-eyebrow { margin: 0; color: var(--accent-2); font-size: .67rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.difficulty-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; margin: 0; padding: 0; border: 0; }
.difficulty-picker legend { width: 100%; margin-bottom: .5rem; color: #17324d; font-size: .72rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.difficulty-picker label { position: relative; min-width: 0; cursor: pointer; }
.difficulty-picker input { position: absolute; opacity: 0; pointer-events: none; }
.difficulty-picker label span { min-height: 4.7rem; display: grid; place-content: center; gap: .25rem; padding: .55rem; border: 2px solid #17324d; border-radius: 9px; background: var(--panel); box-shadow: 3px 3px 0 rgba(23,50,77,.13); text-align: center; }
.difficulty-picker small { color: var(--muted); font-size: .67rem; font-weight: 700; line-height: 1.25; }
.difficulty-picker input:checked + span { background: var(--accent); }
.difficulty-picker input:focus-visible + span { outline: 3px solid var(--danger); outline-offset: 2px; }
.setup-actions { display: flex; justify-content: flex-end; gap: .65rem; }
.guide-dialog article { position: relative; overflow: auto; }
.guide-dialog h3 { margin: .2rem 0 -.55rem; color: #17324d; }
.guide-dialog p, .guide-dialog ul { margin: 0; color: var(--muted); line-height: 1.48; }
.guide-dialog ul { padding-left: 1.25rem; }
.guide-tip { padding: .8rem; border-left: 4px solid var(--accent); background: #f6f1e8; }
.guide-keys { font-size: .76rem; }
.guide-close { position: absolute; top: .65rem; right: .65rem; width: 2.5rem; height: 2.5rem; border: 0; background: transparent; color: #17324d; font-size: 1.7rem; cursor: pointer; }
.guide-dialog [data-close-guide] { position: sticky; bottom: 0; }
@keyframes hint-pop { 50% { transform: scale(.84); background: #bce4d8; } }
@media (max-width: 420px) {
  .difficulty-picker { grid-template-columns: 1fr; }
  .difficulty-picker label span { min-height: 3.2rem; grid-template-columns: 5rem 1fr; align-items: center; text-align: left; }
  .setup-dialog form, .guide-dialog article { padding: 1.15rem; }
}
@media (max-height: 700px) {
  .game-shell { gap: .45rem; padding-top: max(.45rem, env(safe-area-inset-top)); padding-bottom: max(.45rem, env(safe-area-inset-bottom)); }
  .game-header { min-height: 3rem; }
  .scorebar { padding: .45rem .75rem; }
  .sudoku-stage { gap: .35rem; }
  .sudoku-board { width: min(100%, 26rem, calc(100cqh - 6.2rem)); }
  .number-pad button { min-height: 2.2rem; }
  .tool-button { min-height: 2rem; }
  .game-actions .action-button { min-height: 2.5rem; padding: .4rem .75rem; }
}
@media (max-height: 420px) and (orientation: landscape) {
  .setup-dialog { max-height: calc(100dvh - 1rem); }
  .setup-dialog form { gap: .4rem; padding: .6rem .8rem; }
  .setup-dialog h2 { margin: 0; font-size: 1.35rem; }
  .setup-eyebrow { font-size: .58rem; }
  .difficulty-picker { gap: .4rem; }
  .difficulty-picker legend { margin-bottom: .2rem; }
  .difficulty-picker label span { min-height: 3.2rem; padding: .3rem; }
  .difficulty-picker small { font-size: .57rem; }
  .setup-actions .action-button { min-height: 2.35rem; padding: .35rem .65rem; }
}
@media (prefers-reduced-motion: reduce) {
  .sudoku-cell.hinted { animation: none; }
}
