/* Layout concept: a neon arcade cabinet. A fixed starfield sits behind
   centred, gap-spaced columns of dark glass cards; the game screen locks to
   the visible viewport with touch controls under the player's thumbs. */
:root {
  /* Colour */
  --bg: #050613;
  --surface: rgba(14, 16, 44, 0.94);
  --surface-raised: #1a1c48;
  --inset: rgba(4, 5, 18, 0.72);
  --border: rgba(127, 246, 255, 0.2);
  --border-soft: rgba(127, 246, 255, 0.1);
  --text: #e8ecff;
  --muted: #9ba6d4;
  --cyan: #7ff6ff;
  --magenta: #ff5ef7;
  --green: #4dffc0;
  --yellow: #ffd23f;
  --red: #ff5e7a;
  --red-soft: #ffb3c0;

  /* Type */
  --pixel: "Press Start 2P", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --text-xs: 0.75rem;   /* 12 */
  --text-sm: 0.875rem;  /* 14 */
  --text-md: 1rem;      /* 16 */
  --text-lg: 1.25rem;   /* 20 */
  --px-xs: 0.625rem;    /* 10, pixel font runs large */
  --px-sm: 0.75rem;     /* 12 */
  --px-md: 0.875rem;    /* 14 */
  --px-lg: 1.125rem;    /* 18 */
  --px-xl: 1.5rem;      /* 24 */

  /* Space: one 4px-based scale for every margin, padding and gap */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --card-pad: var(--s5);
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));

  --radius: 14px;
  --radius-sm: 8px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button, input, select, label { touch-action: manipulation; }

/* While playing, the page itself must not scroll or bounce. */
html.in-game, html.in-game body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ---------- Starfield backdrop ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at 50% 120%, #1c0b3a 0%, transparent 60%), var(--bg);
}
.stars, .stars::before { content: ""; position: absolute; inset: 0; background-repeat: repeat; }
.stars {
  opacity: .7;
  background-image:
    radial-gradient(1px 1px at 24px 48px, rgba(255,255,255,.9), transparent),
    radial-gradient(1px 1px at 140px 96px, rgba(255,255,255,.55), transparent),
    radial-gradient(1px 1px at 230px 28px, rgba(255,255,255,.75), transparent),
    radial-gradient(1px 1px at 310px 170px, rgba(255,255,255,.6), transparent);
  background-size: 360px 220px;
}
.stars::before {
  opacity: .25;
  background-image:
    radial-gradient(1px 1px at 64px 118px, rgba(255,255,255,.9), transparent),
    radial-gradient(1px 1px at 190px 38px, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 288px 145px, rgba(255,255,255,.8), transparent);
  background-size: 420px 260px;
  animation: twinkle 18s ease-in-out infinite;
}
@keyframes twinkle { 0%, 72%, 100% { opacity: .18; } 78%, 84% { opacity: .62; } }

/* ---------- Page layout ---------- */
#app { position: relative; z-index: 1; overflow-x: clip; }

.view {
  width: 100%;
  max-width: 1040px;
  margin-inline: auto;
  padding-top: var(--s6);
  padding-bottom: calc(var(--s7) + env(safe-area-inset-bottom, 0px));
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  display: flex;
  flex-direction: column;
  gap: var(--s6);
}

