* { box-sizing: border-box; }

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --paper: #fff;
  --ink: #152642;
  --muted: #4e6079;
  --edge: #cdd8e6;
  --accent: #2454ba;
  --strong: #194399;
  --on-accent: #fff;
  --tint: #e9f0fc;
  --peer: #edf3ff;
  --match: #c8dcfc;
  --grid: #92a3ba;
  --block: #354a67;
  --focus: #a44500;
  --bad: #9e2332;
  --bad-bg: #fff0f1;
  --hint: #714e0d;
  --hint-bg: #fff4d8;
  --reserve: #eef2f7;
  --radius: 12px;
  --page: 992px;
  --sans: "Segoe UI", Arial, sans-serif;
  font-family: var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111b29;
  --paper: #1a273a;
  --ink: #edf3ff;
  --muted: #b9c9df;
  --edge: #455872;
  --accent: #a6c7ff;
  --strong: #c7dcff;
  --on-accent: #11213a;
  --tint: #283c59;
  --peer: #23354e;
  --match: #3a5175;
  --grid: #657992;
  --block: #bdcde2;
  --focus: #ffce81;
  --bad: #ffc2c8;
  --bad-bg: #492831;
  --hint: #ffe09f;
  --hint-bg: #493b21;
  --reserve: #1d2a3d;
}

body { margin: 0; line-height: 1.5; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(2.25rem, 4.2vw, 3.5rem); line-height: 1.08; letter-spacing: -.045em; }
h2 { font-size: 1.35rem; line-height: 1.25; letter-spacing: -.02em; }
a { color: var(--strong); text-underline-offset: .2em; }
button, select, input { font: inherit; }
button, summary, select, label:has(input) { cursor: pointer; }
button { padding: 0; border: 0; background: none; color: inherit; touch-action: manipulation; }
button:disabled { opacity: .48; cursor: default; }
button svg, a svg { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.wrap { width: min(var(--page), calc(100% - 64px)); margin-inline: auto; }

.header { background: var(--paper); border-bottom: 1px solid var(--edge); }
.header-inner { max-width: 1192px; min-height: 68px; margin: auto; padding: 0 32px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 48px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 1.5rem; font-weight: 580; line-height: 1; letter-spacing: -.055em; color: var(--ink); text-decoration: none; }
.brand b { color: var(--strong); font-weight: 750; }
.mark { display: grid; flex: none; grid-template-columns: repeat(3, 1fr); gap: 2px; width: 30px; aspect-ratio: 1; transform: rotate(-5deg); }
.mark i { border-radius: 2px; background: var(--accent); }
.mark i:nth-child(3), .mark i:nth-child(4), .mark i:nth-child(8) { opacity: .4; }
.mark i:nth-child(5) { border-radius: 50%; }
.header nav, .header-tools, .status-right, #time { display: flex; align-items: center; }
.header nav { gap: 26px; align-self: stretch; flex-wrap: wrap; }
.header nav :is(a, button) { display: grid; align-items: center; position: relative; align-self: stretch; font-size: .95rem; font-weight: 600; text-decoration: none; color: var(--muted); }
.header nav [aria-current="page"] { color: var(--strong); }
.header nav [aria-current="page"]::after { position: absolute; content: ""; inset: auto 0 0; height: 3px; background: var(--accent); }
.header-tools { gap: 4px; margin-inline-start: auto; }
.icon-btn, .tiny { display: inline-grid; place-items: center; width: 44px; min-height: 44px; border-radius: 9px; }
.tiny svg { width: 18px; height: 18px; }
.mobile-only { display: none; }
.heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 26px 0 16px; }
.kicker { display: flex; align-items: center; gap: 8px; margin-block-end: 5px; color: var(--muted); font-size: .8125rem; font-weight: 650; letter-spacing: .1em; text-transform: uppercase; }
.kicker svg { width: 16px; height: 16px; color: var(--accent); }
.kicker i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.primary, .hint-btn, .text-btn { display: inline-flex; justify-content: center; align-items: center; gap: 8px; min-height: 44px; font-weight: 650; }
.primary { padding: 9px 17px; border-radius: var(--radius); background: var(--accent); color: var(--on-accent); text-decoration: none; }
.text-btn { color: var(--strong); text-decoration: underline; text-underline-offset: .2em; }

