/* ============================================================
   Apex Academy — global styles
   Dark motorsport theme, mobile-first, touch-friendly.
   ============================================================ */

:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --bg2: #11161f;
  --panel: #161d29;
  --panel2: #1c2534;
  --line: #2a3548;
  --line2: rgba(104, 128, 171, .36);
  --asphalt: #0f141c;
  --carbon: #111823;
  --track-surface: #262f3d;
  --stroke-soft: rgba(104,128,171,.24);
  --text: #e8edf5;
  --muted: #93a1b8;
  --accent: #29d3ff;      /* cyan — primary */
  --accent2: #ff8a2a;     /* orange — throttle/energy */
  --good: #3ddc84;
  --warn: #ffd23f;
  --bad: #ff5d5d;
  --brake: #ff5d5d;
  --throttle: #3ddc84;
  --gold: #ffcf4d;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 12px 26px rgba(0,0,0,.20);
  --shadow-panel: 0 22px 48px rgba(0,0,0,.32);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 18% -10%, rgba(41,211,255,.12), transparent 28%),
    radial-gradient(circle at 88% 10%, rgba(255,138,42,.10), transparent 24%),
    linear-gradient(180deg, #090c12 0%, var(--bg) 46%, #070a0f 100%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.018) 0 1px, transparent 1px 30px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
/* form fields must stay selectable (backup-code copy relies on it on iOS) */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}
#app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    linear-gradient(90deg, transparent 0 23%, rgba(41,211,255,.05) 23.2% 23.5%, transparent 23.7% 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.018) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.014) 0 1px, transparent 1px 42px);
  opacity: .50;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.85), rgba(0,0,0,.10) 52%, rgba(0,0,0,.45));
}

/* ---------- typography ---------- */
h1, h2, h3 { font-weight: 800; letter-spacing: 0.2px; }
.small { font-size: 12px; color: var(--muted); }
.kicker {
  font-size: 11px; font-weight: 800; letter-spacing: 2.2px;
  text-transform: uppercase; color: var(--accent);
}

/* ---------- screens ---------- */
.screen {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden; /* longhand: two-value shorthand needs iOS 15.4+ */
  overflow-y: auto;
  padding: calc(14px + var(--sat)) calc(16px + var(--sar)) calc(20px + var(--sab)) calc(16px + var(--sal));
  animation: fadein .25s ease;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.screen::-webkit-scrollbar { width: 0; height: 0; }
.screen.no-scroll { overflow: hidden; padding: 0; }
.screen > :not(.drill-stage) { flex-shrink: 0; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (min-width: 980px) {
  .screen:not(.no-scroll) {
    width: min(100%, 1120px);
    margin: 0 auto;
  }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 12px;
}
.topbar .title { font-size: 17px; font-weight: 800; flex: 1; text-align: center; }
.topbar .spacer { width: 44px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 12px 20px;
  border: none; border-radius: 14px;
  background: var(--panel2);
  color: var(--text);
  font: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0,0,0,.18);
  transition: transform .08s ease, filter .15s ease, background .15s, border-color .15s, box-shadow .15s;
}
.btn:active { transform: scale(.965); filter: brightness(1.15); }
.btn.primary {
  background: linear-gradient(135deg, #29d3ff, #1f8fff);
  color: #04121c;
  box-shadow: 0 12px 28px rgba(41,211,255,.22);
}
.btn.orange { background: linear-gradient(135deg, #ffcf4d, #ff8a2a); color: #221000; box-shadow: 0 12px 28px rgba(255,138,42,.22); }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--muted); }
.btn.icon { min-height: 44px; width: 44px; flex: 0 0 44px; padding: 0; border-radius: 12px; font-size: 18px; }
.btn.big { font-size: 17px; min-height: 56px; border-radius: 16px; width: 100%; }
.btn:disabled { opacity: .38; pointer-events: none; }
.btn:focus-visible, .card.tappable:focus-visible, .fcard:focus-visible, .ctl-btn:focus-visible, .pedal:focus-visible, .quiz-opt:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- cards ---------- */
.card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.010)),
    linear-gradient(135deg, rgba(41,211,255,.025), transparent 34%),
    var(--carbon);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 12px; }
.card.tappable { cursor: pointer; transition: transform .08s, border-color .15s, box-shadow .15s, background .15s; }
.card.tappable:active { transform: scale(.985); border-color: var(--accent); box-shadow: 0 10px 26px rgba(41,211,255,.13); }
.card.locked { opacity: .55; }

.row { display: flex; align-items: center; gap: 12px; }
.col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.grow { flex: 1; min-width: 0; }

/* chapter number badge */
.chip {
  width: 46px; height: 46px; flex: 0 0 46px;
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 18px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.01)),
    var(--panel2);
  color: var(--accent);
  border: 1px solid var(--line2);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 8px 18px rgba(0,0,0,.18);
}
.chip.done { background: linear-gradient(180deg, rgba(61,220,132,.20), rgba(61,220,132,.07)); color: var(--good); border-color: rgba(61,220,132,.48); }
.chip.gold { background: linear-gradient(180deg, rgba(255,207,77,.22), rgba(255,207,77,.07)); color: var(--gold); border-color: rgba(255,207,77,.55); }

