/* Sudoku Ascend — original design. */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --ink: #1d2230;
  --ink-soft: #5b6273;
  --ink-faint: #9aa0ad;
  --line: #d9d5cc;
  --line-strong: #2a3042;
  --accent: #2f6df6;
  --accent-ink: #ffffff;
  --accent-soft: #dfe8fe;
  --peer: #eceae4;
  --same: #c9d8fd;
  --sel: #a9c2fb;
  --given: #1d2230;
  --entry: #2f5fd8;
  --error: #d6403a;
  --error-bg: #fbe1df;
  --success: #1f9d6b;
  --gold: #e3a41c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 6px 20px rgba(20, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #14161c;
  --surface: #1d2029;
  --surface-2: #262a35;
  --ink: #e9ebf1;
  --ink-soft: #a8aec0;
  --ink-faint: #6b7183;
  --line: #333847;
  --line-strong: #a8aec0;
  --accent: #6c9bff;
  --accent-ink: #0f1320;
  --accent-soft: #23314f;
  --peer: #232734;
  --same: #2c3d63;
  --sel: #3b5590;
  --given: #e9ebf1;
  --entry: #8fb3ff;
  --error: #ff6b63;
  --error-bg: #4a2224;
  --success: #3ccf93;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

#app { height: 100%; position: relative; z-index: 1; }
#bg-photo { position: fixed; inset: 0; z-index: 0; background: center / cover no-repeat; pointer-events: none; }
#bg-shade { position: fixed; inset: 0; z-index: 0; background: var(--bg); opacity: 0; pointer-events: none; }
body.has-photo { background: #000; }
/* keep text and controls readable over a photo */
body.has-photo .home-header, body.has-photo .game-meta, body.has-photo .tools, body.has-photo .section-title,
body.has-photo .link-btn, body.has-photo .game-header .icon-btn {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-radius: 14px;
}
body.has-photo .home-header { padding: 8px 10px; }
body.has-photo .game-meta { flex: 0 1 auto; margin: 0 auto; padding: 4px 16px; }
body.has-photo .tools { padding: 4px; }
body.has-photo .section-title { align-self: flex-start; padding: 4px 10px; }
body.has-photo .link-btn { padding: 10px 18px; }
.photo-row { flex-wrap: wrap; }
.photo-btns { display: inline-flex; align-items: center; gap: 8px; }
.small-btn { min-height: 38px; padding: 0 14px; font-size: 15px; display: inline-flex; align-items: center; cursor: pointer; }
.photo-thumb { width: 38px; height: 38px; border-radius: 8px; background: center / cover; box-shadow: var(--shadow); }
.slider-row input[type=range] { width: 46%; accent-color: var(--accent); height: 32px; }
.screen {
  display: none;
  height: 100%;
  padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
}
.screen.active { display: flex; flex-direction: column; }

/* ---------- buttons ---------- */
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: inline-grid; place-items: center; color: var(--ink-soft);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn.small svg { width: 18px; height: 18px; }
.btn {
  min-height: 48px; padding: 0 22px; border-radius: 12px; font-weight: 600; font-size: 17px;
  background: var(--surface-2); color: var(--ink);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--error); }
.btn:active { transform: scale(.98); }
.link-btn { color: var(--accent); font-weight: 600; padding: 14px; align-self: center; }

