:root {
  --bg: #0c0b0a;
  --panel: #161310;
  --leather: #2c211b;
  --ink: #efe6d8;
  --muted: #a89884;
  --amber: #f0b429;
  --amber-dim: #9a7318;
  --red: #e23b32;
  --green: #3ecf8e;
  --cyan: #7ad4ff;
  --chrome: #c5b9a4;
  --line: rgba(255, 230, 190, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
button, input { font: inherit; }
kbd {
  display: inline-block;
  padding: 0.05em 0.4em;
  border: 1px solid #5a4d40;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #2a241f;
  font-size: 0.8em;
}

#boot {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 0%, #3a2a18 0%, transparent 50%),
    linear-gradient(#1a140f, #090807);
}
.boot-card {
  width: min(520px, 92vw);
  padding: 2.2rem;
  background: #16110d;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--amber);
  font-size: 0.72rem;
  margin: 0 0 0.6rem;
}
.boot-card h1 { font-size: 2.4rem; margin: 0 0 0.7rem; letter-spacing: -0.03em; }
.lede { color: var(--muted); line-height: 1.5; }
.hint { color: var(--muted); font-size: 0.85rem; }
.mode-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin: 1.1rem 0 0.8rem;
}
.mode-card {
  text-align: left;
  background: #1c1612;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1rem 1.1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mode-card:hover, .mode-card:focus {
  border-color: var(--amber-dim);
  background: #241c16;
}
.mode-card strong { font-size: 1.15rem; }
.mode-card small { color: var(--muted); line-height: 1.35; }
.mode-icon {
  display: inline-grid; place-items: center;
  width: 2.4rem; height: 2.4rem; margin-bottom: 0.2rem;
  border-radius: 8px; background: #2a211a; color: var(--amber);
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em;
  text-transform: uppercase;
}
.mobile-only { display: none !important; }
body.mode-mobile .mobile-only { display: revert !important; }
body.mode-mobile button.mobile-only,
body.mode-mobile .ghost.mobile-only { display: inline-flex !important; }
body.mode-mobile .rlock.mobile-only { display: inline-block !important; }
body.mode-mobile .pc-only { display: none !important; }
body.mode-mobile .mobile-only[hidden] { display: none !important; }
body.mode-pc .help-mobile { display: none; }
body.mode-mobile .help-pc { display: none; }
.primary {
  background: linear-gradient(#f3c14e, #c88812);
  color: #1a1208;
  border: none;
  padding: 0.75rem 1.4rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 0.6rem;
}
.primary:hover { filter: brightness(1.08); }
.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}
.ghost:hover { border-color: var(--amber-dim); }

#app {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top lesson"
    "cockpit lesson";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  background: #100e0c;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 0.7rem; align-items: center; min-width: 220px; }
.brand span:last-child, .brand div span { display: block; color: var(--muted); font-size: 0.75rem; }
.logo {
  width: 36px; height: 36px; border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(#3a2a1c, #1c1410);
  border: 1px solid var(--amber-dim);
  color: var(--amber); font-weight: 800;
}
.hud-pills { display: flex; gap: 0.45rem; flex: 1; flex-wrap: wrap; }
.pill {
  background: #1c1814;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.2rem 0.65rem 0.25rem;
  min-width: 64px;
}
.pill label { display: block; font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.pill b { font-size: 1.05rem; }
.pill small { margin-left: 0.2rem; color: var(--muted); }
.pill.warn b { color: var(--amber); }
.top-actions { display: flex; gap: 0.35rem; }

.cockpit {
  grid-area: cockpit;
  display: grid;
  grid-template-columns: 1.3fr 0.9fr 0.6fr 0.3fr;
  grid-template-rows: 1fr auto;
  min-height: 0;
  background: #0b0a09;
}
.windshield-wrap { grid-column: 1 / -1; grid-row: 1; }
#gauges { grid-column: 1; grid-row: 2; }
.center-stack { grid-column: 2; grid-row: 2; }
.pedal-left { grid-column: 3; grid-row: 2; }
.pedal-right { grid-column: 4; grid-row: 2; }
.windshield-wrap { position: relative; min-height: 0; overflow: hidden; }
#road { width: 100%; height: 100%; display: block; }
.hood {
  position: absolute; left: 0; right: 0; bottom: 0; height: 18%;
  background: linear-gradient(transparent, #1a120e 30%, #0e0b09);
  pointer-events: none;
}
#alerts {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px; align-items: center;
  pointer-events: none;
}
.alert {
  background: rgba(20, 10, 8, 0.82);
  border: 1px solid var(--red);
  color: #ffd0c8;
  padding: 0.35rem 0.8rem;
  border-radius: 8px;
  font-weight: 700;
  letter-spacing: 0.04em;
  animation: pop 0.2s ease;
}
.alert.info { border-color: var(--amber); color: var(--amber); }
@keyframes pop { from { transform: scale(0.9); opacity: 0; } }
.winds-hud { position: absolute; left: 16px; bottom: 22%; }
.bite-meter {
  background: rgba(12, 10, 8, 0.75);
  border: 1px solid var(--line);
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  width: 240px;
  font-size: 0.8rem;
}
.bite-track {
  position: relative; height: 10px; margin: 0.4rem 0;
  background: #2a241e; border-radius: 99px; overflow: hidden;
}
.bite-track i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #e23b32, #f0b429, #3ecf8e);
}
.bite-track em {
  position: absolute; top: -2px; width: 3px; height: 14px;
  background: white; left: 42%;
}

#gauges, .center-stack, .pedal-left, .pedal-right {
  background: linear-gradient(#241a14, #140f0c);
  border-top: 1px solid #3a2c22;
  min-height: 0;
}
#gauges { width: 100%; height: 220px; padding: 0.4rem; box-sizing: border-box; }

.center-stack { display: flex; flex-direction: column; gap: 0.4rem; }
.ignition-row { display: flex; gap: 0.4rem; align-items: center; }
.ignition, .handbrake {
  width: 64px; height: 36px; border-radius: 8px; cursor: pointer; font-weight: 800;
}
.ignition {
  background: radial-gradient(circle at 30% 30%, #6a6a6a, #222);
  color: #ddd; border: 1px solid #888;
}
.ignition:active { transform: translateY(1px); }
.handbrake { background: #3a1515; color: #f8b; border: 1px solid #833; }
.handbrake.on { background: #a31b1b; color: white; box-shadow: 0 0 10px #e23b32aa; }
.rlock {
  min-width: 72px; height: 36px; border-radius: 8px; cursor: pointer; font-weight: 800;
  background: #1a1a22; color: #bbb; border: 1px solid #555;
}
.rlock.held { background: var(--red); color: white; border-color: var(--red); }
.status-lamps { display: flex; gap: 0.3rem; margin-left: auto; }
.lamp {
  font-size: 0.65rem; letter-spacing: 0.08em;
  padding: 0.2rem 0.35rem; border-radius: 4px;
  border: 1px solid #333; color: #555; background: #151515;
}
.lamp.on { color: #1a1208; background: var(--amber); border-color: var(--amber); }
.lamp.hot { color: white; background: var(--red); border-color: var(--red); }

.shifter-block { flex: 1; display: flex; flex-direction: column; align-items: center; }
#gate { width: min(220px, 100%); height: 170px; cursor: grab; touch-action: none; }
#gate .g { fill: #d8c4a4; font-size: 14px; font-weight: 700; text-anchor: middle; }
#gate .g.r { fill: #e23b32; }
#knob { cursor: grab; }
.shift-hint { margin: 0; font-size: 0.72rem; color: var(--muted); }
.shift-hint.dim { opacity: 0.75; }

.pedal-left, .pedal-right {
  display: flex; gap: 0.8rem; align-items: flex-end; justify-content: center;
  padding: 0.4rem 0.4rem 0;
}
.pedal { text-align: center; color: var(--muted); font-size: 0.75rem; user-select: none; }
.pedal-arm {
  width: 46px; height: 130px; margin: 0 auto 0.35rem;
  background: linear-gradient(#2a2a2a, #111);
  border-radius: 8px 8px 4px 4px;
  border: 1px solid #555;
  position: relative;
  cursor: ns-resize;
}
.pedal-arm.wide { width: 58px; }
.pedal-arm::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: calc(var(--pos, 0) * 100%);
  background: linear-gradient(transparent, rgba(240, 180, 41, 0.22));
  pointer-events: none;
  border-radius: inherit;
}
.pedal-arm i {
  position: absolute; left: 5px; right: 5px;
  top: calc(3% + 79% * var(--pos, 0));
  height: 18%;
  background: linear-gradient(#e8e8e8, #6a6a6a);
  border-radius: 5px;
  border: 1px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  transform: none;
}
.pedal label { display: block; color: var(--ink); font-weight: 700; }
.pedal.floored .pedal-arm { box-shadow: inset 0 0 0 2px var(--amber); }

.lesson-rail {
  grid-area: lesson;
  background: #14110f;
  border-left: 1px solid var(--line);
  padding: 0.9rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.lesson-head h2 { margin: 0.15rem 0 0; font-size: 1.25rem; }
#lesson-list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem;
}
#lesson-list button {
  width: 100%; text-align: left; background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 8px; padding: 0.35rem 0.5rem; cursor: pointer;
}
#lesson-list button.active, #lesson-list button:hover {
  background: #221c18; color: var(--ink); border-color: var(--line);
}
#lesson-list button.done::after { content: " ✓"; color: var(--green); }
.lesson-body { background: #1b1613; border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; }
#lesson-text { margin: 0 0 0.6rem; line-height: 1.45; color: #e7dccb; }
#lesson-goals { margin: 0; padding-left: 1.1rem; color: var(--muted); }
#lesson-goals li.met { color: var(--green); }
.lesson-progress { height: 6px; background: #2a241e; border-radius: 99px; margin: 0.7rem 0; overflow: hidden; }
#lesson-bar { display: block; height: 100%; width: 0; background: var(--amber); }
.feedback { min-height: 1.3em; color: var(--amber); font-weight: 600; margin: 0; }
.toggles { display: flex; flex-direction: column; gap: 0.35rem; color: var(--muted); font-size: 0.85rem; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: grid; place-items: center; z-index: 20;
}
.modal-card {
  width: min(720px, 92vw);
  background: #171310; border: 1px solid var(--line); border-radius: 16px;
  padding: 1.4rem; box-shadow: var(--shadow);
}
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.help-grid ul { padding-left: 1.1rem; color: var(--muted); line-height: 1.55; }
.help-grid h3 { margin: 0 0 0.3rem; color: var(--amber); font-size: 0.9rem; }

@media (max-width: 1100px) {
  body.mode-pc #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; grid-template-areas: "top" "cockpit" "lesson"; }
  body.mode-pc .lesson-rail { max-height: 280px; border-left: none; border-top: 1px solid var(--line); }
  body.mode-pc .cockpit { grid-template-columns: 1fr 1fr; }
  body.mode-pc .windshield-wrap { grid-column: 1 / -1; }
  body.mode-pc #gauges { grid-column: 1 / -1; height: 160px; }
  body.mode-pc .center-stack { grid-column: 1; }
  body.mode-pc .pedal-left { grid-column: 2; }
  body.mode-pc .pedal-right { grid-column: 2; }
  .help-grid { grid-template-columns: 1fr; }
  .mode-pick { grid-template-columns: 1fr; }
}

/* —— Mobile cockpit —— */
html.mode-mobile body {
  overflow: hidden;
  overscroll-behavior: none;
}
body.mode-mobile #app {
  position: fixed;
  top: var(--app-top, 0px);
  left: 0;
  right: 0;
  width: auto;
  height: var(--app-h, 100svh);
  max-height: var(--app-h, 100svh);
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top" "cockpit";
  overflow: hidden;
}
body.mode-mobile #gauges,
body.mode-mobile #road {
  display: block;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0 !important;
  pointer-events: none;
}
body.mode-mobile #road {
  width: 100% !important;
  height: 100% !important;
}
body.mode-mobile .topbar {
  padding: 0.25rem 0.45rem;
  gap: 0.3rem;
  flex-wrap: wrap;
  z-index: 5;
}
body.mode-mobile .brand { min-width: 0; gap: 0.35rem; flex: 0 0 auto; }
body.mode-mobile .brand div span,
body.mode-mobile .brand strong { display: none; }
body.mode-mobile .logo { width: 26px; height: 26px; font-size: 0.7rem; }
body.mode-mobile .hud-pills { flex-wrap: nowrap; min-width: 0; }
body.mode-mobile .pill.warn,
body.mode-mobile #pill-smooth { display: none; }
body.mode-mobile .pill { min-width: 44px; padding: 0.08rem 0.35rem; }
body.mode-mobile .pill b { font-size: 0.9rem; }
body.mode-mobile .ghost { padding: 0.3rem 0.5rem; min-height: 32px; flex: 0 0 auto; }
body.mode-mobile .top-actions { flex-shrink: 0; }
body.mode-mobile .ignition, body.mode-mobile .handbrake, body.mode-mobile .rlock {
  height: 44px;
  min-width: 64px;
  font-size: 0.88rem;
  touch-action: manipulation;
  position: relative;
  z-index: 6;
}
body.mode-mobile .status-lamps { display: none; }
body.mode-mobile .shifter-block { min-height: 0; overflow: hidden; }
body.mode-mobile #gate { touch-action: none; }
body.mode-mobile .pedal {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body.mode-mobile .pedal-arm,
body.mode-mobile .pedal-arm.wide {
  flex: 1;
  width: 100%;
  max-width: none;
  min-height: 0;
  height: auto;
  touch-action: none;
  border-radius: 12px;
}
body.mode-mobile .pedal-arm i { height: 18%; }
body.mode-mobile .pedal label {
  flex: 0 0 auto;
  font-size: 0.72rem;
  line-height: 1.1;
  padding: 0.12rem 0 0.18rem;
}
body.mode-mobile .pedal small { display: none !important; }
body.mode-mobile .lesson-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 14;
}
body.mode-mobile .lesson-scrim:not([hidden]) { display: block !important; }
body.mode-mobile .lesson-rail {
  position: fixed;
  z-index: 16;
  left: 0; right: 0; bottom: 0;
  max-height: 70%;
  border-left: none;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  transform: translateY(110%);
  transition: transform 0.22s ease;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.4);
}
body.mode-mobile .lesson-rail.open { transform: none; }
body.mode-mobile #lesson-list button { padding: 0.7rem 0.65rem; font-size: 1rem; }
body.mode-mobile .lesson-rail,
body.mode-mobile .modal-card { touch-action: pan-y; }
body.mode-mobile .bite-meter { width: min(220px, 68vw); font-size: 0.72rem; }
body.mode-mobile .alert { font-size: 0.8rem; }
body.mode-mobile .modal-card { padding: 1rem; max-height: 85%; overflow: auto; }
body.mode-mobile .windshield-wrap,
body.mode-mobile .center-stack,
body.mode-mobile .pedal-left,
body.mode-mobile .pedal-right { min-height: 0; overflow: hidden; }
body.mode-mobile #gate, body.mode-mobile .pedal-arm { touch-action: none; }
body.mode-mobile .winds-hud { display: none; }
body.mode-mobile .shift-hint { display: none !important; }
body.mode-mobile #btn-units,
body.mode-mobile #btn-mute,
body.mode-mobile #btn-help { display: none !important; }

/*
  Absolute layout on mobile. CSS Grid + orientation media queries
  keep leaking the PC dash on iPhone Safari (skinny left column,
  missing shifter/pedals). JS sets is-portrait / is-landscape from
  visualViewport width vs height.
*/
body.mode-mobile .cockpit {
  display: block !important;
  position: relative;
  overflow: hidden;
  padding: 0;
  grid-template-columns: none !important;
  grid-template-rows: none !important;
  grid-template-areas: none !important;
}
body.mode-mobile .cockpit > .windshield-wrap,
body.mode-mobile .cockpit > #gauges,
body.mode-mobile .cockpit > .center-stack,
body.mode-mobile .cockpit > .pedal-left,
body.mode-mobile .cockpit > .pedal-right {
  position: absolute !important;
  grid-area: unset !important;
  grid-column: auto !important;
  grid-row: auto !important;
  margin: 0;
}

/* Portrait: full-width stack, pedals in a row, shifter always visible */
body.mode-mobile .windshield-wrap {
  left: 1%; right: 1%; top: 0.4%; height: 13%;
  z-index: 1;
}
body.mode-mobile #gauges {
  left: 1%; right: 1%; top: 13.8%; height: 20% !important;
  z-index: 2;
  overflow: hidden;
}
body.mode-mobile .center-stack {
  left: 1%; right: 1%; top: 34.2%; height: 37%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.mode-mobile .pedal-left {
  left: 1%; width: 64%; top: 71.8%; bottom: 0.6%; height: auto;
  z-index: 4;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}
body.mode-mobile .pedal-right {
  left: 66%; right: 1%; width: auto; top: 71.8%; bottom: 0.6%; height: auto;
  z-index: 4;
  display: flex;
  flex-direction: row;
  align-items: stretch;
}
body.mode-mobile .ignition-row { justify-content: stretch; flex: 0 0 auto; }
body.mode-mobile .ignition,
body.mode-mobile .handbrake,
body.mode-mobile .rlock { flex: 1; }
body.mode-mobile .shifter-block { flex: 1; min-height: 0; }
body.mode-mobile #gate {
  width: min(250px, 80vw);
  height: 100%;
  max-height: none;
}

/* Landscape: clutch+brake | road (gauges overlaid) | throttle | shifter */
html.is-landscape body.mode-mobile .windshield-wrap,
body.mode-mobile.is-landscape .windshield-wrap {
  left: 16% !important; width: 46% !important; right: auto !important;
  top: 0.5% !important; height: auto !important; bottom: 0.5% !important;
}
html.is-landscape body.mode-mobile #gauges,
body.mode-mobile.is-landscape #gauges {
  left: 16% !important; width: 46% !important; right: auto !important;
  top: auto !important; height: 46% !important; bottom: 0.5% !important;
  background: transparent;
}
html.is-landscape body.mode-mobile .pedal-left,
body.mode-mobile.is-landscape .pedal-left {
  left: 0.5% !important; width: 15% !important; right: auto !important;
  top: 0.5% !important; bottom: 0.5% !important; height: auto !important;
  flex-direction: column;
}
html.is-landscape body.mode-mobile .pedal-right,
body.mode-mobile.is-landscape .pedal-right {
  left: 62.5% !important; width: 15% !important; right: auto !important;
  top: 0.5% !important; bottom: 0.5% !important; height: auto !important;
  flex-direction: column;
}
html.is-landscape body.mode-mobile .center-stack,
body.mode-mobile.is-landscape .center-stack {
  left: 78% !important; width: auto !important; right: 0.5% !important;
  top: 0.5% !important; bottom: 0.5% !important; height: auto !important;
}
html.is-landscape body.mode-mobile .ignition-row,
body.mode-mobile.is-landscape .ignition-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
}
html.is-landscape body.mode-mobile .rlock,
body.mode-mobile.is-landscape .rlock { grid-column: 1 / -1; }
html.is-landscape body.mode-mobile #gate,
body.mode-mobile.is-landscape #gate {
  width: 100%;
  height: 100%;
}
html.is-landscape body.mode-mobile .pedal label,
body.mode-mobile.is-landscape .pedal label {
  font-size: 0.68rem;
  padding: 0.08rem 0 0.12rem;
}
