/* Tangram — lacquer on rice paper, gold leaf on slate, jade on celadon.
   Every colour arrives as a custom property from themes.js; the defaults
   below are the rice-paper look. */

:root {
  --bg-a: #f3ede1;
  --bg-b: #e2d7c3;
  --blob-1: rgba(255, 252, 244, 0.95);
  --blob-2: rgba(166, 61, 42, 0.1);
  --blob-3: rgba(70, 96, 130, 0.1);
  --ink: #2c2620;
  --ink-soft: #786b5b;
  --paper: #fbf7ef;
  --paper-2: #f2eadc;
  --line: rgba(70, 50, 30, 0.13);
  --accent: #a23b27;
  --accent-2: #bf5a3e;
  --accent-ink: #fff8f1;
  --glow: #e3a95b;
  --good: #4f7a4a;
  --star: #c4882d;
  --star-off: rgba(70, 50, 30, 0.18);
  --card: rgba(255, 252, 245, 0.5);
  --card-border: rgba(255, 255, 255, 0.65);
  --btn-bg: rgba(255, 252, 245, 0.62);
  --btn-hover: rgba(255, 252, 245, 0.95);
  --btn-border: rgba(70, 50, 30, 0.15);
  --hover: rgba(70, 50, 30, 0.07);
  --track: #d8ccb7;
  --shadow: 60, 40, 20;
  --backdrop: rgba(45, 32, 18, 0.38);
  --toast-bg: rgba(44, 38, 32, 0.95);
  --toast-ink: #fbf7ef;
  --thumb-ink: #3a3631;
  --thumb-ghost: rgba(58, 54, 49, 0.16);
  --fin-a: #c4553a;
  --fin-b: #7e2316;
  --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;
}

* { 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;
}

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.fin-a { stop-color: var(--fin-a); }
.fin-b { stop-color: var(--fin-b); }

