/* Hexa Sort — glossy jelly tiles on soft linen (and two other looks).
   Page colours per look live in [data-theme] blocks; the board and tiles
   are drawn on the canvas by render.js with palettes from themes.js. */

:root {
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.4, 0.5, 1);
  --radius: 18px;

  /* Linen (default, light) */
  --bg-a: #f0e6d7;
  --bg-b: #d8c8b1;
  --blob-1: rgba(255, 252, 245, 0.95);
  --blob-2: rgba(255, 190, 150, 0.38);
  --blob-3: rgba(140, 200, 235, 0.32);
  --ink: #3b332d;
  --ink-soft: #7d7063;
  --paper: #fbf8f2;
  --paper-2: #f1eadf;
  --line: rgba(70, 50, 30, 0.12);
  --chip: rgba(255, 255, 255, 0.5);
  --chip-border: rgba(255, 255, 255, 0.75);
  --btn: rgba(255, 255, 255, 0.62);
  --btn-hover: rgba(255, 255, 255, 0.9);
  --btn-border: rgba(80, 58, 36, 0.13);
  --accent: #ee6448;
  --accent-2: #d04a33;
  --accent-ink: #fffaf5;
  --accent-soft: rgba(238, 100, 72, 0.18);
  --badge: #3b332d;
  --badge-ink: #fffaf3;
  --shadow: rgba(70, 48, 26, 0.22);
  --backdrop: rgba(60, 42, 24, 0.34);
  --toast: rgba(52, 42, 34, 0.92);
  --gold: #e9a92e;
  color-scheme: light;
}

:root[data-theme="porcelain"] {
  --bg-a: #33281f;
  --bg-b: #17110d;
  --blob-1: rgba(255, 210, 160, 0.08);
  --blob-2: rgba(230, 150, 70, 0.12);
  --blob-3: rgba(90, 160, 210, 0.08);
  --ink: #f4ebdf;
  --ink-soft: #bfae9b;
  --paper: #2c231d;
  --paper-2: #3a2f27;
  --line: rgba(255, 230, 200, 0.1);
  --chip: rgba(255, 240, 220, 0.06);
  --chip-border: rgba(255, 240, 220, 0.09);
  --btn: rgba(255, 240, 220, 0.07);
  --btn-hover: rgba(255, 240, 220, 0.13);
  --btn-border: rgba(255, 230, 200, 0.13);
  --accent: #e8b25a;
  --accent-2: #c18733;
  --accent-ink: #2b1a0b;
  --accent-soft: rgba(232, 178, 90, 0.2);
  --badge: #e8b25a;
  --badge-ink: #2b1a0b;
  --shadow: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(8, 5, 3, 0.55);
  --toast: rgba(250, 238, 222, 0.94);
  --gold: #f0bf5e;
  color-scheme: dark;
}

:root[data-theme="frost"] {
  --bg-a: #1b2536;
  --bg-b: #0b1018;
  --blob-1: rgba(140, 200, 255, 0.1);
  --blob-2: rgba(120, 110, 255, 0.12);
  --blob-3: rgba(70, 220, 190, 0.08);
  --ink: #e9f0f8;
  --ink-soft: #9badc2;
  --paper: #172030;
  --paper-2: #212c3f;
  --line: rgba(190, 220, 255, 0.1);
  --chip: rgba(200, 225, 255, 0.06);
  --chip-border: rgba(200, 225, 255, 0.1);
  --btn: rgba(200, 225, 255, 0.07);
  --btn-hover: rgba(200, 225, 255, 0.13);
  --btn-border: rgba(200, 225, 255, 0.14);
  --accent: #8fd3ff;
  --accent-2: #5aa8e8;
  --accent-ink: #07203a;
  --accent-soft: rgba(143, 211, 255, 0.18);
  --badge: #8fd3ff;
  --badge-ink: #07203a;
  --shadow: rgba(0, 0, 0, 0.5);
  --backdrop: rgba(3, 6, 12, 0.6);
  --toast: rgba(232, 241, 251, 0.94);
  --gold: #ffd56b;
  color-scheme: dark;
}

* { 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)) fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
}

