/* Breakout — a glass atelier. Page colours live on [data-theme]; the canvas
   side of each look (bricks, pearl, paddle) lives in js/themes.js. */

:root {
  --bg-a: #f7f0e4;
  --bg-m: #efe5d5;
  --bg-b: #e2d6c3;
  --blob1: rgba(255, 243, 214, 0.95);
  --blob2: rgba(110, 150, 225, 0.26);
  --blob3: rgba(230, 105, 125, 0.2);
  --ink: #3b2f22;
  --ink-soft: #85735d;
  --paper: #fcf8f1;
  --paper-2: #f2eadd;
  --line: rgba(80, 60, 30, 0.13);
  --accent: #a87a35;
  --accent-2: #c99a4e;
  --accent-ink: #fffaf0;
  --metal-a: #f6dc9a;
  --metal-b: #c4954a;
  --metal-c: #85601f;
  --metal-edge: rgba(70, 45, 10, 0.45);
  --glow: #ffd58a;
  --stat-bg: rgba(255, 255, 255, 0.45);
  --stat-border: rgba(255, 255, 255, 0.75);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-hover: rgba(255, 255, 255, 0.85);
  --btn-border: rgba(80, 60, 30, 0.14);
  --backdrop: rgba(60, 42, 20, 0.3);
  --sheet-shadow: rgba(60, 40, 20, 0.25);
  --field-shadow: rgba(80, 55, 20, 0.45);
  --plaque: rgba(252, 248, 241, 0.72);
  --pearl: radial-gradient(circle at 34% 30%, #ffffff 0 18%, #f6eedd 45%, #c9b48d 100%);
  --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="cathedral"] {
  --bg-a: #26202e;
  --bg-m: #1b1722;
  --bg-b: #0f0d13;
  --blob1: rgba(225, 60, 85, 0.2);
  --blob2: rgba(50, 110, 235, 0.2);
  --blob3: rgba(240, 160, 50, 0.16);
  --ink: #f3eadb;
  --ink-soft: #b0a38f;
  --paper: #231e2b;
  --paper-2: #2d2737;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #d6a548;
  --accent-2: #ecc46e;
  --accent-ink: #1d1609;
  --metal-a: #6a6670;
  --metal-b: #36333c;
  --metal-c: #19171d;
  --metal-edge: rgba(214, 165, 72, 0.45);
  --glow: #f0b45a;
  --stat-bg: rgba(255, 255, 255, 0.05);
  --stat-border: rgba(255, 255, 255, 0.09);
  --btn-bg: rgba(255, 255, 255, 0.06);
  --btn-hover: rgba(255, 255, 255, 0.12);
  --btn-border: rgba(255, 255, 255, 0.12);
  --backdrop: rgba(6, 4, 10, 0.55);
  --sheet-shadow: rgba(0, 0, 0, 0.55);
  --field-shadow: rgba(0, 0, 0, 0.7);
  --plaque: rgba(30, 25, 38, 0.7);
  --pearl: radial-gradient(circle at 34% 30%, #ffffff 0 18%, #fff0cf 45%, #d9b46a 100%);
  color-scheme: dark;
}
:root[data-theme="frost"] {
  --bg-a: #f4f9fd;
  --bg-m: #e6eff7;
  --bg-b: #d2e1ee;
  --blob1: rgba(255, 255, 255, 0.95);
  --blob2: rgba(110, 200, 230, 0.3);
  --blob3: rgba(170, 150, 240, 0.24);
  --ink: #24384f;
  --ink-soft: #6c8096;
  --paper: #fafdff;
  --paper-2: #ebf2f8;
  --line: rgba(40, 70, 110, 0.12);
  --accent: #4b82c4;
  --accent-2: #6fa2dc;
  --accent-ink: #ffffff;
  --metal-a: #fbfdff;
  --metal-b: #b8c5d3;
  --metal-c: #7d8b9c;
  --metal-edge: rgba(40, 70, 110, 0.35);
  --glow: #a6dcff;
  --btn-border: rgba(40, 70, 110, 0.13);
  --backdrop: rgba(30, 50, 80, 0.28);
  --sheet-shadow: rgba(30, 50, 80, 0.22);
  --field-shadow: rgba(40, 70, 110, 0.4);
  --plaque: rgba(250, 253, 255, 0.72);
  --pearl: radial-gradient(circle at 34% 30%, #ffffff 0 18%, #eef7ff 45%, #9ec2e4 100%);
}

* { 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) 50%, 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.8;
  will-change: transform;
  transition: background 0.8s;
}
.bg .b1 { width: 64vmax; height: 64vmax; left: -24vmax; top: -28vmax; background: var(--blob1); animation: drift 56s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -22vmax; bottom: -18vmax; background: var(--blob2); animation: drift 68s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 26vw; bottom: -24vmax; background: var(--blob3); animation: drift 80s 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: 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, 10, 0.25)); }
.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; }
.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, 20, 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: 50px;
  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: center; min-height: 1.15em; }
