/* Bubble Shooter — soap bubbles on a soft sky. Page colours live on
   [data-theme]; the canvas side of each look lives in js/themes.js. */

:root {
  --bg-a: #fbe6e3;
  --bg-m: #efe2f3;
  --bg-b: #d8e6f7;
  --blob1: rgba(255, 246, 236, 0.95);
  --blob2: rgba(190, 210, 255, 0.6);
  --blob3: rgba(255, 190, 220, 0.5);
  --ink: #3a3352;
  --ink-soft: #7a7290;
  --paper: #fcf9fd;
  --paper-2: #f2edf7;
  --line: rgba(70, 55, 110, 0.12);
  --accent: #7a6ad8;
  --accent-2: #9d8ff0;
  --accent-ink: #ffffff;
  --glow: #c3b4ff;
  --star: #f2b234;
  --stat-bg: rgba(255, 255, 255, 0.42);
  --stat-border: rgba(255, 255, 255, 0.7);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-hover: rgba(255, 255, 255, 0.82);
  --btn-border: rgba(70, 55, 110, 0.13);
  --backdrop: rgba(50, 40, 80, 0.32);
  --sheet-shadow: rgba(50, 40, 90, 0.25);
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 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;
  color-scheme: light;
}
:root[data-theme="dusk"] {
  --bg-a: #262a57;
  --bg-m: #2a2250;
  --bg-b: #14162d;
  --blob1: rgba(120, 110, 230, 0.35);
  --blob2: rgba(220, 120, 200, 0.22);
  --blob3: rgba(70, 170, 220, 0.22);
  --ink: #eceaf8;
  --ink-soft: #a7a4c6;
  --paper: #23264a;
  --paper-2: #2d3159;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #8c7cf0;
  --accent-2: #a99cff;
  --accent-ink: #ffffff;
  --glow: #9d8cff;
  --star: #ffcc55;
  --stat-bg: rgba(255, 255, 255, 0.06);
  --stat-border: rgba(255, 255, 255, 0.1);
  --btn-bg: rgba(255, 255, 255, 0.07);
  --btn-hover: rgba(255, 255, 255, 0.13);
  --btn-border: rgba(255, 255, 255, 0.13);
  --backdrop: rgba(5, 5, 20, 0.55);
  --sheet-shadow: rgba(0, 0, 0, 0.5);
}
:root[data-theme="sorbet"] {
  --bg-a: #fdeee0;
  --bg-m: #f9e5ec;
  --bg-b: #def2e8;
  --blob1: rgba(255, 250, 240, 0.95);
  --blob2: rgba(170, 225, 200, 0.6);
  --blob3: rgba(255, 190, 200, 0.55);
  --ink: #3f3138;
  --ink-soft: #86727c;
  --paper: #fffaf6;
  --paper-2: #f7ede7;
  --line: rgba(90, 50, 60, 0.12);
  --accent: #df5a80;
  --accent-2: #f07f9d;
  --accent-ink: #ffffff;
  --glow: #ffb0c4;
  --star: #f3a92c;
  --btn-border: rgba(90, 50, 60, 0.13);
  --backdrop: rgba(70, 40, 50, 0.32);
  --sheet-shadow: rgba(70, 40, 50, 0.22);
}

