/* Nonogram — paper and ink. Three sheets of paper (graph paper, blueprint,
   slate) set the palette through custom properties on [data-theme]; the
   board itself is prefixed ng- so nothing collides with the panels. */

:root {
  --radius: 18px;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Graph paper: warm cream, pencil graphite, pale blue rulings */
:root, [data-theme="paper"] {
  --bg-a: #f1e9d8;
  --bg-b: #d9d0bd;
  --page-grid: rgba(96, 124, 160, 0.16);
  --paper: #fbf7ee;
  --paper-2: #efe8da;
  --panel: #f8f3e9;
  --grid: #b7c6d8;
  --grid-5: #6f86a6;
  --ink: #2b2925;
  --ink-soft: #6e665b;
  --fill-a: #4b4743;
  --fill-b: #2a2724;
  --cross: #8c8378;
  --clue: #2f2c28;
  --clue-done: #b9b1a3;
  --accent: #3a5a8a;
  --accent-2: #5d7fb0;
  --accent-ink: #f8f4ec;
  --hint-line: rgba(246, 205, 90, 0.42);
  --hint-cell: #e9b83c;
  --wrong: #c8463f;
  --line: rgba(60, 45, 30, 0.12);
  --chip: rgba(255, 255, 255, 0.45);
  --chip-border: rgba(255, 255, 255, 0.6);
  --shadow: rgba(50, 40, 25, 0.35);
  --blob-1: rgba(255, 252, 243, 0.95);
  --blob-2: rgba(140, 170, 210, 0.45);
  --blob-3: rgba(230, 196, 120, 0.35);
  --toast: rgba(43, 41, 37, 0.92);
}

/* ---- Blueprint: deep navy, white ink, gold accent */
[data-theme="blueprint"] {
  --bg-a: #1a3864;
  --bg-b: #0b1d3a;
  --page-grid: rgba(255, 255, 255, 0.07);
  --paper: #1e4078;
  --paper-2: #1a365f;
  --panel: #152f58;
  --grid: rgba(220, 232, 255, 0.28);
  --grid-5: rgba(230, 240, 255, 0.7);
  --ink: #eef3ff;
  --ink-soft: #a9bbdc;
  --fill-a: #ffffff;
  --fill-b: #d9e4fb;
  --cross: rgba(230, 238, 255, 0.62);
  --clue: #f2f6ff;
  --clue-done: rgba(238, 243, 255, 0.32);
  --accent: #efc15c;
  --accent-2: #f7d98a;
  --accent-ink: #1b2a44;
  --hint-line: rgba(239, 193, 92, 0.33);
  --hint-cell: #f3cc6c;
  --wrong: #ff8377;
  --line: rgba(255, 255, 255, 0.12);
  --chip: rgba(255, 255, 255, 0.07);
  --chip-border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(0, 10, 30, 0.6);
  --blob-1: rgba(70, 120, 200, 0.5);
  --blob-2: rgba(240, 200, 110, 0.18);
  --blob-3: rgba(120, 180, 240, 0.25);
  --toast: rgba(238, 243, 255, 0.95);
}

/* ---- Slate: dark grey board, chalk, teal accent */
[data-theme="slate"] {
  --bg-a: #3c3f45;
  --bg-b: #1f2125;
  --page-grid: rgba(255, 255, 255, 0.05);
  --paper: #30333a;
  --paper-2: #2a2d33;
  --panel: #2b2e34;
  --grid: rgba(255, 255, 255, 0.17);
  --grid-5: rgba(255, 255, 255, 0.5);
  --ink: #ecebe6;
  --ink-soft: #a9a8a1;
  --fill-a: #f6f3ec;
  --fill-b: #d8d4ca;
  --cross: rgba(240, 237, 230, 0.6);
  --clue: #f0ede6;
  --clue-done: rgba(240, 237, 230, 0.3);
  --accent: #7fb3a6;
  --accent-2: #a3d1c6;
  --accent-ink: #1b2522;
  --hint-line: rgba(127, 179, 166, 0.3);
  --hint-cell: #9ad3c4;
  --wrong: #ff8a80;
  --line: rgba(255, 255, 255, 0.12);
  --chip: rgba(255, 255, 255, 0.07);
  --chip-border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(0, 0, 0, 0.6);
  --blob-1: rgba(120, 130, 150, 0.45);
  --blob-2: rgba(127, 179, 166, 0.22);
  --blob-3: rgba(230, 200, 150, 0.14);
  --toast: rgba(236, 235, 230, 0.95);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  transition: background 0.8s, color 0.4s;
}

/* ---------------------------------------------------------- background */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.6;
  will-change: transform;
  transition: background 0.8s;
}
.bg .b1 { width: 60vmax; height: 60vmax; left: -20vmax; top: -25vmax; background: var(--blob-1); animation: drift 48s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -20vmax; background: var(--blob-2); animation: drift 60s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 30vw; bottom: -25vmax; background: var(--blob-3); animation: drift 72s ease-in-out infinite alternate; }
.bg .paper-grid {
  position: absolute;
  inset: -40px;
  background:
    linear-gradient(var(--page-grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--page-grid) 1px, transparent 1px) 0 0 / 28px 28px;
  animation: slide 90s linear infinite;
}
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}
@keyframes slide {
  from { transform: translate(0, 0); }
  to { transform: translate(28px, 28px); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 820px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 4px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; box-shadow: 0 2px 6px -1px var(--shadow); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: 0.02em; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }
.menu { display: flex; gap: 4px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: var(--chip); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg, .pen-btn svg, .stat svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 4px 16px 6px;
}
.stat {
  background: var(--chip);
  border: 1px solid var(--chip-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  border-radius: 12px;
  padding: 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 0;
}
.stat span { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.logic span.with-check { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-size: 9.5px; letter-spacing: 0.04em; max-width: 100%; }
.stat.logic span i { font-style: normal; }
.stat.logic svg { width: 13px; height: 13px; stroke-width: 2.4; }
[data-theme="paper"] .stat.logic span.with-check { color: #2f7a4c; }

.stage {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 8px 12px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 16px 12px;
}
.buttons { display: flex; gap: 10px; }
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; }
.btn:hover { background: var(--paper-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 4px 12px -4px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary.thinking { animation: breathe 0.8s ease-in-out infinite; }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; color: var(--ink-soft); font-size: 13.5px; margin: 18px auto 0; display: flex; border-color: transparent; }
@keyframes breathe { 50% { opacity: 0.6; } }

/* the pen switch: a thumb-sized segmented control */
.pen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}
.pen-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 14px var(--sans);
  letter-spacing: 0.02em;
  padding: 10px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background 0.25s var(--ease), color 0.25s, box-shadow 0.25s, transform 0.15s;
}
.pen-btn svg { width: 20px; height: 20px; }
.pen-btn:active { transform: scale(0.97); }
.pen-btn[aria-checked="true"] {
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 2px 6px -1px var(--shadow), 0 0 0 1px var(--line);
}
.pen-btn[aria-checked="true"] svg { color: var(--accent); }
[data-theme="paper"] .pen-btn[aria-checked="true"] svg { color: var(--fill-b); }

/* --------------------------------------------------------------- board */
.ng-board {
  --cell: 28px;
  --rcw: 60px;
  --cch: 60px;
  --nw: 17px;
  --nh: 17px;
  --fs: 14px;
  position: relative;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  scrollbar-width: thin;
  background: var(--paper);
  border-radius: 10px;
  padding: 8px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 18px 40px -16px var(--shadow),
    0 4px 12px -4px var(--shadow);
  transition: background 0.6s, box-shadow 0.6s;
}
.ng-top { display: flex; position: sticky; top: 0; z-index: 3; background: var(--paper); }
.ng-corner { position: sticky; left: 0; z-index: 4; flex: 0 0 auto; width: var(--rcw); height: var(--cch); background: var(--paper); }
.ng-corner::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 40%;
  height: 40%;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  opacity: 0.6;
  border-radius: 0 0 3px 0;
}
.ng-main { display: flex; align-items: flex-start; }
.ng-rowclues { position: sticky; left: 0; z-index: 2; flex: 0 0 auto; width: var(--rcw); display: grid; gap: 1px; padding: 2px 0; background: var(--paper); }
.ng-colclues { display: grid; gap: 1px; padding: 0 2px; height: var(--cch); }

.ng-rc, .ng-cc { display: flex; align-items: center; font-family: var(--serif); font-size: var(--fs); font-weight: 600; color: var(--clue); font-variant-numeric: tabular-nums; transition: opacity 0.4s, background 0.3s; border-radius: 3px; }
.ng-rc { height: var(--cell); justify-content: flex-end; padding-right: 5px; }
.ng-cc { width: var(--cell); flex-direction: column; justify-content: flex-end; padding-bottom: 4px; }
.ng-n { display: inline-flex; align-items: center; justify-content: center; line-height: 1; transition: color 0.35s, opacity 0.35s; }
.ng-rc .ng-n { min-width: var(--nw); height: 100%; }
.ng-cc .ng-n { height: var(--nh); width: 100%; }
.ng-n.done { color: var(--clue-done); }
.ng-rc.complete, .ng-cc.complete { opacity: 0.4; }
.ng-rc.hint, .ng-cc.hint { background: var(--hint-line); opacity: 1; }
.ng-rc.hint .ng-n, .ng-cc.hint .ng-n { color: var(--clue); }

.ng-grid {
  position: relative;
  display: grid;
  gap: 1px;
  background: var(--grid);
  border: 2px solid var(--grid-5);
  border-radius: 2px;
  touch-action: none;
  cursor: crosshair;
  transition: background 0.6s, border-color 0.6s;
}
.ng-cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  background: var(--paper);
  transition: background 0.25s;
}
.ng-cell::after {
  /* hint line tint, also the keyboard cursor */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: var(--hint-line);
  transition: opacity 0.3s;
}
.ng-cell.hl::after { opacity: 1; }
.ng-cell.cursor::after { opacity: 1; background: transparent; box-shadow: inset 0 0 0 2px var(--accent); border-radius: 2px; }

