/* ── Reset & Design Tokens (Material 3–inspired) ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root,
:root[data-theme="light"] {
  color-scheme: light;

  /* Surfaces & Ink */
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-container: #e8eef6;
  --surface-container-high: #dce5f2;
  --text: #0f172a;
  --text-secondary: #334155;
  --muted: #475569;

  /* Brand & Semantic */
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-fill: #1d4ed8;
  --primary-fill-hover: #1e40af;
  --on-primary: #ffffff;
  --primary-container: #dbeafe;
  --on-primary-container: #1e3a8a;

  --green: #047857;
  --ok-bg: #ecfdf5;
  --ok-border: #6ee7b7;
  --ok-text: #065f46;

  --err: #b91c1c;
  --err-bg: #fee2e2;
  --err-border: #fca5a5;
  --err-text: #991b1b;
  --err-hover-bg: #fecaca;
  --err-hover-text: #7f1d1d;

  /* Borders & Focus */
  --outline: #94a3b8;
  --outline-variant: #cbd5e1;
  --focus-ring: #1d4ed8;

  /* Grid & Cage Outlines */
  --cell: clamp(34px, calc((100vw - 38px) / 9), 58px);
  --grid-thin: #cbd5e1;
  --box-border: #0f172a;
  --cage-inset: 3px;
  --cage-stroke: #475569;
  --cage-stroke-active: #047857;
  --cage-stroke-err: #dc2626;
  --cage-lbl: #1e293b;
  --cage-lbl-ok: #047857;
  --cage-lbl-err: #b91c1c;

  /* Cell States */
  --cell-val: #1e40af;
  --hl: #eff6ff;
  --same-val: #e0e7ff;
  --cage-hl: #d1fae5;
  --sel: #bfdbfe;
  --sel-err: #fecaca;

  /* Tables & Elevation */
  --table-head: #f1f5f9;
  --table-row-border: #e2e8f0;
  --unique-bg: #ecfdf5;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-board: 0 8px 24px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0e131a;
    --surface: #171e29;
    --surface-container: #202a38;
    --surface-container-high: #2a374a;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --muted: #94a3b8;

    --primary: #93c5fd;
    --primary-hover: #bfdbfe;
    --primary-fill: #93c5fd;
    --primary-fill-hover: #bfdbfe;
    --on-primary: #0b1220;
    --primary-container: #1e3a5f;
    --on-primary-container: #dbeafe;

    --green: #34d399;
    --ok-bg: #0e3328;
    --ok-border: #10b981;
    --ok-text: #6ee7b7;

    --err: #fca5a5;
    --err-bg: #45141b;
    --err-border: #f87171;
    --err-text: #fecaca;
    --err-hover-bg: #631d27;
    --err-hover-text: #fee2e2;

    --outline: #64748b;
    --outline-variant: #334155;
    --focus-ring: #93c5fd;

    --grid-thin: #2d3849;
    --box-border: #cbd5e1;
    --cage-stroke: #7c93b0;
    --cage-stroke-active: #34d399;
    --cage-stroke-err: #f87171;
    --cage-lbl: #e2e8f0;
    --cage-lbl-ok: #6ee7b7;
    --cage-lbl-err: #fca5a5;

    --cell-val: #93c5fd;
    --hl: #1e2a3c;
    --same-val: #283154;
    --cage-hl: #11382d;
    --sel: #1e3e68;
    --sel-err: #631d27;

    --table-head: #1f2937;
    --table-row-border: #263244;
    --unique-bg: #0f2f25;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .28);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .38), 0 2px 4px rgba(0, 0, 0, .24);
    --shadow-board: 0 12px 28px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0e131a;
  --surface: #171e29;
  --surface-container: #202a38;
  --surface-container-high: #2a374a;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted: #94a3b8;

  --primary: #93c5fd;
  --primary-hover: #bfdbfe;
  --primary-fill: #93c5fd;
  --primary-fill-hover: #bfdbfe;
  --on-primary: #0b1220;
  --primary-container: #1e3a5f;
  --on-primary-container: #dbeafe;

  --green: #34d399;
  --ok-bg: #0e3328;
  --ok-border: #10b981;
  --ok-text: #6ee7b7;

  --err: #fca5a5;
  --err-bg: #45141b;
  --err-border: #f87171;
  --err-text: #fecaca;
  --err-hover-bg: #631d27;
  --err-hover-text: #fee2e2;

  --outline: #64748b;
  --outline-variant: #334155;
  --focus-ring: #93c5fd;

  --grid-thin: #2d3849;
  --box-border: #cbd5e1;
  --cage-stroke: #7c93b0;
  --cage-stroke-active: #34d399;
  --cage-stroke-err: #f87171;
  --cage-lbl: #e2e8f0;
  --cage-lbl-ok: #6ee7b7;
  --cage-lbl-err: #fca5a5;

  --cell-val: #93c5fd;
  --hl: #1e2a3c;
  --same-val: #283154;
  --cage-hl: #11382d;
  --sel: #1e3e68;
  --sel-err: #631d27;

  --table-head: #1f2937;
  --table-row-border: #263244;
  --unique-bg: #0f2f25;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 3px rgba(0, 0, 0, .28);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, .38), 0 2px 4px rgba(0, 0, 0, .24);
  --shadow-board: 0 12px 28px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .35);
}

