:root {
  color-scheme: light dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --page: #edf3f0;
  --ink: #192b29;
  --muted: #47615d;
  --accent: #126b59;
  --inverse: #fff;
  --surface: #fbfdfc;
  --glass: rgb(251 253 252 / 78%);
  --line: #afc2bc;
  --heavy: #3f625a;
  --given: #e4ede8;
  --selected: #b8ded1;
  --region: #e8f4ef;
  --mark: #fce7b7;
  --bad: #a82d36;
  --bad-bg: #ffe2df;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #101d1c;
    --ink: #e9f3ed;
    --muted: #adcbc0;
    --accent: #9be0c8;
    --inverse: #102a23;
    --surface: #192a28;
    --glass: rgb(25 42 40 / 85%);
    --line: #506760;
    --heavy: #93aca2;
    --given: #223b35;
    --selected: #305f50;
    --region: #263c35;
    --mark: #604a25;
    --bad: #ffb7bd;
    --bad-bg: #5d292f;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); }
button, input { font: inherit; }
button { cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; opacity: .7; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.shell { width: min(100%, 1040px); margin-inline: auto; padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); }
.bar { background: var(--glass); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.bar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 62px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; font-weight: 750; white-space: nowrap; }
.brand img { border-radius: 9px; }
#profile-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); }
main { padding-block: clamp(22px, 5vw, 52px) max(24px, env(safe-area-inset-bottom)); }
h1 { margin: 0 0 16px; font-size: clamp(1.9rem, 5vw, 3rem); font-weight: 760; letter-spacing: -.045em; overflow-wrap: anywhere; }
h2 { margin: 0 0 12px; font-size: 1.19rem; }
p { line-height: 1.5; }
p, ul { margin-block: 0 12px; }
.narrow { max-width: 650px; }
.panel { border: 1px solid var(--line); border-radius: 20px; background: var(--surface); padding: clamp(14px, 3vw, 23px); }
.list { display: grid; padding: 0; list-style: none; gap: 9px; }
.list button { text-align: left; width: 100%; }
.list strong, .list small { display: block; overflow-wrap: anywhere; }
.list small { color: var(--muted); margin-top: 4px; }
.flow { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; min-height: 44px; padding: 9px 14px; font-weight: 630; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--inverse); }
.btn[aria-pressed="true"] { border-color: var(--accent); background: var(--selected); }
.btn.back { border: 0; background: transparent; padding-inline: 0 12px; color: var(--accent); }
.form { display: grid; gap: 10px; margin-top: 14px; }
.form input { width: 100%; min-height: 44px; background: var(--surface); color: var(--ink); border: 1px solid var(--heavy); border-radius: 10px; padding: 9px 12px; }
.form button { justify-self: start; }
.status { color: var(--muted); margin: 10px 0 0; }
.status:empty { display: none; }
.error { color: var(--bad); }
.game-top { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 4px 18px; margin-bottom: 12px; }
.game-top .back { grid-column: 1 / -1; justify-self: start; }
.game-top h1 { margin: 0; }
.save { text-align: right; font-size: .86rem; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; max-width: 570px; }
.board { width: 100%; aspect-ratio: 1; display: grid; grid-template-rows: repeat(9, minmax(0, 1fr)); border: 2px solid var(--heavy); border-radius: 7px; overflow: hidden; background: var(--surface); container-type: inline-size; touch-action: manipulation; }
.row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); }
.cell { border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0; background: var(--surface); color: var(--accent); font-size: clamp(1rem, 6.5cqi, 2.3rem); line-height: 1; font-variant-numeric: tabular-nums; font-weight: 520; padding: 0; position: relative; }
.cell:nth-child(3n) { border-right: 2px solid var(--heavy); }
.row:nth-child(3n) .cell { border-bottom: 2px solid var(--heavy); }
.cell:last-child { border-right: 0; }
.row:last-child .cell { border-bottom: 0; }
.cell.given { background: var(--given); color: var(--ink); font-weight: 750; }
.cell.related { background: var(--region); }
.cell.mark { background: var(--mark); }
.cell.conflict { background: var(--bad-bg); color: var(--bad); }
.cell[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--accent); z-index: 1; }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; z-index: 2; }
.notes { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); position: absolute; inset: 1px; align-items: center; font-size: clamp(.46rem, 2.3cqi, .79rem); }
.side { min-width: 0; display: grid; align-content: start; gap: 12px; }
.keypad { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.keypad .btn { min-width: 0; padding: 6px 0; font-size: 1.2rem; touch-action: manipulation; }
.help-panel { border-top: 1px solid var(--line); padding-top: 12px; }
.help-panel ul { padding-left: 1.25em; }
.help-panel .btn { margin-block: 4px; }
details summary { color: var(--muted); cursor: pointer; min-height: 44px; display: flex; align-items: center; width: max-content; }
@media (min-width: 760px) {
  .game-layout { max-width: 100%; grid-template-columns: minmax(0, 570px) minmax(245px, 1fr); gap: 24px; }
  .side { padding: 16px; background: var(--glass); border: 1px solid var(--line); border-radius: 18px; }
  .keypad { grid-template-columns: repeat(3, 1fr); gap: 6px; }
}
@media (max-width: 450px) {
.keypad { grid-template-columns: repeat(5, minmax(44px, 1fr)); }
}
@media (max-width: 390px) {
  .game-top { grid-template-columns: 1fr; }
  .save { text-align: left; margin: 0; }
  .shell { padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
}