button { font: inherit; color: inherit; -webkit-touch-callout: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------- background */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg .blob { position: absolute; border-radius: 50%; filter: blur(64px); will-change: transform; }
.bg .b1 { width: 64vmax; height: 64vmax; left: -22vmax; top: -28vmax; background: var(--blob-1); animation: drift 52s ease-in-out infinite alternate; }
.bg .b2 { width: 48vmax; height: 48vmax; right: -20vmax; bottom: -18vmax; background: var(--blob-2); animation: drift 64s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 30vw; bottom: -26vmax; background: var(--blob-3); animation: drift 76s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(7vmax, 5vmax) scale(1.1); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  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 14px 4px 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 3px var(--shadow)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--round); font-weight: 750; font-size: 22px; letter-spacing: 0.005em; white-space: nowrap; }
.brand small { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.1em; text-transform: uppercase; margin-top: 3px; 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(--btn); }
.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 {
  position: relative;
  appearance: none;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  box-shadow: 0 1px 2px var(--shadow);
  border-radius: 14px;
  padding: 6px 6px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 0;
  overflow: hidden;
}
.stat span { font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stat b { font-family: var(--round); font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.mode { cursor: pointer; transition: background 0.2s, transform 0.15s; }
.stat.mode:hover { background: var(--btn-hover); }
.stat.mode:active { transform: scale(0.97); }
.stat.mode b svg { width: 19px; height: 19px; vertical-align: -3px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.stat .bar { position: absolute; left: 10px; right: 10px; bottom: 4px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; display: none; }
.stat .bar i { position: absolute; inset: 0; border-radius: 2px; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transform-origin: left; transform: scaleX(0); transition: transform 0.5s var(--ease); }
.stat.has-goal .bar { display: block; }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  touch-action: none;
}
.stage canvas { position: absolute; left: 0; top: 0; display: block; touch-action: none; -webkit-user-select: none; user-select: none; outline: none; }

.actions { display: flex; gap: 8px; padding: 6px 14px 14px; }
.btn {
  appearance: none;
  position: relative;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--btn-border);
  background: var(--btn);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 10px;
  border-radius: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px var(--shadow);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.38; cursor: default; transform: none; }
.btn.primary {
  background:
    radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0) 55%),
    linear-gradient(180deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  border-color: color-mix(in oklab, var(--accent-2) 80%, black);
  box-shadow: 0 5px 14px -6px color-mix(in oklab, var(--accent-2) 80%, black), inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -2px 0 rgba(0, 0, 0, 0.08);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.active { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.pulse { animation: bump 0.6s var(--spring); }
@keyframes bump { 30% { transform: scale(1.12); } }
.btn .badge {
  position: absolute;
  top: -6px;
  right: -4px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--badge);
  color: var(--badge-ink);
  font: 700 11px/19px var(--round);
  font-style: normal;
  text-align: center;
  box-shadow: 0 1px 3px var(--shadow);
}
.btn:disabled .badge { opacity: 0.8; }
.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; }