/* stars */
.stars { display: inline-flex; gap: 2px; font-size: 14px; letter-spacing: 1px; }
.stars .on { color: var(--gold); }
.stars .off { color: #3a4356; }

/* progress bar */
.pbar { height: 8px; border-radius: 99px; background: rgba(28,37,52,.9); overflow: hidden; box-shadow: inset 0 1px 4px rgba(0,0,0,.45); }
.pbar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), #1f8fff); transition: width .55s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 14px rgba(41,211,255,.55); }
.pbar.xp > i { background: linear-gradient(90deg, #ffb02a, #ff7a2a); }

/* ---------- home hero ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(41,211,255,.16), transparent 34%),
    linear-gradient(315deg, rgba(255,138,42,.11), transparent 34%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.032) 0 1px, transparent 1px 18px),
    var(--carbon);
  border: 1px solid rgba(104,128,171,.42);
  margin-bottom: 14px;
  box-shadow: var(--shadow-panel), inset 0 1px 0 rgba(255,255,255,.06);
}
.hero::after {
  content: "";
  position: absolute;
  right: -22px;
  top: 14px;
  width: 160px;
  height: 70px;
  border-top: 3px solid rgba(41,211,255,.38);
  border-radius: 50%;
  transform: rotate(-12deg);
  pointer-events: none;
}
.hero h1 { font-size: 24px; margin: 4px 0 5px; }
.home-dashboard { display: grid; gap: 12px; }
@media (min-width: 980px) {
  .home-dashboard {
    grid-template-columns: minmax(340px, .88fr) minmax(420px, 1.12fr);
    align-items: start;
  }
  .home-dashboard > .card { margin-top: 0; }
}
.title-screen {
  align-items: center;
}
.title-track {
  position: relative;
  width: min(470px, 88vw);
  height: clamp(150px, 30vh, 230px);
  margin: 0 auto 18px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 74% 34%, rgba(255,207,77,.20), transparent 18%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 1px, transparent 1px 18px),
    linear-gradient(180deg, rgba(255,255,255,.075), rgba(255,255,255,.01)),
    #101722;
  border: 1px solid rgba(104,128,171,.42);
  box-shadow: 0 22px 46px rgba(0,0,0,.30);
  overflow: hidden;
}
.title-track i {
  position: absolute;
  inset: 24px 34px;
  border: 15px solid #465875;
  border-right-color: #2f3d55;
  border-radius: 50% 38% 50% 42%;
  transform: rotate(-11deg);
}
.title-track b {
  position: absolute;
  left: 102px;
  top: 59px;
  width: 72px;
  border-top: 8px dotted var(--accent);
  transform: rotate(-13deg);
  filter: drop-shadow(0 0 10px rgba(41,211,255,.55));
}
.title-track span {
  position: absolute;
  left: 82px;
  top: 67px;
  width: 34px;
  height: 17px;
  border-radius: 7px 12px 12px 7px;
  background: var(--accent);
  transform: rotate(-30deg);
  box-shadow: 0 10px 18px rgba(0,0,0,.35);
}

/* rank badge */
.rank-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 99px;
  background: rgba(10,14,20,.74); border: 1px solid var(--line2);
  font-size: 12px; font-weight: 800; letter-spacing: 1px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.rank-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }

.program-card {
  position: relative;
  overflow: hidden;
  border-color: rgba(41,211,255,.28);
}
.program-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(110deg, transparent 0%, rgba(255,255,255,.055) 42%, transparent 58%);
  transform: translateX(-130%);
  animation: sheen 9s ease-in-out infinite;
  opacity: .65;
}
.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.metric {
  min-height: 66px;
  border-radius: 14px;
  padding: 10px 11px;
  background: rgba(10,14,20,.38);
  border: 1px solid rgba(104,128,171,.24);
}
.metric b { color: var(--text); font-size: 18px; display: block; margin-top: 2px; }
.metric span { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; }
.mission-card { border-color: rgba(255,207,77,.28); }
.mission-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.mission-score { color: var(--gold); font-weight: 900; font-size: 13px; }
.mission-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.mission-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 13px;
  background: rgba(10,14,20,.35);
  border: 1px solid rgba(104,128,171,.20);
}
.mission-row.done {
  border-color: rgba(61,220,132,.36);
  background: rgba(61,220,132,.07);
}
.mission-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 28px;
  font-weight: 900;
  color: var(--muted);
  border: 1px solid rgba(104,128,171,.35);
}
.mission-row.done .mission-check {
  color: #07130d;
  background: var(--good);
  border-color: var(--good);
  box-shadow: 0 0 16px rgba(61,220,132,.35);
}
.skill-rail {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.skill-tile {
  border-radius: 13px;
  padding: 10px 8px;
  text-align: center;
  background: rgba(10,14,20,.32);
  border: 1px solid rgba(104,128,171,.22);
}
.skill-tile b { display: block; font-size: 15px; }
.skill-tile span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }

