:root {
  color-scheme: light;
  --page: #eef2f8;
  --surface: #ffffff;
  --ink: #22324a;
  --muted: #5b6b82;
  --accent: #3458d4;
  --accent-dark: #2445b4;
  --line: #d6dfec;
  --peer: #edf2fc;
  --same: #d8e3ff;
  --selected: #3458d4;
  --error: #b32638;
  --success: #287357;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--ink); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
button, a, input { touch-action: manipulation; }
button { cursor: pointer; }
button { color: inherit; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
[hidden] { display: none !important; }
.icon-definitions { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.app-shell { width: min(100%, 480px); margin: 0 auto; padding: max(22px, env(safe-area-inset-top)) 24px max(16px, env(safe-area-inset-bottom)); }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); }
.tabs { display: flex; border-bottom: 1px solid var(--line); gap: 28px; margin-bottom: 20px; }
.tab { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 0 13px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font-size: 14px; font-weight: 600; min-height: 44px; }
.tab .icon { width: 18px; height: 18px; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
h1, h2, p { margin: 0; }
h1 { font-size: 23px; line-height: 1.25; font-weight: 700; letter-spacing: -.035em; text-wrap: balance; }
.section-heading p { color: var(--muted); font-size: 12px; margin-top: 7px; line-height: 1.6; }
.connection { display: flex; align-items: center; gap: 5px; font-size: 10px; white-space: nowrap; color: var(--muted); }
.connection > span:first-child { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.connection.online > span:first-child { background: var(--success); }
.connection.offline { color: var(--error); }
.connection.offline > span:first-child { background: var(--error); }
.game-meta { display: flex; align-items: center; gap: 17px; margin-bottom: 12px; font-size: 12px; }
.difficulty-badge { color: var(--accent-dark); background: #e0e8ff; padding: 6px 10px; border-radius: 5px; font-weight: 650; }
.mistakes { color: var(--muted); }
.mistakes strong { margin-left: 4px; font-weight: 600; color: var(--ink); }
.timer { display: flex; align-items: center; gap: 7px; margin-left: auto; font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 550; }
.timer .icon { width: 16px; height: 16px; color: var(--muted); }
.board-wrap { position: relative; }
.board { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); aspect-ratio: 1; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; background: var(--surface); }
.cell { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0; aspect-ratio: 1; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); font-size: clamp(21px, 6vw, 29px); line-height: 1; font-weight: 450; font-variant-numeric: tabular-nums; color: var(--accent); }
.cell:nth-child(3n) { border-right: 2px solid var(--ink); }
.cell:nth-child(9n) { border-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27), .cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ink); }
.cell:nth-child(n+73) { border-bottom: 0; }
.cell.given { color: var(--ink); font-weight: 550; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); color: var(--accent-dark); }
.cell.selected { background: var(--selected); color: #fff; }
.cell:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: -3px; z-index: 1; }
.cell.selected:focus-visible { outline-color: white; }
.cell.mistake { animation: wrong .45s ease-out; background: #fce1e5; color: var(--error); }
.cell.hinted { animation: revealed .7s ease-out; }
.cell:disabled { opacity: 1; }
.cell-notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; padding: 3px; }
.cell-notes span { display: flex; align-items: center; justify-content: center; font-size: clamp(8px, 2.2vw, 11px); font-weight: 550; color: var(--muted); }
.selected .cell-notes span { color: white; }
.progress-line { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; font-size: 10px; color: var(--muted); }
progress { appearance: none; display: block; border: 0; border-radius: 2px; width: 100%; height: 3px; margin-top: 9px; background: var(--line); color: var(--accent); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px -5px; }
.tool { display: flex; align-items: center; flex-direction: column; gap: 5px; padding: 7px 2px; border: 1px solid transparent; border-radius: 8px; background: transparent; font-size: 11px; font-weight: 550; }
.tool .icon { width: 23px; height: 23px; }
.tool small { color: var(--muted); font-size: 9px; font-weight: 400; }
.tool[aria-pressed="true"] { color: var(--accent-dark); background: #e0e8ff; border-color: #c5d2fa; }
.tool[aria-pressed="true"] small { color: var(--accent-dark); }
.keypad { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.number-key { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; height: 63px; border: 1px solid #d2ddec; border-radius: 7px; background: var(--surface); color: var(--accent); font-size: 26px; font-weight: 500; box-shadow: 0 2px 1px #22324a05; }
.number-key small { color: var(--muted); font-size: 9px; font-weight: 400; }
.number-key:disabled { opacity: .4; box-shadow: none; }
.input-caption { text-align: center; color: var(--muted); font-size: 11px; line-height: 1.5; margin-top: 13px; min-height: 17px; }
.new-game-button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; margin-top: 16px; padding: 13px 17px; border: 1px solid #c8d4e8; border-radius: 8px; background: transparent; font-size: 13px; font-weight: 650; }
.new-game-button .icon { width: 19px; height: 19px; }
.new-game-button .icon:last-child { margin-left: auto; color: var(--accent); }
.primary-button { display: flex; justify-content: center; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 13px 20px; border: 0; border-radius: 8px; color: white; background: var(--accent); font-size: 14px; font-weight: 600; }
.primary-button .icon { width: 18px; height: 18px; }
.text-button { min-height: 44px; padding: 10px; border: 0; background: none; color: var(--muted); font-size: 13px; }
dialog { width: min(calc(100% - 32px), 420px); padding: 28px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px #14233e26; }
dialog::backdrop { background: #18274280; }
dialog h2 { font-size: 23px; line-height: 1.25; letter-spacing: -.03em; }
dialog p { color: var(--muted); font-size: 13px; line-height: 1.75; margin-top: 12px; }
.dialog-top { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.dialog-top .icon-button { flex-shrink: 0; width: 38px; height: 38px; border: 0; }
.difficulty-options { margin: 22px 0; padding: 0; border: 0; display: grid; gap: 8px; }
.difficulty-options label { display: flex; align-items: center; gap: 13px; padding: 16px 13px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.difficulty-options label:has(input:checked) { border-color: var(--accent); background: var(--peer); }
.difficulty-options input { accent-color: var(--accent); width: 17px; height: 17px; flex-shrink: 0; margin: 0; }
.difficulty-options strong { display: block; font-size: 14px; font-weight: 650; }
.difficulty-options small { display: block; font-size: 11px; color: var(--muted); margin-top: 5px; }
.level-bars { margin-left: auto; display: flex; align-items: flex-end; gap: 3px; height: 20px; }
.level-bars i { width: 4px; height: 8px; border-radius: 1px; background: var(--accent); }
.level-bars i:nth-child(2) { height: 13px; }
.level-bars i:last-child { height: 18px; }
.difficulty-options label:first-of-type .level-bars i:not(:first-child),
.difficulty-options label:nth-of-type(2) .level-bars i:last-child { background: var(--line); }
.help-rule { display: flex; align-items: flex-start; gap: 13px; margin-top: 22px; }
.help-rule .icon { margin-top: 3px; color: var(--accent); }
.help-rule p { margin-top: 0; font-size: 12px; }
.help-rule strong { display: block; color: var(--ink); margin-bottom: 3px; font-size: 13px; }
dialog .help-footnote { font-size: 11px; border-top: 1px solid var(--line); padding-top: 18px; margin: 22px 0; }
.pause-overlay { position: absolute; inset: 0; z-index: 2; background: var(--peer); border: 2px solid var(--ink); border-radius: 4px; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 24px; text-align: center; }
.pause-overlay > .icon { width: 36px; height: 36px; margin-bottom: 20px; color: var(--accent); }
.pause-overlay h2 { font-size: 22px; letter-spacing: -.035em; }
.pause-overlay p { font-size: 12px; color: var(--muted); margin-top: 9px; line-height: 1.6; }
.pause-overlay .primary-button { margin-top: 24px; max-width: 240px; }
.toast { position: fixed; z-index: 10; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(calc(100% - 40px), 420px); padding: 14px 18px; border-radius: 8px; background: var(--ink); color: white; font-size: 13px; line-height: 1.6; box-shadow: 0 6px 24px #14233e26; }
.access-panel { padding: 44px 10px 70px; text-align: center; }
.access-mark { font-size: 64px; color: var(--ink); font-weight: 650; letter-spacing: .05em; margin-bottom: 24px; font-variant-numeric: tabular-nums; }
.access-mark span { color: var(--accent); }
.access-panel h1 { font-size: 27px; }
.access-panel p { font-size: 14px; color: var(--muted); line-height: 1.75; margin: 15px 0 25px; }
.inline-error { color: var(--error); font-size: 12px; margin-bottom: 15px; }
.section-heading { margin-bottom: 30px; }
.stats-totals { display: grid; grid-template-columns: 1fr 1fr; padding-bottom: 26px; border-bottom: 1px solid var(--line); margin-bottom: 28px; }
.stats-totals strong { display: block; font-variant-numeric: tabular-nums; font-size: 42px; font-weight: 600; letter-spacing: -.04em; }
.stats-totals span { font-size: 12px; color: var(--muted); }
.stats-totals > div + div { border-left: 1px solid var(--line); padding-left: 25px; }
.stats-title { font-size: 16px; margin-bottom: 10px; }
.stats-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.stats-row > div { display: flex; flex-direction: column; gap: 5px; }
.stats-row small { font-size: 11px; color: var(--muted); }
.stats-row strong { font-size: 16px; font-weight: 550; font-variant-numeric: tabular-nums; }
.stats-block + .stats-block { margin-top: 30px; }
.empty-state { padding: 25px 0; color: var(--muted); font-size: 13px; line-height: 1.75; }
#win-dialog { text-align: center; }
.win-mark { display: grid; place-items: center; width: 72px; height: 72px; border: 1px solid #b7d8c6; border-radius: 50%; margin: 5px auto 24px; background: #edf6f1; color: var(--success); }
.win-mark .icon { width: 36px; height: 36px; }
.win-summary { display: flex; justify-content: center; gap: 24px; padding: 25px 0; margin: 25px 0; border-block: 1px solid var(--line); }
.win-summary strong { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.win-summary span { display: block; font-size: 10px; color: var(--muted); margin-top: 7px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
@keyframes wrong { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 70% { transform: translateX(3px); } }
@keyframes revealed { 0% { background: #c9e8d8; } }
@media (hover: hover) {
  .number-key:not(:disabled):hover, .tool:not(:disabled):hover { background: #e0e8ff; }
  .primary-button:not(:disabled):hover { background: var(--accent-dark); }
  .new-game-button:hover { border-color: var(--accent); color: var(--accent); }
}
@media (min-width: 700px) {
  .app-shell { margin-top: 28px; padding-top: 28px; }
}
@media (max-width: 380px) {
  .app-shell { padding-inline: 16px; padding-top: 14px; }
  .tabs { margin-bottom: 20px; }
  h1 { font-size: 21px; }
  .connection { font-size: 9px; }
  .keypad { gap: 4px; }
  .number-key { height: 56px; font-size: 23px; }
  .tools { margin-block: 13px; }
  .tool { font-size: 10px; }
  .new-game-button { margin-top: 17px; }
  dialog { padding: 22px; }
}
@media (max-height: 760px) and (max-width: 699px) {
  .tabs { margin-bottom: 16px; }
  .app-shell { padding-top: 10px; }
  .tools { margin-top: 12px; margin-bottom: 10px; }
  .tool { gap: 5px; padding-block: 7px; }
  .number-key { height: 53px; }
  .new-game-button { margin-top: 15px; min-height: 46px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.tabs { align-items: center; gap: 22px; margin-bottom: 12px; }
.tabs .tab { padding-block: 8px; }
.tabs .icon-button { margin-left: auto; border: 0; }
.connection { border: 0; background: transparent; padding: 4px 0 4px 8px; min-height: 24px; }
body.playing .app-shell {
  display: flex;
  flex-direction: column;
  height: var(--app-height, 100dvh);
  max-height: calc(min(100vw, 480px) + 323px);
  margin-block: 0;
  padding: max(8px, var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top)) 16px max(8px, var(--tg-content-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom));
}
body.playing .tabs { flex: 0 0 44px; margin-bottom: 8px; }
body.playing main { flex: 1; min-height: 0; }
body.playing #game-view {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: 28px minmax(0, 1fr) 24px 3px 68px 60px 17px 44px;
  gap: 6px;
}
body.playing .game-meta { margin: 0; }
body.playing .board-wrap { container-type: size; display: grid; place-items: center; min-height: 0; }
body.playing .board {
  width: min(100%, 100cqh);
  height: min(100cqw, 100%);
  aspect-ratio: 1;
  grid-template-rows: repeat(9, minmax(0, 1fr));
}
body.playing .cell { min-height: 0; aspect-ratio: auto; font-size: clamp(17px, 6cqh, 29px); }
body.playing .cell-notes span { font-size: clamp(7px, 2.5cqh, 11px); }
body.playing .pause-overlay { inset: 50% auto auto 50%; transform: translate(-50%, -50%); width: min(100%, 100cqh); height: min(100cqw, 100%); padding: 16px; }
body.playing .pause-overlay h2 { font-size: 19px; }
body.playing .pause-overlay > .icon { margin-bottom: 10px; }
body.playing .pause-overlay .primary-button { margin-top: 14px; min-height: 44px; }
body.playing .progress-line, body.playing progress, body.playing .tools, body.playing .input-caption, body.playing .new-game-button { margin: 0; }
body.playing .progress-line { align-items: center; }
body.playing .tool { gap: 4px; padding: 5px 2px; }
body.playing .number-key { height: 60px; }
body.playing .new-game-button { min-height: 44px; padding-block: 10px; }
body.playing .input-caption { font-size: 10px; }
body.playing .toast { top: max(8px, var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top)); bottom: auto; }
body.playing.compact-height #game-view { grid-template-rows: 28px minmax(0, 1fr) 24px 3px 48px 48px 0 44px; gap: 4px; }
body.playing.compact-height .number-key { height: 48px; gap: 2px; font-size: 23px; }
body.playing.compact-height .tool small, body.playing.compact-height .input-caption { display: none; }
body.playing.compact-height .pause-overlay > .icon, body.playing.compact-height .pause-overlay p { display: none; }
