:root {
  --ink: #1c1915;
  --muted: #5c564c;
  --paper: #f6f1e7;
  --card: #fffdf8;
  --line: #d9d0c0;
  --teal: #0f5f63;
  --teal-dark: #0a3f43;
  --teal-soft: #dceeee;
  --accent: #c46a1a;
  --good: #1b7a45;
  --good-soft: #dcecde;
  --bad: #b42318;
  --bad-soft: #f8d0cc;
  --given: #1c1915;
  --user: #0f5f63;
  --note: #5c564c;
  --radius: 14px;
  --max: 1080px;
  --grid-line: #1c1915;
  --grid-thin: #b9b09f;
  --cell-select: #ffe3b8;
  --cell-peer: #efe7d6;
  --cell-same: #cbe7e6;
  --cell-hint: #d9ecff;
  --shadow: 0 8px 24px rgba(28, 25, 21, 0.08);
  --focus: 0 0 0 3px #fff, 0 0 0 6px var(--teal);
  --pad: 16px;
  color-scheme: light;
}
html[data-theme="dark"] {
  --ink: #f3eee4;
  --muted: #b3ab9e;
  --paper: #161411;
  --card: #221e19;
  --line: #3a342b;
  --teal: #6ec4c8;
  --teal-dark: #0e2c2e;
  --teal-soft: #1a3335;
  --accent: #f0a35a;
  --good: #6dca8c;
  --good-soft: #1d3a28;
  --bad: #f0a099;
  --bad-soft: #5a2622;
  --given: #f3eee4;
  --user: #8fd5d8;
  --note: #c9c0b2;
  --grid-line: #e8e0d4;
  --grid-thin: #5a5348;
  --cell-select: #5a3d16;
  --cell-peer: #2c2822;
  --cell-same: #1d4345;
  --cell-hint: #1d3550;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --focus: 0 0 0 3px #161411, 0 0 0 6px var(--teal);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.55;
  min-height: 100vh;
  font-size: 1.05rem;
}
img, svg { max-width: 100%; }
a { color: var(--teal); }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.wrap { width: min(var(--max), calc(100% - 32px)); margin: 0 auto; }
.skip {
  position: absolute; left: -999px; top: 0;
  background: var(--card); color: var(--ink); padding: 8px 12px; z-index: 100;
}
.skip:focus { left: 8px; top: 8px; }

/* Header */
.site-header {
  background: var(--teal-dark);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 0 rgba(196, 106, 26, 0.9);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  font-weight: 750;
}
.brand:hover { color: #fff; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  overflow: hidden;
}
.brand-mark img, .brand-mark svg { width: 34px; height: 34px; display: block; }
.brand-name { font-size: 1.1rem; line-height: 1.15; }
.brand-name small {
  display: block;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: .85;
}
.nav { display: flex; gap: 4px 6px; flex-wrap: wrap; align-items: center; }
.nav a {
  color: #eef6f6;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 10px;
  border-radius: 999px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.nav a:hover, .nav a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }
.header-tools { display: flex; gap: 8px; align-items: center; }
.theme-btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,.35);
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 650;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 40px;
}
.theme-btn:hover { background: rgba(255,255,255,.12); }

/* Footer */
.site-footer {
  margin-top: 48px;
  border-top: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-size: 0.95rem;
}
.site-footer .wrap { padding: 28px 0 36px; display: block; text-align: center; }
.site-footer p { margin: 0 0 8px; }
.site-footer a { color: inherit; }
.iprof-more, .more-sites {
  max-width: 960px;
  margin: 14px auto 6px;
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}
.iprof-more-h, .more-sites-h { margin: 0 0 4px; font-weight: 700; color: var(--ink); }
.iprof-more ul, .more-sites ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 16px;
}
.iprof-more li, .more-sites li { margin: 0; padding: 0; }
.iprof-more a, .more-sites a { color: inherit; text-decoration: underline; }