/* -------------------------------------------------------- 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(--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(--round); font-weight: 750; font-size: 24px; margin: 0; letter-spacing: 0.005em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
  -webkit-user-select: text;
  user-select: text;
}
.sheet-body h3 { font-family: var(--round); font-weight: 700; 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; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 24px; 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: 92dvh;
  overflow: auto;
  background: var(--paper);
  border-radius: 26px;
  padding: 26px 22px 20px;
  box-shadow: 0 24px 64px var(--shadow);
  text-align: center;
  animation: popc 0.34s var(--spring);
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -46%) scale(0.92); } }
.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 .col { display: flex; flex-direction: column; gap: 10px; }
.dialog .col .btn { flex: 0 0 auto; }
.dialog .btn { flex-direction: row; gap: 8px; font-size: 15px; padding: 12px 12px; }
.dialog .btn span { display: inline; }
.dialog .count { font: 700 12px/1 var(--round); font-style: normal; background: rgba(0, 0, 0, 0.14); border-radius: 999px; padding: 4px 8px; }
.btn.subtle-end { background: transparent; box-shadow: none; border-color: transparent; color: var(--ink-soft); }

.result { overflow: hidden; }
.result .glow {
  position: absolute;
  inset: -45% -20% auto;
  height: 75%;
  background: radial-gradient(ellipse at 50% 45%, var(--accent-soft), transparent 65%);
  pointer-events: none;
}
.result[data-outcome="won"] .glow { background: radial-gradient(ellipse at 50% 45%, color-mix(in oklab, var(--gold) 40%, transparent), transparent 65%); }
.result h2 { position: relative; font-size: 29px; }
.result-stars { position: relative; display: flex; justify-content: center; min-height: 0; margin: -4px 0 8px; }
.result-stars:empty { display: none; }
.result-stars .stars svg { width: 40px; height: 40px; }
.result-stars .stars svg:nth-child(2) { width: 50px; height: 50px; margin: -8px 2px 0; }
.result-stars .stars svg.on { animation: starIn 0.6s var(--spring) backwards; }
.result-stars .stars svg.on:nth-child(2) { animation-delay: 0.15s; }
.result-stars .stars svg.on:nth-child(3) { animation-delay: 0.3s; }
@keyframes starIn { from { transform: scale(0.2) rotate(-40deg); opacity: 0; } }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 16px; }
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; justify-content: 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.07em; text-transform: uppercase; color: var(--ink-soft); text-align: center; }
.result-stats b, .summary b { font-family: var(--round); font-size: 19px; font-weight: 700; }
.score { position: relative; display: flex; flex-direction: column; align-items: center; margin: 2px 0 14px; }
.score span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.score b { font-family: var(--round); font-size: 46px; font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; }
.score em { font-style: normal; font: 700 13px var(--round); color: var(--accent-ink); background: linear-gradient(180deg, var(--accent), var(--accent-2)); padding: 3px 10px; border-radius: 999px; margin-top: 4px; animation: starIn 0.5s var(--spring) 0.3s backwards; }

.stars { display: inline-flex; gap: 1px; vertical-align: middle; }
.stars svg { width: 13px; height: 13px; fill: var(--line); stroke: none; }
.stars svg.on { fill: var(--gold); filter: drop-shadow(0 1px 1px rgba(120, 70, 0, 0.3)); }

/* ---------------------------------------------------------------- modes */
.mode-card { border: 1px solid var(--line); background: var(--paper-2); border-radius: 18px; padding: 14px 14px 14px; margin-top: 12px; }
.mode-card.current { border-color: color-mix(in oklab, var(--accent) 60%, transparent); box-shadow: 0 0 0 3px var(--accent-soft); }
.mode-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.mode-card h3 { margin: 0 0 2px; }
.mode-card p { margin: 0; font-size: 13.5px; line-height: 1.45; }
.mode-meta { flex: 0 0 auto; font: 700 13px var(--round); color: var(--ink-soft); background: var(--paper); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.mode-card .row { display: flex; gap: 8px; margin-top: 12px; }
.mode-card .row .btn { padding: 10px; font-size: 14.5px; }
.level-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; margin-top: 12px; }
.level {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--paper);
  border-radius: 12px;
  aspect-ratio: 1;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 2px;
  transition: transform 0.15s, border-color 0.2s;
}
.level b { font: 700 16px var(--round); line-height: 1; }
.level .stars svg { width: 10px; height: 10px; }
.level:hover { border-color: var(--accent); }
.level:active { transform: scale(0.95); }
.level.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.level:disabled { opacity: 0.45; cursor: default; }
.level svg.lk { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 6px; }
.empty { margin-top: 18px; }
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: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th.cleared, th.moves, th.score, td.cleared, td.moves, td.score { text-align: right; }
td.game > span.cell { display: inline-flex; align-items: center; gap: 6px; }
td.game small { font-size: 11px; }
td.score { font-family: var(--round); font-weight: 700; font-size: 15px; }
@media (max-width: 400px) { th.moves, td.moves { 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;
  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 var(--accent-soft); }
.opts.lang .opt, .opts.pace .opt { padding-left: 14px; min-width: 92px; justify-content: center; }
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  clip-path: polygon(25% 6%, 75% 6%, 100% 50%, 75% 94%, 25% 94%, 0 50%);
  background: linear-gradient(135deg, var(--a) 0 50%, var(--b) 50%);
  box-shadow: inset 0 0 0 4px var(--bg), inset 0 0 0 5px rgba(0, 0, 0, 0.12);
}
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 18px; 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(--line); position: relative; transition: background 0.25s; box-shadow: inset 0 0 0 1px var(--btn-border); }
.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(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 15;
  background: var(--toast);
  color: var(--paper);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  width: max-content;
  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 var(--shadow);
}
.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: 19px; }
  .stat b { font-size: 16px; }
  .stat { padding: 4px 6px 5px; }
  .actions { padding-bottom: 8px; }
}
@media (max-width: 560px) {
  .actions { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .btn { flex-direction: column; gap: 3px; padding: 8px 2px 7px; font-size: 12px; border-radius: 14px; }
  .btn span { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .btn svg { width: 21px; height: 21px; }
  .stats { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .level-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 400px) {
  .top { padding-left: 12px; padding-right: 8px; }
  .brand { gap: 8px; }
  .brand img { width: 36px; height: 36px; }
  .brand b { font-size: 21px; }
  .brand small { font-size: 9.5px; letter-spacing: 0.05em; }
  .menu { gap: 0; }
  .icon-btn { width: 42px; height: 42px; }
}
@media (max-width: 560px) and (max-height: 640px) {
  .btn { flex-direction: row; padding: 9px 4px; }
  .btn span { display: none; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 26px; }
  .app { max-width: 820px; }
}
/* phones on their side: header, stats and buttons move into a side column,
   the board gets the full height */
@media (max-height: 500px) and (orientation: landscape) {
  .app {
    display: grid;
    max-width: 980px;
    grid-template-columns: minmax(230px, 32%) 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "top stage" "stats stage" ". stage" "actions stage";
  }
  .top { grid-area: top; padding: 8px 8px 2px 14px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 18px; }
  .brand small { display: none; }
  .icon-btn { width: 40px; height: 40px; }
  .stats { grid-area: stats; grid-template-columns: repeat(2, 1fr); padding: 6px 8px 0 14px; }
  .stat b { font-size: 16px; }
  .stage { grid-area: stage; }
  .actions { grid-area: actions; padding: 0 8px 10px 14px; gap: 5px; }
  .actions .btn { flex-direction: column; gap: 2px; padding: 7px 0 6px; font-size: 10.5px; border-radius: 12px; }
  .actions .btn span { display: block; }
  .actions .btn svg { width: 19px; height: 19px; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .sheet, .dialog, .backdrop, .btn.pulse, .result-stars .stars svg.on, .score em { animation: none; }
  .btn, .stat .bar i, .toast { transition-duration: 0.01s; }
}