html {
  scroll-padding-top: 72px;
  scroll-padding-bottom: 96px;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  background: var(--primary-fill);
  color: var(--on-primary);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
}
.skip-link:focus {
  left: 12px;
  text-decoration: none;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--outline-variant);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 22px;
  min-width: 0;
}

h1 {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
  white-space: nowrap;
}

nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

nav a {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  padding: 6px 4px;
  border-radius: 6px;
  transition: color .14s ease;
}

nav a:hover {
  color: var(--primary);
  text-decoration: none;
}

/* Theme Control */
.theme-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.theme-select {
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--outline-variant);
  border-radius: 10px;
  background: var(--surface-container);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color .14s ease, background .14s ease;
}

.theme-select:hover {
  border-color: var(--primary);
  background: var(--surface-container-high);
}

/* ── Main ───────────────────────────────────────────────────────────────── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 28px;
}

.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ── Controls ───────────────────────────────────────────────────────────── */
.controls-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.diff-btns {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  box-shadow: var(--shadow-sm);
}

.diff-btn {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}

.diff-btn:hover {
  background: var(--surface-container-high);
  color: var(--text);
}

.diff-btn.active {
  background: var(--primary-fill);
  color: var(--on-primary);
  box-shadow: var(--shadow-sm);
}

.diff-btn.active:hover {
  background: var(--primary-fill-hover);
  color: var(--on-primary);
}

.game-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.action-btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow-sm);
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .08s ease;
}

.action-btn:hover {
  background: var(--surface-container);
  border-color: var(--primary);
  color: var(--primary);
}

.action-btn:active {
  transform: scale(0.98);
}

.timer {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  min-width: 72px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-container);
  border: 1px solid var(--outline-variant);
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Live Cage Sum / Remaining Bar ──────────────────────────────────────── */
.cage-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  width: 100%;
  max-width: 680px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  box-shadow: var(--shadow-sm);
  font-size: 0.875rem;
  color: var(--text);
}

.cage-status-main {
  font-weight: 600;
  color: var(--text);
}

.cage-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--primary-container);
  color: var(--on-primary-container);
  border: 1px solid transparent;
}

.cage-status-badge:empty {
  display: none;
}

.cage-status-badge.is-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
  border-color: var(--ok-border);
}

.cage-status-badge.is-err {
  background: var(--err-bg);
  color: var(--err-text);
  border-color: var(--err-border);
}