/* ---------- lesson viewer ---------- */
.lesson-fig {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 12px 0;
  position: relative;
}
.lesson-fig canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.lesson-body h2 { font-size: 20px; margin-bottom: 6px; }
.lesson-body p { color: #c6d0e0; line-height: 1.55; font-size: 15px; margin-top: 10px; }
.lesson-body b, .lesson-body strong { color: var(--text); }
.lesson-body .tip {
  margin-top: 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(41,211,255,.07); border: 1px solid rgba(41,211,255,.25);
  font-size: 14px; line-height: 1.5; color: #cdeffb;
}
.lesson-body .tip b { color: var(--accent); }
.lesson-nav {
  display: flex; gap: 10px; align-items: center;
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding: 12px 0 calc(4px + var(--sab));
  margin-top: auto;
  background: linear-gradient(180deg, rgba(11,14,20,0), var(--bg) 28%);
}
.dots { display: flex; gap: 6px; justify-content: center; flex: 1; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: #33405a; transition: background .2s, transform .2s; }
.dots i.on { background: var(--accent); transform: scale(1.25); }

/* quiz */
.quiz-opt {
  display: block; width: 100%; text-align: left;
  margin-top: 10px; padding: 14px;
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--panel2); color: var(--text);
  font: inherit; font-size: 14.5px; font-weight: 600; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.quiz-opt.correct { border-color: var(--good); background: rgba(61,220,132,.12); }
.quiz-opt.wrong { border-color: var(--bad); background: rgba(255,93,93,.10); }
.quiz-opt:disabled { cursor: default; }

/* ---------- drill stage (game container) ---------- */
.drill-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--bg);
  display: flex; flex-direction: column;
}
.drill-canvas-wrap { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.drill-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* HUD strip on top of drills */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--sat)) calc(12px + var(--sar)) 8px calc(12px + var(--sal));
  pointer-events: none;
  z-index: 5;
}
.hud > * { pointer-events: auto; }
.hud .hud-pill {
  background: rgba(10, 14, 20, .78);
  border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.hud .grow { flex: 1; }
@media (max-width: 430px) {
  .hud {
    gap: 6px;
    padding: calc(6px + var(--sat)) calc(8px + var(--sar)) 6px calc(8px + var(--sal));
  }
  .hud .hud-pill {
    padding: 6px 8px;
    border-radius: 10px;
    font-size: 11px;
    gap: 5px;
  }
  .hud .btn.icon {
    width: 44px;
    min-height: 44px;
    border-radius: 10px;
    font-size: 16px;
  }
  .hud > .row {
    gap: 5px !important;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .track-end-btn {
    top: calc(94px + env(safe-area-inset-top)) !important;
    right: calc(8px + env(safe-area-inset-right)) !important;
    min-height: 44px !important;
    padding: 8px 11px !important;
    border-radius: 11px !important;
    font-size: 11px !important;
  }
  .track-toast {
    top: calc(150px + env(safe-area-inset-top)) !important;
    max-width: calc(100% - 24px) !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
}

/* overlay (drill intro / results) */
.overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 12, .62);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  padding: 20px calc(16px + var(--sar)) calc(20px + var(--sab)) calc(16px + var(--sal));
  animation: fadein .2s ease;
}
.overlay .sheet {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100dvh - 40px - var(--sat) - var(--sab));
  overflow-x: hidden;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.015)),
    var(--panel);
  border: 1px solid rgba(104,128,171,.38);
  border-radius: 20px;
  padding: 22px;
  text-align: center;
  box-shadow: 0 28px 70px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.06);
}
.overlay .sheet h2 { font-size: 21px; margin-bottom: 4px; }
.practice-standard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: 12px 0 2px;
}
.practice-standard div {
  min-width: 0;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid rgba(104,128,171,.32);
  background: rgba(16,24,36,.72);
  text-align: center;
}
.practice-standard b {
  display: block;
  color: var(--gold);
  font-size: 13px;
  line-height: 1.1;
}
.practice-standard span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1.15;
}
.overlay .sheet .objective { color: #c6d0e0; font-size: 14.5px; line-height: 1.55; margin: 10px 0 4px; text-align: left; }
.overlay .sheet .objective li { margin: 6px 0 0 18px; }
.overlay .big-stars { font-size: 34px; letter-spacing: 6px; margin: 10px 0 2px; }
.overlay .scoreline { font-size: 40px; font-weight: 900; margin: 2px 0; }
.result-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 10px 0 2px;
}
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  color: var(--text);
  background: rgba(10,14,20,.5);
  border: 1px solid rgba(104,128,171,.30);
}
.result-badge.good { color: var(--good); border-color: rgba(61,220,132,.42); background: rgba(61,220,132,.08); }
.result-badge.gold { color: var(--gold); border-color: rgba(255,207,77,.45); background: rgba(255,207,77,.09); }
.next-action {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 13px;
  background: rgba(255,138,42,.08);
  border: 1px solid rgba(255,138,42,.24);
  color: #ffd9b2;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}
.next-delta {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(61,220,132,.08);
  border: 1px solid rgba(61,220,132,.24);
  color: #c8f7da;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
}
.reward-sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}
.reward-sparks i {
  position: absolute;
  width: 6px;
  height: 12px;
  border-radius: 99px;
  background: var(--gold);
  opacity: 0;
  animation: spark 900ms ease-out forwards;
}
.reward-sparks i:nth-child(1) { left: 18%; top: 24%; animation-delay: 30ms; }
.reward-sparks i:nth-child(2) { left: 78%; top: 25%; animation-delay: 100ms; background: var(--accent); }
.reward-sparks i:nth-child(3) { left: 28%; top: 72%; animation-delay: 170ms; background: var(--good); }
.reward-sparks i:nth-child(4) { left: 68%; top: 70%; animation-delay: 240ms; }
.reward-sparks i:nth-child(5) { left: 50%; top: 18%; animation-delay: 310ms; background: var(--accent2); }
.overlay .coach {
  margin: 12px 0; padding: 12px 14px; border-radius: 12px; text-align: left;
  background: rgba(41,211,255,.07); border: 1px solid rgba(41,211,255,.25);
  font-size: 13.5px; line-height: 1.5; color: #cdeffb;
}
.overlay .btnrow { display: flex; gap: 10px; margin-top: 14px; }
.overlay .btnrow .btn { flex: 1; }
@media (max-width: 430px) {
  .overlay {
    padding: calc(10px + var(--sat)) calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal));
    align-items: stretch;
  }
  .overlay .sheet {
    border-radius: 16px;
    padding: 16px;
    width: 100%;
  }
  .overlay .sheet h2 { font-size: 19px; }
  .overlay .big-stars { font-size: 28px; }
  .overlay .scoreline { font-size: 34px; }
  .overlay .btnrow {
    position: sticky;
    bottom: 0;
    padding: 10px 0 calc(2px + var(--sab));
    background: linear-gradient(180deg, rgba(22,29,41,0), var(--panel) 30%);
  }
}