/* ---------- Type ---------- */
.logo { font-family: var(--pixel); font-weight: 400; text-align: center; margin: 0; line-height: 1.2; }
.logo span { display: block; }
.logo-top {
  font-size: clamp(14px, 3.2vw, 24px);
  color: var(--cyan);
  letter-spacing: .1em;
  text-shadow: 0 0 12px rgba(127, 246, 255, .55);
}
.logo-bottom {
  font-size: clamp(30px, 8.4vw, 64px);
  margin-top: var(--s3);
  background: linear-gradient(180deg, #fff 0%, #ff8af9 45%, #b04bff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 94, 247, .5));
}

.page-title {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(var(--px-lg), 4vw, var(--px-xl));
  margin: 0;
  color: var(--magenta);
  text-shadow: 0 0 12px rgba(255, 94, 247, .45);
}

.card-title {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: var(--px-sm);
  line-height: 1.6;
  letter-spacing: .06em;
  color: var(--cyan);
  margin: 0;
  text-wrap: balance;
}

.sub-title {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.field-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hint { color: var(--muted); font-size: var(--text-sm); line-height: 1.5; margin: 0; max-width: 62ch; }
.hint.warn { color: var(--yellow); }
.error { color: #ff9cb0; font-size: var(--text-sm); margin: 0; }
.error:empty { display: none; }

.help {
  margin: 0 auto;
  max-width: 60ch;
  text-align: center;
  color: var(--muted);
  font-size: var(--text-sm);
  text-wrap: balance;
}

.help-touch { display: none; }
@media (pointer: coarse) {
  .help-keys { display: none; }
  .help-touch { display: inline; }
}

/* ---------- Cards ---------- */
.card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  padding: var(--card-pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
.card p, .card ol, .card ul { margin: 0; }
.card-lead { font-size: var(--text-md); }
.card-lead strong { color: var(--yellow); }
.card-section { display: flex; flex-direction: column; gap: var(--s3); padding-top: var(--s2); }
.card-action { align-self: flex-start; margin-top: auto; }

/* ---------- Welcome ---------- */
.welcome-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s5);
}
#welcome-returning, #welcome-create { display: flex; flex-direction: column; gap: var(--s4); }
.welcome-line { font-size: var(--text-lg); line-height: 1.3; margin: 0; }
.welcome-line strong { color: var(--yellow); }

.legend-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s3) var(--s6);
  font-family: var(--pixel);
  font-size: var(--px-sm);
  color: var(--muted);
}
.legend-row span { display: inline-flex; align-items: center; gap: var(--s3); }
.legend-sprite { height: 28px; width: auto; image-rendering: pixelated; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }

input[type="text"], input[type="number"], select {
  font: inherit;
  font-size: var(--text-md); /* 16px stops iOS zooming on focus */
  color: var(--text);
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s3) var(--s3);
  width: 100%;
  min-height: 46px;
}
input:focus-visible, select:focus-visible { outline: 2px solid var(--cyan); outline-offset: 1px; }
input[type="range"] { width: 100%; accent-color: var(--magenta); min-height: 32px; margin: 0; }

.check { display: flex; gap: var(--s3); align-items: center; cursor: pointer; min-height: 32px; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--magenta); flex: none; }

.segmented { border: 0; margin: 0; padding: 0; min-width: 0; }
.segmented legend { padding: 0; margin-bottom: var(--s2); }
.segmented-options { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: var(--s2) var(--s3);
  font-family: var(--pixel);
  font-size: var(--px-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--inset);
  color: var(--muted);
  transition: background .15s, color .15s, box-shadow .15s;
}
.segmented input:checked + span {
  background: linear-gradient(180deg, #ff6ef8, #a446ff);
  border-color: transparent;
  color: #fff;
}
.segmented input:focus-visible + span { outline: 2px solid var(--cyan); outline-offset: 2px; }

.range-row { display: flex; align-items: center; gap: var(--s4); }
.range-row input[type="range"] { flex: 1; min-width: 0; }
.number-unit { display: inline-flex; align-items: center; gap: var(--s2); color: var(--muted); flex: none; }
.number-unit input { width: 5.5em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--pixel);
  font-size: var(--px-sm);
  line-height: 1.4;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 46px;
  padding: var(--s3) var(--s5);
  cursor: pointer;
  transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:hover { box-shadow: 0 0 0 1px var(--cyan), 0 0 18px rgba(127, 246, 255, .22); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(180deg, #ff6ef8, #a446ff);
  border-color: transparent;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .3);
}
.btn-primary:hover { box-shadow: 0 0 24px rgba(255, 94, 247, .5); }
.btn-big { font-size: var(--px-lg); min-height: 64px; }
.btn-danger-outline { background: transparent; border-color: rgba(255, 94, 122, .55); color: var(--red-soft); }
.btn-danger-outline:hover { box-shadow: 0 0 0 1px var(--red), 0 0 18px rgba(255, 94, 122, .25); }
.btn-danger { background: linear-gradient(180deg, #ff6b84, #d0244a); border-color: transparent; color: #fff; }
.btn-small { min-height: 36px; padding: var(--s2) var(--s3); font-size: var(--px-xs); }

.btn-stack { display: flex; flex-direction: column; gap: var(--s3); }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.btn-wide { grid-column: 1 / -1; }
.btn-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s3); }

/* ---------- Leaderboard ---------- */
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: rank;
  font-family: var(--pixel);
  font-size: var(--px-xs);
  font-variant-numeric: tabular-nums;
}
.leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 3.5ch minmax(0, 1fr) auto;
  gap: var(--s3);
  align-items: baseline;
  padding: var(--s3) var(--s2);
  border-bottom: 1px dashed var(--border-soft);
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li::before { content: counter(rank) "."; color: var(--muted); }
.leaderboard .lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard .lb-score { color: var(--green); text-align: right; }
.leaderboard li:nth-child(1) .lb-score { color: var(--yellow); }
.leaderboard li.is-new { background: rgba(255, 94, 247, .14); border-radius: 6px; }
.leaderboard .empty { display: block; padding: var(--s2) 0; color: var(--muted); font-family: var(--sans); font-size: var(--text-sm); border: 0; }
.leaderboard .empty::before { content: none; }
.leaderboard.compact li { padding: var(--s2); }