/* Content */
main { padding: 24px 0 40px; }
h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); line-height: 1.2; margin: 0 0 10px; }
h2 { font-size: 1.25rem; margin: 1.4em 0 0.5em; }
.lead { font-size: 1.12rem; color: var(--muted); margin: 0 0 18px; max-width: 46rem; }
.crumb { font-size: 0.95rem; color: var(--muted); margin: 0 0 10px; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.prose { max-width: 46rem; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 1.3em; }
.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--teal-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 0.9em;
}

/* Play layout */
.play-layout {
  display: grid;
  grid-template-columns: minmax(280px, 540px) minmax(240px, 1fr);
  gap: 28px;
  align-items: start;
}
@media (max-width: 820px) {
  .play-layout { grid-template-columns: 1fr; }
}
.play-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin: 0 0 14px;
  font-weight: 650;
}
.play-meta .timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.9rem;
}
html[data-theme="dark"] .badge { color: var(--teal); }
.status {
  min-height: 1.5em;
  margin: 10px 0 0;
  font-weight: 650;
}
.status.ok { color: var(--good); }
.status.bad { color: var(--bad); }
.status.win {
  background: var(--good-soft);
  color: var(--good);
  padding: 10px 12px;
  border-radius: 10px;
}

/* Sudoku grid */
.sudoku {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 540px);
  aspect-ratio: 1;
  border: 3px solid var(--grid-line);
  background: var(--card);
  margin: 0 auto;
  user-select: none;
  touch-action: manipulation;
}
.sudoku .cell {
  position: relative;
  appearance: none;
  border: 0;
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  background: var(--card);
  color: var(--user);
  padding: 0;
  margin: 0;
  font: 700 clamp(1.05rem, 4.6vw, 1.85rem)/1 "Segoe UI", system-ui, sans-serif;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}
.sudoku .cell:nth-child(9n) { border-right: 0; }
.sudoku .cell:nth-child(n+73) { border-bottom: 0; }
.sudoku .cell:nth-child(3n):not(:nth-child(9n)) {
  border-right: 3px solid var(--grid-line);
}
.sudoku .cell:nth-child(n+19):nth-child(-n+27),
.sudoku .cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 3px solid var(--grid-line);
}
.sudoku .cell.given { color: var(--given); font-weight: 800; }
.sudoku .cell.peer { background: var(--cell-peer); }
.sudoku .cell.same { background: var(--cell-same); }
.sudoku .cell.selected { background: var(--cell-select); box-shadow: inset 0 0 0 2px var(--accent); }
.sudoku .cell.mistake { background: var(--cell-bad); color: var(--bad); }
.sudoku .cell.hinted { background: var(--cell-hint); }
.sudoku .cell.conflict:not(.given) { color: var(--bad); }
.sudoku .cell:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--teal); z-index: 1; }
.notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
  font-size: clamp(0.5rem, 2.1vw, 0.75rem);
  font-weight: 650;
  color: var(--note);
  line-height: 1;
}
.notes span { display: grid; place-items: center; }

