:root {
  color-scheme: light;
  --page: #f4f4f3; --surface: #fff; --border: #dededc; --text: #1b1c1e;
  --muted: #63676d; --header: #1b1c1e; --header-text: #fff; --backdrop: #e3e3e1;
  --tile: #f0f0ef; --tile-hover: #e3e3e1; --accent: #1b1c1e; --accent-text: #fff;
  --success: #186646; --success-bg: #e3f2e9; --error: #ac2929; --error-bg: #fce8e8;
  --hint: #815006; --hint-bg: #fff2d4; --cover: #ffffff;
  --font-body: 'Work Sans', system-ui, -apple-system, sans-serif;
  --font-display: 'Oswald', 'Arial Narrow', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #101112; --surface: #191a1c; --border: #37393c; --text: #ededec;
    --muted: #afb1b6; --header: #3a3c40; --header-text: #f5f5f4; --backdrop: #08090a;
    --tile: #252729; --tile-hover: #34373a; --accent: #ededec; --accent-text: #101112;
    --success: #8ee0b2; --success-bg: #193a2c; --error: #ffabab; --error-bg: #492525;
    --hint: #f6ce87; --hint-bg: #45361b; --cover: #191a1c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101112; --surface: #191a1c; --border: #37393c; --text: #ededec;
  --muted: #afb1b6; --header: #3a3c40; --header-text: #f5f5f4; --backdrop: #08090a;
  --tile: #252729; --tile-hover: #34373a; --accent: #ededec; --accent-text: #101112;
  --success: #8ee0b2; --success-bg: #193a2c; --error: #ffabab; --error-bg: #492525;
  --hint: #f6ce87; --hint-bg: #45361b; --cover: #191a1c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--backdrop); color: var(--text); font-family: var(--font-body); font-size: 1rem; line-height: 1.5; }
button, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; color: inherit; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .5; }
a { color: inherit; text-underline-offset: 3px; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible + .slider { outline: 3px solid var(--hint); outline-offset: 4px; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.2; }
.app { max-width: 760px; min-height: 100vh; min-height: 100dvh; margin: auto; background: var(--page); display: flex; flex-direction: column; box-shadow: 0 0 0 1px var(--border); }
.page-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 3px solid #afafaf; background: var(--header); color: var(--header-text); }
.brand a { font-size: .875rem; text-decoration: none; opacity: .85; }
h1 { font-size: 2rem; letter-spacing: .015em; margin-top: 2px; }
.menu-host { position: relative; }
.menu-btn { width: 44px; height: 44px; display: grid; place-items: center; background: transparent; border: 1px solid #777; border-radius: 10px; }
.menu-icon, .menu-icon::before, .menu-icon::after { content: ''; display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .15s ease; }
.menu-icon { position: relative; }
.menu-icon::before, .menu-icon::after { position: absolute; }
.menu-icon::before { transform: translateY(-6px); }
.menu-icon::after { transform: translateY(6px); }
.menu-host.open .menu-icon { background: transparent; }
.menu-host.open .menu-icon::before { transform: rotate(45deg); }
.menu-host.open .menu-icon::after { transform: rotate(-45deg); }
.menu-dropdown { position: absolute; right: 0; top: calc(100% + 10px); width: 264px; max-width: calc(100vw - 32px); padding: 8px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); box-shadow: 0 12px 28px #0003; z-index: 10; }
.menu-dropdown button, .menu-dropdown > a { display: block; width: 100%; min-height: 44px; text-align: left; padding: 10px; background: none; border: 0; border-radius: 6px; text-decoration: none; }
.menu-dropdown button:hover, .menu-dropdown > a:hover, .switch-row:hover { background: var(--tile); }
.menu-section-label, .eyebrow, .stat-label { font-size: .875rem; font-weight: 600; color: var(--muted); }
.menu-section-label { padding: 6px 10px; }
.menu-divider { height: 1px; margin: 6px; background: var(--border); }
.switch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px; min-height: 48px; border-radius: 6px; cursor: pointer; }
.switch { display: inline-flex; position: relative; width: 42px; height: 24px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.slider { pointer-events: none; width: 42px; height: 24px; border-radius: 20px; background: #73767b; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .slider { background: #3b7960; }
.switch input:checked + .slider::before { transform: translateX(18px); }
main { flex: 1; padding: 0 24px; }
.game-meta { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 10px; margin: 10px 0; font-size: .875rem; color: var(--muted); }
.settings-summary { display: inline-flex; flex-wrap: wrap; max-width: 100%; align-items: center; gap: 6px; padding: 10px 0; min-height: 44px; color: var(--text); font-weight: 600; background: none; border: 0; }
.chevron { width: 7px; height: 7px; border-bottom: 2px solid; border-right: 2px solid; transform: rotate(45deg); margin: -4px 4px 0 5px; }
.scoreboard { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.scoreboard > div { display: flex; flex: 1 1 4rem; flex-direction: column; }
.stat-value { font-family: var(--font-display); font-size: 1.6rem; line-height: 1.3; font-variant-numeric: tabular-nums; }
.stat-total { font-family: var(--font-body); font-size: 1rem; color: var(--muted); }
.pause-button { height: 44px; width: 44px; flex: 0 0 44px; background: var(--tile); border: 1px solid var(--border); border-radius: 8px; font-size: 1.3rem; }
.game-panel { margin-top: 22px; text-align: center; }
.round-header h2 { font-size: 1.9rem; margin: 5px 0 6px; }
.round-header p { color: var(--muted); font-size: .9375rem; max-width: 440px; margin: auto; }
.group-tabs { display: flex; flex-wrap: wrap; gap: 8px; max-width: 440px; margin: 18px auto 0; }
.group-tab { display: flex; flex: 1 1 3rem; min-width: 0; flex-direction: column; align-items: center; justify-content: center; min-height: 56px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: .875rem; line-height: 1.3; }
.group-tab .tab-value { font-weight: 600; }
.group-tab[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--tile); }
.group-tab.solved { color: var(--success); background: var(--success-bg); border-color: var(--success); }
.play-area { position: relative; max-width: 440px; margin: 14px auto 0; }
.number-board { position: relative; width: min(100%, 356px); aspect-ratio: 1.18; margin: auto; }
.number-board.concealed { visibility: hidden; }
.number-tile { position: absolute; width: 25%; height: 29.5%; border: 1px solid var(--border); border-bottom-width: 4px; border-radius: 16px; background: var(--tile); font-family: var(--font-display); font-weight: 500; font-size: clamp(1.6rem, 7vw, 2.3rem); font-variant-numeric: tabular-nums; transition: background .12s, transform .12s; }
.number-tile:nth-child(1) { left: 37.5%; top: 0; }
.number-tile:nth-child(2) { right: 0; top: 29%; }
.number-tile:nth-child(3) { right: 14%; bottom: 0; }
.number-tile:nth-child(4) { left: 14%; bottom: 0; }
.number-tile:nth-child(5) { left: 0; top: 29%; }
.number-tile:hover:not(:disabled) { background: var(--tile-hover); }
.number-tile:active:not(:disabled) { transform: translateY(2px); }
.number-tile:disabled { opacity: 1; }
.number-tile.hint { background: var(--hint-bg); border-color: var(--hint); color: var(--hint); }
.number-tile.correct { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.number-tile.wrong { background: var(--error-bg); border-color: var(--error); color: var(--error); }
.board-operation { position: absolute; left: 40%; top: 40%; width: 20%; color: var(--muted); font-size: 2rem; font-weight: 500; }
.board-cover { position: absolute; inset: -5px -2px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; gap: 12px; border: 1px dashed var(--border); border-radius: 14px; background: var(--cover); }
.cover-symbol { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 10px; color: var(--muted); font-size: 1.8rem; line-height: 1; }
.board-cover h3 { font-size: 1.45rem; }
.board-cover p { max-width: 300px; font-size: .9375rem; color: var(--muted); }
.primary, .secondary { min-height: 46px; padding: 10px 20px; border: 1px solid var(--accent); border-radius: 8px; font-weight: 600; }
.primary { background: var(--accent); color: var(--accent-text); }
.secondary { border-color: var(--border); background: var(--surface); color: var(--text); }
.feedback { display: flex; min-height: 55px; align-items: center; justify-content: center; padding: 10px 0; color: var(--muted); font-size: .9375rem; }
.feedback.success { color: var(--success); font-weight: 600; }
.feedback.error { color: var(--error); }
.feedback.hint { color: var(--hint); }
.game-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 46px; }
.game-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 4px 12px; border-top: 1px solid var(--border); margin-top: 22px; padding: 8px 0; color: var(--muted); font-size: .875rem; }
.game-footer button { background: none; border: 0; min-height: 44px; padding: 8px 0; text-decoration: underline; text-underline-offset: 3px; }
.credit { padding: 14px 24px max(18px, env(safe-area-inset-bottom)); text-align: center; color: var(--muted); font-size: .8125rem; }
.result-panel { text-align: center; padding: 35px 12px 20px; }
.result-panel h2 { font-size: 3rem; margin: 10px 0; }
.result-equation { font-family: var(--font-display); font-size: 2.2rem; color: var(--success); }
.result-panel p { margin: 10px 0; }
.result-panel .primary { margin-top: 16px; }
dialog { width: min(460px, calc(100% - 28px)); max-height: calc(100dvh - 32px); padding: 24px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow-y: auto; }
dialog::backdrop { background: #0009; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.dialog-header h2 { font-size: 1.6rem; }
.close-button { width: 44px; height: 44px; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 8px; font-size: 1.8rem; line-height: 1; background: var(--tile); }
dialog p { margin: 12px 0; }
.field { display: flex; flex-direction: column; gap: 8px; font-weight: 600; margin: 16px 0; }
select { width: 100%; min-height: 48px; padding: 10px 40px 10px 12px; color: var(--text); background: var(--page) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='10' viewBox='0 0 14 10'%3E%3Cpath d='m2 2 5 5 5-5' fill='none' stroke='%2373777c' stroke-width='2'/%3E%3C/svg%3E") right 14px center / 14px no-repeat; border: 1px solid var(--border); border-radius: 8px; appearance: none; }
.dialog-note { color: var(--muted); font-size: .875rem; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.example { display: flex; gap: 8px; margin: 20px 0 8px; }
.example span { flex: 1; text-align: center; padding: 8px 0; background: var(--tile); border-radius: 6px; font-family: var(--font-display); font-size: 1.5rem; }
.example .example-answer { background: var(--success-bg); color: var(--success); outline: 2px solid var(--success); }
.example-caption { text-align: center; }
ol { padding-left: 24px; }
li { padding: 4px 0 4px 2px; }
.full-width { width: 100%; }
.noscript { position: fixed; inset: 20% 20px auto; padding: 20px; background: var(--surface); border: 2px solid var(--error); }
@media (max-width: 400px) {
  .page-header { padding: 14px 16px; }
  main { padding: 0 16px; }
  .scoreboard { padding: 10px 12px; }
  .game-meta { margin: 6px 0; }
  .game-panel { margin-top: 16px; }
  .group-tabs { gap: 6px; margin-top: 14px; }
  .group-tab { font-size: .875rem; }
  .game-footer { margin-top: 16px; }
  dialog { padding: 18px; }
}
@media (max-height: 900px) {
  .number-board { width: min(100%, 300px); }
}
@media (max-height: 760px) and (min-width: 401px) {
  .game-panel { margin-top: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
