/* Color tokens follow the sibling puzzle toolkit (yajilin / polyomino-panel / multiverse-star-battle). */
:root {
  color-scheme: light;
  --primary-blue: #1976d2;
  --color-solved: #2e7d32;
  --color-progress: #ffca28;
  --color-progress-text: #3a2a00;
  --color-error: #c62828;
  --bg-white: #fff;
  --bg-light: #f8f9fa;
  --border-light: #e0e0e0;
  --border-input: #ddd;
  --border-subtle: #eee;
  --border-strong: #bbb;
  --primary-blue-hover-bg: #f0f6ff;
  --text-primary: #111;
  --text-secondary: #666;

  --cell-bg: #fff;
  --cell-border: #d8d8d8;
  --grid-dot: #bcbcbc;
  --void-cutout: #111;
  --void-cutout-stroke: #e0e0e0;
  --void-hatch-stroke: #e0e0e0;
  --void-hatch-opacity: 0.45;
  --pearl-ink: #111;
  --pearl-white-fill: #fff;
  --pearl-gray-fill: #b6bcc4;
  --pearl-gray-ring: #5a626c;
  --pearl-gray-quad-w: #aeb5be;
  --pearl-gray-quad-b: #969ea8;
  --pearl-bad: #c62828;
  --midloop-fill: #0d9488;
  --midloop-stroke: #fff;
  --loop: #1976d2;
  --edge-x: #757575;
  --axis: #888;
  --axis-here: #1976d2;
  --edge-hover: rgba(25, 118, 210, 0.25);
  --face-in: rgba(38, 166, 154, 0.28);
  --face-out: rgba(245, 166, 85, 0.28);
  --face-in-stroke: rgba(38, 166, 154, 0.7);
  --face-out-stroke: rgba(230, 140, 50, 0.7);
  --face-hover: rgba(0, 0, 0, 0.05);

  --hint-focus: rgba(244, 236, 156, 0.8);
  --hint-undecided: rgba(244, 236, 156, 0.4);
  --hint-clue: rgba(25, 118, 210, 0.26);
  --hint-range: rgba(25, 118, 210, 0.13);
  --hint-path: rgba(122, 81, 149, 0.28);
  --hint-problem: #d55e00;
  --hint-ink: #8a6d00;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --primary-blue: #64b5f6;
  --color-solved: #66bb6a;
  --color-progress: #b8860b;
  --color-progress-text: #fff;
  --color-error: #ef5350;
  --bg-white: #1a1a1a;
  --bg-light: #1e1e1e;
  --border-light: #3a3a3a;
  --border-input: #444;
  --border-subtle: #333;
  --border-strong: #666;
  --primary-blue-hover-bg: #1a2a3a;
  --text-primary: #eee;
  --text-secondary: #aaa;

  --cell-bg: #222;
  --cell-border: #4a4a4a;
  --grid-dot: #626262;
  --void-cutout: #5e636e;
  --void-cutout-stroke: #7a808d;
  --void-hatch-stroke: #8c93a1;
  --void-hatch-opacity: 0.35;
  --pearl-ink: #e6e6e6;
  --pearl-white-fill: #222;
  --pearl-gray-fill: #78808a;
  --pearl-gray-ring: #c6cdd6;
  --pearl-gray-quad-w: #8a929c;
  --pearl-gray-quad-b: #7c8590;
  --pearl-bad: #ef5350;
  --midloop-fill: #2dd4bf;
  --midloop-stroke: #1b2226;
  --loop: #64b5f6;
  --edge-x: #aaa;
  --axis: #999;
  --axis-here: #64b5f6;
  --edge-hover: rgba(100, 181, 246, 0.35);
  --face-in: rgba(52, 211, 153, 0.36);
  --face-out: rgba(224, 155, 245, 0.46);
  --face-in-stroke: rgba(52, 211, 153, 0.78);
  --face-out-stroke: rgba(224, 155, 245, 0.78);
  --face-hover: rgba(255, 255, 255, 0.07);

  --hint-focus: rgba(255, 213, 79, 0.35);
  --hint-undecided: rgba(255, 213, 79, 0.2);
  --hint-clue: rgba(100, 181, 246, 0.32);
  --hint-range: rgba(100, 181, 246, 0.16);
  --hint-path: rgba(179, 157, 219, 0.35);
  --hint-problem: #ff8a50;
  --hint-ink: #ffd54f;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg-white); color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
#game-container { max-width: 640px; margin: 0 auto; padding: 8px 12px 40px; }

.topbar { display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 1.3rem; margin: 6px 0; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; padding: 0; font-size: 1.25rem; line-height: 1; border-radius: 50%;
  background: var(--bg-light); border: 1px solid var(--border-light); color: var(--text-secondary);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:not(:disabled):hover { background: var(--primary-blue-hover-bg); border-color: var(--primary-blue); color: var(--primary-blue); }
button, select, input[type=number] {
  font: inherit; color: inherit; background: var(--bg-light);
  border: 1px solid var(--border-input); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--primary-blue); }
button:disabled { opacity: 0.45; cursor: default; }
button.ghost { background: transparent; }

.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 4px 0; }
.pager { display: flex; align-items: center; gap: 4px; }
.pager input { width: 4.2rem; text-align: center; cursor: text; }
.pager-total { color: var(--text-secondary); margin-right: 4px; }
.step-btn { width: 2rem; padding: 4px 0; }