/* ---------- Game ---------- */
.view-game {
  max-width: none;
  height: 100vh;
  height: 100dvh;
  padding-top: max(var(--s3), env(safe-area-inset-top, 0px));
  padding-bottom: max(var(--s3), env(safe-area-inset-bottom, 0px));
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s4);
}
.stage {
  position: relative;
  flex: none;
  width: min(100%, calc((100vh - 24px) * 4 / 3));
  width: min(100%, calc((100dvh - 24px) * 4 / 3));
  max-width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 0 40px rgba(127, 246, 255, .12), 0 0 0 1px rgba(0, 0, 0, .6);
  touch-action: none;
}
#game { display: block; width: 100%; height: 100%; background: #060818; image-rendering: pixelated; }

/* Overlays cover the whole screen so their cards never get clipped by a
   small game screen on phones; the frozen game stays visible behind. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: max(var(--s4), env(safe-area-inset-top, 0px)) var(--gutter-r) max(var(--s4), env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  background: rgba(4, 5, 18, .6);
}
.overlay-card { width: min(420px, 100%); text-align: center; gap: var(--s4); }
.overlay-title {
  font-family: var(--pixel);
  font-weight: 400;
  font-size: var(--px-lg);
  margin: 0;
  color: var(--magenta);
  text-shadow: 0 0 12px rgba(255, 94, 247, .55);
}
.final-score { font-size: var(--text-lg); font-variant-numeric: tabular-nums; }
.final-score strong { color: var(--yellow); }
.rank { color: var(--green); font-weight: 600; }
.rank:empty { display: none; }
#gameover-overlay .leaderboard { text-align: left; }

/* ---------- Drill ---------- */
.quiz { z-index: 12; background: rgba(4, 5, 18, .7); }
.quiz-card {
  width: min(500px, 100%);
  text-align: center;
  gap: var(--s5);
  border-color: rgba(255, 210, 63, .45);
  box-shadow: 0 0 50px rgba(255, 210, 63, .16), 0 12px 40px rgba(0, 0, 0, .5);
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.quiz-title { font-family: var(--pixel); font-size: var(--px-sm); line-height: 1.6; color: var(--yellow); text-wrap: balance; }
#quiz-body { display: flex; flex-direction: column; gap: var(--s4); }
#quiz-body[hidden] { display: none; }
.quiz-timer { display: flex; align-items: center; gap: var(--s4); }
.quiz-count { font-family: var(--pixel); font-size: var(--px-xl); color: var(--cyan); width: 2ch; flex: none; }
.quiz-track { flex: 1; height: 12px; background: rgba(255, 255, 255, .08); border-radius: 6px; overflow: hidden; }
.quiz-track.thin { flex: none; width: 100%; height: 4px; }
.quiz-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--green), var(--cyan)); transform-origin: left center; }
.quiz-timer.urgent .quiz-count { color: var(--red); animation: pulse .5s ease-in-out infinite alternate; }
.quiz-timer.urgent .quiz-bar { background: linear-gradient(90deg, var(--red), #ff9a3d); }
@keyframes pulse { to { transform: scale(1.2); } }
#quiz-feedback { display: flex; flex-direction: column; align-items: center; gap: var(--s3); }
.quiz-result { font-family: var(--pixel); font-size: var(--px-xl); }
.quiz-line { font-size: var(--text-lg); line-height: 1.4; font-style: italic; text-wrap: balance; max-width: 34ch; }
.quiz-answer { font-family: var(--pixel); font-size: var(--px-lg); color: var(--yellow); padding-top: var(--s2); }
.quiz-given { color: var(--muted); }
.quiz-given:empty { display: none; }
#quiz-continue { min-width: 180px; margin-top: var(--s2); }
.quiz.is-success .quiz-card { border-color: rgba(77, 255, 192, .6); box-shadow: 0 0 60px rgba(77, 255, 192, .22); }
.quiz.is-success .quiz-result { color: var(--green); }
.quiz.is-fail .quiz-card { border-color: rgba(255, 94, 122, .6); box-shadow: 0 0 60px rgba(255, 94, 122, .22); animation: shake .4s; }
.quiz.is-fail .quiz-result { color: var(--red); }
.shake { animation: shake .3s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- Touch controls ---------- */
.touch-controls { display: none; width: min(100%, 640px); gap: var(--s3); flex: none; }
.touch-btn {
  flex: 1;
  height: 72px;
  font-family: var(--pixel);
  font-size: var(--px-md);
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.touch-btn.arrow { font-family: var(--sans); font-size: 28px; line-height: 1; }
.touch-btn.fire { flex: 1.4; background: linear-gradient(180deg, #ff6ef8, #a446ff); border-color: transparent; }
.touch-btn.is-down { filter: brightness(1.35); }

@media (pointer: coarse) {
  .touch-controls { display: flex; }
  .view-game { justify-content: space-between; }
  .stage {
    margin-block: auto;
    width: min(100%, calc((100vh - 24px - 88px) * 4 / 3));
    width: min(100%, calc((100dvh - 24px - 88px) * 4 / 3));
  }
  /* Keep the drill card in the top part of the screen, clear of the keyboard. */
  .quiz { place-items: start center; padding-top: max(8vh, env(safe-area-inset-top, 0px)); }
}

/* ---------- Settings ---------- */
.settings-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: var(--s4);
}
.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s5);
}
.span-2 { grid-column: 1 / -1; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); }
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: var(--s4);
  background: var(--inset);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.stat-value { font-family: var(--pixel); font-size: var(--px-lg); color: var(--yellow); font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-sm); color: var(--muted); }

.toughest { display: flex; flex-wrap: wrap; gap: var(--s2); list-style: none; padding: 0; }
.toughest li {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s2);
  font-family: var(--pixel);
  font-size: var(--px-xs);
  padding: var(--s2) var(--s3);
  border-radius: var(--radius-sm);
  background: rgba(255, 94, 122, .12);
  border: 1px solid rgba(255, 94, 122, .35);
}
.toughest li small { font-family: var(--sans); font-size: var(--text-xs); color: var(--muted); }
.toughest .empty { background: none; border: 0; padding: 0; font-family: var(--sans); font-size: var(--text-sm); color: var(--muted); }