* { 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(172deg, var(--bg-a) 0%, var(--bg-m) 48%, var(--bg-b) 100%);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: 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.75;
  will-change: transform;
  transition: background 0.8s;
}
.bg .b1 { width: 62vmax; height: 62vmax; left: -22vmax; top: -26vmax; background: var(--blob1); animation: drift 54s ease-in-out infinite alternate; }
.bg .b2 { width: 52vmax; height: 52vmax; right: -22vmax; bottom: -20vmax; background: var(--blob2); animation: drift 66s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 42vmax; height: 42vmax; left: 28vw; bottom: -26vmax; background: var(--blob3); 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); }
}
.bg .stars {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.8s;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 27% 62%, #fff 50%, transparent 51%),
    radial-gradient(1.4px 1.4px at 41% 9%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 58% 33%, #fff 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 72% 14%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 86% 48%, #fff 50%, transparent 51%),
    radial-gradient(1.2px 1.2px at 93% 8%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 82%, #fff 50%, transparent 51%),
    radial-gradient(1.1px 1.1px at 35% 88%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 64% 76%, #fff 50%, transparent 51%),
    radial-gradient(1.3px 1.3px at 80% 92%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 50% 52%, #fff 50%, transparent 51%);
}
:root[data-theme="dusk"] .bg .stars { opacity: 0.55; animation: twinkle 7s ease-in-out infinite alternate; }
@keyframes twinkle { to { opacity: 0.3; } }

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  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 16px 4px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 4px rgba(60, 40, 110, 0.22)); }
.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: 22px; letter-spacing: 0.01em; 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; }
@media (max-width: 380px) { .brand { gap: 8px; } .brand img { width: 34px; height: 34px; } .brand b { font-size: 19px; } }
.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(--btn-bg); }
.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; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 4px 16px 4px;
}
.stat {
  background: var(--stat-bg);
  border: 1px solid var(--stat-border);
  box-shadow: 0 1px 2px rgba(60, 45, 90, 0.06);
  border-radius: 14px;
  padding: 5px 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  min-height: 52px;
  min-width: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.stat span { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.stat b { font-family: var(--serif); font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; display: inline-flex; align-items: baseline; }
.stat b.word { font-size: 17px; }
.stat b small { font-size: 13px; color: var(--ink-soft); font-weight: 500; margin-left: 1px; }
.stat b.bump { animation: bump 0.35s var(--ease); }
@keyframes bump { 40% { transform: scale(1.16); } }

.mini-stars { display: inline-flex; gap: 1px; align-items: center; }
.mini-stars svg { width: 15px; height: 15px; fill: color-mix(in oklab, var(--ink-soft) 28%, transparent); stroke: none; transition: fill 0.3s; }
.mini-stars svg.on { fill: var(--star); filter: drop-shadow(0 1px 1px rgba(150, 90, 0, 0.25)); }
.stat .mini-stars { margin-top: 3px; }
.stat .mini-stars svg { width: 17px; height: 17px; }

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 6px 10px 4px;
  touch-action: none;
  cursor: crosshair;
}
.stage.over-hand { cursor: pointer; }
.field { position: relative; width: 100px; height: 100px; }
.field canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  border-radius: 16px;
}
.field canvas:focus-visible { box-shadow: 0 0 0 2px color-mix(in oklab, var(--accent) 35%, transparent); }

.actions {
  display: flex;
  gap: 10px;
  padding: 4px 16px 14px;
}
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  min-height: 46px;
  border-radius: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(60, 45, 90, 0.08);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.btn svg { width: 20px; height: 20px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.42; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: transparent;
  color: var(--accent-ink);
  box-shadow: 0 5px 14px -5px color-mix(in oklab, var(--accent) 75%, black), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-soft); font-size: 13.5px; margin: 18px auto 0; display: flex; backdrop-filter: none; }

/* -------------------------------------------------------- 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 var(--sheet-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: 82dvh;
    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: 94dvh;
  overflow: auto;
  background: var(--paper);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px var(--sheet-shadow);
  text-align: center;
  animation: popc 0.32s 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; }
.result { overflow: hidden; }
.result .glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 50%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.85;
}
.result[data-outcome="over"] .glow { opacity: 0.3; }
.result h2 { position: relative; font-size: 27px; line-height: 1.2; }
.result-stars { position: relative; display: flex; justify-content: center; gap: 6px; margin: -4px 0 8px; }
.result-stars svg {
  width: 46px;
  height: 46px;
  fill: color-mix(in oklab, var(--ink-soft) 22%, transparent);
  animation: star-in 0.5s var(--spring) both;
}
.result-stars svg:nth-child(2) { width: 56px; height: 56px; margin-top: -8px; }
.result-stars svg.on {
  fill: var(--star);
  filter: drop-shadow(0 2px 3px rgba(160, 100, 0, 0.3)) drop-shadow(0 0 10px color-mix(in oklab, var(--star) 55%, transparent));
}
@keyframes star-in { from { opacity: 0; transform: scale(0.3) rotate(-25deg); } }
.result-stats {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.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; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.result-stats b, .summary b { font-family: var(--serif); font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.final-score { display: flex; flex-direction: column; align-items: center; margin: 4px 0 18px; }
.final-score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.final-score b { font-family: var(--serif); font-size: 44px; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.final-score small { font-size: 13px; color: var(--ink-soft); min-height: 1em; margin-top: 2px; }

/* ---------------------------------------------------------- new game */
.modes { display: grid; gap: 10px; margin-top: 4px; }
.mode-card {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 18px;
  padding: 10px 14px 10px 10px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.mode-card:active { transform: scale(0.985); }
.mode-card[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent); }
.mode-card .art { flex: 0 0 auto; }
.mode-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.mode-text b { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.mode-text small { font-size: 13.5px; color: var(--ink-soft); }
.mode-text em { font-style: normal; font-size: 12px; letter-spacing: 0.04em; color: var(--accent); margin-top: 2px; font-weight: 500; }
:root[data-theme="dusk"] .mode-text em { color: var(--accent-2); }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 10px 6px; }
.lvl {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  min-height: 62px;
}
.lvl .num {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 600 16px var(--serif);
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95) 0 9%, rgba(255, 255, 255, 0) 30%),
    radial-gradient(circle at 50% 50%, color-mix(in oklab, var(--accent) 10%, var(--paper)) 0 55%, color-mix(in oklab, var(--accent) 40%, var(--paper)) 100%);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 30%, transparent), 0 2px 5px -2px rgba(50, 40, 90, 0.35);
  transition: transform 0.15s var(--ease);
}
.lvl.done .num {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95) 0 9%, rgba(255, 255, 255, 0) 30%),
    radial-gradient(circle at 50% 50%, color-mix(in oklab, var(--accent) 30%, var(--paper)) 0 50%, var(--accent) 100%);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