.stat b.bump { animation: bump 0.35s var(--ease); }
@keyframes bump { 40% { transform: scale(1.14); } }
.lives { gap: 3px; }
.lives i {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--pearl);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 6px color-mix(in oklab, var(--glow) 50%, transparent);
  transition: transform 0.3s var(--spring), opacity 0.3s;
}
.lives em { font-style: normal; font-size: 17px; margin-left: 3px; }

.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 14px 8px;
  touch-action: none;
}
.field {
  position: relative;
  z-index: 0;
  width: 100px;
  height: 100px;
  border-radius: 14px;
  container-type: size;
  touch-action: none;
}
/* the frame: brass in the atelier, iron with a gold edge in the cathedral, silver in frost */
.field::before {
  content: "";
  position: absolute;
  inset: -6px;
  z-index: -1;
  border-radius: 19px;
  background: linear-gradient(155deg, var(--metal-a), var(--metal-b) 42%, var(--metal-c) 100%);
  box-shadow:
    0 0 0 1px var(--metal-edge),
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 26px 50px -22px var(--field-shadow),
    0 8px 18px -8px var(--field-shadow);
}
.field::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.22), inset 0 2px 8px rgba(0, 0, 0, 0.16);
}
.field canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  touch-action: none;
}
.field.playing { cursor: none; }

/* ------------------------------------------------------------ overlay */
.overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: 14px; }
.banner {
  position: absolute;
  left: 50%;
  top: 49%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 3cqw 7cqw 3.4cqw;
  border-radius: 4cqw;
  background: var(--plaque);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px -12px var(--field-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 0 0 1px var(--line);
  opacity: 0;
  white-space: nowrap;
  max-width: 90%;
}
.banner.show { animation: banner 2.5s var(--ease) both; }
.banner.hold { animation: banner-in 0.5s var(--ease) both; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -38%) scale(0.96); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  76% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -38%) scale(0.96); } to { opacity: 1; transform: translate(-50%, -50%); } }
.banner small { font-size: max(10px, 2.9cqw); letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-soft); }
.banner b { font-family: var(--serif); font-weight: 600; font-size: max(20px, 8cqw); line-height: 1.15; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.banner span { font-size: max(11px, 3.3cqw); color: var(--ink-soft); margin-top: 0.4cqw; }
.banner span:empty { display: none; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 25%;
  transform: translateX(-50%) translateY(6px);
  font-size: max(11px, 3.3cqw);
  color: var(--ink);
  background: var(--plaque);
  padding: 1.4cqw 3.6cqw;
  border-radius: 999px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.35s, transform 0.35s var(--ease);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: inset 0 0 0 1px var(--line);
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hint.show { opacity: 0.92; transform: translateX(-50%) translateY(0); }

.paused {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: color-mix(in oklab, var(--paper) 30%, transparent);
  backdrop-filter: blur(3px) saturate(0.8);
  -webkit-backdrop-filter: blur(3px) saturate(0.8);
  animation: fade 0.3s var(--ease);
  cursor: pointer;
}
.paused-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 26px 16px;
  border-radius: 22px;
  background: var(--plaque);
  box-shadow: 0 16px 40px -16px var(--field-shadow), inset 0 0 0 1px var(--line);
  text-align: center;
  max-width: 86%;
}
.paused-card svg {
  width: 52px;
  height: 52px;
  padding: 14px 12px 14px 16px;
  border-radius: 50%;
  fill: var(--accent-ink);
  stroke: none;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 6px 16px -6px color-mix(in oklab, var(--accent) 70%, black), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  margin-bottom: 6px;
}
.paused-card b { font-family: var(--serif); font-size: 24px; font-weight: 600; }
.paused-card span { font-size: 14px; color: var(--ink-soft); line-height: 1.35; }

/* -------------------------------------------------------------- actions */
.actions {
  display: flex;
  gap: 10px;
  padding: 6px 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, 20, 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; flex: 0 0 auto; }
.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.35);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
:root[data-theme="cathedral"] .btn.primary { text-shadow: none; }
.btn.primary:hover { filter: brightness(1.06); }
#btn-pause svg use { transition: opacity 0.2s; }
.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); }
.sheet-body h3:first-child { margin-top: 6px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.muted { color: var(--ink-soft); }
.note { font-size: 13px; color: var(--ink-soft); margin: 8px 2px 0; }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

.powers { display: grid; gap: 10px; margin: 4px 0 4px; }
.power { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; }
.power canvas { justify-self: center; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18)); }
.power b { display: block; font-weight: 600; font-size: 15px; }
.power span { display: block; font-size: 13.5px; color: var(--ink-soft); line-height: 1.4; }