.infobar { display: flex; justify-content: space-between; align-items: baseline; min-height: 1.8rem; color: var(--text-secondary); font-size: 0.92rem; }
.status { font-weight: 600; }
.status.solved { color: var(--color-solved); }
.controls { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.btn-group { display: flex; gap: 6px; }

/* ---- Board SVG (scoped to #board / .help-fig so screen styles never leak into #print-root) ---- */
.board-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
#board { margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; }
#board svg { width: 100%; height: auto; display: block; }
#board .board-bg { fill: var(--cell-bg); stroke: var(--border-light); stroke-width: 1.5; }
#board.solved .board-bg { stroke: var(--color-solved); stroke-width: 2.5; }
:is(#board, .help-fig) .void-cutout { fill: var(--void-cutout); pointer-events: none; }
#board .void-cutout-frame { fill: url(#void-hatch); stroke: var(--void-cutout-stroke); stroke-width: 1.5; pointer-events: none; }
#board .void-hatch-line { stroke: var(--void-hatch-stroke); opacity: var(--void-hatch-opacity); }
:is(#board, .help-fig) .face-in { fill: var(--face-in); pointer-events: none; }
:is(#board, .help-fig) .face-out { fill: var(--face-out); pointer-events: none; }
#board .face-in.auto, #board .face-out.auto { opacity: 0.72; }
#board .face-hover { fill: var(--face-hover); pointer-events: none; }
#board .face-bad { fill: none; stroke: var(--color-error); stroke-width: 1.8; stroke-dasharray: 4 3; opacity: 0.85; pointer-events: none; }
#board .grid-line { stroke: var(--cell-border); stroke-width: 1; stroke-dasharray: 2 3.5; stroke-linecap: round; fill: none; pointer-events: none; }
:is(#board, .help-fig) .grid-dot { fill: var(--grid-dot); pointer-events: none; }
:is(#board, .help-fig) .grid-dot.full-board { fill: var(--text-secondary); }
#board .seg { stroke: var(--loop); stroke-linecap: round; fill: none; pointer-events: none; }
#board .seg.bad { stroke: var(--color-error); }
#board .seg-given { stroke: var(--pearl-ink); stroke-linecap: round; fill: none; pointer-events: none; }
#board .seg-given.bad { stroke: var(--color-error); }
#board .seg-bad-halo { stroke: var(--color-error); stroke-linecap: round; fill: none; opacity: 0.28; pointer-events: none; }
#board .edge-x { stroke: var(--edge-x); stroke-width: 1.8; stroke-linecap: round; fill: none; pointer-events: none; }
#board .edge-x.auto { opacity: 0.45; }
#board .edge-x-halo { stroke: var(--cell-bg); stroke-width: 3.8; stroke-linecap: round; fill: none; pointer-events: none; }
#board .edge-x-halo.auto { opacity: 0.6; }
#board .wall-given { stroke: var(--pearl-ink); stroke-width: 2.8; stroke-linecap: round; fill: none; pointer-events: none; }
#board .wall-given-halo { stroke: var(--cell-bg); stroke-width: 5.2; stroke-linecap: round; fill: none; pointer-events: none; }
:is(#board, .help-fig) .trapped-cell { fill: none; stroke: var(--color-error); stroke-width: 2.6; pointer-events: none; }
#board .slither-num {
  fill: var(--pearl-ink); font-size: 21px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none;
}
#board .slither-num.bad { fill: var(--pearl-bad); }
:root[data-theme="dark"] #board .slither-num.bad {
  fill: #ff6b6b; paint-order: stroke; stroke: var(--cell-bg); stroke-width: 3px; stroke-linejoin: round;
}
:is(#board, .help-fig) .corral-badge {
  fill: rgba(255, 255, 255, 0.86); stroke: #2f6f4e; stroke-width: 2; pointer-events: none;
}
:is(#board, .help-fig) .corral-badge.bad {
  fill: #fde8e8; stroke: var(--pearl-bad); stroke-width: 2.8;
}
:is(#board, .help-fig) .corral-num {
  fill: #1b4332; font-weight: 700;
  text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none;
}
:is(#board, .help-fig) .corral-num.bad { fill: #b71c1c; }
:root[data-theme="dark"] :is(#board, .help-fig) .corral-badge {
  fill: rgba(22, 34, 28, 0.9); stroke: #5fb889;
}
:root[data-theme="dark"] :is(#board, .help-fig) .corral-badge.bad {
  fill: #4a151b; stroke: var(--pearl-bad);
}
:root[data-theme="dark"] :is(#board, .help-fig) .corral-num { fill: #d8f3e5; }
:root[data-theme="dark"] :is(#board, .help-fig) .corral-num.bad { fill: #ff9494; }
svg [hidden] { display: none; }
.help-fig .hr-num {
  fill: var(--pearl-ink); font-size: 13px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central; pointer-events: none;
}
.help-fig .hr-num.bad { fill: var(--pearl-bad); }

/* Masyu circles (pearls) & Mid-loop dots */
:is(#board, .help-fig) .pearl-white-fill { fill: var(--pearl-white-fill); pointer-events: none; }
:is(#board, .help-fig) .pearl-white-ring { fill: none; stroke: var(--pearl-ink); stroke-width: 2.6; pointer-events: none; }
:is(#board, .help-fig) .pearl-white-ring.bad { stroke: var(--pearl-bad); stroke-width: 3.1; }
:is(#board, .help-fig) .pearl-black { fill: var(--pearl-ink); stroke: var(--pearl-ink); stroke-width: 1; pointer-events: none; }
:is(#board, .help-fig) .pearl-black.bad { fill: var(--pearl-bad); stroke: var(--pearl-bad); }
:is(#board, .help-fig) .midloop-dot { fill: var(--midloop-fill); stroke: var(--midloop-stroke); stroke-width: 2; pointer-events: none; }
:is(#board, .help-fig) .midloop-dot.bad { fill: var(--pearl-bad); stroke: var(--midloop-stroke); }
:is(#board, .help-fig) .castle-tile-W { fill: #ffffff; stroke: #222222; stroke-width: 2.2; pointer-events: none; }
:is(#board, .help-fig) .castle-tile-B { fill: #1f2429; stroke: #1f2429; stroke-width: 2.2; pointer-events: none; }
:is(#board, .help-fig) .castle-tile-G { fill: #c4cbd3; stroke: #4b5563; stroke-width: 2; pointer-events: none; }
#help-modal .help-fig .castle-tile-W,
#help-modal .help-fig .castle-tile-B,
#help-modal .help-fig .castle-tile-G { stroke-width: 1.2; }
#board .castle-bad-halo { fill: none; stroke: var(--color-error); stroke-width: 6; opacity: 0.34; pointer-events: none; }
:is(#board, .help-fig) .castle-tile-W.bad { fill: #fde8e8; stroke: var(--pearl-bad); stroke-width: 3.2; }
:is(#board, .help-fig) .castle-tile-B.bad { fill: #4a151b; stroke: var(--pearl-bad); stroke-width: 3.2; }
:is(#board, .help-fig) .castle-tile-G.bad { fill: #e3c2c6; stroke: var(--pearl-bad); stroke-width: 3.2; }
:is(#board, .help-fig) .castle-text-W { fill: #111111; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none; }
:is(#board, .help-fig) .castle-text-B { fill: #ffffff; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none; }
:is(#board, .help-fig) .castle-text-G { fill: #111111; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; user-select: none; }
:is(#board, .help-fig) .castle-text-W.bad { fill: #b71c1c; }
:is(#board, .help-fig) .castle-text-B.bad { fill: #ff9494; }
:is(#board, .help-fig) .castle-text-G.bad { fill: #8c1212; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-W { fill: #f0f3f7; stroke: #111111; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-B { fill: #0d1117; stroke: #8d96a0; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-G { fill: #4c5664; stroke: #9aa4b2; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-text-G { fill: #ffffff; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-text-G.bad { fill: #ffd6d6; }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-W.bad { fill: #fce4e4; stroke: var(--pearl-bad); }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-B.bad { fill: #3f1218; stroke: var(--pearl-bad); }
:root[data-theme="dark"] :is(#board, .help-fig) .castle-tile-G.bad { fill: #693840; stroke: var(--pearl-bad); }
#board .hint-castle-clue { fill: none; stroke: var(--primary-blue); stroke-width: 3.4; pointer-events: none; }
#board .hint-castle-focus { fill: none; stroke: var(--hint-ink); stroke-width: 3.4; pointer-events: none; }
#board .hint-castle-problem { fill: none; stroke: var(--hint-problem); stroke-width: 3.6; stroke-dasharray: 5 3; pointer-events: none; }
#board .pearl-gray-fill { fill: var(--pearl-gray-fill); pointer-events: none; }
#board .pearl-gray-ring { fill: none; stroke: var(--pearl-gray-ring); stroke-width: 2.4; pointer-events: none; }
#board .pearl-gray-ring.bad { stroke: var(--pearl-bad); stroke-width: 3.1; }
:is(#board, .help-fig) .pearl-black-fill { fill: var(--pearl-ink); pointer-events: none; }
:is(#board, .help-fig) .pearl-black-fill.bad { fill: var(--pearl-bad); }
:is(#board, .help-fig) .pearl-black-ring { fill: none; stroke: var(--pearl-ink); stroke-width: 2.2; pointer-events: none; }
:is(#board, .help-fig) .pearl-black-ring.bad { stroke: var(--pearl-bad); stroke-width: 3.1; }
:is(#board, .help-fig) .pearl-gray-quad-w { fill: var(--pearl-gray-quad-w); pointer-events: none; }
:is(#board, .help-fig) .pearl-gray-quad-b { fill: var(--pearl-gray-quad-b); pointer-events: none; }
/* In dark mode, keep white circles light and black circles dark (rimmed so they pop against #222) so colors always match the rules and hint text. */
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-white-fill { fill: #f0f3f7; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-white-ring { stroke: #111; stroke-width: 2.4; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-white-ring.bad { stroke: var(--pearl-bad); stroke-width: 3.2; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black { fill: #090a0c; stroke: #8d96a0; stroke-width: 2.2; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black.bad { stroke: var(--pearl-bad); stroke-width: 3; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black-fill { fill: #090a0c; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black-fill.bad { fill: var(--pearl-bad); }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black-ring { stroke: #c6cdd6; stroke-width: 2.2; }
:root[data-theme="dark"] :is(#board, .help-fig) .pearl-black-ring.bad { stroke: var(--pearl-bad); stroke-width: 3.2; }

#board .edge-hover { fill: var(--edge-hover); pointer-events: none; }
#board .pearl-hover { fill: none; stroke: var(--primary-blue); stroke-width: 2; opacity: 0.55; pointer-events: none; }
#board .over { fill: none; stroke: var(--color-error); stroke-width: 3; pointer-events: none; }
#board .axis-label { fill: var(--axis); font-size: 11px; text-anchor: middle; dominant-baseline: auto; pointer-events: none; }
#board .axis-label.side { text-anchor: end; dominant-baseline: central; }
#board .axis-label.here { fill: var(--axis-here); font-weight: 700; }
#board .line-end { fill: none; stroke: var(--primary-blue); stroke-width: 2.2; stroke-linejoin: round; pointer-events: none; }
#board .line-end-halo { fill: none; stroke: var(--cell-bg); stroke-width: 4.5; stroke-linejoin: round; pointer-events: none; }

/* ---- Hint overlays ---- */
#board .hint-face-in { fill: var(--face-in); stroke: var(--face-in-stroke); stroke-width: 1.5; stroke-dasharray: 4 3; pointer-events: none; }
#board .hint-face-out { fill: var(--face-out); stroke: var(--face-out-stroke); stroke-width: 1.5; stroke-dasharray: 4 3; pointer-events: none; }
#board .hint-undecided { fill: var(--hint-undecided); pointer-events: none; }
#board .hint-area { fill: var(--hint-range); pointer-events: none; }
#board .hint-clue { fill: var(--hint-clue); pointer-events: none; }
#board .hint-path { fill: var(--hint-path); pointer-events: none; }
#board .hint-focus { fill: var(--hint-focus); pointer-events: none; }
#board .hint-problem { fill: url(#hatch); pointer-events: none; }
#board .hatch-bg { fill: transparent; }
#board .hatch-line { stroke: var(--hint-problem); opacity: 0.6; }
#board .hint-exit { fill: none; stroke: var(--color-solved); stroke-width: 2.2; stroke-dasharray: 4 3; pointer-events: none; }
#board .hint-focus-ring { fill: none; stroke: var(--hint-ink); stroke-width: 3; pointer-events: none; }
#board .chain-seg { stroke: var(--hint-problem); stroke-linecap: round; stroke-dasharray: 6 5; opacity: 0.92; pointer-events: none; }
#board .ghost-seg { stroke: var(--hint-ink); stroke-linecap: round; stroke-dasharray: 5 4; pointer-events: none; }
#board .ghost-x { stroke: var(--color-error); stroke-width: 2.8; stroke-linecap: round; fill: none; pointer-events: none; }
#board .ghost-x-halo { stroke: var(--cell-bg); stroke-width: 5.5; stroke-linecap: round; fill: none; pointer-events: none; }
#board .ghost-gray-white { fill: #fff; stroke: var(--hint-ink); stroke-width: 2.2; stroke-dasharray: 4 2.5; pointer-events: none; }
#board .ghost-gray-black { fill: #111; stroke: var(--hint-ink); stroke-width: 2.2; stroke-dasharray: 4 2.5; pointer-events: none; }
#board .wrong-seg { stroke: var(--color-error); stroke-linecap: round; opacity: 0.5; pointer-events: none; }
#board .wrong-clue { fill: none; stroke: var(--color-error); stroke-width: 3.2; opacity: 0.85; pointer-events: none; }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); max-width: 90vw;
  background: var(--text-primary); color: var(--bg-white); padding: 8px 14px; border-radius: 8px; cursor: pointer; z-index: 2500;
}
.toast[hidden] { display: none; }
.toast.below { position: static; transform: none; margin: 12px auto 0; width: min(560px, 94vw); }
.toast.ghost { visibility: hidden; pointer-events: none; }
.toast.hint { text-align: left; width: min(560px, 94vw); line-height: 1.45; padding: 10px 14px; }
.toast.hint .hint-meta { font-size: 0.75rem; opacity: 0.78; margin-bottom: 3px; font-family: ui-monospace, Menlo, monospace; }
.toast.hint .hint-more { margin-top: 5px; font-size: 0.8rem; opacity: 0.82; }
.hint-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: 0.75rem; opacity: 0.9; }
.hint-legend .chip { display: inline-block; width: 11px; height: 11px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; border: 1px solid color-mix(in srgb, currentColor 40%, transparent); }

/* ---- Modals ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; justify-content: center; align-items: center; z-index: 2000;
  transition: opacity 0.2s, visibility 0.2s;
}
.modal-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.modal-box {
  background: var(--bg-white); border-radius: 8px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  max-width: 480px; width: 90%; max-height: 80vh; overflow-y: auto;
}
.modal-box--wide { max-width: 560px; width: 94%; max-height: 85vh; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 1; background: var(--bg-white);
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-header button { background: none; border: none; font-size: 1.2rem; padding: 4px 8px; color: var(--text-secondary); }
.modal-header button:not(:disabled):hover { background: var(--border-light); border-radius: 4px; }
.modal-body { padding: 16px 20px; line-height: 1.6; }
.modal-body h3 { margin: 18px 0 6px; font-size: 1rem; }
.modal-body p { margin: 0 0 8px; }
.modal-body ul { margin: 4px 0 8px; padding-left: 1.25em; }
.modal-body li { margin: 6px 0; }

.settings-list { display: flex; flex-direction: column; }
.settings-section { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--border-light); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border-subtle); cursor: pointer; }
.settings-row:last-child { border-bottom: none; }
.settings-row-text { display: flex; flex-direction: column; gap: 2px; }
.settings-label { font-weight: 600; font-size: 0.95rem; color: var(--text-primary); }
.settings-desc { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.35; }
.settings-row button { white-space: nowrap; flex-shrink: 0; }
#palette-group[hidden], .palette-custom[hidden], #offline-actions[hidden] { display: none; }
#offline-group { border-bottom: 1px solid var(--border-subtle); }
#offline-group .settings-row { border-bottom: none; }
.offline-actions { display: flex; align-items: center; gap: 8px; padding: 0 0 12px; }
.offline-actions button { font-size: 0.82rem; padding: 4px 10px; }
.settings-row--sub { cursor: default; border-bottom: none; padding-bottom: 8px; padding-left: 14px; }
.settings-row--sub select { flex-shrink: 0; max-width: 55%; }
.palette-panel { padding: 0 0 14px 14px; border-bottom: 1px solid var(--border-subtle); }
.palette-strip { display: flex; flex-wrap: wrap; gap: 8px 7px; padding-top: 4px; }
.swatch { position: relative; width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border-strong); }
.swatch input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: none; background: none; cursor: pointer; opacity: 0; }
.swatch-x { position: absolute; top: -7px; right: -7px; width: 16px; height: 16px; padding: 0; border-radius: 50%; line-height: 1; font-size: 11px; background: var(--bg-white); border: 1px solid var(--border-strong); color: var(--text-secondary); }
.palette-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.palette-custom .settings-desc { flex-basis: 100%; }
.settings-row .danger-btn { border: 1.5px solid #d9534f; background: transparent; color: #d9534f; font-weight: 600; }
.settings-row .danger-btn:hover, .settings-row .danger-btn.danger-btn--confirm { background: #d9534f; color: #fff; border-color: #d9534f; }

.toggle-switch { flex-shrink: 0; position: relative; }
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track { display: block; width: 44px; height: 24px; background: var(--border-strong); border-radius: 12px; position: relative; transition: background 0.2s; cursor: pointer; }
.toggle-switch input:checked + .toggle-track { background: var(--primary-blue); }
.toggle-switch input:focus-visible + .toggle-track { outline: 2px solid var(--primary-blue); outline-offset: 2px; }
.toggle-switch input:disabled + .toggle-track { opacity: 0.45; cursor: not-allowed; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: var(--bg-white); border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }

.ok-text { color: var(--color-solved); font-weight: 600; }
.bad-text { color: var(--color-error); font-weight: 600; }

/* ---- Browse grid ---- */
.browse-btn { padding: 4px 10px; font-size: 0.85rem; margin-left: 4px; }
.browse-modal-body { padding: 12px 16px 20px; }
.browse-summary { font-weight: 600; margin-bottom: 8px; }
.browse-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.browse-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; font-size: 0.8rem; color: var(--text-secondary); }
.legend-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-right: 2px; }
.legend-solved { background: var(--color-solved); }
.legend-in-progress { background: var(--color-progress); }
.legend-current { background: var(--primary-blue); }
.legend-unsolved { background: var(--border-light); border: 1px solid var(--border-strong); }
.browse-jump-btn { font-size: 0.82rem; padding: 5px 10px; white-space: nowrap; }
.browse-jumps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.browse-jump-pill {
  font-size: 0.78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--bg-white); border: 1px solid var(--border-input); color: var(--text-primary);
}
.browse-jump-pill:hover { border-color: var(--primary-blue); color: var(--primary-blue); }
.browse-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 55vh; overflow-y: auto; padding: 2px; }
.browse-tile {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; border-radius: 6px; cursor: pointer; padding: 0; min-width: 0;
  border: 2px solid transparent; background: var(--border-light); color: var(--text-primary);
}
.browse-tile:hover { filter: brightness(0.93); }
.browse-tile.bt-solved { background: var(--color-solved); color: #fff; }
.browse-tile.bt-in-progress { background: var(--color-progress); color: var(--color-progress-text); }
.browse-tile.bt-current { border-color: var(--primary-blue); box-shadow: 0 0 0 2px var(--primary-blue); }
.browse-section-header { grid-column: 1 / -1; padding: 8px 2px 2px; margin-bottom: 2px; border-bottom: 1px solid var(--border-light); }
.browse-section-name { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-secondary); }

/* ---- Book picker ---- */
.book-btn {
  display: flex; align-items: center; gap: 6px; min-width: 0; max-width: 60%; padding: 5px 10px; text-align: left;
  background: var(--bg-white); border: 1px solid var(--border-input); border-radius: 6px; color: var(--text-primary);
}
.book-btn .book-btn-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-btn::after { content: '▾'; flex-shrink: 0; color: var(--text-secondary); }
.bp-body { padding: 8px 16px 20px; }
.bp-title { margin: 8px 0 2px; font-size: 1.05rem; }
.bp-blurb { margin: 0 0 8px; font-size: 0.85rem; color: var(--text-secondary); line-height: 1.35; }
.bp-back { background: none; border: none; padding: 4px 0; color: var(--primary-blue); font: inherit; font-size: 0.9rem; cursor: pointer; }
.bp-back:hover { text-decoration: underline; }
.bp-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.bp-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 12px; text-align: left; background: var(--bg-white);
  border: 1px solid var(--border-light); border-radius: 10px; color: var(--text-primary); cursor: pointer;
}
.bp-card:hover { border-color: var(--border-strong); }
.bp-card.bp-current { background: var(--primary-blue-hover-bg); border-color: var(--primary-blue); }
.bp-card-icon { font-size: 1.6rem; line-height: 1.1; }
.bp-card-name { font-weight: 600; font-size: 1rem; }
.bp-card-blurb { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.3; }
.bp-card-meta { margin-top: auto; padding-top: 4px; font-size: 0.78rem; color: var(--text-secondary); }
.bp-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.bp-cards + .bp-list { margin-top: 10px; }
.bp-book {
  display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 12px; text-align: left;
  background: var(--bg-white); border: 1px solid var(--border-light); border-radius: 8px; color: var(--text-primary); cursor: pointer;
}
.bp-book:hover { border-color: var(--border-strong); }
.bp-book.bp-current { background: var(--primary-blue-hover-bg); border-color: var(--primary-blue); }
.bp-book-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.bp-book-title { font-weight: 600; font-size: 0.95rem; }
.bp-book-blurb { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.3; }
.bp-count { flex-shrink: 0; font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; }
.bp-count-done { color: var(--color-solved); font-weight: 600; }
@media (max-width: 380px) { .bp-cards { grid-template-columns: 1fr; } }

/* ---- Help modal rule diagrams ---- */
.help-rules { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 14px; }
.help-rule-card { background: var(--bg-light); border: 1px solid var(--border-light); border-radius: 8px; padding: 10px 12px; }
.help-rule-card--wide { grid-column: 1 / -1; }
.help-rule-card--wide .help-diagrams { max-width: 280px; }
.help-rule-title { font-weight: 700; font-size: 0.94rem; margin-bottom: 3px; }
.help-rule-desc { margin: 0 0 8px; font-size: 0.84rem; color: var(--text-secondary); line-height: 1.35; }
.help-diagrams { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.help-fig { margin: 0; text-align: center; }
.help-fig svg { width: 100%; height: auto; display: block; }
.help-fig figcaption { font-size: 0.74rem; margin-top: 3px; }
.hr-bg { fill: var(--cell-bg); stroke: var(--border-light); stroke-width: 1.2; }
.hr-grid { fill: none; stroke: var(--cell-border); stroke-width: 1; stroke-dasharray: 2 3; }
.hr-dot { fill: var(--grid-dot); }
.hr-line { fill: none; stroke: var(--loop); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.hr-line-bad { fill: none; stroke: var(--color-error); stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; }
.hr-given { fill: none; stroke: var(--pearl-ink); stroke-width: 5; stroke-linecap: round; }
.hr-wall { fill: none; stroke: var(--pearl-ink); stroke-width: 2.2; stroke-linecap: round; }
.help-controls { margin: 4px 0 12px; padding-left: 20px; }
.help-controls li { margin: 4px 0; font-size: 0.9rem; }
.help-foot { margin: 0; font-size: 0.83rem; color: var(--text-secondary); }
@media (max-width: 520px) { .help-rules { grid-template-columns: 1fr; } }

/* ---- Print dialog & booklet ---- */
.print-form { display: grid; grid-template-columns: auto 1fr; gap: 10px 12px; align-items: center; margin: 8px 0; }
.print-form input[type="text"], .print-form select { min-width: 0; font: inherit; padding: 6px 8px; }
.print-form input[type="checkbox"] { justify-self: start; width: 18px; height: 18px; }
.print-error { color: var(--color-error); font-size: 0.85rem; margin: 6px 0; }
.print-summary { color: var(--text-secondary); font-size: 0.85rem; min-height: 1.3em; }
.print-actions { display: flex; justify-content: flex-end; }

#print-root { display: none; }
#print-root, #print-root * { box-sizing: border-box; }
#print-root .print-page {
  display: block; color: #111; background: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  page-break-after: always; break-after: page;
}
#print-root .print-page:last-child { page-break-after: auto; break-after: auto; }
#print-root .print-head {
  display: flex; align-items: center; gap: 4mm; border-bottom: 0.4mm solid #111;
  padding-bottom: 2mm; margin-bottom: 5mm; white-space: nowrap;
  page-break-inside: avoid; break-inside: avoid;
}
#print-root .print-brand { font-weight: 700; font-size: 5mm; flex-shrink: 0; }
#print-root .print-name, #print-root .print-url { color: inherit; text-decoration: none; }
#print-root .print-url { font-size: 3.2mm; color: #555; flex-shrink: 0; }
#print-root .print-book { margin-left: auto; font-size: 3.6mm; color: #333; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#print-root .print-grid { display: grid; grid-template-columns: repeat(var(--cols, 1), max-content); gap: 6mm 5mm; justify-content: center; justify-items: center; align-content: start; }
#print-root .print-item { margin: 0; text-align: center; page-break-inside: avoid; break-inside: avoid; }
#print-root .print-caption { font-weight: 600; font-size: 3.6mm; margin-bottom: 1.5mm; text-align: left; white-space: nowrap; }
#print-root .print-board { display: block; }
@media print {
  @page { margin: 10mm; }
  :root, html, body.printing-booklet {
    color-scheme: light !important;
    background: #fff !important;
    color: #111 !important;
  }
  body.printing-booklet > *:not(#print-root) { display: none !important; }
  body.printing-booklet #print-root {
    display: block;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