.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--s1); }
.weight-grid { display: grid; gap: 2px; width: 100%; min-width: min-content; justify-content: start; font-family: var(--pixel); font-size: 9px; font-variant-numeric: tabular-nums; }
.weight-grid .cell { height: 26px; display: grid; place-items: center; border-radius: 4px; }
.weight-grid .head { color: var(--cyan); }
.weight-grid .corner { color: var(--muted); }
.weight-grid .fact { cursor: default; }

.profile-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s2); }
.profile-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  min-width: 0;
  padding: var(--s2) var(--s2) var(--s2) var(--s4);
  background: var(--inset);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-list .tag { font-size: var(--text-xs); color: var(--green); margin-left: var(--s2); }
.danger-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border-soft); }
.danger-row .hint { flex: 1 1 240px; }

/* ---------- Modal and toast ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(var(--s4), env(safe-area-inset-top, 0px)) var(--gutter-r) max(var(--s4), env(safe-area-inset-bottom, 0px)) var(--gutter-l);
  background: rgba(2, 3, 12, .75);
}
.modal-card { width: min(440px, 100%); animation: pop .18s ease-out; }
.modal-card .btn-row { margin-top: var(--s1); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s5) + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: var(--s3) var(--s4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small screens ---------- */
/* ---------- Intro crawl ---------- */
html.intro-open, html.intro-open body { overflow: hidden; overscroll-behavior: none; }

