:root {
  color-scheme: light;
  --canvas: #eef6fc;
  --paper: #fff;
  --ink: #1d2b4a;
  --muted: #566479;
  --sky: #8fd0f5;
  --tint: #d8eefb;
  --blue: #1f84c9;
  --deep: #145f94;
  --line: #cfe1ef;
  --bad: #c8322b;
  --wrong-surface: #f8d9d7;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: 'Trebuchet MS', Arial, sans-serif; font-size: 16px; line-height: 1.45; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
a { color: var(--deep); text-underline-offset: 4px; }
button, a { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
::selection { background: var(--sky); color: var(--ink); }
[hidden] { display: none !important; }
.app { width: min(100%, 1000px); margin: 0 auto; padding: 0 28px max(18px, env(safe-area-inset-bottom)); }
.header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: max(22px, env(safe-area-inset-top)) 0 18px; border-bottom: 1px solid var(--line); }
.identity { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
h1 { margin: 0; font-size: 23px; font-weight: 800; line-height: 1.1; letter-spacing: .01em; }
nav { display: flex; align-items: center; gap: 20px; position: relative; }
.settings-trigger { display: grid; place-items: center; border: 1px solid var(--line); background: var(--paper); border-radius: 7px; min-height: 44px; min-width: 44px; color: var(--deep); }
.settings-trigger:hover, .settings-trigger[aria-expanded='true'] { background: var(--tint); }
.settings-trigger svg { stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linejoin: round; }
.settings-panel { position: absolute; right: 0; top: calc(100% + 10px); width: min(300px, calc(100vw - 24px)); padding: 20px; background: var(--paper); border-radius: 14px; box-shadow: 0 12px 40px #0003; z-index: 20; max-height: calc(100svh - 85px); overflow-y: auto; }
.settings-panel h2 { font-size: 19px; margin-bottom: 10px; }
.settings-link { color: var(--deep); text-decoration: underline; background: transparent; border: 0; padding: 8px 0; min-height: 44px; font-size: 14px; }
.settings-choice { margin: 14px 0; padding: 0; border: 0; }
.settings-choice legend { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.settings-options { display: flex; gap: 6px; }
.settings-options button { flex: 1; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--deep); padding: 9px 10px; min-height: 44px; font-size: 14px; font-weight: 700; }
.settings-options button[aria-pressed='true'] { background: var(--sky); color: var(--ink); border-color: var(--deep); }
.settings-options button:hover { background: var(--tint); }
#sound-status { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.settings-brand { font-weight: 700; font-size: 14px; }
.settings-promise { margin: 5px 0 0; font-size: 12px; color: var(--muted); }
.game-layout { display: grid; grid-template-areas: 'instructions' 'modes' 'difficulty' 'start' 'board' 'actions' 'feedback' 'finished'; }
.game-controls { display: contents; }
.start-action { grid-area: start; justify-self: center; min-width: 140px; margin-top: 14px; }
.game-layout.is-ready .number { cursor: default; }
.instructions { grid-area: instructions; text-align: center; margin: 22px 0 12px; }
h2 { margin: 0; font-size: 23px; line-height: 1.25; font-weight: 700; text-wrap: balance; }
.instructions > p { margin: 5px 0 0; color: var(--muted); font-size: 14px; }
.round-status { display: flex; justify-content: center; align-items: baseline; flex-wrap: wrap; gap: 3px 18px; margin-top: 8px; }
.instructions .progress { margin: 0; color: var(--deep); font-size: 12px; font-variant-numeric: tabular-nums; }
.clock { color: var(--deep); font-size: 12px; white-space: nowrap; }
#timer { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.game-layout.is-finished .round-status { flex-direction: column; align-items: center; gap: 6px; }
.game-layout.is-finished .clock { display: flex; align-items: baseline; gap: 12px; font-size: 14px; }
.game-layout.is-finished #timer { font-size: clamp(2.75rem, 7vw, 4rem); line-height: 1.05; }
.mode-picker { grid-area: modes; border: 0; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.mode-picker legend { float: left; padding: 0; font-size: 13px; color: var(--muted); }
.modes { display: flex; gap: 5px; }
.mode { border: 1px solid var(--line); background: var(--paper); color: var(--deep); border-radius: 6px; padding: 7px 12px; min-height: 40px; font-size: 14px; font-weight: 700; }
.mode:hover { background: var(--tint); }
.mode[aria-checked='true'] { background: var(--sky); color: var(--ink); border-color: var(--deep); }
.difficulty { grid-area: difficulty; border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.difficulty legend { float: left; margin: 0; padding: 0; font-size: 13px; color: var(--muted); }
.levels { display: flex; gap: 5px; }
.level { min-width: 40px; min-height: 40px; border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 6px; font-size: 14px; font-weight: 700; }
.level:hover { background: var(--tint); }
.level[aria-checked='true'] { color: var(--ink); background: var(--sky); border-color: var(--deep); }
#level-detail { margin: 0; color: var(--muted); font-size: 12px; }
.board-wrap { grid-area: board; display: flex; align-items: center; justify-content: center; margin: 12px 0 8px; min-width: 0; }
#board { display: block; width: min(100%, 660px, calc((100svh - 440px) * 1.057)); height: auto; overflow: visible; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.outline, .hub { stroke: var(--ink); stroke-width: 2.7; stroke-linejoin: miter; }
.outline { fill: white; }
.centre-outline, .hub { fill: var(--sky); }
.sector-line { stroke: var(--ink); stroke-width: .9; pointer-events: none; }
.number { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.number .hit-sector { fill: transparent; transition: fill 160ms ease-out; }
.number:hover .hit-sector, .number:focus-visible .hit-sector { fill: var(--tint); }
.number:focus { outline: none; }
.number:focus-visible .hit-sector { stroke: var(--deep); stroke-width: 2.5; }
.number text, .hub-answer, .operation { fill: var(--ink); font-family: Arial, Helvetica, sans-serif; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.number text { font-size: 25px; }
.number .strike { stroke: var(--bad); stroke-width: 2.5; stroke-linecap: round; opacity: 0; pointer-events: none; }
.number.struck .strike { opacity: 1; }
.number.struck text { fill: var(--muted); }
.number.wrong .hit-sector { fill: var(--wrong-surface); }
.number.right .hit-sector { fill: var(--tint); }
.puzzle.solved .number { cursor: default; }
.puzzle.solved .number:not(.right) text { fill: var(--muted); }
.puzzle.solved .number .hit-sector { fill: transparent; }
.puzzle.solved .number.right .hit-sector { fill: var(--tint); }
.puzzle.solved .number.right text { fill: var(--deep); }
.hub-answer { font-size: 19px; }
.operation { font-size: 24px; font-weight: 700; }
.operation-mark { stroke: var(--ink); fill: none; stroke-width: 9.1; stroke-linecap: round; pointer-events: none; }
.operation.small { font-size: 24px; font-weight: 700; }
.centre-final .number:hover .hit-sector, .centre-final .number:focus-visible .hit-sector { fill: var(--tint); }
.puzzle.centre-final.solved .number.right .hit-sector { fill: var(--tint); }
.locked-centre { cursor: help; -webkit-tap-highlight-color: transparent; }
.locked-centre:focus-visible .centre-outline { stroke-width: 4; stroke: var(--deep); }
.locked-centre:focus { outline: none; }
.hub { pointer-events: none; }
.actions { grid-area: actions; display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; }
.button { min-height: 44px; border-radius: 7px; padding: 10px 18px; font-size: 14px; font-weight: 700; border: 1px solid transparent; transition: background 150ms ease-out; }
.primary { background: var(--deep); color: var(--paper); }
.primary:hover { background: var(--ink); }
.secondary { background: white; border-color: var(--line); color: var(--deep); }
.secondary:hover { background: var(--tint); }
.quiet { background: white; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; }
.quiet:hover { color: var(--deep); }
.button:disabled { opacity: .45; }
.feedback { grid-area: feedback; margin: 9px auto 0; min-height: 21px; max-width: 65ch; text-align: center; font-size: 13px; color: var(--deep); }
.feedback.error { color: var(--bad); }
.finished { grid-area: finished; margin: 14px auto 0; text-align: center; padding: 18px 28px; border-top: 1px solid var(--line); }
.finished p { margin: 6px 0 12px; font-size: 24px; font-weight: 700; color: var(--deep); font-variant-numeric: tabular-nums; }
.finished .result-detail { font-size: 13px; font-weight: 400; color: var(--muted); }
.calculations { margin: 12px 0; font-size: 13px; color: var(--deep); }
.calculations summary { cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.calculations ol { text-align: left; line-height: 1.7; font-variant-numeric: tabular-nums; }
.footer { display: flex; justify-content: center; flex-wrap: wrap; gap: 5px 24px; color: var(--muted); font-size: 12px; margin-top: 8px; }
dialog { background: white; color: var(--ink); width: min(480px, calc(100% - 32px)); max-height: calc(100svh - 32px); border: none; border-radius: 14px; padding: 26px; box-shadow: 0 12px 40px #0003; }
dialog::backdrop { background: #0b233880; }
.help-content h2 { margin-bottom: 18px; }
.help-content p { margin: 10px 0; font-size: 15px; max-width: 65ch; }
.help-content h3 { font-size: 16px; margin: 22px 0 6px; }
.help-content form { margin-top: 22px; }
.stat-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 24px; margin: 22px 0; }
.stat-totals dt { font-size: 13px; color: var(--muted); }
.stat-totals dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; color: var(--deep); font-variant-numeric: tabular-nums; }
.statistics-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.statistics-table th, .statistics-table td { padding: 9px 5px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.statistics-table th:first-child, .statistics-table td:first-child { text-align: left; }
.statistics-table th { color: var(--deep); }
.round-history { margin: 10px 0; padding-left: 22px; font-size: 13px; }
.round-history li { margin: 8px 0; }
#statistics { width: min(560px, calc(100% - 32px)); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 10; }
#board.celebrating .centre-final .centre-outline { animation: centre-confirm 800ms ease-out; }
#board.celebrating .centre-final .number.right text { transform-box: fill-box; transform-origin: center; animation: answer-confirm 700ms cubic-bezier(.16, 1, .3, 1); }
#finished.celebrating #equation { animation: equation-confirm 700ms cubic-bezier(.16, 1, .3, 1); }
@keyframes centre-confirm { 0%, 100% { fill: var(--sky); } 35% { fill: var(--tint); } }
@keyframes answer-confirm { 0%, 100% { transform: scale(1); } 35% { transform: scale(1.18); } }
@keyframes equation-confirm { from { transform: translateY(8px); opacity: .55; } to { transform: translateY(0); opacity: 1; } }
@media (max-width: 600px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .header { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: 12px; gap: 8px; }
  h1 { font-size: 19px; }
  .identity { gap: 6px; }
  nav { gap: 9px; }
  .instructions { margin: 18px 0 10px; }
  h2 { font-size: 21px; }
  .instructions > p { font-size: 12px; }
  .round-status { margin-top: 5px; gap: 2px 12px; }
  .instructions .progress { font-size: 12px; }
  .mode-picker { gap: 6px; }
  .mode { padding: 7px 10px; font-size: 13px; }
  .difficulty { gap: 7px; }
  .level { min-width: 36px; min-height: 40px; }
  #level-detail { font-size: 12px; }
  .board-wrap { margin: 14px -2px 12px; }
  #board { width: min(100%, 560px); }
  .actions { gap: 5px; }
  .button { padding: 9px 14px; font-size: 13px; }
  .footer { margin-top: 10px; }
}
@media (orientation: landscape) and (min-width: 680px) {
  .app { width: min(100%, 1360px); padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
  .header { padding-top: 8px; padding-bottom: 7px; }
  .game-layout { grid-template-columns: minmax(260px, .8fr) minmax(0, 1.6fr); grid-template-areas: 'controls board'; align-items: center; gap: 28px; margin-top: 16px; }
  .game-controls { grid-area: controls; display: flex; flex-direction: column; align-items: center; gap: 12px; max-height: calc(100svh - 108px); min-width: 0; overflow-y: auto; padding: 0 6px 6px; scrollbar-width: thin; scrollbar-color: var(--sky) var(--canvas); }
  .game-controls > * { flex-shrink: 0; }
  .instructions { margin-top: 10px; margin-bottom: 8px; }
  .mode-picker { margin-bottom: 6px; gap: 4px; }
  .mode-picker legend { font-size: 12px; }
  .mode { padding: 6px 9px; font-size: 12px; min-height: 36px; }
  .difficulty { gap: 6px; }
  #level-detail { width: 100%; text-align: center; }
  .board-wrap { align-self: center; margin: 0; height: calc(100svh - 108px); }
  #board { width: min(100%, calc((100svh - 116px) * 1.057)); }
  .actions { margin-top: 8px; gap: 5px; }
  .button { padding: 9px 11px; }
  .finished { padding: 8px 0; margin: 4px auto 0; }
  .finished h2 { font-size: 19px; }
  .finished p { font-size: 20px; margin: 4px 0 8px; }
  .footer { margin-top: 3px; }
  .start-action { margin: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

@media (max-width: 350px) {
  .header { padding-top: 10px; padding-bottom: 10px; }
  h1 { font-size: 16px; }
  .identity { gap: 4px; }
  .instructions { margin-top: 14px; }
  .instructions h2 { font-size: 19px; }
}