/* ---------------------------------------------------------- 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: 1180px;
  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.04em; }
.brand small { font-family: var(--serif); font-style: italic; font-size: 13.5px; color: var(--ink-soft); letter-spacing: 0.01em; margin-top: 1px; 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; }

.stats {
  display: grid;
  grid-template-columns: 1.7fr 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 em { font-style: normal; font-variant-numeric: tabular-nums; opacity: 0.8; }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stat.fig b { font-size: 18px; font-style: italic; font-weight: 500; letter-spacing: 0.01em; }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 4px 8px;
}
.board {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
  border-radius: 18px;
  box-shadow: 0 10px 30px -18px rgba(var(--shadow), 0.55);
}

.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: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.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; }

/* Per-look touches on the chrome */
[data-theme="paper"] .btn.primary { border-radius: 13px 15px 13px 14px; }
[data-theme="paper"] .brand b { letter-spacing: 0.06em; }
[data-theme="ink"] .btn.primary { box-shadow: 0 0 18px -5px rgba(240, 200, 110, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
[data-theme="ink"] .board { box-shadow: 0 14px 34px -16px rgba(0, 0, 0, 0.8); }
[data-theme="jade"] .btn.primary { box-shadow: 0 4px 14px -5px rgba(30, 90, 60, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3); }

/* -------------------------------------------------------- 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; } }
.backdrop.clear { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 580px;
  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: 200px; height: auto; margin: 6px auto 16px; }
.figure.pieces { filter: drop-shadow(0 3px 5px rgba(var(--shadow), 0.25)); }
.muted { color: var(--ink-soft); }
.note { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; line-height: 1.45; }
.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, 380px);
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 24px 22px 20px;
  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: 6px 0 14px; color: var(--ink-soft); font-size: 15px; line-height: 1.5; position: relative; }
.dialog .row { display: flex; gap: 10px; position: relative; }
.result .glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 45%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.85;
}
.result h2 { position: relative; font-size: 29px; font-style: italic; font-weight: 500; }
#result-stars { position: relative; margin: 8px 0 2px; }
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  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; }
.total { display: flex; flex-direction: column; align-items: center; margin: 0 0 12px; 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: 42px; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-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); } }

/* The result card keeps clear of the finished figure: over the tray. */
@media (max-width: 560px) and (max-aspect-ratio: 1.08/1) {
  .dialog.result { padding: 16px 18px 16px; }
  .result h2 { font-size: 25px; }
  .stars.big svg { width: 24px; height: 24px; }
  #result-stars { margin: 4px 0 0; }
  .dialog.result p { margin: 4px 0 8px; font-size: 14px; }
  .total { margin-bottom: 8px; }
  .total b { font-size: 32px; }
  .result-stats { margin-bottom: 12px; }
  .result-stats div { padding: 6px 4px; }
}
@media (max-aspect-ratio: 1.08/1) {
  .dialog.result {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    transform: translateX(-50%);
    animation: risec 0.42s var(--spring);
  }
  @keyframes risec { from { opacity: 0; transform: translate(-50%, 30px); } }
}
@media (min-aspect-ratio: 1.08/1) {
  .dialog.result {
    left: auto;
    right: max(18px, calc((100vw - 1180px) / 2 + 22px));
    transform: translateY(-50%);
    animation: slidec 0.42s var(--spring);
  }
  @keyframes slidec { from { opacity: 0; transform: translate(24px, -50%); } }
}

/* -------------------------------------------------------------- stars */
.stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.stars svg { width: 14px; height: 14px; fill: var(--star-off); stroke: none; }
.stars svg.on { fill: var(--star); }
.stars.big { gap: 6px; }
.stars.big svg { width: 30px; height: 30px; filter: drop-shadow(0 2px 3px rgba(var(--shadow), 0.25)); }
.stars.big svg.on { animation: starpop 0.5s var(--spring) both; }
.stars.big svg.on:nth-child(2) { animation-delay: 0.12s; }
.stars.big svg.on:nth-child(3) { animation-delay: 0.24s; }
@keyframes starpop { from { opacity: 0; transform: scale(0.4) rotate(-20deg); } }
.stars.small svg { width: 11px; height: 11px; }

/* ----------------------------------------------------------- figure picker */
.btn.start { width: 100%; margin-top: 6px; }
.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; }
.figs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.fig-tile {
  appearance: none;
  position: relative;
  aspect-ratio: 1;
  min-height: 64px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 6px 18px;
  cursor: pointer;
  font: inherit;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.fig-tile:active { transform: scale(0.95); }
.fig-tile .thumb { display: block; width: 100%; height: 100%; min-height: 0; }
.fig-tile .cap { position: absolute; left: 0; right: 0; bottom: 4px; display: flex; justify-content: center; line-height: 1; }
.fig-tile .cap { gap: 4px; align-items: center; }
.fig-tile .cap small { font-size: 10.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; line-height: 1; }
.stars.tiny { gap: 1px; }
.stars.tiny svg { width: 9px; height: 9px; }
.fig-tile[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.thumb path { fill: var(--thumb-ink); stroke: var(--thumb-ink); }
.thumb.solved path { fill: url(#fin-grad); stroke: url(#fin-grad); }
.fig-tile:not(.solved) .thumb { opacity: 0.85; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.set-progress { display: flex; flex-direction: column; gap: 8px; }
.set-row { display: grid; grid-template-columns: minmax(0, 11em) 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.set-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-row small { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 12.5px; min-width: 3.2em; text-align: right; }
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--paper-2); overflow: hidden; box-shadow: inset 0 1px 2px rgba(var(--shadow), 0.12); }
.bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: linear-gradient(90deg, var(--fin-a), var(--fin-b)); }
.gallery { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.gal { aspect-ratio: 1; display: block; min-width: 0; }
.gal .thumb { display: block; width: 100%; height: 100%; }
/* ghosts fade as a whole, so the seams between pieces never show */
.gal:not(.solved) .thumb { opacity: 0.16; }
.sheet-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.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-fig { overflow: hidden; text-overflow: ellipsis; max-width: 9em; font-style: italic; font-family: var(--serif); font-size: 15px; }
@media (max-width: 420px) { .sheet-body td { padding: 7px 3px; } .sheet-body th { padding: 4px 3px; font-size: 10px; } .gallery { grid-template-columns: repeat(7, minmax(0, 1fr)); } .set-row { grid-template-columns: minmax(0, 9.5em) 1fr auto; font-size: 13.5px; } }

/* ------------------------------------------------------------- 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: 42px;
  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); }
.opts.lang .opt, .opts.guides .opt { padding-left: 14px; min-width: 76px; justify-content: center; }
.swatch { display: inline-block; width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18); }
.sw-paper { background: linear-gradient(135deg, transparent 50%, #b4432c 50% 74%, #3d5d87 74%), #f4eee2; }
.sw-ink { background: linear-gradient(135deg, transparent 50%, #e2c97e 50% 74%, #c58a5e 74%), radial-gradient(circle at 30% 30%, #2f363c, #15191c); }
.sw-jade { background: linear-gradient(135deg, transparent 50%, #3f8f63 50% 74%, #8fbf98 74%), #d4e2d2; }
.sw-auto { background: linear-gradient(135deg, #f4eee2 0 50%, #1b2024 50%); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 20px; 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: max-content;
  max-width: min(calc(100vw - 24px), 460px);
  min-height: 44px;
  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); }

/* ------------------------------------------------------- small screens */
@media (max-height: 640px) {
  .top { padding-top: 6px; }
  .brand small { display: none; }
  .brand b { font-size: 20px; }
  .brand img { width: 32px; height: 32px; }
  .stat b { font-size: 17px; }
  .stat.fig b { font-size: 16px; }
  .stat { padding: 4px 6px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 9px 10px; min-height: 46px; }
}
@media (max-width: 520px) {
  .actions { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .actions .btn { flex-direction: column; gap: 3px; padding: 7px 4px 6px; font-size: 12px; }
  .actions .btn svg { width: 21px; height: 21px; }
}
@media (max-width: 380px) {
  .top { padding-left: 12px; padding-right: 8px; }
  .brand { gap: 8px; }
  .brand img { width: 36px; height: 36px; }
  .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: 18px; }
  .stat.fig b { font-size: 16px; }
  .actions .btn { font-size: 11.5px; }
  .figs { gap: 6px; }
}
@media (min-width: 600px) {
  .figs { grid-template-columns: repeat(6, 1fr); }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 27px; }
  .stage { margin: 8px 16px; }
}

/* Phones on their side: chrome in a column on the left, the stage fills the rest. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    display: grid;
    grid-template-columns: minmax(230px, 30%) 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "top stage" "stats stage" "gap stage" "actions stage";
    max-width: none;
  }
  .top { grid-area: top; flex-wrap: wrap; gap: 2px 8px; padding: 8px 10px 2px 14px; }
  .brand b { font-size: 20px; }
  .menu { margin-left: -6px; }
  .stats { grid-area: stats; grid-template-columns: 1fr 1fr 1fr; padding: 4px 10px 4px 14px; gap: 6px; }
  .stat.fig { grid-column: 1 / -1; }
  .stat b { font-size: 17px; }
  .stage { grid-area: stage; margin: 6px 8px 6px 2px; }
  .actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-areas: "undo undo reset reset flip flip" "figures figures figures hint hint hint";
    padding: 4px 10px 10px 14px;
    gap: 6px;
  }
  #btn-undo { grid-area: undo; }
  #btn-reset { grid-area: reset; }
  #btn-flip { grid-area: flip; }
  #btn-figures { grid-area: figures; }
  #btn-hint { grid-area: hint; }
  .actions .btn { flex-direction: row; gap: 5px; padding: 6px 4px; font-size: 12.5px; min-height: 42px; }
  .actions .btn svg { width: 19px; height: 19px; }
  .toast { top: auto; bottom: 112px; left: calc(max(230px, 30vw) / 2 + 4px); width: auto; max-width: calc(max(230px, 30vw) - 20px); font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .sheet, .dialog, .backdrop, .total em, .stars.big svg.on { animation: none !important; transition-duration: 0.01s; }
}
