/* Fillomino — cut paper on washi, indigo-dyed paper or terrazzo. Every
   colour arrives as a custom property from themes.js; the defaults below are
   washi. --p1 … --p9 are the region colours. */

:root {
  --bg-a: #efe8dc;
  --bg-b: #ddd3c2;
  --blob-1: rgba(255, 252, 244, 0.95);
  --blob-2: rgba(242, 163, 149, 0.22);
  --blob-3: rgba(95, 176, 162, 0.18);
  --ink: #2c2622;
  --ink-soft: #776c60;
  --paper: #fbf7ef;
  --paper-2: #f1e9dc;
  --line: rgba(70, 52, 35, 0.13);
  --accent: #2f4f7a;
  --accent-2: #47689a;
  --accent-ink: #f6f8fc;
  --glow: #f2c44f;
  --warn: #c2463a;
  --good: #4f8a5b;
  --card: rgba(255, 252, 246, 0.5);
  --card-border: rgba(255, 255, 255, 0.65);
  --btn-bg: rgba(255, 252, 246, 0.66);
  --btn-hover: rgba(255, 252, 246, 0.95);
  --btn-border: rgba(70, 52, 35, 0.15);
  --hover: rgba(70, 52, 35, 0.08);
  --track: #d6ccbb;
  --shadow: 70, 48, 25;
  --backdrop: rgba(50, 38, 25, 0.38);
  --toast-bg: rgba(44, 38, 34, 0.95);
  --toast-ink: #fbf7ef;
  --key-bg: #fbf8f1;
  --key-ink: #2c2622;
  --p1: #e3d9c6; --p2: #ee9589; --p3: #f3c650; --p4: #56a898; --p5: #7d9fd9;
  --p6: #9cc06c; --p7: #e9853f; --p8: #7a589f; --p9: #b9475c;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.3, 1.35, 0.5, 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;
  --digits: "Avenir Next", Avenir, "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", Roboto, system-ui, sans-serif;
}

* { 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-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  transition: background 0.8s, color 0.8s;
}

/* ---------------------------------------------------------- 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 52s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -20vmax; background: var(--blob-2); animation: drift 66s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 30vw; bottom: -25vmax; background: var(--blob-3); animation: drift 78s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 980px;
  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;
  gap: 8px;
  padding: 10px 12px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 10px; filter: drop-shadow(0 2px 3px rgba(var(--shadow), 0.3)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 23px; letter-spacing: 0.02em; white-space: nowrap; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { display: flex; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.board:focus-visible { outline: none; }

.stats {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 4px 16px 6px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.06);
  border-radius: 12px;
  padding: 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 0;
  transition: background 0.8s, border-color 0.8s;
}
.stat span { font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stat b small { font-size: 0.62em; font-weight: 500; color: var(--ink-soft); letter-spacing: 0; }
.stat.filled b { transition: color 0.4s; }
.stat.filled.done b { color: var(--good); }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 2px 6px;
}
.board {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.busy {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  box-shadow: 0 6px 20px rgba(var(--shadow), 0.22);
  font-size: 14px;
  white-space: nowrap;
  animation: fade 0.3s;
}
.busy i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in oklab, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ the pad */
.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 6px 16px 2px;
  touch-action: manipulation;
}
.key {
  --c: var(--p1);
  appearance: none;
  position: relative;
  min-width: 0;
  height: 46px;
  border: 1px solid var(--btn-border);
  border-radius: 12px;
  background: var(--key-bg);
  color: var(--key-ink);
  font: 600 22px/1 var(--digits);
  font-variant-numeric: tabular-nums;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 1px 2px rgba(var(--shadow), 0.12);
  transition: transform 0.15s var(--ease), box-shadow 0.2s, background 0.2s, border-color 0.2s, color 0.2s;
}
/* the region colour as a paper tab along the bottom */
.key::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: var(--c);
  opacity: 0.9;
  transition: height 0.22s var(--ease), opacity 0.2s;
}
.key b { position: relative; z-index: 1; font-weight: inherit; margin-top: -3px; }
.key svg { position: relative; z-index: 1; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; margin-top: -2px; }
.key:hover { border-color: color-mix(in oklab, var(--c) 60%, var(--btn-border)); }
.key:active { transform: scale(0.94); }
.key:disabled { opacity: 0.45; cursor: default; transform: none; }
.key[aria-pressed="true"] {
  border-color: color-mix(in oklab, var(--c) 70%, #000 10%);
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--c) 55%, transparent), 0 4px 10px -4px rgba(var(--shadow), 0.45);
  transform: translateY(-2px);
}
.key[aria-pressed="true"]::after { height: 100%; opacity: 1; }
.key[aria-pressed="true"] b { color: var(--ink-on, var(--key-ink)); }
.key.erase { --c: var(--track); color: var(--ink-soft); }
.key.erase[aria-pressed="true"] { color: var(--ink); }
.key[data-n="8"], .key[data-n="9"] { --ink-on: #fdf8ee; }
[data-theme="indigo"] .key[data-n="4"] { --ink-on: #161a26; }

.actions {
  display: flex;
  gap: 8px;
  padding: 6px 16px 14px;
}
.btn {
  appearance: none;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  min-height: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.08);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }
.btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.square { flex: 0 0 52px; padding: 0; }
.btn.square svg { width: 22px; height: 22px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.96); }
.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 rgba(var(--shadow), 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.btn.primary.thinking { animation: breathe 0.8s ease-in-out infinite; }
.btn.primary.next { animation: nudge 2.4s var(--ease) infinite; }
@keyframes breathe { 50% { opacity: 0.6; } }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: translateX(3px); } 90% { transform: translateX(-1px); } }
.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; min-height: 40px; }
.btn.subtle svg { width: 17px; height: 17px; }