/* ---------- touch controls ---------- */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal));
  pointer-events: none;
  z-index: 6;
  gap: 10px;
}
.controls .cluster { display: flex; gap: 10px; pointer-events: auto; }
.ctl-btn {
  width: 74px; height: 74px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: rgba(16, 22, 32, .8);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 26px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.ctl-btn.active { border-color: var(--accent); background: rgba(41,211,255,.18); }

/* vertical pedal */
.pedal {
  width: 84px; height: 128px;
  border-radius: 20px;
  border: 1.5px solid var(--line);
  background: rgba(16, 22, 32, .8);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.pedal .fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  transition: height .04s linear;
}
.pedal.brake .fill { background: linear-gradient(180deg, rgba(255,93,93,.25), rgba(255,93,93,.75)); }
.pedal.throttle .fill { background: linear-gradient(180deg, rgba(61,220,132,.25), rgba(61,220,132,.75)); }
.pedal .lbl {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 12px; font-weight: 800; letter-spacing: 1.5px; color: var(--text);
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.pedal .lbl .pct { font-size: 17px; }
@media (max-width: 430px) {
  .controls {
    gap: 8px;
    padding: 0 calc(8px + var(--sar)) calc(10px + var(--sab)) calc(8px + var(--sal));
  }
  .controls .cluster { gap: 6px; }
  .ctl-btn {
    width: 56px;
    height: 60px;
    border-radius: 16px;
    font-size: 22px;
  }
  .pedal {
    width: 62px;
    height: 112px;
    border-radius: 16px;
  }
  .pedal .lbl {
    gap: 2px;
    font-size: 10.5px;
    letter-spacing: .6px;
  }
  .pedal .lbl .pct { font-size: 14px; }
}
@media (orientation: landscape) and (max-height: 430px) {
  .controls {
    padding: 0 calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal));
    gap: 7px;
  }
  .controls .cluster { gap: 6px; }
  .ctl-btn {
    width: 54px;
    height: 54px;
    border-radius: 15px;
    font-size: 21px;
  }
  .pedal {
    width: 58px;
    height: 88px;
    border-radius: 15px;
  }
  .pedal .lbl {
    gap: 1px;
    font-size: 10px;
    letter-spacing: .5px;
  }
  .pedal .lbl .pct { font-size: 13px; }
  .track-end-btn {
    top: calc(58px + env(safe-area-inset-top)) !important;
    padding: 5px 10px !important;
    min-height: 44px !important;
  }
  .track-toast {
    top: calc(104px + env(safe-area-inset-top)) !important;
    padding: 7px 11px !important;
    font-size: 12px !important;
  }
}

