:root {
  --label: #fff;
  --secondary: #e3eeea;
  --glass-fill: rgba(255, 255, 255, 0.08);
  --glass-stroke: rgba(255, 255, 255, 0.23);
  --scrim: rgba(0, 0, 0, 0.62);
  --icon-well: rgba(255, 255, 255, 0.64);
  --icon-well-stroke: rgba(255, 255, 255, 0.23);
  --track: rgba(255, 255, 255, 0.12);
  --dim: rgba(255, 255, 255, 0.22);
  --sheet: rgba(28, 28, 30, 0.72);
  --green: #0b8043;
  --red: #d23f31;
  --ink: #111;
  --paper: #f7f7f7;
  --font: ui-rounded, "SF Pro Rounded", "Avenir Next", "Segoe UI", sans-serif;
  --pan: 0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

html[data-scheme="light"] {
  --label: #1a1a1c;
  --secondary: rgba(0, 0, 0, 0.6);
  --glass-fill: rgba(255, 255, 255, 0.55);
  --glass-stroke: rgba(0, 0, 0, 0.12);
  --scrim: rgba(0, 0, 0, 0.42);
  --icon-well: rgba(255, 255, 255, 0.78);
  --icon-well-stroke: rgba(0, 0, 0, 0.12);
  --track: rgba(0, 0, 0, 0.1);
  --dim: rgba(0, 0, 0, 0.12);
  --sheet: rgba(255, 255, 255, 0.78);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #000;
}

body {
  font-family: var(--font);
  color: var(--label);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

.shell, button {
  -webkit-user-select: none;
  user-select: none;
}

button { touch-action: manipulation; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:disabled { cursor: default; }

img { display: block; max-width: 100%; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #111;
}

.bg-photo {
  position: absolute;
  inset: -6%;
  width: 112%;
  height: 112%;
  object-fit: cover;
  object-position: center;
  transform: scale(1.08) translateX(calc(var(--pan) * -3%));
  transition: opacity 0.45s ease, transform 0.55s ease;
}

html[data-intro="cover"] .bg-photo { transform: scale(1.16); }

.bg-photo.is-fading { opacity: 0; }

.scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(120% 80% at 50% 42%, transparent, rgba(0, 0, 0, 0.28) 78%),
    var(--scrim);
  transition: background 0.45s ease;
}

.wash {
  position: absolute;
  inset: 0;
  background: transparent;
  transition: background 0.45s ease;
}

.cover {
  position: absolute;
  inset: 0;
  background: #000;
  transition: opacity 0.65s ease;
}

html[data-intro="photo"] .cover,
html[data-intro="mark"] .cover,
html[data-intro="home"] .cover { opacity: 0; }

.intro-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
}

html[data-intro="mark"] .intro-layer {
  opacity: 1;
  transition: opacity 0.35s ease;
}

html[data-intro="home"] .intro-layer {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.logo-hero {
  width: min(275px, 72vw);
  height: auto;
  aspect-ratio: 661 / 200;
}

html[data-intro="mark"] .logo-hero {
  animation: pop 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pop {
  from { opacity: 0; scale: 0.2; }
  to { opacity: 1; scale: 1; }
}

html[data-scheme="dark"] .for-light { filter: invert(1); }
html[data-scheme="light"] .for-dark { filter: invert(1); }

.shell {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  container-type: inline-size;
  pointer-events: none;
}

html[data-intro="home"] .shell { pointer-events: auto; }

.glass {
  background: var(--glass-fill);
  border: 1px solid var(--glass-stroke);
  backdrop-filter: blur(22px) saturate(1.6);
  -webkit-backdrop-filter: blur(22px) saturate(1.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.rise {
  opacity: 0;
  transform: translateY(28px);
}

html[data-intro="home"] .rise {
  opacity: 1;
  transform: none;
  transition:
    opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-intro="home"] .rise.d1 { transition-delay: 0.05s; }
html[data-intro="home"] .rise.d2 { transition-delay: 0.14s; }
html[data-intro="home"] .rise.d3 { transition-delay: 0.22s; }

html.settled .rise {
  opacity: 1;
  transform: none;
  transition: none;
}

.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(24px + var(--safe-top)) 24px 8px;
}

.brand {
  width: 106px;
  height: 32px;
  object-fit: contain;
  object-position: left center;
}

.icon-btn {
  width: 44px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--label);
}

.icon-btn.square { height: 44px; }

.home-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 32px;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 12px 24px 20px;
  min-height: 0;
}

.hero { min-width: 0; }

.drills {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.theme-dock {
  margin-top: auto;
  padding: 18px 20px calc(16px + var(--safe-bottom));
  border-radius: 32px 32px 0 0;
}

.kicker {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary);
}

.kicker img { width: 24px; height: 24px; }

.stat {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0;
}

.stat strong {
  font-size: clamp(56px, 18cqi, 80px);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.stat span {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary);
}

.themes {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.theme {
  flex: 1 1 0;
  width: 100%;
  max-width: 64px;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--label) 44%, transparent);
  background: center / cover no-repeat;
}

.theme[aria-pressed="true"] { border-color: var(--label); }

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 20px;
  border-radius: 24px;
}