@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);
  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.34s var(--ease);
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -48%) scale(0.95); } }
.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: 72%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 55%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.9;
}
.result[data-outcome="over"] .glow { opacity: 0.3; }
/* three slivers of glass that drift in behind the title */
.result .facets { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.result .facets i {
  position: absolute;
  top: 14px;
  width: 54px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.85), color-mix(in oklab, var(--c, var(--accent)) 70%, transparent));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5), 0 4px 10px -4px rgba(0, 0, 0, 0.25);
  opacity: 0.55;
  animation: facet 0.9s var(--spring) both;
}
.result .facets i:nth-child(1) { left: 12%; --c: #e0566f; transform: rotate(-16deg); animation-delay: 0.05s; }
.result .facets i:nth-child(2) { left: 50%; margin-left: -27px; top: 6px; --c: #3c7cd6; transform: rotate(4deg); animation-delay: 0.12s; }
.result .facets i:nth-child(3) { right: 12%; --c: #ee9a3a; transform: rotate(14deg); animation-delay: 0.19s; }
.result[data-outcome="over"] .facets { display: none; }
@keyframes facet { from { opacity: 0; translate: 0 -24px; } }
.result h2 { position: relative; font-size: 28px; line-height: 1.2; margin-top: 18px; }
.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; white-space: nowrap; }
.final-score { position: relative; 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; }
.final-score small.new { color: var(--accent); font-weight: 600; letter-spacing: 0.04em; }
:root[data-theme="cathedral"] .final-score small.new { color: var(--accent-2); }

/* ---------------------------------------------------------- new game */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  appearance: none;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 16px;
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 44px;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.seg button b { font-family: var(--serif); font-size: 16.5px; font-weight: 600; }
.seg button small { font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.seg button[aria-checked="true"], .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); }
.seg button:active, .mode-card:active { transform: scale(0.985); }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  border-radius: 16px;
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.mode-card b { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.mode-card small { font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.mode-card em { font-style: normal; font-size: 12px; color: var(--accent); margin-top: 3px; font-weight: 500; }
:root[data-theme="cathedral"] .mode-card em { color: var(--accent-2); }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 10px 8px; }
.lvl {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  border-radius: 14px;
  padding: 7px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--ink);
  font: inherit;
  min-height: 74px;
  position: relative;
  transition: transform 0.15s var(--ease), border-color 0.2s, box-shadow 0.2s;
}
.lvl .thumb {
  width: 56px;
  height: 34px;
  display: grid;
  place-items: start center;
  overflow: hidden;
  border-radius: 6px;
  background: color-mix(in oklab, var(--paper) 70%, var(--ink) 4%);
  box-shadow: inset 0 0 0 1px var(--line);
}
.lvl .num { font: 600 14px var(--serif); line-height: 1; display: inline-flex; align-items: center; gap: 3px; }
.lvl .num svg { width: 12px; height: 12px; fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.lvl .best { font-size: 10.5px; color: var(--ink-soft); line-height: 1; font-variant-numeric: tabular-nums; min-height: 1em; }
.lvl.current { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.lvl:active { transform: scale(0.95); }
.lvl:disabled { cursor: default; }
.lvl:disabled .thumb canvas { opacity: 0.18; filter: grayscale(1); }
.lvl .lock { position: absolute; top: 15px; left: 50%; margin-left: -9px; width: 18px; height: 18px; fill: none; stroke: var(--ink-soft); stroke-width: 1.8; stroke-linecap: round; }
.lvl:disabled .num, .lvl:disabled .best { opacity: 0.5; }
.start { width: 100%; margin-top: 14px; font-size: 16px; padding: 13px; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(2, 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 { text-align: right; }
.results-table td.col-score { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.results-table td.col-mode small { color: var(--ink-soft); font-size: 11.5px; margin-left: 4px; }
@media (max-width: 400px) { .results-table td { padding: 7px 3px; } .results-table td.col-mode small { display: none; } }

/* ------------------------------------------------------------- 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.plain .opt { padding-left: 14px; min-width: 64px; justify-content: center; }
.swatch { display: inline-block; width: 34px; height: 30px; border-radius: 10px; flex: 0 0 auto; position: relative; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.swatch i { position: absolute; width: 13px; height: 7px; border-radius: 2px; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6), inset 0 -1px 0 rgba(0, 0, 0, 0.15); }
.swatch i:nth-child(1) { left: 3px; top: 6px; }
.swatch i:nth-child(2) { left: 17px; top: 6px; }
.swatch i:nth-child(3) { left: 10px; top: 15px; }
.sw-atelier { background: linear-gradient(160deg, #fbf7f0, #e9dfcf); }
.sw-cathedral { background: linear-gradient(160deg, #2b2535, #121016); }
.sw-frost { background: linear-gradient(160deg, #f6fafd, #d9e6f2); }
.sw-auto { background: linear-gradient(90deg, #f3ebdd 0 50%, #1d1924 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: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 25;
  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: 42px; padding: 3px 6px; }
  .stat b { font-size: 18px; }
  .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; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 400px) {
  .stat span { letter-spacing: 0.03em; font-size: 10px; }
  .stats { gap: 6px; }
}
@media (max-width: 380px) {
  .brand { gap: 8px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 19px; }
  .menu { gap: 0; }
  .icon-btn { width: 42px; }
  .top { padding-left: 12px; padding-right: 8px; }
  .stats, .actions { padding-left: 12px; padding-right: 12px; }
  .actions { gap: 8px; }
  .btn svg { width: 18px; height: 18px; }
  .stat b { font-size: 18px; }
  .lives i { width: 9px; height: 9px; }
}

/* Wide screens: stats on the left, actions on the right, the board takes the height. */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) and (min-height: 561px) {
  .app {
    max-width: 1120px;
    display: grid;
    grid-template-columns: minmax(170px, 1fr) minmax(320px, 560px) minmax(170px, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 18px;
  }
  .top { grid-column: 1 / 4; grid-row: 1; padding: 14px 20px 6px; }
  .brand b { font-size: 26px; }
  .stats { grid-column: 1; grid-row: 2; grid-template-columns: 1fr; align-content: center; justify-self: end; width: 180px; gap: 10px; padding: 0 0 40px; }
  .stat { min-height: 62px; }
  .stat b { font-size: 24px; }
  .stage { grid-column: 2; grid-row: 2; padding: 16px 8px 24px; }
  .actions { grid-column: 3; grid-row: 2; flex-direction: column; justify-content: center; justify-self: start; width: 180px; padding: 0 0 40px; }
  .actions .btn { flex: 0 0 auto; justify-content: flex-start; padding-left: 16px; }
  .actions .btn.primary { order: -1; }
}

/* Landscape phones: the board takes the height, everything else lives in the side columns. */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(150px, 1fr) auto minmax(150px, 1fr);
    grid-template-rows: auto 1fr;
    column-gap: 10px;
  }
  .top { display: contents; }
  .brand { grid-column: 1; grid-row: 1; padding: 8px 0 4px 14px; align-self: start; }
  .brand small { display: none; }
  .brand b { font-size: 18px; }
  .brand img { width: 30px; height: 30px; }
  .menu { grid-column: 3; grid-row: 1; justify-self: end; padding: 4px 8px 0 0; }
  .stats { grid-column: 1; grid-row: 2; grid-template-columns: 1fr 1fr; align-content: center; padding: 0 0 8px 14px; gap: 6px; }
  .stat { min-height: 44px; }
  .stat b { font-size: 18px; }
  .stage { grid-column: 2; grid-row: 1 / 3; padding: 10px 8px; }
  .actions { grid-column: 3; grid-row: 2; flex-direction: column; justify-content: center; padding: 0 14px 10px 0; gap: 8px; }
  .actions .btn { flex: 0 0 auto; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .sheet, .dialog, .backdrop, .stat b, .paused, .result .facets i { animation: none !important; transition-duration: 0.01s; }
  .banner.show { animation-duration: 2.2s; animation-name: banner-fade; }
  .toast, .hint { transition: opacity 0.2s; }
}
@keyframes banner-fade { 0%, 100% { opacity: 0; transform: translate(-50%, -50%); } 10%, 85% { opacity: 1; transform: translate(-50%, -50%); } }