/* Per-look touches on the chrome */
[data-theme="washi"] .stat { box-shadow: inset 0 0 0 2px rgba(255, 252, 246, 0.4), 0 1px 2px rgba(var(--shadow), 0.06); }
[data-theme="washi"] .btn.primary { border-radius: 13px 15px 14px 13px; }
[data-theme="indigo"] .btn.primary { box-shadow: 0 0 18px -5px rgba(235, 201, 127, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3); text-shadow: none; }
[data-theme="indigo"] .key { box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06); }
[data-theme="terrazzo"] .key, [data-theme="terrazzo"] .stat { border-radius: 8px; }
[data-theme="terrazzo"] .btn { border-radius: 10px; }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  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: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(var(--shadow), 0.25);
  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: 5px 0; }
.figure { display: block; width: 100%; max-width: 380px; height: auto; margin: 4px auto 14px; }
.figure text { font: 600 16px var(--digits); text-anchor: middle; }
.figure .cap { font: 700 15px var(--sans); fill: var(--ink-soft); }
.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: 84dvh;
    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);
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(var(--shadow), 0.35);
  text-align: center;
  animation: popc 0.34s var(--spring);
  overflow: hidden;
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } }
#confirm.over-sheet { box-shadow: 0 20px 60px rgba(var(--shadow), 0.35), 0 0 0 200vmax var(--backdrop); }
.dialog p { margin: 8px 0 12px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; position: relative; }
.dialog .row { display: flex; gap: 10px; position: relative; }
.result { padding-top: 34px; }
.result h2 { position: relative; font-size: 30px; }
/* a strip of cut-paper pieces across the top of the card */
.confetti-paper { position: absolute; left: 0; right: 0; top: 0; height: 12px; display: flex; gap: 3px; padding: 0 3px; }
.confetti-paper i { flex: 1; border-radius: 0 0 5px 5px; box-shadow: 0 2px 3px rgba(var(--shadow), 0.18); animation: drop 0.6s var(--spring) both; }
.confetti-paper i:nth-child(1) { background: var(--p2); flex-grow: 2; animation-delay: 0.05s; }
.confetti-paper i:nth-child(2) { background: var(--p3); flex-grow: 3; animation-delay: 0.1s; }
.confetti-paper i:nth-child(3) { background: var(--p4); flex-grow: 1; animation-delay: 0.15s; }
.confetti-paper i:nth-child(4) { background: var(--p5); flex-grow: 4; animation-delay: 0.2s; }
.confetti-paper i:nth-child(5) { background: var(--p6); flex-grow: 2; animation-delay: 0.25s; }
.confetti-paper i:nth-child(6) { background: var(--p7); flex-grow: 3; animation-delay: 0.3s; }
.confetti-paper i:nth-child(7) { background: var(--p9); flex-grow: 2; animation-delay: 0.35s; }
@keyframes drop { from { transform: translateY(-14px); } }
.stars { display: flex; justify-content: center; gap: 6px; margin: 0 0 6px; position: relative; }
.stars svg { width: 26px; height: 26px; fill: var(--line); stroke: none; animation: popc2 0.5s var(--spring) both; }
.stars svg.on { fill: var(--glow); filter: drop-shadow(0 1px 1px rgba(var(--shadow), 0.3)); }
.stars svg:nth-child(2) { animation-delay: 0.12s; }
.stars svg:nth-child(3) { animation-delay: 0.24s; }
.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 18px;
  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; min-width: 0; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.result-stats b, .summary b { font-family: var(--serif); font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums lining-nums; }