/* Controls */
.controls { display: flex; flex-direction: column; gap: 12px; }
.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
@media (min-width: 821px) {
  .numpad { grid-template-columns: repeat(3, 1fr); }
}
.numpad button, .toolbar button, .btn, .btn-row a, select.field, .field {
  appearance: none;
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  min-height: 48px;
  padding: 8px 12px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.numpad button { font-size: 1.35rem; min-height: 52px; }
.numpad button:hover, .toolbar button:hover, .btn:hover { border-color: var(--teal); }
.numpad button[aria-pressed="true"], .toolbar button[aria-pressed="true"] {
  background: var(--teal-soft);
  border-color: var(--teal);
  color: var(--teal);
}
html[data-theme="dark"] .numpad button[aria-pressed="true"],
html[data-theme="dark"] .toolbar button[aria-pressed="true"] { color: var(--ink); }
.toolbar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-primary, .toolbar .btn-primary, .btn-row a.btn-primary, a.btn-primary, button.btn-primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
html[data-theme="dark"] .btn-primary { color: #102224; }
.btn-primary:hover { filter: brightness(1.05); }
label.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  cursor: pointer;
  min-height: 44px;
}
label.switch input { width: 20px; height: 20px; accent-color: var(--teal); }
.tiny { font-size: 0.92rem; color: var(--muted); margin: 0; }

/* Library & archive */
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 16px 0; }
.puzzle-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  margin: 16px 0 24px;
}
.puzzle-list a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}
.puzzle-list a:hover, .puzzle-list a:focus-visible { border-color: var(--teal); background: var(--teal-soft); }
.puzzle-list a.done { box-shadow: inset 0 -3px 0 var(--good); }
.jump { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.jump input {
  width: 8rem;
  min-height: 48px;
  font: inherit;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
}
.level-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin: 18px 0 28px;
}
.level-cards a {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
}
.level-cards a:hover { border-color: var(--teal); }
.level-cards h2 { margin: 0 0 6px; }
.cal { width: 100%; border-collapse: collapse; margin: 12px 0 24px; }
.cal th, .cal td { text-align: center; padding: 4px; }
.cal th { font-size: 0.85rem; color: var(--muted); font-weight: 650; }
.cal a, .cal .empty, .cal .future {
  display: flex; align-items: center; justify-content: center;
  min-height: 44px; border-radius: 10px; text-decoration: none; color: inherit;
  border: 1px solid transparent;
}
.cal a { background: var(--card); border-color: var(--line); font-weight: 700; }
.cal a:hover { border-color: var(--teal); background: var(--teal-soft); }
.cal a.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal a.done { box-shadow: inset 0 -3px 0 var(--good); }
.cal .future { color: var(--muted); }

/* Print page form */
.form-grid { display: grid; gap: 14px; max-width: 32rem; }
.form-grid label { font-weight: 700; display: grid; gap: 6px; }
select.field, .field { width: 100%; text-align: left; justify-content: flex-start; }

/* Printable sheets */
.print-sheet { display: none; }
@media print {
  .site-header, .site-footer, .no-print, .iprof-more, .more-sites, .theme-btn, .skip { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; }
  .wrap { width: auto; margin: 0; }
  a { color: #000; text-decoration: none; }
  .play-layout { display: block; }
  .controls, .btn-row, .status, label.switch, .lead, .crumb { display: none !important; }
  .sudoku {
    width: 5.6in;
    border-color: #000;
    background: #fff;
  }
  .sudoku .cell {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    border-color: #888;
  }
  .sudoku .cell:nth-child(3n):not(:nth-child(9n)),
  .sudoku .cell:nth-child(n+19):nth-child(-n+27),
  .sudoku .cell:nth-child(n+46):nth-child(-n+54) {
    border-color: #000;
  }
  .print-current-title { display: block !important; margin: 0 0 12px; }
  .print-sheet { display: block; }
  .print-ui { display: none !important; }
  .print-page { break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
}

.print-current-title { display: none; }
.print-grid-wrap { display: grid; gap: 20px; }
.print-grid-wrap.cols-2 { grid-template-columns: 1fr 1fr; }
.print-grid-wrap.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.print-mini h3 { margin: 0 0 6px; font-size: 12pt; }
.print-mini .sudoku {
  width: 100%;
  border-width: 2px;
}
.print-mini .sudoku .cell { font-size: 12pt; }
.print-key { font-size: 11pt; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

.btn[aria-disabled="true"] { opacity: 0.4; pointer-events: none; cursor: default; }
.jump label { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 0; }
.cal { table-layout: fixed; width: 100%; }
.cal td { height: 52px; vertical-align: middle; }
.cal a, .cal .future {
  width: 100%;
  min-height: 44px;
}
.cal .future { border: 1px solid var(--line); background: transparent; opacity: 0.5; }