.intro-link-row { margin: calc(-1 * var(--s5)) 0 0; text-align: center; }
.link-btn {
  font: inherit;
  font-size: var(--text-sm);
  color: var(--cyan);
  background: none;
  border: 0;
  padding: var(--s2) var(--s3);
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: #fff; }
.link-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 4px; }

.intro {
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 130%, #120826 0%, transparent 55%), #000;
  opacity: 1;
  transition: opacity var(--intro-fade, 0ms) ease;
}
.intro.is-leaving { opacity: 0; pointer-events: none; }
.intro-stars { opacity: 1; background-size: 240px 160px; }
.intro-stars::before { opacity: .5; background-size: 300px 190px; }

.intro-enter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--s5) var(--gutter-r) var(--s5) var(--gutter-l);
}
.intro-enter-btn {
  font-size: clamp(20px, 6vw, 32px);
  min-width: min(280px, 80vw);
  min-height: 88px;
  padding: var(--s4) var(--s6);
  border-radius: var(--radius);
  box-shadow: 0 0 32px rgba(255, 94, 247, .45);
}

.intro-stage { position: absolute; inset: 0; }
.intro-title {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  margin: 0;
  width: 92vw;
  text-align: center;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(40px, 15vw, 132px);
  line-height: 1.15;
  overflow-wrap: anywhere;
  color: var(--yellow);
  text-shadow: 0 0 24px rgba(255, 210, 63, .45);
  opacity: 0;
  pointer-events: none;
}
/* The plane tilts back about its bottom edge; text sliding up it recedes
   towards a vanishing point just above the screen, and a mask fades it out
   near the top. perspective ≈ 1.15 × height × tan(25deg). */
.intro-perspective {
  position: absolute;
  inset: 0;
  perspective: 54vh;
  perspective-origin: 50% 100%;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, transparent 16%, #000 50%);
  mask-image: linear-gradient(to bottom, transparent 0%, transparent 16%, #000 50%);
}
.intro-plane {
  position: absolute;
  left: 50%;
  bottom: 0;
  height: 0;
  width: min(88vw, 34em);
  font-size: clamp(20px, 5.4vw, 34px);
  transform-origin: 50% 100%;
  transform: translateX(-50%) rotateX(25deg);
}
.intro-crawl {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  font-family: var(--sans);
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
  color: var(--yellow);
  will-change: transform;
}
.intro-crawl p, .intro-static-text p { margin: 0 0 1.1em; text-wrap: pretty; }
.intro-art {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 1.1em;
  font-family: ui-monospace, Consolas, Menlo, monospace;
  font-weight: 700;
  font-size: .6em;
  line-height: 1.15;
  text-align: left;
  white-space: pre;
  overflow: hidden;
}

.intro-static {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s5);
  padding: calc(var(--s7) + env(safe-area-inset-top, 0px)) var(--gutter-r) calc(var(--s7) + env(safe-area-inset-bottom, 0px)) var(--gutter-l);
}
.intro-static-title {
  margin: 0;
  font-family: var(--pixel);
  font-weight: 400;
  font-size: clamp(28px, 10vw, 64px);
  color: var(--yellow);
  text-align: center;
  overflow-wrap: anywhere;
}
.intro-static-text {
  max-width: 34em;
  font-weight: 700;
  font-size: clamp(17px, 4.4vw, 22px);
  line-height: 1.5;
  text-align: center;
  color: var(--yellow);
}
.intro-static .btn { min-width: 200px; min-height: 56px; flex: none; }

.intro-skip {
  position: absolute;
  right: calc(var(--s4) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--s4) + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  min-width: 112px;
  min-height: 52px;
  background: rgba(14, 16, 44, .8);
}

@media (max-width: 720px) {
  :root { --card-pad: 20px; }
  .view { padding-top: var(--s5); gap: var(--s5); }
  .welcome-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); gap: var(--s4); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-list { grid-template-columns: minmax(0, 1fr); }
  .legend-row { display: grid; grid-template-columns: repeat(2, auto); justify-content: center; gap: var(--s4) var(--s6); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Per-quiz settings ---------- */
.game-settings-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3) var(--s5); }
.game-settings-pick { flex: 0 1 280px; }
.game-settings { display: flex; flex-direction: column; gap: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border-soft); }
.game-settings-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3) var(--s5); }
.game-settings-row .field { flex: 0 1 240px; }
.game-settings-row .hint { flex: 1 1 260px; }
.game-settings .danger-row { margin-top: var(--s2); }