/* horizontal slider (brake trace drills) */
.hslider {
  height: 64px; border-radius: 18px;
  border: 1.5px solid var(--line);
  background: rgba(16,22,32,.85);
  position: relative; overflow: hidden;
  touch-action: none;
  pointer-events: auto;
}
.hslider .fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0%; }
.hslider.brake .fill { background: linear-gradient(90deg, rgba(255,93,93,.25), rgba(255,93,93,.8)); }
.hslider .lbl {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; letter-spacing: 1.5px; text-shadow: 0 1px 4px rgba(0,0,0,.7);
}

/* ---------- flashcards ---------- */
.fcard {
  perspective: 1200px;
  height: min(58vh, 430px);
  height: min(58dvh, 430px);
  cursor: pointer;
}
.fcard-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .45s cubic-bezier(.2, .8, .25, 1);
}
.fcard-inner.flipped { transform: rotateY(180deg); }
.fcard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  border: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 26px;
}
.fcard-front {
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(41,211,255,.14), transparent 55%),
    var(--panel);
}
.fcard-back {
  background:
    radial-gradient(120% 140% at 0% 100%, rgba(255,138,42,.12), transparent 55%),
    var(--panel2);
  transform: rotateY(180deg);
  /* long answers scroll; margin:auto on the inner wrapper keeps short ones centred */
  justify-content: flex-start;
  overflow-y: auto;
}