.ng-cell > i {
  position: absolute;
  inset: 2px;
  border-radius: 2px;
  display: block;
  pointer-events: none;
  transform: scale(0.2);
  opacity: 0;
  transition: transform 0.18s cubic-bezier(0.5, 0, 0.6, 1), opacity 0.15s, background 0.3s;
}
.ng-cell.f > i {
  opacity: 1;
  transform: scale(1);
  background: linear-gradient(155deg, var(--fill-a), var(--fill-b));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), inset 0 -1px 0 rgba(0, 0, 0, 0.18);
  animation: ng-pop 0.26s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes ng-pop {
  0% { transform: scale(0.3); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}
.ng-cell.x > i { opacity: 1; transform: scale(1); background: transparent; }
.ng-cell.x > i::before, .ng-cell.x > i::after {
  content: "";
  position: absolute;
  left: 22%;
  top: 50%;
  width: 56%;
  height: 2px;
  margin-top: -1px;
  border-radius: 2px;
  background: var(--cross);
  transform-origin: left center;
  animation: ng-stroke 0.18s ease-out both;
}
.ng-cell.x > i::before { transform: rotate(45deg); transform-origin: 50% 50%; animation-name: ng-stroke-a; }
.ng-cell.x > i::after { transform: rotate(-45deg); transform-origin: 50% 50%; animation-name: ng-stroke-b; animation-delay: 0.07s; }
@keyframes ng-stroke-a { from { transform: rotate(45deg) scaleX(0); } to { transform: rotate(45deg) scaleX(1); } }
@keyframes ng-stroke-b { from { transform: rotate(-45deg) scaleX(0); } to { transform: rotate(-45deg) scaleX(1); } }

.ng-cell.wrong.f > i { background: linear-gradient(155deg, color-mix(in oklab, var(--wrong) 85%, white), var(--wrong)); }
.ng-cell.wrong.x > i::before, .ng-cell.wrong.x > i::after { background: var(--wrong); }
.ng-cell.hint > i { animation: ng-hint 1.1s ease-in-out 3; }
@keyframes ng-hint {
  50% { box-shadow: 0 0 0 3px var(--hint-cell), 0 0 10px 2px var(--hint-cell); }
}
.ng-cell.hint.x > i::before, .ng-cell.hint.x > i::after { background: var(--hint-cell); }

.ng-tl { position: absolute; pointer-events: none; background: var(--grid-5); z-index: 1; transition: background 0.6s; }
.ng-tl.v { top: 0; bottom: 0; width: 3px; }
.ng-tl.h { left: 0; right: 0; height: 3px; }

/* fresh puzzle: cells arrive in a diagonal wave */
.ng-board.fresh .ng-cell { animation: ng-in 0.32s var(--ease) both; animation-delay: calc(var(--d) * 9ms); }
@keyframes ng-in { from { opacity: 0; transform: scale(0.6); } }
.ng-board.fresh .ng-n { animation: ng-in 0.4s var(--ease) both; animation-delay: calc(var(--d) * 9ms); }

/* solved: the picture lights up in colour, crosses fade, lines dissolve */
.ng-board.solved .ng-grid { cursor: default; background: transparent; border-color: transparent; transition: background 1.2s, border-color 1.2s; }
.ng-board.solved .ng-tl { background: transparent; transition: background 1.2s; }
.ng-board.solved .ng-cell.x > i { opacity: 0; transition: opacity 0.6s; }
.ng-board.solved .ng-cell.f > i {
  inset: 0;
  border-radius: 0;
  background: var(--cc);
  box-shadow: none;
  animation: none;
  transition: background 0.9s var(--ease), inset 0.6s var(--ease), border-radius 0.6s;
  transition-delay: calc(var(--d) * 14ms);
}
.ng-board.solved .ng-cell::after { opacity: 0; }
.ng-board.solved .ng-rc, .ng-board.solved .ng-cc { opacity: 0.25; transition: opacity 1.2s; }
.ng-board.solved { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset, 0 22px 50px -14px var(--shadow), 0 0 0 0 transparent; }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(20, 18, 14, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 22px;
  flex: 0 0 auto;
}
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 24px;
    max-height: 80dvh;
    animation: pop 0.28s var(--ease);
  }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  max-height: 92dvh;
  overflow: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px var(--shadow);
  text-align: center;
  animation: popc 0.3s var(--ease);
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); } }
.dialog p { margin: 8px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog .row { display: flex; gap: 10px; }
.dialog .lose { color: var(--wrong); margin-top: -10px; font-size: 14px; }
.result .glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--accent) 35%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.8;
}
.result h2 { position: relative; font-size: 30px; animation: shimmer 2.4s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--accent) 70%, white); } }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
  position: relative;
}
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.result-stats b, .summary b { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.total { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; position: relative; }
.total span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.total b { font-family: var(--serif); font-size: 44px; font-weight: 600; line-height: 1.05; }

/* new puzzle dialog */
.sizes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.size-btn {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
}
.size-btn:hover { border-color: var(--accent); }
.size-btn:active { transform: scale(0.97); }
.size-btn b { font-family: var(--serif); font-size: 24px; font-weight: 600; letter-spacing: 0.02em; }
.size-btn span { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); }
.size-btn[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent); }
.size-btn .mini { display: grid; gap: 1px; margin-bottom: 6px; background: var(--grid); padding: 1px; border-radius: 2px; }
.size-btn .mini i { width: 5px; height: 5px; background: var(--paper); display: block; }
.size-btn .mini i.on { background: var(--fill-b); }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.size-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.size-row b.sz { font-family: var(--serif); font-size: 18px; min-width: 64px; }
.size-row .cell-stat { display: flex; flex-direction: column; flex: 1; line-height: 1.2; align-items: center; }
.size-row .cell-stat span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.size-row .cell-stat b { font-family: var(--serif); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.c-time, th.c-hints, th.c-undos, th.c-score, td.c-time, td.c-hints, td.c-undos, td.c-score { text-align: right; }
td.c-score { font-family: var(--serif); font-weight: 600; font-size: 15px; }
td.c-size { font-family: var(--serif); font-weight: 600; }
@media (max-width: 420px) { th.c-undos, td.c-undos { display: none; } td { padding: 7px 3px; } }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent); }
.opts.lang .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.swatch { display: inline-block; width: 26px; height: 26px; border-radius: 7px; flex: 0 0 auto; position: relative; overflow: hidden; background: var(--sw0); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); }
.swatch::before { content: ""; position: absolute; left: 5px; top: 5px; width: 7px; height: 7px; background: var(--sw1); border-radius: 1px; box-shadow: 9px 0 0 var(--sw1), 0 9px 0 var(--sw1); }
.swatch::after { content: ""; position: absolute; right: 5px; bottom: 5px; width: 7px; height: 7px; border-radius: 1px; background: var(--sw2); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 22px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: color-mix(in oklab, var(--ink-soft) 45%, var(--paper-2)); position: relative; transition: background 0.25s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(136px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: var(--toast);
  color: var(--bg-b);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
[data-theme="paper"] .toast { color: #fff; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- small screens */
@media (max-height: 640px) {
  .top { padding-top: 6px; padding-bottom: 2px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .brand img { width: 32px; height: 32px; }
  .stats { padding-bottom: 4px; }
  .stat { padding: 4px 6px; }
  .stat b { font-size: 17px; }
  .stage { padding: 6px 12px; }
  .actions { padding-bottom: 8px; gap: 6px; }
  .btn { padding: 8px 10px; }
  .pen-btn { padding: 7px 8px; }
  .toast { bottom: calc(116px + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  .btn { flex-direction: column; gap: 3px; padding: 8px 6px 7px; font-size: 12.5px; }
  .btn span { white-space: nowrap; }
  .btn svg { width: 21px; height: 21px; }
  .dialog .row .btn { flex-direction: row; padding: 10px 8px; font-size: 14px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 26px; }
  .stage { padding: 14px 16px; }
  .actions { flex-direction: row; align-items: stretch; }
  .pen { flex: 0 0 300px; }
  .buttons { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob, .bg .paper-grid, .result h2 { animation: none; }
  .ng-cell, .ng-cell > i, .ng-n, .sheet, .dialog, .backdrop, .ng-board.fresh .ng-cell, .ng-board.fresh .ng-n { animation: none; transition-duration: 0.01s; }
  .ng-cell.f > i, .ng-cell.x > i::before, .ng-cell.x > i::after, .ng-cell.hint > i { animation: none; }
}