/* ---------- home ---------- */
.home-header { display: flex; align-items: center; gap: 12px; max-width: 760px; width: 100%; margin: 0 auto; }
.logo svg { width: 52px; height: 52px; display: block; }
.logo-bg { fill: var(--accent); stroke: none; }
.logo-line { stroke: #fff; stroke-width: 3.4; }
.logo-dot { fill: #fff; stroke: none; }
.home-header h1 { margin: 0; font-size: 25px; letter-spacing: -.02em; white-space: nowrap; }
.tagline { margin: 2px 0 0; color: var(--ink-soft); font-size: 15px; }
.home-actions { margin-left: auto; display: flex; gap: 4px; }
.home-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  max-width: 760px; width: 100%; margin: 0 auto; padding: 18px 2px 8px;
  display: flex; flex-direction: column; gap: 14px;
}
.continue-card, .daily-card {
  display: flex; align-items: center; gap: 14px; text-align: left;
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.continue-card { background: var(--accent); color: var(--accent-ink); }
.cc-label { font-weight: 700; font-size: 19px; }
.cc-detail { opacity: .85; font-size: 15px; }
.cc-arrow { width: 22px; height: 22px; margin-left: auto; }
.daily-date {
  width: 56px; height: 56px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05;
}
.daily-date span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.daily-date strong { font-size: 22px; }
.daily-text { display: flex; flex-direction: column; gap: 2px; }
.daily-title { font-weight: 700; font-size: 18px; }
.daily-sub { color: var(--ink-soft); font-size: 14px; }
.daily-badge { margin-left: auto; background: var(--success); color: #fff; font-size: 13px; font-weight: 700; padding: 5px 10px; border-radius: 99px; }
.section-title { margin: 8px 2px 0; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.level-card {
  position: relative; text-align: left; background: var(--surface); border-radius: var(--radius);
  padding: 14px 16px 14px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; overflow: hidden;
}
.level-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--lvl); }
.level-card:active { transform: scale(.985); }
.level-name { font-weight: 700; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.level-dots { display: inline-flex; gap: 3px; }
.level-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.level-dots i.on { background: var(--lvl); }
.level-desc { color: var(--ink-soft); font-size: 14px; line-height: 1.35; }
.level-best { color: var(--ink-faint); font-size: 13px; margin-top: 2px; }

/* ---------- game ---------- */
.game-header { display: flex; align-items: center; gap: 8px; width: 100%; max-width: 1100px; margin: 0 auto; }
.game-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 16px; line-height: 1.2; white-space: nowrap; }
.game-meta .meta-sep { display: none; }
.meta-mistakes { font-size: 13px; }
.meta-level { font-weight: 700; }
.meta-sep { color: var(--ink-faint); }
.meta-mistakes { color: var(--ink-soft); }
.meta-mistakes.warn { color: var(--error); font-weight: 600; }
.timer {
  min-width: 92px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--surface);
  box-shadow: var(--shadow); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-variant-numeric: tabular-nums; font-weight: 600; font-size: 16px;
}
.timer .pause-ico { width: 16px; height: 16px; color: var(--ink-soft); }
.timer.off { visibility: hidden; }

.game-layout {
  position: relative; flex: 1; min-height: 0; width: 100%; max-width: 1100px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding-top: 10px;
  --board: min(calc(100vw - 32px - var(--safe-l) - var(--safe-r)), calc(100dvh - 270px - var(--safe-t) - var(--safe-b)), 640px);
}
.board-wrap { position: relative; width: var(--board); height: var(--board); flex: none; }
.board {
  width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(var(--N, 9), 1fr); grid-template-rows: repeat(var(--N, 9), 1fr);
  background: var(--surface); border: 2.5px solid var(--line-strong); border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow);
}
.cell {
  position: relative; display: grid; place-items: center;
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  font-size: calc(var(--cell, calc(var(--board) / 9)) * .58); line-height: 1; font-weight: 500; color: var(--entry);
  cursor: pointer; transition: background-color .08s;
}
.cell.bR { border-right: 2px solid var(--line-strong); }
.cell.lastC { border-right: 0; }
.cell.bB { border-bottom: 2px solid var(--line-strong); }
.cell.lastR { border-bottom: 0; }
.cell.given { color: var(--given); font-weight: 650; }
.cell.peer { background: var(--peer); }
.cell.same { background: var(--same); }
.cell.selected { background: var(--sel); }
.cell.error { color: var(--error); }
.cell.conflict::after {
  content: ""; position: absolute; inset: 3px; border-radius: 6px; border: 2px solid var(--error); opacity: .55; pointer-events: none;
}
.cell.error.selected, .cell.error.same { background: var(--error-bg); }
.cell.hinted { animation: hintPulse 1.2s ease-out 2; }
.cell.pop { animation: pop .25s ease-out; }
.cell.unit-done { animation: unitDone .6s ease-out; }
@keyframes hintPulse { 0% { box-shadow: inset 0 0 0 0 var(--gold); } 40% { box-shadow: inset 0 0 0 4px var(--gold); } 100% { box-shadow: inset 0 0 0 0 var(--gold); } }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes unitDone { 0% { background: var(--accent-soft); } 100% {} }
.notes {
  position: absolute; inset: 1px; display: grid; grid-template-columns: repeat(var(--n, 3), 1fr); grid-template-rows: repeat(var(--n, 3), 1fr);
  font-size: calc(var(--cell, calc(var(--board) / 9)) / var(--n, 3) * .78); font-weight: 600; color: var(--ink-soft); line-height: 1;
}
.notes span { display: grid; place-items: center; }
.notes span.hl { color: var(--accent-ink); background: var(--accent); border-radius: 4px; }