.hint-actions { display:flex; gap:6px 22px; align-items:center; flex-wrap:wrap; }
#hint-copy p { margin:.35em 0; max-width:85ch; }
.hint-actions a { font-weight:600; }
.board .hint-region { border-top:2px dotted var(--hint); background:var(--hint-bg); color:var(--hint); }
.board .hint-region.selected { outline:2px solid var(--accent); outline-offset:-3px; }
.board .hint-pivot { outline:2px solid var(--hint); outline-offset:-3px; }
#hint-legend { font-size:.875rem; }
.math-pencil .support { text-decoration:underline; text-underline-offset:.1em; font-weight:800; }
.math-pencil .cut { text-decoration:line-through double; color:var(--bad); }
.board :is(.target,.evidence) .math-pencil .cut { color:var(--bad); }
.answer-grid { font:600 clamp(1rem,5vw,1.5rem)/1.7 monospace; text-align:center; }
/* Server-rendered ads stay in the document flow at their declared size. */
.ad {
  --reserve-height: 42px;
  display: grid;
  place-items: center;
  height: var(--reserve-height);
  contain: layout;
  background: var(--reserve);
  border: 1px dashed var(--edge);
  border-radius: 7px;
  color: var(--muted);
  font-size: .75rem;
}
.ad-bottom { --reserve-height: 72px; }
.ad-sticker { --reserve-height: 50px; }
.partners, .feedback { margin: 20px 0; color: var(--muted); font-size: .9rem; }
.partners { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; }
.partners { margin-block: 0; }
.partners aside { display: flex; flex-wrap: wrap; gap: 8px; margin-block: 12px; }
.partners a { overflow-wrap: anywhere; }
.ad[data-ad-size] { margin-inline: auto; width: 100%; text-align: center; padding-inline: 6px; overflow-wrap: anywhere; }
.ad[data-ad-size="strip"] { --reserve-height: 50px; max-width: 320px; }
.ad[data-ad-size="banner"] { --reserve-height: 90px; max-width: 728px; }
.ad[data-ad-size="rectangle"] { --reserve-height: 250px; max-width: 300px; }
@media (max-width: 767px) {
  .ad[data-ad-size="banner"] { --reserve-height: 50px; max-width: 320px; }
}
/* Keep the mobile controls reachable on short game screens. */
@media (max-width: 680px) and (max-height: 760px) {
  #game > .ad-top[data-ad-size] { --reserve-height: 32px; }
}
@media print {
  [data-ad-slot], .partners { display: none !important; }
}