/* ---------- decision drills ---------- */
.daily-card { border-color: rgba(255,138,42,.34); }
.decision-root {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(64px + var(--sat)) 14px calc(22px + var(--sab));
}
.decision-card h2 { font-size: 20px; margin: 4px 0 8px; }
.decision-card p {
  color: #d2dbea;
  font-size: 15px;
  line-height: 1.55;
  margin: 12px 0 4px;
}
.decision-card > .btn.big:last-child {
  position: sticky;
  bottom: calc(10px + var(--sab));
  z-index: 5;
  box-shadow: 0 18px 34px rgba(0,0,0,.32), 0 0 0 1px rgba(255,255,255,.08) inset;
}
.decision-type {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 8px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(41,211,255,.08);
  border: 1px solid rgba(41,211,255,.24);
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
.flag-visual {
  min-height: 104px;
  border-radius: 16px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
  overflow: hidden;
  position: relative;
}
.flag-visual:before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.18) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.18) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,.18) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.18) 75%);
  background-size: 34px 34px;
  background-position: 0 0, 0 17px, 17px -17px, -17px 0;
  opacity: .35;
}
.flag-visual span {
  position: relative;
  z-index: 1;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(10,14,20,.78);
  border: 1px solid rgba(255,255,255,.18);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
}
.flag-yellow { background: #f3cf3b; color: #1d1600; }
.flag-blue { background: #1d65db; }
.flag-red { background: #dd3047; }
.flag-surface { background: repeating-linear-gradient(45deg, #f4d23c 0 18px, #d92c35 18px 36px); }
.flag-black { background: #07090d; }
.flag-white { background: #f5f7fb; color: #111722; }
.flag-green { background: #1fbf68; color: #06130b; }
.flag-double-yellow { background: repeating-linear-gradient(90deg, #f3cf3b 0 16px, #c99b16 16px 32px); color: #1d1600; }
.flag-checkered { background: conic-gradient(#f5f7fb 0 25%, #111722 0 50%, #f5f7fb 0 75%, #111722 0); color: #111722; }
.flag-meatball { background: radial-gradient(circle at 50% 50%, #ff8a2a 0 21%, #07090d 22%); }
.flag-black-white { background: linear-gradient(135deg, #07090d 0 50%, #f5f7fb 50%); color: #111722; }
.flag-safety-car { background: repeating-linear-gradient(45deg, #f3cf3b 0 18px, #151a23 18px 36px); color: #1d1600; }
.flag-pit-exit { background: linear-gradient(90deg, #1fbf68 0 48%, #dd3047 48%); }
.flag-checkered span, .flag-black-white span { color: var(--text); }
.lane-map {
  height: 118px;
  border-radius: 16px;
  background:
    linear-gradient(90deg, transparent 31%, rgba(255,255,255,.12) 31% 32%, transparent 32% 66%, rgba(255,255,255,.12) 66% 67%, transparent 67%),
    linear-gradient(180deg, #242b32, #171d25);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  margin: 12px 0;
}
.lane-map i {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.24) 0 18px, transparent 18px 34px);
}
.lane-map i:nth-child(1) { top: 28%; }
.lane-map i:nth-child(2) { top: 50%; }
.lane-map i:nth-child(3) { top: 72%; }
.lane-map .car {
  position: absolute;
  width: 40px;
  height: 20px;
  border-radius: 7px 12px 12px 7px;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.lane-map .car:after {
  content: "";
  position: absolute;
  right: 6px;
  top: 5px;
  width: 8px;
  height: 10px;
  border-radius: 3px;
  background: rgba(255,255,255,.45);
}
.lane-map .car-a { left: 34%; top: 49%; background: var(--accent); }
.lane-map .car-b { left: 54%; top: 28%; background: var(--accent2); }
.lane-map.attack .car-a { left: 48%; top: 56%; }
.lane-map.attack .car-b { left: 38%; top: 33%; }
.lane-map.defend .car-a { left: 45%; top: 32%; }
.lane-map.defend .car-b { left: 28%; top: 53%; }
.lane-map.start .car-a { left: 34%; top: 28%; }
.lane-map.start .car-b { left: 42%; top: 53%; }
.lane-map .apex-dot {
  position: absolute;
  right: 17%;
  top: 45%;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(255,207,77,.65);
}
.statgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}
.statgrid > div {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--panel2);
}
.statgrid b { display: block; font-size: 22px; }
.statgrid span { color: var(--muted); font-size: 12px; }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.center { text-align: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.toast {
  position: absolute; left: 50%; bottom: calc(90px + var(--sab));
  transform: translateX(-50%);
  background: rgba(10,14,20,.92); border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 18px;
  font-size: 13.5px; font-weight: 700; z-index: 30;
  animation: toastin .25s ease;
  max-width: calc(100% - 32px);
  width: max-content;
  text-align: center;
  line-height: 1.4;
}
.setting-switch {
  display: block;
  position: relative;
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.setting-switch .row {
  pointer-events: none;
}
.setting-switch:focus-within {
  outline: 3px solid rgba(41,211,255,.55);
  outline-offset: 3px;
  border-radius: 16px;
}
.setting-input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.setting-toggle-btn {
  min-width: 86px;
  padding-left: 14px;
  padding-right: 14px;
  pointer-events: none;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sheen {
  0%, 58% { transform: translateX(-130%); }
  78%, 100% { transform: translateX(130%); }
}
@keyframes spark {
  0% { opacity: 0; transform: translateY(16px) rotate(0deg) scale(.7); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-54px) rotate(160deg) scale(1); }
}

/* ---------- motion polish (v1.20) ---------- */
/* result sheets spring up instead of just appearing */
.overlay .sheet { animation: sheet-up .34s cubic-bezier(.22, 1.4, .36, 1); }
@keyframes sheet-up {
  from { opacity: 0; transform: translateY(26px) scale(.96); }
  to { opacity: 1; transform: none; }
}
/* stars land one at a time — the reward moment */
.overlay .big-stars span { display: inline-block; animation: star-pop .5s cubic-bezier(.3, 1.6, .4, 1) backwards; }
.overlay .big-stars span:nth-child(1) { animation-delay: .12s; }
.overlay .big-stars span:nth-child(2) { animation-delay: .30s; }
.overlay .big-stars span:nth-child(3) { animation-delay: .48s; }
@keyframes star-pop {
  0% { opacity: 0; transform: scale(.2) rotate(-40deg); }
  70% { opacity: 1; transform: scale(1.25) rotate(6deg); }
  100% { opacity: 1; transform: none; }
}
/* cards respond to touch like buttons do */
.card.tappable { transition: transform .1s ease, border-color .15s ease; }
.card.tappable:active { transform: scale(.985); }
/* gold chips breathe */
.chip.gold { animation: gold-glow 2.6s ease-in-out infinite; }
@keyframes gold-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(255,207,77,0); }
  50% { box-shadow: 0 0 14px rgba(255,207,77,.45); }
}
/* periodic sheen across the XP bar */
.pbar.xp > i { position: relative; overflow: hidden; }
.pbar.xp > i::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: bar-sheen 3.2s ease-in-out infinite;
}
@keyframes bar-sheen { 0%, 55% { transform: translateX(-100%); } 85%, 100% { transform: translateX(100%); } }
.hud-pill { animation: fadein .3s ease backwards; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
::-webkit-scrollbar-track { background: transparent; }