.lvl.current .num { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px var(--accent), 0 2px 5px -2px rgba(50, 40, 90, 0.35); }
.lvl:active .num { transform: scale(0.93); }
.lvl:disabled { cursor: default; opacity: 0.45; }
.lvl .lock { width: 17px; height: 17px; fill: none; stroke: var(--ink-soft); stroke-width: 1.8; stroke-linecap: round; }
.lvl .mini-stars svg { width: 11px; height: 11px; }
.start { width: 100%; margin-top: 16px; font-size: 16px; padding: 13px; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.results-table 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); }
.results-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.results-table .col-score, .results-table .col-time, .results-table .col-shots { text-align: right; }
.results-table td.col-score { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.results-table td .mini-stars svg { width: 13px; height: 13px; }
.results-table tr[data-outcome="over"] td.col-result { color: var(--ink-soft); }
@media (max-width: 420px) { .results-table .col-shots { display: none; } .results-table 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: 7px 14px 7px 8px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  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) 20%, transparent); }
.opts.lang .opt { padding-left: 14px; min-width: 96px; justify-content: center; }
.swatch { display: inline-block; width: 34px; height: 30px; border-radius: 10px; flex: 0 0 auto; overflow: hidden; }
.swatch canvas { display: block; flex: 0 0 auto; }
.sw-dawn, .sw-auto { background: linear-gradient(160deg, #fbe6e3, #d8e6f7); }
.sw-dusk { background: linear-gradient(160deg, #2c2f60, #15172f); }
.sw-sorbet { background: linear-gradient(160deg, #fdeee0, #def2e8); }
.sw-auto { display: inline-flex; background: linear-gradient(90deg, #fbe6e3 0 50%, #22254d 50% 100%); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 18px; cursor: pointer; font-size: 15px; line-height: 1.35; min-height: 44px; }
.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) 40%, 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: var(--toast-bottom, calc(86px + env(safe-area-inset-bottom)));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: color-mix(in oklab, var(--ink) 90%, transparent);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  max-width: min(90vw, 440px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- small screens */
@media (max-height: 700px) {
  .top { padding-top: 6px; padding-bottom: 2px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .brand img { width: 32px; height: 32px; }
  .stat { min-height: 44px; padding: 3px 6px; }
  .stat b { font-size: 18px; }
  .stat b.word { font-size: 15px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 8px 10px; min-height: 44px; }
}
@media (max-width: 520px) {
  .btn { font-size: 14px; padding: 9px 8px; gap: 6px; }
  .btn span { white-space: nowrap; }
}
@media (max-width: 400px) {
  .stat span { letter-spacing: 0.03em; font-size: 10px; }
}
@media (max-width: 360px) {
  .stats { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .actions { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .btn svg { display: none; }
}
@media (min-width: 900px) and (min-height: 760px) {
  .brand b { font-size: 26px; }
  .stage { padding: 10px 16px; }
}

/* Landscape phones: the board takes the height, the rest moves to a side column. */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr auto;
    column-gap: 4px;
  }
  .brand b { font-size: 18px; }
  .brand img { width: 32px; height: 32px; }
  .top { grid-column: 1; grid-row: 1; padding: 8px 4px 2px 10px; }
  .stats { grid-column: 1; grid-row: 2; grid-template-columns: repeat(2, 1fr); padding: 4px 4px 4px 10px; }
  .stage { grid-column: 2; grid-row: 1 / 5; padding: 6px 8px; }
  .actions { grid-column: 1; grid-row: 4; padding: 4px 4px 10px 10px; }
  .brand small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob, .bg .stars { animation: none; }
  .sheet, .dialog, .backdrop, .stat b, .result-stars svg { animation: none !important; transition-duration: 0.01s; }
  .toast { transition: opacity 0.2s; }
}