.card-copy { flex: 1; min-width: 0; }

.card h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 500;
}

.card p {
  margin: 0;
  font-size: 13px;
  color: var(--secondary);
}

.well {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: var(--icon-well);
  border: 1px solid var(--icon-well-stroke);
  flex: none;
}

.well img { width: 20px; height: 20px; }

.round, .done {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: calc(8px + var(--safe-top)) 24px calc(8px + var(--safe-bottom));
}

.round { gap: 24px; }

.enter { animation: slide-in 0.48s cubic-bezier(0.22, 1, 0.36, 1); }
.swipe-back { animation: slide-back 0.48s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(42px); }
  to { opacity: 1; transform: none; }
}

@keyframes slide-back {
  from { opacity: 0; transform: translateX(-36px); }
  to { opacity: 1; transform: none; }
}

.tables-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.tables-title {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 500;
}

.header-balance {
  width: 44px;
  height: 44px;
  flex: none;
}

.header-slot {
  flex: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 0 18px;
}

.header-slot .track { flex: 1; }

.play {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.play .round,
.play .done {
  flex: 1;
  min-height: 0;
  padding-top: 8px;
}

.tables-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 32px calc(28px + var(--safe-bottom));
}

.table-grid.table-grid-surface {
  width: min(680px, 100%);
  gap: 16px;
}

.table-grid.table-grid-surface button {
  height: 104px;
  border-radius: 28px;
  font-size: 40px;
  font-weight: 500;
}

.progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

.track {
  position: relative;
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--track);
  border: 1px solid var(--glass-stroke);
  overflow: hidden;
}

.track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--label);
}

.equation {
  flex: 1;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.16em;
  border-radius: 36px;
  font-size: clamp(64px, 22cqi, 96px);
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
}

.times {
  font-size: 0.67em;
  font-weight: 300;
  color: var(--secondary);
}

.answers {
  display: flex;
  gap: 12px;
  height: 156px;
}

.answer {
  flex: 1;
  border-radius: 36px;
  font-size: clamp(42px, 16cqi, 64px);
  font-weight: 200;
  letter-spacing: -0.03em;
  color: var(--label);
}

.answer.is-selected {
  font-weight: 500;
  box-shadow: inset 0 0 0 2px var(--label);
}

.answer.is-dimmed {
  color: color-mix(in srgb, var(--label) 40%, transparent);
  background: var(--dim);
}

.reveal-btn {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 14px 32px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.reveal-btn img { width: 14px; height: 14px; }
.reveal-btn:disabled { opacity: 0.55; }

.reveal-top, .done-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.fact-pill {
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 20px;
  font-weight: 700;
  color: color-mix(in srgb, var(--label) 80%, transparent);
}

.badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px 0 12px;
  border-radius: 999px;
  background: #fff;
  color: var(--green);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.12);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge img { width: 20px; height: 20px; }
.badge.bad { color: var(--red); }

.reveal-card, .done-card {
  position: relative;
  flex: 1;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  border-radius: 36px;
  overflow: hidden;
  text-align: center;
}

.reveal-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--glow, transparent), transparent 68%);
  pointer-events: none;
}

.reveal-card p, .done-card p {
  position: relative;
  margin: 0;
  font-size: clamp(28px, 8cqi, 40px);
  font-weight: 200;
}

.reveal-card strong, .done-card strong {
  position: relative;
  font-size: clamp(72px, 28cqi, 120px);
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 0.9;
}

.done-card em {
  position: relative;
  font-style: normal;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary);
}

.streak-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 700;
}

.streak-row span { display: inline-flex; align-items: center; gap: 8px; }
.streak-row img { width: 24px; height: 24px; }
.streak-row b { font-weight: 800; }

.next-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 56px;
  margin-bottom: 8px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 8px 8px rgba(0, 0, 0, 0.2);
}

.next-btn svg { display: block; }

.done-top { justify-content: flex-end; }