.level-group { display: flex; align-items: center; gap: 16px; margin: 18px 0 14px; }
.minor-label { font-size: .9rem; font-weight: 600; color: var(--muted); }
.levels { display: flex; gap: 2px; padding: 3px; border-radius: 11px; background: var(--tint); }
.levels :is(a,button) { display: grid; place-content: center; padding: 5px 14px; min-height: 38px; border-radius: 8px; font-size: .9rem; font-weight: 600; color: var(--ink); text-decoration: none; }
.levels :is([aria-pressed="true"], [aria-current="page"]) { background: var(--accent); color: var(--on-accent); }
.classic-layout { display: grid; grid-template-columns: minmax(0, 456px) minmax(0, 316px); align-items: start; justify-content: space-between; gap: 30px; padding: 14px clamp(20px, 4vw, 54px) 24px; background: var(--paper); border: 1px solid var(--edge); border-radius: 18px; box-shadow: 0 5px 22px #16294106; }
.board-block, .console { min-width: 0; }
.board-status, .entry-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.board-status { font-size: .875rem; font-weight: 600; color: var(--muted); }
#game-id { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.status-right { flex-shrink: 0; gap: 9px; }
#errors { font-size: .8125rem; font-weight: 500; }
#time { gap: 5px; }
#time svg { width: 16px; height: 16px; }
.board-wrap { width: 100%; container-type: inline-size; }
.board, .print-grid {
  display: grid;
  grid-template: repeat(9, minmax(0, 1fr)) / repeat(9, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  border: 2px solid var(--block);
  background: var(--paper);
}
.board button, .print-grid > * { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
:is(.board, .print-grid) > :nth-child(3n) { border-right: 2px solid var(--block); }
:is(.board, .print-grid) > :nth-child(9n) { border-right: 0; }
:is(.board, .print-grid) > :is(:nth-child(n+19):nth-child(-n+27), :nth-child(n+46):nth-child(-n+54)) { border-bottom: 2px solid var(--block); }
:is(.board, .print-grid) > :nth-child(n+73) { border-bottom: 0; }
.board button { border-radius: 0; color: var(--ink); font: 600 6.45cqw/1 var(--sans); }
.board .related { background: var(--peer); }
.board .equal { background: var(--match); font-weight: 750; }
.board .entered { color: var(--strong); font-style: italic; font-weight: 500; }
.board .selected { background: var(--accent); color: var(--on-accent); box-shadow: inset 0 0 0 2px var(--block); }
.board .evidence { box-shadow: inset 0 -3px var(--hint); }
.board :is(.evidence, .target) { color: var(--hint); background: var(--hint-bg); }
.board .target::before { content: ""; position: absolute; inset: 2px; border: 2px dashed var(--hint); pointer-events: none; }
.board .error { color: var(--bad); background: var(--bad-bg); text-decoration: underline wavy; text-decoration-thickness: 1.5px; text-underline-offset: 1px; }
.board .error::after { content: "!"; position: absolute; right: 2px; top: 2px; font: 750 .7rem/1 var(--sans); }
.board .selected:is(.evidence, .error, .target) { box-shadow: inset 0 0 0 2px var(--accent); }
.board button:focus-visible { z-index: 1; outline: 3px solid var(--focus); outline-offset: -4px; }
.board .selected:focus-visible:not(.evidence, .error, .target) { outline-color: var(--on-accent); }
.pencil { width: 100%; height: 100%; display: grid; grid-template: repeat(3, minmax(0, 1fr)) / repeat(3, minmax(0, 1fr)); place-items: center; }
.pencil i { font: 650 clamp(.625rem, 3.1cqw, .9375rem)/1 var(--sans); color: var(--muted); }
.selected .pencil i { color: var(--on-accent); }
:is(.target, .evidence) .pencil i { color: var(--hint); }
.covered { background: var(--tint); aspect-ratio: 1; }
.covered .board { visibility: hidden; }

.entry-head h2 { font-size: 1.05rem; }
.pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.pad button { display: grid; place-content: center; position: relative; min-width: 0; min-height: 64px; background: var(--tint); color: var(--strong); border-radius: 9px; }
.pad b { font-size: 1.85rem; font-weight: 600; line-height: 1; }
.pad small { position: absolute; right: 8px; top: 6px; font-size: .75rem; line-height: 1; color: var(--muted); font-weight: 600; }
.pad button:active { background: var(--match); }
.tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; margin: 12px 0; }
.tools button { min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-radius: 7px; font-size: .8125rem; font-weight: 600; }
.tools button svg { width: 21px; height: 21px; }
.tools [aria-pressed="true"] { background: var(--tint); color: var(--strong); box-shadow: inset 0 -3px var(--accent); }
.hint-btn { width: 100%; border: 1px solid var(--edge); border-radius: 8px; color: var(--strong); }
#hint-copy, .storage-status { margin: 10px 0; padding: 12px 14px; overflow-wrap: anywhere; border-inline-start: 4px solid var(--hint); border-radius: 3px 9px 9px 3px; background: var(--hint-bg); color: var(--hint); font-size: .95rem; }
#hint-copy button { display: block; min-height: 44px; font-weight: 650; text-decoration: underline; text-underline-offset: .2em; }
.progress { margin-top: 17px; border-top: 1px solid var(--edge); padding-top: 14px; font-size: .875rem; color: var(--muted); }
.progress div { display: flex; justify-content: space-between; gap: 8px; }
.progress b { color: var(--ink); }
progress { appearance: none; width: 100%; display: block; height: 6px; margin-top: 8px; border: 0; border-radius: 4px; overflow: hidden; background: var(--edge); }
progress::-webkit-progress-bar { background: var(--edge); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.discovery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 20px 0; }
.feature { display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: var(--radius); background: var(--tint); }
.feature p { color: var(--muted); margin-top: 4px; font-size: .95rem; }
.mini-grid { flex: none; width: 50px; }
.mini-grid > div { width: 44px; aspect-ratio: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; border: 2px solid var(--strong); background: var(--strong); transform: rotate(-5deg); }
.mini-grid i { background: var(--paper); }
.mini-grid i:nth-child(2), .mini-grid i:nth-child(4), .mini-grid i:nth-child(8) { background: var(--match); }
.learn { display: grid; grid-template-columns: 1fr 1.2fr; gap: 44px; padding: 28px 0; }
.learn h2 { margin-bottom: 10px; font-size: 1.65rem; }
.learn p, .feedback p { max-width: 55ch; color: var(--muted); }
details { border-bottom: 1px solid var(--edge); }
summary { padding: 12px 0; font-weight: 600; }
details p { margin-bottom: 16px; }
footer { margin-top: 28px; border-top: 1px solid var(--edge); color: var(--muted); }
.footer-inner { min-height: 80px; display: flex; align-items: center; flex-wrap: wrap; gap: 16px; padding-block: 14px; font-size: .875rem; }
.footer-inner .brand { margin-right: auto; font-size: 1.125rem; }
.footer-inner .mark { width: 22px; }

dialog { width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: 20px; border: 1px solid var(--edge); border-radius: var(--radius); background: var(--paper); color: var(--ink); box-shadow: 0 14px 68px #0004; }
dialog::backdrop { background: #0b192aa1; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.dialog-head h2 { font-size: 1.5rem; }
#dialog-body > p { color: var(--muted); margin-bottom: 14px; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 46px; border-top: 1px solid var(--edge); padding: 7px 0; font-size: .95rem; }
.setting input { flex: none; width: 21px; height: 21px; accent-color: var(--accent); }
select { min-height: 38px; max-width: 64%; padding: 5px; border: 1px solid var(--edge); border-radius: 6px; color: var(--ink); background: var(--paper); font-size: .9rem; }
.choose-level { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 18px; }
.choose-level > *, .menu-list > * { min-height: 44px; padding: 8px 10px; border: 1px solid var(--edge); border-radius: 8px; display: flex; align-items: center; gap: 7px; }
.choose-level input { accent-color: var(--accent); }
.menu-list { display: grid; gap: 6px; }
code { overflow-wrap: anywhere; }

@media (hover: hover) {
  a:hover { text-decoration: underline; }
  .header a:hover, .brand:hover, .primary:hover { text-decoration: none; }
  .icon-btn:hover, .tiny:hover, .tools button:hover:not(:disabled, [aria-pressed="true"]), .hint-btn:hover { background: var(--tint); }
  .pad button:hover:not(:disabled) { box-shadow: inset 0 0 0 2px var(--accent); }
  .primary:hover { background: var(--strong); }
  .board button:hover:not(.selected, .target, .evidence, .error) { box-shadow: inset 0 0 0 2px var(--accent); }
}
@media (prefers-reduced-motion: no-preference) {
  @keyframes hint-appear { from { opacity: .4; } to { opacity: 1; } }
  html[data-motion="on"] #hint-copy:not([hidden]) { animation: hint-appear .16s ease-out; }
  html[data-motion="on"] .pad button { transition: background-color .09s ease-out; }
}
@media (max-width: 840px) {
  .wrap { width: calc(100% - 32px); }
  .header-inner { padding-inline: 18px; gap: 22px; }
  .header nav { gap: 18px; }
  .classic-layout { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); padding: 12px 16px 18px; gap: 20px; }
  .pad button { min-height: 54px; }
}
@media (max-width: 680px), (max-width: 960px) and (max-height: 500px) {
  .wrap { width: calc(100% - 20px); }
  .header-inner { padding: 0 10px; min-height: 54px; gap: 6px; }
  .header-tools { gap: 0; }
  .header nav { display: none; }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .brand { font-size: 1.3rem; gap: 7px; }
  .mark { width: 25px; }
  .heading { margin: 14px 0 10px; flex-wrap: wrap; column-gap: 8px; }
  h1 { font-size: clamp(1.65rem, 7.4vw, 2.6rem); letter-spacing: -.035em; }
  .kicker { font-size: .75rem; gap: 6px; letter-spacing: .075em; margin-bottom: 2px; }
  .primary { padding-inline: 11px; font-size: .875rem; gap: 5px; }
  .ad-top { --reserve-height: 32px; }
  .level-group { margin: 10px 0 0; }
  .level-group .minor-label { display: none; }
  .levels { width: 100%; gap: 0; padding: 2px; }
  .levels :is(button,a) { flex: 1 1 auto; padding: 4px 2px; min-height: 40px; font-size: .85rem; }
  .classic-layout { display: block; padding: 0; border: 0; background: transparent; box-shadow: none; }
  .board button { font-size: 6.8cqw; }
  .console { margin-top: 5px; }
  .entry-head h2 { font-size: .95rem; }
  .pad { grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
  .pad button { min-height: 50px; border-radius: 7px; }
  .pad b { font-size: 1.55rem; }
  .pad small { position: static; margin-top: 2px; font-size: .75rem; }
  .tools { margin: 6px 0; }
  .tools button { min-height: 48px; }
  .progress { margin-top: 10px; padding-top: 8px; }
  .learn { grid-template-columns: 1fr; gap: 14px; }
  .discovery { grid-template-columns: 1fr; gap: 10px; }
  .footer-inner { gap: 8px 16px; }
}
@media (min-width: 1280px) and (min-height: 960px) {
  :root { --page: 1056px; }
  .classic-layout { grid-template-columns: minmax(0, clamp(500px, calc(100vh - 445px), 552px)) minmax(0, 316px); }
}
.resume-banner { margin-block-end: 8px; }
.tools [aria-pressed="true"] { background: var(--accent); color: var(--on-accent); box-shadow: none; }
#hint-text { margin-block: 5px; line-height: 1.6; }
@media (max-width: 680px), (max-width: 960px) and (max-height: 500px) {
  .header-inner { flex-wrap: wrap; }
  .header nav.expanded { display: flex; order: 1; width: 100%; flex-wrap: wrap; }
  .header nav.expanded a { min-height: 44px; }
  .heading { margin-block: 6px 4px; }
  .heading .kicker { display: none; }
  .level-group { margin-block-start: 6px; }
  .console { display: flex; flex-direction: column; gap: 4px; margin-top: 3px; }
  .entry-head { order: 1; }
  .tools { margin-block: 0; }
  .tools button { min-height: 44px; gap: 2px; }
  .pad { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .pad button { min-height: 44px; }
  .pad small { position: absolute; top: 6px; right: 7px; margin: 0; }
  [data-keypad="large"] .pad { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  [data-keypad="large"] .pad button { min-height: 52px; }
}
@media (max-width: 350px) {
  .wrap { width: calc(100% - 16px); }
  .header-inner { padding-inline: 8px; }
  .status-right { gap: 3px; }
  .heading .primary { padding-inline: 8px; }
  .heading .primary svg { width: 16px; }
  .setting { flex-wrap: wrap; }
}
@media (orientation: landscape) and (max-width: 960px) and (max-height: 500px) {
  main.wrap { max-width: 510px; }
}
.seo-links { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.seo-help { margin-block: 20px; }
.seo-archive { padding-block: 24px; }
.seo-archive nav { margin-block: 16px; }
.seo-archive form input { max-width: 7em; }
.archive-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(78px, 1fr)); gap: 4px 12px; list-style: none; padding: 0; }
.archive-list a { display: inline-block; padding-block: 8px; }