/* Puzzle setup and completion */
.puzzle-options { position: relative; z-index: 8; }
.puzzle-options summary {
  display: flex; align-items: center; gap: 10px; min-height: 44px;
  padding: 0 14px; border: 1px solid var(--outline-variant); border-radius: 12px;
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 650;
}
.puzzle-options summary::-webkit-details-marker { display: none; }
.puzzle-options summary::after {
  content: ''; border: solid currentColor; border-width: 0 2px 2px 0; width: 7px; height: 7px;
  transform: translateY(-2px) rotate(45deg);
}
.puzzle-options[open] summary::after { transform: translateY(2px) rotate(225deg); }
.puzzle-options summary:focus-visible, .result-link:focus-visible {
  outline: 2.5px solid var(--focus-ring); outline-offset: 2px;
}
.puzzle-menu {
  position: absolute; top: calc(100% + 4px); left: 0;
  display: grid; gap: 8px; width: max-content; max-width: calc(100vw - 24px); padding: 8px;
  max-height: min(65svh, 26rem); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--outline-variant);
  border-radius: 14px; box-shadow: var(--shadow-md);
}
.size-setting {
  display: flex; align-items: center; gap: 9px; min-height: 44px; padding: 0 8px;
  font-size: .875rem; font-weight: 600; cursor: pointer;
}
.size-setting input { width: 20px; height: 20px; accent-color: var(--primary-fill); }
#size-help { display: none; max-width: 25ch; padding: 0 8px 4px; font-size: .8rem; }
#undo-btn:disabled { color: var(--muted); cursor: default; }
.input-area { display: grid; width: 228px; max-width: 100%; }
.input-area > * { grid-area: 1 / 1; }
.is-won .numpad { visibility: hidden; }
.result-panel {
  align-self: start; display: grid; gap: 5px;
  padding: 12px; background: var(--surface); border: 2px solid var(--ok-border);
  border-radius: 14px; color: var(--text);
}
.result-panel[hidden] { display: none; }
.result-panel h2 { margin: 0; font-size: 1.13rem; line-height: 1.2; color: var(--text); }
.result-panel h2:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.result-mark { display: inline-block; color: var(--ok-text); }
.result-panel p { margin: 0; font-size: .875rem; line-height: 1.3; color: var(--text-secondary); }
.result-actions { display: flex; gap: 4px 12px; flex-wrap: wrap; align-items: center; }
.result-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 650; }
html:not([data-study]) .study-only,
html[data-study] :is(.diff-btns, #daily-btn, #another-puzzle, .is-won .regular-return) { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .celebrate .result-mark { animation: settle-result 180ms ease-out; }
  @keyframes settle-result { from { transform: scale(.74); } 60% { transform: scale(1.14); } to { transform: scale(1); } }
}

/* ── Game Area ──────────────────────────────────────────────────────────── */
.game-area {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

/* ── Grid & Distinct Box / Cage Outlines ────────────────────────────────── */
.board-shell {
  border: 3px solid var(--box-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-board);
  line-height: 0;
}

.sudoku-grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  user-select: none;
  -webkit-user-select: none;
}

.sudoku-grid tr { height: 11.111111%; }

.cell {
  --cell-bg: var(--surface);
  --active-cage-stroke: var(--cage-stroke);
  box-sizing: content-box;
  width: var(--cell);
  height: var(--cell);
  position: relative;
  cursor: pointer;
  background: var(--cell-bg);
  border: 0;
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  padding: 0;
  vertical-align: middle;
  text-align: center;
  touch-action: manipulation;
  transition: background-color .1s ease;
}

/* Clean 3×3 solid box dividers (never override inset dashed cage outlines) */
.cell.box-div-r { border-right: 3px solid var(--box-border); }
.cell.box-div-b { border-bottom: 3px solid var(--box-border); }
.cell.edge-r    { border-right: 0; }
.cell.edge-b    { border-bottom: 0; }

/* Inset dashed cage outline */
.cell::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  pointer-events: none;
  z-index: 2;
}

.cell.bt::after { top: var(--cage-inset); border-top: 1.5px dashed var(--active-cage-stroke); }
.cell.br::after { right: var(--cage-inset); border-right: 1.5px dashed var(--active-cage-stroke); }
.cell.bb::after { bottom: var(--cage-inset); border-bottom: 1.5px dashed var(--active-cage-stroke); }
.cell.bl::after { left: var(--cage-inset); border-left: 1.5px dashed var(--active-cage-stroke); }

/* Closed inner corners for L/T/Z polyomino cages */
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background-repeat: no-repeat;
  background-image:
    var(--ic-tl, none),
    var(--ic-tr, none),
    var(--ic-bl, none),
    var(--ic-br, none);
  background-position: top left, top right, bottom left, bottom right;
  background-size: 4.5px 4.5px;
}

