:root {
  color-scheme: light;
  --canvas: #eef1ed;
  --surface: #fff;
  --ink: #17211e;
  --muted: #68736f;
  --line: #d4dbd7;
  --line-strong: #6d7974;
  --accent: #16705a;
  --accent-soft: #dff0e9;
  --amber: #a96d16;
  --red: #b23f35;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { min-height: 100vh; background: var(--canvas); color: var(--ink); letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(22, 112, 90, .23); outline-offset: 3px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar { min-height: 70px; padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .95); }
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; background: #25332e; color: #fff; font-weight: 900; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; font-weight: 750; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .nav-link { min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.icon-button { width: 38px; padding: 0; display: grid; place-items: center; cursor: pointer; }
.icon-button svg, .nav-link svg { width: 19px; height: 19px; }
.link-button { text-decoration: none; }
.nav-link { padding: 0 12px; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 780; text-decoration: none; }

.game-layout { width: min(1040px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 54px; display: grid; grid-template-columns: minmax(0, 660px) minmax(260px, 1fr); gap: 34px; align-items: start; }
.play-area { min-width: 0; }
.game-heading { margin-bottom: 17px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.eyebrow, .section-heading p, .modal-kicker { margin: 0 0 5px; color: var(--accent); font-size: 10px; font-weight: 850; }
h1 { margin: 0; font-size: 29px; line-height: 1.1; }
.live-stats { display: flex; align-items: center; gap: 8px; }
.live-stats span { min-width: 74px; padding: 7px 10px; border-left: 1px solid var(--line); }
.live-stats small, .live-stats strong { display: block; }
.live-stats small { margin-bottom: 2px; color: var(--muted); font-size: 9px; }
.live-stats strong { font-size: 13px; }

.board-wrap { position: relative; width: min(100%, 620px); aspect-ratio: 1; }
.sudoku-board { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr); border: 2px solid #34423d; background: #34423d; gap: 1px; box-shadow: 0 14px 34px rgba(29, 45, 39, .1); }
.sudoku-cell { position: relative; min-width: 0; min-height: 0; padding: 0; display: grid; place-items: center; border: 0; background: #fff; color: #24302c; cursor: pointer; font-size: clamp(19px, 4.1vw, 31px); font-weight: 560; }
.sudoku-cell.box-right { margin-right: 2px; }
.sudoku-cell.box-bottom { margin-bottom: 2px; }
.sudoku-cell.related { background: #edf3f0; }
.sudoku-cell.matching { background: #d7ebe4; }
.sudoku-cell.selected { background: #bde0d4; box-shadow: inset 0 0 0 2px var(--accent); z-index: 1; }
.sudoku-cell.given { color: #111a17; font-weight: 850; }
.sudoku-cell.wrong { background: #fae5e2; color: var(--red); }
.sudoku-cell:disabled { cursor: default; }
.check-setting { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; }
.check-setting input { width: 18px; height: 18px; accent-color: var(--accent); }
.check-help { margin: 11px 0 0; color: var(--muted); font-size: 12px; line-height: 1.8; }
.notes-grid { position: absolute; inset: 4px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.notes-grid span { display: grid; place-items: center; color: #4f655d; font-size: clamp(7px, 1.25vw, 10px); font-weight: 700; }
.pause-overlay { position: absolute; z-index: 4; inset: 0; display: grid; place-content: center; justify-items: center; gap: 11px; background: rgba(246, 248, 247, .96); }
.pause-overlay svg { width: 34px; height: 34px; color: var(--accent); }
.pause-overlay strong { font-size: 18px; }
.pause-overlay button { min-height: 40px; padding: 0 18px; border: 0; border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 800; }

.number-pad { width: min(100%, 620px); margin-top: 15px; display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 6px; }
.number-button { height: 52px; padding: 0; display: grid; place-content: center; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--accent); cursor: pointer; }
.number-button strong { font-size: 22px; line-height: 1; }
.number-button small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.number-button:hover { border-color: #9caaa4; }
.number-button.complete { color: #a8b0ad; background: #f3f5f4; }

.tool-row { width: min(100%, 620px); margin-top: 9px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.tool-button { position: relative; min-height: 56px; padding: 6px 4px; display: grid; place-content: center; justify-items: center; gap: 3px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
.tool-button svg { width: 20px; height: 20px; }
.tool-button span { color: var(--muted); font-size: 9px; font-weight: 750; }
.tool-button i { position: absolute; top: 5px; right: 6px; padding: 2px 4px; border-radius: 3px; background: #eef0ef; color: var(--muted); font-size: 8px; font-style: normal; }
.tool-button[aria-pressed="true"] { border-color: var(--amber); background: #fff9ec; color: var(--amber); }
.tool-button[aria-pressed="true"] i { background: var(--amber); color: #fff; }
.tool-button:disabled { opacity: .45; cursor: default; }

.game-sidebar { padding-top: 61px; }
.side-section { padding: 20px 0 22px; border-top: 1px solid var(--line); }
.side-section:last-of-type { border-bottom: 1px solid var(--line); }
.section-heading { margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 17px; }
.segmented-control { padding: 3px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 3px; border: 1px solid var(--line); border-radius: 6px; background: #e6eae7; }
.segmented-control button { min-height: 38px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.segmented-control button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 5px rgba(25, 37, 33, .11); }
.primary-button { width: 100%; min-height: 44px; margin-top: 10px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 820; }
.primary-button svg { width: 19px; height: 19px; }
.secondary-actions { margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.secondary-actions button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-size: 11px; font-weight: 750; }
.secondary-actions svg { width: 18px; height: 18px; }
.record-list { margin: 0; }
.record-list div { min-height: 38px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-bottom: 1px solid #e3e7e5; }
.record-list div:last-child { border-bottom: 0; }
.record-list dt { color: var(--muted); font-size: 11px; }
.record-list dd { margin: 0; font-size: 13px; font-weight: 800; }
.local-note { margin: 15px 0 0; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.local-note span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.modal { width: min(420px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); box-shadow: 0 24px 80px rgba(22, 32, 28, .25); }
.modal::backdrop { background: rgba(22, 32, 28, .46); backdrop-filter: blur(3px); }
.modal form { padding: 25px; }
.modal h2 { margin: 0; font-size: 21px; }
.modal form > p:not(.modal-kicker) { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.modal-actions { margin-top: 24px; display: flex; justify-content: flex-end; gap: 9px; }
.secondary-button, .primary-button.compact { width: auto; min-height: 40px; margin: 0; padding: 0 16px; }
.secondary-button { border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; font-weight: 750; }
.complete-modal form { text-align: center; }
.complete-mark { width: 48px; height: 48px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 26px; font-weight: 900; }
.complete-stats { margin-top: 20px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 6px; }
.complete-stats span { padding: 11px 6px; border-right: 1px solid var(--line); }
.complete-stats span:last-child { border: 0; }
.complete-stats small, .complete-stats strong { display: block; }
.complete-stats small { margin-bottom: 3px; color: var(--muted); font-size: 9px; }
.complete-stats strong { font-size: 16px; }
.rules-modal ol { margin: 18px 0 0; padding-left: 22px; color: #3e4a46; font-size: 13px; line-height: 2; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); max-width: calc(100% - 30px); padding: 10px 14px; transform: translate(-50%, 14px); border-radius: 6px; background: #202b27; color: #fff; opacity: 0; pointer-events: none; font-size: 12px; transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .game-layout { width: min(620px, calc(100% - 28px)); grid-template-columns: 1fr; gap: 8px; padding-top: 24px; }
  .game-sidebar { padding-top: 0; }
  .game-heading { align-items: center; }
  .side-section { padding: 18px 0; }
}

@media (max-width: 540px) {
  .topbar { min-height: 62px; padding-left: max(13px, env(safe-area-inset-left)); padding-right: max(13px, env(safe-area-inset-right)); }
  .brand small, .nav-link span { display: none; }
  .nav-link { width: 38px; padding: 0; justify-content: center; }
  .header-actions { gap: 6px; }
  .game-layout { width: calc(100% - 20px); padding-top: 18px; }
  .game-heading { margin-bottom: 12px; }
  h1 { font-size: 24px; }
  .live-stats { gap: 0; }
  .live-stats span { min-width: 58px; padding: 5px 7px; }
  .sudoku-cell { font-size: clamp(18px, 7vw, 28px); }
  .notes-grid { inset: 2px; }
  .notes-grid span { font-size: clamp(6px, 2.4vw, 9px); }
  .number-pad { gap: 3px; margin-top: 10px; }
  .number-button { height: 47px; border-radius: 4px; }
  .number-button strong { font-size: 20px; }
  .tool-row { gap: 4px; }
  .tool-button { min-height: 53px; }
  .game-sidebar { padding-bottom: 20px; }
}

@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