dialog {
  color: var(--label);
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

dialog.sheet {
  width: min(520px, 100%);
  max-width: 100%;
  max-height: 100dvh;
  margin: auto auto 0;
}

dialog.sheet[open] { animation: sheet-in 0.4s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes sheet-in {
  from { translate: 0 100%; }
  to { translate: 0 0; }
}

.sheet-card {
  background: var(--sheet);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  border: 1px solid var(--glass-stroke);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  padding: 8px 24px calc(24px + var(--safe-bottom));
  max-height: min(92dvh, 760px);
  overflow: auto;
}

.grabber {
  width: 36px;
  height: 5px;
  margin: 4px auto 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--label) 28%, transparent);
}

.sheet-card h2 {
  margin: 8px 0 24px;
  font-size: 22px;
  font-weight: 500;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.table-grid button {
  height: 72px;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 500;
}

.field-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--secondary);
}

.segment {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  margin-bottom: 24px;
}

.segment button {
  flex: 1;
  padding: 10px 8px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
}

.segment button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--label) 14%, transparent);
}

.reset {
  width: 100%;
  text-align: left;
  padding: 20px;
  border-radius: 24px;
}

.reset strong { display: block; font-size: 20px; font-weight: 500; margin-bottom: 4px; }
.reset span { font-size: 13px; color: var(--secondary); }

.privacy-link {
  display: inline-block;
  margin: 20px 0 8px;
  color: var(--secondary);
  font-size: 13px;
}

dialog.confirm {
  width: min(360px, calc(100% - 48px));
  margin: auto;
}

.confirm-card {
  padding: 24px;
  border-radius: 28px;
  background: var(--sheet);
  border: 1px solid var(--glass-stroke);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
}

.confirm-card h2 { margin: 0 0 8px; font-size: 22px; font-weight: 500; }
.confirm-card p { margin: 0 0 20px; color: var(--secondary); font-size: 15px; }

.confirm-actions { display: flex; gap: 8px; }

.confirm-actions button {
  flex: 1;
  height: 48px;
  border-radius: 999px;
  font-weight: 600;
}

.confirm-actions .ghost {
  background: color-mix(in srgb, var(--label) 10%, transparent);
}

.confirm-actions .danger {
  background: var(--red);
  color: white;
}

:focus-visible {
  outline: 2px solid var(--label);
  outline-offset: 3px;
}

@media (hover: hover) {
  .card:hover, .answer:hover, .table-grid button:hover, .theme:hover {
    filter: brightness(1.06);
  }
}

.card:active, .next-btn:active, .answer:active, .table-grid button:active {
  transform: scale(0.985);
}

@media (max-height: 700px) {
  .answers { height: 120px; }
  .equation { min-height: 120px; }
  .home-stage { gap: 20px; padding-top: 8px; padding-bottom: 12px; }
  .theme-dock { padding-top: 12px; }
}

@media (min-width: 760px) {
  .shell { width: min(1120px, calc(100% - 64px)); }

  .home > .header,
  .tables-view > .header,
  .play > .header {
    box-sizing: border-box;
    width: min(1040px, 100%);
    margin-inline: auto;
    padding: calc(32px + var(--safe-top)) 4px 16px;
  }

  .home-stage {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: clamp(36px, 5vw, 88px);
    width: min(1040px, 100%);
    padding: 0 4px 8px;
  }

  .hero { flex: 1 1 340px; }
  .drills { flex: 1.15 1 400px; }

  .stat strong { font-size: clamp(88px, 12cqi, 120px); }

  .theme-dock {
    width: fit-content;
    max-width: calc(100% - 48px);
    margin: 0 auto 28px;
    padding: 12px 16px 14px;
    border-radius: 22px;
  }

  .theme-dock .kicker {
    margin-bottom: 10px;
    font-size: 11px;
    letter-spacing: 0.08em;
  }

  .theme-dock .kicker img {
    width: 14px;
    height: 14px;
  }

  .theme-dock .themes { gap: 8px; }

  .theme-dock .theme {
    flex: none;
    width: 36px;
    max-width: 36px;
    height: 36px;
  }

  .round, .done {
    width: min(820px, 100%);
    margin-inline: auto;
    justify-content: center;
    padding-inline: 8px;
  }

  .equation {
    flex: none;
    height: min(42vh, 420px);
    min-height: 260px;
    font-size: clamp(88px, 14cqi, 128px);
  }

  .answers { height: 176px; }

  .answer { font-size: clamp(56px, 8cqi, 84px); }

  .reveal-card, .done-card {
    flex: none;
    height: min(46vh, 460px);
    min-height: 280px;
  }

  dialog.sheet { width: min(680px, 100%); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
  .bg-photo { transform: none; }
  .rise { opacity: 1; transform: none; }
}

.noscript {
  position: relative;
  z-index: 2;
  max-width: 28rem;
  margin: 20vh auto;
  padding: 0 24px;
  text-align: center;
}