.cell.ic-tl { --ic-tl: conic-gradient(from 270deg at 3px 3px, transparent 0 90deg, var(--active-cage-stroke) 90deg); }
.cell.ic-tr { --ic-tr: conic-gradient(from 0deg at 1.5px 3px, transparent 0 90deg, var(--active-cage-stroke) 90deg); }
.cell.ic-bl { --ic-bl: conic-gradient(from 180deg at 3px 1.5px, transparent 0 90deg, var(--active-cage-stroke) 90deg); }
.cell.ic-br { --ic-br: conic-gradient(from 90deg at 1.5px 1.5px, transparent 0 90deg, var(--active-cage-stroke) 90deg); }

/* Cell visual states (ordered by precedence) */
.cell.hl              { --cell-bg: var(--hl); }
.cell.same-val        { --cell-bg: var(--same-val); }
.cell.cage-hl         { --cell-bg: var(--cage-hl); --active-cage-stroke: var(--cage-stroke-active); }
.cell.sel             { --cell-bg: var(--sel); --active-cage-stroke: var(--cage-stroke-active); }
.cell.cage-sum-err    { --active-cage-stroke: var(--cage-stroke-err); }
.cell.err             { --cell-bg: var(--err-bg); }
.cell.err.sel         { --cell-bg: var(--sel-err); }
.cell.err .val        { color: var(--err); }

/* Keyboard focus indicator on gridcell */
.cell:focus {
  outline: none;
}

.cell:focus-visible {
  outline: 2.5px solid var(--focus-ring);
  outline-offset: -2.5px;
  z-index: 5;
}

/* Cage sum label — crisp, legible on mobile, cleanly interrupts top-left dashed corner */
.cage-lbl {
  position: absolute;
  top: 1px;
  left: 2px;
  padding: 0 2px;
  border-radius: 3px;
  background: var(--cell-bg);
  font-size: clamp(10.5px, 2.75vw, 12.5px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.08;
  color: var(--cage-lbl);
  pointer-events: none;
  transform-origin: left top;
  z-index: 3;
  transition: background-color .1s ease, color .1s ease;
}

.cage-lbl.cage-ok {
  color: var(--cage-lbl-ok);
}

.cage-lbl.cage-ok::after { content: '✓'; }
.cage-lbl.cage-err::after { content: '!'; }

.cage-lbl.cage-err {
  color: var(--cage-lbl-err);
}

.cell.err .val { text-decoration: underline wavy; text-underline-offset: .12em; }

/* Digit */
.val {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding-top: 8px;
  font-size: clamp(18px, 5vw, 29px);
  font-weight: 600;
  line-height: 1;
  color: var(--cell-val);
  pointer-events: none;
}

/* ── Number Pad ─────────────────────────────────────────────────────────── */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  box-shadow: var(--shadow-md);
}

.num-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 62px;
  height: 58px;
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  background: var(--surface-container);
  color: var(--text);
  font-family: inherit;
  font-size: 1.32rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .08s ease;
}

.num-btn:hover {
  background: var(--primary-container);
  border-color: var(--primary);
  color: var(--on-primary-container);
}

.num-btn:active {
  transform: scale(0.96);
  background: var(--primary-fill);
  color: var(--on-primary);
}

.erase-btn {
  grid-column: span 3;
  width: 100%;
  height: 48px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--err-bg);
  border-color: var(--err-border);
  color: var(--err-text);
}

.erase-btn:hover {
  background: var(--err-hover-bg);
  border-color: var(--err);
  color: var(--err-hover-text);
}

/* ── Share ──────────────────────────────────────────────────────────────── */
.share-area {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
  margin-top: 2px;
}

.share-btn {
  min-height: 44px;
  padding: 0 20px;
}

.share-msg {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green);
}

/* ── Content Sections ───────────────────────────────────────────────────── */
.content-section {
  max-width: 960px;
  margin: 28px auto;
  padding: 0 16px;
}

.section-inner {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: var(--shadow-sm);
}

.content-section h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}

.content-section h3 {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 22px;
  margin-bottom: 8px;
}

.content-section h4 {
  font-size: 0.94rem;
  font-weight: 700;
  margin-top: 16px;
  margin-bottom: 4px;
  color: var(--primary);
}