.summary small { font-size: 11px; color: var(--ink-soft); }
.total { display: flex; flex-direction: column; align-items: center; margin: 2px 0 14px; 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: 46px; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums lining-nums; }
.total em {
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1.5px dashed color-mix(in oklab, var(--accent) 60%, transparent);
  border-radius: 999px;
  padding: 3px 10px;
  margin-top: 6px;
  animation: popc2 0.5s 0.25s var(--spring) both;
}
@keyframes popc2 { from { opacity: 0; transform: scale(0.8); } }

/* ------------------------------------------------------------ play sheet */
.daily-card {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: linear-gradient(135deg, color-mix(in oklab, var(--p3) 22%, var(--paper)), var(--paper-2));
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
}
.daily-card:active { transform: scale(0.985); }
.daily-card[aria-current="true"] { border-color: var(--accent); }
.daily-badge {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #3b2a10;
  background: linear-gradient(160deg, color-mix(in oklab, var(--p3) 80%, white), var(--p3));
  box-shadow: 0 3px 8px -3px rgba(var(--shadow), 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.daily-badge svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.daily-card.done .daily-badge { background: linear-gradient(160deg, color-mix(in oklab, var(--p6) 75%, white), var(--p6)); color: #1f3312; }
.daily-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; flex: 1; }
.daily-text b { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.daily-text small { color: var(--ink-soft); font-size: 13px; }
.daily-text .daily-note { color: color-mix(in oklab, var(--accent) 75%, var(--ink-soft)); font-weight: 500; }

.with-count { display: flex; align-items: baseline; justify-content: space-between; }
.with-count small { font-family: var(--sans); font-weight: 500; font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 10px; }
.level-tile {
  --c: var(--p1);
  appearance: none;
  position: relative;
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font: inherit;
  padding: 0;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.level-tile::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--c); opacity: 0.85; }
.level-tile[data-diff="easy"] { --c: var(--p6); }
.level-tile[data-diff="medium"] { --c: var(--p3); }
.level-tile[data-diff="hard"] { --c: var(--p7); }
.level-tile[data-diff="expert"] { --c: var(--p9); }
.level-tile:active { transform: scale(0.94); }
.level-tile b { font-family: var(--serif); font-size: 18px; font-weight: 600; line-height: 1; position: relative; }
.level-tile small { font-size: 10px; color: var(--ink-soft); line-height: 1; font-variant-numeric: tabular-nums; position: relative; }
.level-tile .mini-stars { display: flex; gap: 1px; position: relative; }
.level-tile .mini-stars svg { width: 9px; height: 9px; fill: var(--line); stroke: none; }
.level-tile .mini-stars svg.on { fill: color-mix(in oklab, var(--glow) 85%, #8a5a00); }
.level-tile > svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8; opacity: 0.5; position: relative; }
.level-tile.solved {
  background: linear-gradient(170deg, color-mix(in oklab, var(--c) 22%, var(--paper)), color-mix(in oklab, var(--c) 34%, var(--paper-2)));
  border-color: color-mix(in oklab, var(--c) 55%, transparent);
  box-shadow: 0 2px 4px -2px rgba(var(--shadow), 0.35);
}
.level-tile.locked { opacity: 0.45; cursor: default; }
.level-tile[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: 12px; color: var(--ink-soft); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 4px; border-radius: 2px; background: var(--c); }

.opt-row { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 10px; }
.opt-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.btn.start { width: 100%; margin-top: 8px; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.sheet-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sheet-body 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); }
.sheet-body td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.sheet-body .num { text-align: right; }
td.rs-time { font-family: var(--serif); font-weight: 600; font-size: 15px; }
td.rs-puzzle { overflow: hidden; text-overflow: ellipsis; max-width: 11em; }
td.rs-stars { color: color-mix(in oklab, var(--glow) 80%, #8a5a00); letter-spacing: 1px; }
.bests { table-layout: fixed; }
.bests th, .bests td { text-align: center; }
.bests td { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.bests td.none { color: color-mix(in oklab, var(--ink-soft) 55%, transparent); font-weight: 400; }
.note { font-size: 12.5px; color: var(--ink-soft); margin: -2px 0 8px; }
@media (max-width: 420px) { .sheet-body td { padding: 7px 3px; } .sheet-body th { padding: 4px 3px; font-size: 10px; } }

/* ------------------------------------------------------------- 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;
  min-height: 40px;
  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) 22%, transparent); }
.opt small { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.opts.lang .opt, .opts.diffs .opt { padding-left: 14px; min-width: 72px; justify-content: center; }
.opts.sizes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.opts.sizes .opt { flex-direction: column; gap: 0; padding: 6px 2px; border-radius: 12px; min-width: 0; justify-content: center; line-height: 1.2; }
.opts.sizes .opt span { font-family: var(--digits); font-weight: 600; font-variant-numeric: tabular-nums; }
.opts.sizes .opt small { font-size: 10.5px; }
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.16);
  position: relative;
  overflow: hidden;
}
.sw-washi { background: linear-gradient(90deg, transparent 52%, #f3c650 52% 100%) 0 0 / 100% 50% no-repeat, linear-gradient(90deg, #ee9589 0 48%, transparent 48%) 0 100% / 100% 50% no-repeat, #f7f2e8; }
.sw-indigo { background: linear-gradient(90deg, transparent 52%, #d6b056 52% 100%) 0 0 / 100% 50% no-repeat, linear-gradient(90deg, #c77a70 0 48%, transparent 48%) 0 100% / 100% 50% no-repeat, #1f2d52; }
.sw-terrazzo { background: radial-gradient(circle at 30% 30%, #3b3935 0 1.4px, transparent 1.6px), radial-gradient(circle at 70% 60%, #c96f4a 0 1.8px, transparent 2px), radial-gradient(circle at 40% 78%, #6f9fb0 0 1.5px, transparent 1.7px), linear-gradient(90deg, transparent 55%, #86a6d4 55%) 0 0 / 100% 45% no-repeat, #e9e6e0; }
.sw-auto { background: linear-gradient(135deg, #f7f2e8 0 50%, #1f2d52 50%); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 16px; 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: var(--track); 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-2); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 8px);
  transform: translateX(-50%) translateY(-8px);
  z-index: 15;
  background: var(--toast-bg);
  color: var(--toast-ink);
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  width: min(calc(100vw - 24px), 460px);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  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);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.long { padding: 12px 18px; text-align: left; justify-content: flex-start; }

/* ------------------------------------------------------- small screens */
@media (max-height: 700px) {
  .top { padding-top: 6px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 21px; }
  .stat { padding: 4px 6px; }
  .stat b { font-size: 18px; }
  .key { height: 42px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 8px 10px; min-height: 44px; }
}
@media (max-height: 620px) {
  .brand small { display: none; }
}
@media (max-width: 520px) {
  .pad { padding-left: 12px; padding-right: 12px; gap: 5px; }
  .actions { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .actions .btn { gap: 6px; padding: 7px 6px; font-size: 14px; }
  .actions .btn.square { flex-basis: 48px; }
}
@media (max-width: 380px) {
  .top { padding-left: 12px; padding-right: 6px; }
  .brand { gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 21px; }
  .menu { gap: 0; }
  .stats { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .stat span { font-size: 9.5px; letter-spacing: 0.04em; }
  .stat b { font-size: 17px; }
  .actions .btn { font-size: 13px; }
  .actions .btn.square { flex-basis: 44px; }
  .levels { gap: 6px; }
}
@media (min-width: 600px) and (min-height: 760px) {
  .pad { grid-template-columns: repeat(10, 1fr); max-width: 640px; width: 100%; margin: 0 auto; }
  .actions { max-width: 640px; width: 100%; margin: 0 auto; }
  .levels { grid-template-columns: repeat(8, 1fr); }
}
@media (min-width: 900px) and (min-height: 700px) {
  .top { max-width: 700px; width: 100%; margin: 0 auto; padding-left: 12px; padding-right: 4px; }
  .brand b { font-size: 27px; }
  .stage { margin: 10px 16px; }
  .stats { max-width: 640px; width: 100%; margin: 0 auto; }
}

/* Phones on their side: chrome in a column on the left, the board fills the rest. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    display: grid;
    grid-template-columns: minmax(250px, 36%) 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas: "top stage" "stats stage" "gap stage" "pad stage" "actions stage";
    max-width: none;
  }
  .top { grid-area: top; padding: 6px 8px 2px 14px; }
  .brand small { display: none; }
  .brand b { font-size: 20px; }
  .brand img { width: 32px; height: 32px; }
  .stats { grid-area: stats; grid-template-columns: 1fr 1fr; padding: 4px 10px 4px 14px; gap: 6px; }
  .stat { padding: 3px 6px; }
  .stat b { font-size: 16px; }
  .stage { grid-area: stage; margin: 4px 6px 4px 2px; }
  .pad { grid-area: pad; padding: 4px 10px 2px 14px; gap: 5px; }
  .key { height: 38px; font-size: 19px; }
  .actions { grid-area: actions; padding: 4px 10px 8px 14px; gap: 6px; }
  .actions .btn { flex-direction: row; gap: 5px; padding: 4px 6px; font-size: 13px; min-height: 40px; }
  .actions .btn.square { flex-basis: 40px; }
  .toast, .toast.long { top: auto; bottom: 12px; left: calc(max(250px, 36vw) / 2 + 4px); width: auto; max-width: calc(max(250px, 36vw) - 20px); font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .sheet, .dialog, .backdrop, .total em, .btn.primary.next, .busy, .confetti-paper i, .stars svg { animation: none; transition-duration: 0.01s; }
  .key, .key::after { transition-duration: 0.01s; }
}