.pause-cover {
  position: absolute; inset: 0; border-radius: 10px; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; box-shadow: var(--shadow);
}
.pause-cover p { margin: 0; font-size: 22px; font-weight: 700; color: var(--ink-soft); }

.controls { width: var(--board); display: flex; flex-direction: column; gap: 12px; }
.hint-banner {
  display: flex; align-items: flex-start; gap: 8px; background: var(--accent-soft); color: var(--ink);
  border-radius: 12px; padding: 6px 4px 6px 12px; font-size: 14px; line-height: 1.35;
  position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: var(--board); z-index: 5; box-shadow: var(--shadow);
}
.hint-banner span { flex: 1; padding-top: 6px; }
.tools { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tool {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0;
  border-radius: 12px; color: var(--ink-soft); font-size: 13px; font-weight: 500;
}
.tool svg { width: 26px; height: 26px; }
.tool span { white-space: nowrap; }
.tool:active { background: var(--surface-2); }
.tool .pill {
  position: absolute; top: 0; right: calc(50% - 30px); font-size: 10px; font-weight: 800; padding: 2px 5px;
  border-radius: 99px; background: var(--surface-2); color: var(--ink-faint); letter-spacing: .03em;
}
.tool[aria-pressed="true"] { color: var(--accent); }
.tool[aria-pressed="true"] .pill { background: var(--accent); color: var(--accent-ink); }
.numpad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.num {
  position: relative; aspect-ratio: 3 / 4; max-height: 76px; border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
  font-size: clamp(22px, calc(var(--board) / 15), 38px); font-weight: 500; color: var(--entry);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.num small { font-size: 11px; color: var(--ink-faint); font-weight: 600; margin-top: 2px; }
.num:active { background: var(--accent-soft); }
.num.done { opacity: .28; }
.notes-mode .num { color: var(--ink-soft); }

/* landscape / iPad: board left, controls right */
@media (orientation: landscape) and (min-width: 700px) {
  .game-layout {
    flex-direction: row; gap: 28px;
    --board: min(calc(100dvh - 110px - var(--safe-t) - var(--safe-b)), calc(100vw - 420px), 760px);
  }
  .controls { width: min(340px, 34vw); justify-content: center; }
  .hint-banner { position: static; box-shadow: none; transform: none; width: auto; }
  .numpad { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .num { aspect-ratio: 1 / 1; max-height: none; font-size: 34px; }
  .tools { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
}
/* short landscape phones */
@media (orientation: landscape) and (max-height: 500px) {
  .screen { padding-top: calc(var(--safe-t) + 4px); padding-bottom: calc(var(--safe-b) + 4px); }
  .game-layout { flex-direction: row; gap: 16px; padding-top: 4px;
    --board: min(calc(100dvh - 64px - var(--safe-t) - var(--safe-b)), 60vw); }
  .controls { width: min(320px, 42vw); gap: 6px; }
  .tool span { display: none; }
  .tool .pill { right: calc(50% - 24px); }
  .numpad { grid-template-columns: repeat(5, 1fr); }
  .num { aspect-ratio: auto; height: calc((100dvh - 150px) / 2.4); max-height: 60px; font-size: 24px; }
  .num small { display: none; }
}
/* big iPad portrait: more room for the board */
@media (orientation: portrait) and (min-width: 700px) {
  .game-layout { --board: min(calc(100vw - 64px), calc(100dvh - 330px), 760px); gap: 22px; }
  .num { max-height: 90px; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 20, .45); display: grid; place-items: center; z-index: 50;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px);
  animation: fade .15s ease-out;
}
.modal {
  width: min(480px, 100%); max-height: 100%; overflow-y: auto; background: var(--surface); border-radius: 20px;
  padding: 22px 22px 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); animation: rise .2s ease-out;
  -webkit-user-select: text; user-select: text;
}
.modal h2 { margin: 0 0 12px; font-size: 22px; }
.modal p { color: var(--ink-soft); line-height: 1.5; margin: 0 0 10px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }

.win-hero { text-align: center; padding: 6px 0 4px; }
.win-hero .trophy { font-size: 52px; line-height: 1; }
.win-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0 6px; }
.win-stats div { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.win-stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.win-stats span { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .05em; }
.record { color: var(--gold); font-weight: 700; text-align: center; margin: 4px 0; }

.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row label { flex: 1; }
.setting-row small { display: block; color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 9px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); font-weight: 600; }
.help h3 { margin: 14px 0 4px; font-size: 16px; }
.help ul { margin: 4px 0 8px; padding-left: 20px; color: var(--ink-soft); line-height: 1.5; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; font-size: 15px;
  z-index: 60; animation: rise .2s ease-out; max-width: calc(100vw - 32px); text-align: center;
}

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 55; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.photo-btns label { flex: none; }

/* ---------- giant grids (16x16, 25x25) ---------- */
.size-badge { font-size: 12px; font-weight: 700; color: #fff; background: var(--lvl); padding: 2px 7px; border-radius: 99px; }
.zoom-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
[data-size="16"] .cell, [data-size="25"] .cell { font-weight: 600; }
[data-size="16"] .cell.given, [data-size="25"] .cell.given { font-weight: 700; }
[data-size="25"] .cell { font-size: calc(var(--cell) * .56); }
[data-size="16"] .cell.conflict::after, [data-size="25"] .cell.conflict::after { inset: 1px; border-radius: 3px; }
[data-size="16"] .notes span.hl, [data-size="25"] .notes span.hl { border-radius: 2px; }
.board-wrap.zoomed {
  overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  border-radius: 10px; box-shadow: var(--shadow); background: var(--surface);
  touch-action: pan-x pan-y;
}
.board-wrap.zoomed .board { border-radius: 0; box-shadow: none; }
.numpad[data-count="16"] { grid-template-columns: repeat(8, 1fr); gap: 5px; }
.numpad[data-count="25"] { grid-template-columns: repeat(9, 1fr); gap: 5px; }
.numpad[data-count="16"] .num, .numpad[data-count="25"] .num { aspect-ratio: auto; height: 46px; font-size: 21px; font-weight: 600; }
.numpad[data-count="16"] .num small, .numpad[data-count="25"] .num small { font-size: 9px; margin-top: 0; }
[data-size="16"] .game-layout { --board: min(calc(100vw - 32px - var(--safe-l) - var(--safe-r)), calc(100dvh - 300px - var(--safe-t) - var(--safe-b)), 720px); }
[data-size="25"] .game-layout { --board: min(calc(100vw - 32px - var(--safe-l) - var(--safe-r)), calc(100dvh - 350px - var(--safe-t) - var(--safe-b)), 760px); }
@media (orientation: landscape) and (min-width: 700px) {
  [data-size="16"] .game-layout, [data-size="25"] .game-layout {
    --board: min(calc(100dvh - 100px - var(--safe-t) - var(--safe-b)), calc(100vw - 400px), 900px);
  }
  .numpad[data-count="16"] { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .numpad[data-count="25"] { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .numpad[data-count="16"] .num { aspect-ratio: 1 / 1; height: auto; font-size: 26px; }
  .numpad[data-count="25"] .num { aspect-ratio: 1 / 1; height: auto; font-size: 22px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  [data-size="16"] .game-layout, [data-size="25"] .game-layout { --board: min(calc(100dvh - 64px - var(--safe-t) - var(--safe-b)), 55vw); }
  .numpad[data-count="16"] { grid-template-columns: repeat(8, 1fr); }
  .numpad[data-count="25"] { grid-template-columns: repeat(9, 1fr); }
  .numpad[data-count="16"] .num, .numpad[data-count="25"] .num { height: 38px; font-size: 18px; }
}
@media (orientation: portrait) and (min-width: 700px) {
  [data-size="16"] .game-layout { --board: min(calc(100vw - 64px), calc(100dvh - 330px), 820px); }
  [data-size="25"] .game-layout { --board: min(calc(100vw - 64px), calc(100dvh - 380px), 820px); }
  .numpad[data-count="16"] .num, .numpad[data-count="25"] .num { height: 56px; font-size: 26px; }
}

.notes.packed { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 0 2px; padding: 1px; overflow: hidden; }
.notes.packed span { display: inline; padding: 0 1px; }
.notes.packed.few { font-size: calc(var(--cell) * .3); }
.notes.packed.some { font-size: calc(var(--cell) * .23); }
.notes.packed.many { font-size: calc(var(--cell) * .18); letter-spacing: -.02em; }

.giant-note { margin: 0 2px; color: var(--ink-soft); font-size: 14px; }
body.has-photo .giant-note { background: color-mix(in srgb, var(--surface) 82%, transparent); padding: 8px 12px; border-radius: 12px; }
.cell.two { font-size: calc(var(--cell) * .46) !important; letter-spacing: -.03em; }
[data-size="16"] .notes.packed, [data-size="25"] .notes.packed { gap: 0 3px; }

/* ---------- Killer Sudoku cages ---------- */
:root {
  --cage-light: #f08a4b; --cage-dark: #ffb07a; --cage-amt: 55%; --cage-w: 1.5px; --cage-style: dashed;
  --cage-base: var(--cage-light);
  --cage: color-mix(in srgb, var(--cage-base) var(--cage-amt), var(--surface));
  --cage-sum: color-mix(in srgb, var(--cage-base) 78%, var(--ink));
  --tint0: #ffb38a; --tint1: #7fd8c8; --tint2: #9cc9f2; --tint3: #c6b6f5; --tint4: #f5b3c4;
}
:root[data-theme="dark"] { --cage-base: var(--cage-dark); --cage-sum: color-mix(in srgb, var(--cage-base) 85%, var(--ink)); }
.cage-layer {
  position: absolute; inset: 2.5px; pointer-events: none; z-index: 2;
  display: grid; grid-template-columns: repeat(9, 1fr); grid-template-rows: repeat(9, 1fr);
}
.cage { position: relative; }
/* cage outlines sit inside the cells so they never overlap a grid line */
.cage::before { content: ""; position: absolute; inset: 0; border: 0 var(--cage-style) var(--cage); }
.cage.t::before { top: 4px; border-top-width: var(--cage-w); }
.cage.b::before { bottom: 4px; border-bottom-width: var(--cage-w); }
.cage.l::before { left: 4px; border-left-width: var(--cage-w); }
.cage.r::before { right: 4px; border-right-width: var(--cage-w); }
/* Tinted style: soft fills, neighbours never share a tint */
[data-cage-style="tinted"] .cage { background: color-mix(in srgb, var(--tintc) calc(var(--cage-amt) * .4), transparent); }
[data-cage-style="tinted"][data-theme="dark"] .cage { background: color-mix(in srgb, var(--tintc) calc(var(--cage-amt) * .3), transparent); }
.cage.tint0 { --tintc: var(--tint0); } .cage.tint1 { --tintc: var(--tint1); } .cage.tint2 { --tintc: var(--tint2); }
.cage.tint3 { --tintc: var(--tint3); } .cage.tint4 { --tintc: var(--tint4); }
.cage-sum {
  position: absolute; top: 1px; left: 1px; z-index: 1;
  font-size: max(10px, calc(var(--board) / 9 * .2)); font-weight: 800; line-height: 1;
  color: var(--cage-sum); background: var(--surface); padding: 2px 3px 2px 2px; border-radius: 0 0 5px 0;
  font-variant-numeric: tabular-nums;
}
[data-cage-style="tinted"] .cage-sum { background: color-mix(in srgb, var(--surface) 85%, transparent); }
/* settings preview */
.setting-block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting-head small { display: block; color: var(--ink-soft); font-size: 13px; margin-top: 2px; }
.cage-settings { display: flex; gap: 14px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.cage-controls { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 220px; }
.cage-controls .seg button { padding: 6px 9px; font-size: 13px; }
.cage-preview { --board: 216px; position: relative; width: 108px; height: 108px; flex: none; border: 2px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.pv-grid, .pv-layer { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.pv-cell { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: grid; place-items: center; font-size: 18px; color: var(--entry); }
.pv-cell:nth-child(3n) { border-right: 0; } .pv-cell:nth-child(n+7) { border-bottom: 0; }
.pv-layer .cage-sum { font-size: 11px; }
.killer-mode .notes { inset: 7px 7px 6px 7px; font-size: calc(var(--board) / 9 * .2); }
.killer-mode .cell.has-sum .notes { top: max(15px, 36%); }
.killer-mode .cell { font-size: calc(var(--board) / 9 * .52); }
.killer-mode .cell.conflict::after { inset: 6px; }
.swatches { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; background: var(--sw); box-shadow: inset 0 0 0 3px var(--surface); border: 2px solid transparent; }
.swatch.on { border-color: var(--ink); }
.pause-cover { z-index: 3; }