.content-section p {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.content-section ul {
  padding-left: 20px;
  margin-bottom: 12px;
}

.content-section li {
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.unique-legend {
  color: var(--green);
  font-weight: 700;
}

/* ── FAQ ────────────────────────────────────────────────────────────────── */
.faq dt {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 18px;
  margin-bottom: 4px;
}

.faq dd {
  font-size: 0.92rem;
  color: var(--text-secondary);
  padding-left: 14px;
  border-left: 2px solid var(--outline-variant);
}

/* ── Combination Tables ─────────────────────────────────────────────────── */
.combo-size {
  margin-bottom: 28px;
  overflow-x: auto;
}

.combo-size h3 {
  margin-top: 0;
}

.combo-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
  max-width: 680px;
}

.combo-table th {
  text-align: left;
  padding: 9px 14px;
  background: var(--table-head);
  border-bottom: 2px solid var(--outline-variant);
  font-size: 0.76rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.combo-table td {
  padding: 6px 14px;
  border-bottom: 1px solid var(--table-row-border);
  color: var(--text);
}

.combo-sum {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  width: 56px;
}

.combo-vals {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Courier New', monospace;
  letter-spacing: .02em;
  color: var(--text-secondary);
}

.unique-combo td {
  background: var(--unique-bg);
}

.unique-combo .combo-sum {
  color: var(--green);
}

/* ── Footer (with bottom-right support chat clearance) ──────────────────── */
footer {
  margin-top: 44px;
  border-top: 1px solid var(--outline-variant);
  background: var(--surface);
  padding: 24px 16px calc(92px + env(safe-area-inset-bottom, 0px));
  text-align: center;
}

.footer-inner {
  max-width: 960px;
  margin: 0 auto;
}

.footer-inner p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

/* ── Responsive / Mobile Play & Support Chat Clearance ──────────────────── */
@media (max-width: 860px) {
  .brand-group {
    gap: 14px;
  }

  nav {
    gap: 10px;
  }

  nav a {
    font-size: 0.8rem;
  }
}

@media (max-width: 780px) {
  .game-area {
    flex-direction: column;
    align-items: center;
    gap: 14px;
  }

  .numpad {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: min(100%, 420px);
    padding: 8px;
    gap: 6px;
  }

  .num-btn {
    width: 100%;
    height: 48px;
    font-size: 1.2rem;
    border-radius: 10px;
  }

  .erase-btn {
    grid-column: span 1;
    height: 48px;
    font-size: 0.82rem;
    padding: 0 4px;
  }
}

@media (max-width: 640px) {
  nav {
    display: none;
  }
}

@media (max-width: 540px) {
  .header-inner {
    padding: 0 12px;
    min-height: 54px;
  }

  h1 {
    font-size: 0.98rem;
  }

  .theme-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .theme-select {
    min-height: 42px;
    padding: 6px 10px;
    font-size: 0.82rem;
  }

  main {
    padding: 12px 10px 24px;
  }

  .game-wrap {
    gap: 10px;
  }

  .controls-top {
    gap: 8px;
  }

  .diff-btns {
    width: 100%;
    max-width: 400px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .diff-btn {
    min-height: 44px;
    padding: 0 6px;
    font-size: 0.8rem;
  }

  .action-btn,
  .timer {
    min-height: 44px;
  }

  .cage-status {
    padding: 7px 12px;
    font-size: 0.82rem;
    gap: 6px 10px;
  }

  .val {
    padding-top: 9px;
  }

  .numpad {
    width: 100%;
    max-width: 400px;
  }

  .erase-label {
    display: none;
  }

  .erase-btn {
    font-size: 1.15rem;
  }

  .share-area {
    justify-content: flex-start;
    max-width: 400px;
    padding-bottom: 12px;
  }

  .section-inner {
    padding: 20px 16px;
  }
}

@media (max-width: 780px) {
  .input-area { width: min(100%, 420px); }
  .input-area .numpad { width: 100%; max-width: none; }
}

@media (max-width: 540px) {
  .header-inner { min-height: 46px; }
  .header-inner h1 { white-space: normal; line-height: 1.12; }
  main#main-content { padding: 4px 8px 20px; }
  .game-wrap { gap: 5px; }
  .controls-top { width: min(100%, 380px); justify-content: flex-start; gap: 6px; }
  .puzzle-options summary { padding: 0 10px; font-size: .86rem; }
  .puzzle-menu .diff-btns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .controls-top .timer { margin-left: auto; padding: 0 9px; }
  .cage-status {
    display: grid; width: min(100%, 380px); gap: 1px; justify-content: start;
    padding: 4px 9px; min-height: 46px; line-height: 1.25;
  }
  .cage-status-badge { justify-self: start; padding: 1px 6px; font-size: .76rem; }
  .game-area { gap: 5px; }
  .board-shell, .input-area { width: min(100%, 380px); }
  .large-squares .board-shell { height: min(calc(100vw - 16px), 380px); }
  .sudoku-grid { width: 100%; height: calc(min(100vw - 16px, 380px) - 6px); }
  .cell { box-sizing: border-box; width: 11.111%; height: auto; }
  .val { position: absolute; inset: 0; }
  .numpad { padding: 3px; gap: 3px; }
  .num-btn, .erase-btn { height: 44px; }
}

@media (orientation: landscape) and (max-height: 540px) and (min-width: 541px) {
  header nav { display: flex; }
  header nav a:not([href="/field-notes.html"]) { display: none; }
  .header-inner { min-height: 44px; }
  .theme-select { min-height: 44px; }
  main#main-content { padding: 4px 8px 16px; }
  .game-wrap {
    --side: min(calc(100svh - 56px), calc(100vw - 300px), 400px);
    display: grid; grid-template-columns: var(--side) minmax(0, 310px);
    grid-template-areas: 'board options' 'board clue' 'board keys' 'board share';
    gap: 4px 12px; align-content: start; align-items: start; justify-content: center;
  }
  .game-area { display: contents; }
  .controls-top { grid-area: options; gap: 4px; justify-content: flex-start; }
  .controls-top > .action-btn { padding-inline: 8px; }
  .controls-top .timer { margin-left: auto; padding: 0 7px; }
  .puzzle-options summary { padding: 0 8px; font-size: .85rem; }
  .puzzle-menu .diff-btns { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .board-shell { grid-area: board; width: var(--side); }
  .large-squares .board-shell { height: var(--side); }
  .sudoku-grid { width: 100%; height: calc(var(--side) - 6px); }
  .cell { box-sizing: border-box; width: 11.111%; height: auto; }
  .val { position: absolute; inset: 0; padding-top: 5px; font-size: clamp(16px, 5svh, 23px); }
  .cage-lbl { font-size: clamp(9px, 2.9svh, 12px); padding: 0 1px; }
  .cage-status { grid-area: clue; min-height: 48px; padding: 4px 7px; gap: 2px 6px; font-size: .8rem; }
  .cage-status-badge { padding: 1px 5px; }
  .input-area { grid-area: keys; width: 100%; }
  .input-area .numpad { width: 100%; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 3px; padding: 3px; }
  .num-btn, .erase-btn { width: 100%; height: 44px; grid-column: auto; }
  .erase-label { display: none; }
  .share-area { grid-area: share; margin: 0; }
}

@media (max-width: 540px), (orientation: landscape) and (max-height: 540px) and (min-width: 541px) {
  .large-squares .board-shell { overflow: auto; overscroll-behavior: contain; }
  .large-squares .sudoku-grid { width: 405px; height: 405px; }
  .large-squares .cage-lbl { font-size: 13px; }
  .large-squares .val { font-size: 23px; }
  .large-squares #size-help { display: block; }
}

@media (max-width: 780px), (orientation: landscape) and (max-height: 540px) {
  .result-panel {
    display: flex; flex-wrap: wrap; align-content: center; align-items: baseline;
    padding: 6px 8px; gap: 2px 8px;
  }
  .result-panel h2 { font-size: 1.04rem; }
  .result-panel p { white-space: nowrap; }
  .result-actions { flex-basis: 100%; }
}

/* The host appends its support control after the page content. In a small
   viewport it belongs in the document so all squares and article links work. */
@media (max-width: 850px), (max-height: 600px) {
  html { scroll-padding-block: 50px 3px; }
  body > [data-bitterdesk-root] {
    position: static;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  }
  footer {
    padding-bottom: 12px;
  }
}

@media (forced-colors: active) {
  .cell.sel { outline: 2px solid Highlight; outline-offset: -3px; }
  .cage-lbl.cage-ok::after, .cage-lbl.cage-err::after { color: CanvasText; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
}
