:root {
  --bg: #0a0c10;
  --surface: #151920;
  --surface-2: #1c212a;
  --line: #262c36;
  --papaya: #ff8200;
  --papaya-wash: rgba(255, 130, 0, 0.14);
  --ink: #f2f0ea;
  --ink-dim: #9aa2b1;
  --ink-faint: #4d5563;
  --green: #35d48c;
  --amber: #ffcc4d;
  --red: #ff4d4d;
  --blue: #4fa8ff;
  --font-display: -apple-system, "SF Pro Display", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --font-body: -apple-system, "SF Pro Text", ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Cascadia Code", monospace;
}

/* This app deliberately stays single-theme (dark) — read at the track /
   under lights, not a document. */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--papaya); }

/* ---------- Install banner ---------- */

.install-banner {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(env(safe-area-inset-top, 0px), 10px) 16px 10px;
  background: var(--papaya-wash);
  border-bottom: 1px solid rgba(255, 130, 0, 0.35);
}

.install-banner-text { flex: 1; min-width: 0; }
.install-banner-text b { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink); }
.install-banner-text span { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 1px; line-height: 1.35; }

.install-banner-btn {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--bg);
  background: var(--papaya);
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}

.install-banner-dismiss {
  flex: none;
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--ink-faint);
  font-size: 13px;
  cursor: pointer;
  border-radius: 50%;
}
.install-banner-dismiss:hover { color: var(--ink-dim); }

/* ---------- Top bar ---------- */

.app-topbar {
  flex: none;
  padding: max(env(safe-area-inset-top, 0px), 20px) 20px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.app-topbar .title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.app-topbar .title small {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--papaya);
  margin-bottom: 4px;
}

/* ---------- Scrollable content ---------- */

.app-content {
  flex: 1;
  min-height: 0; /* flexbug #1: without this, a flex child with overflow-y:auto
                    refuses to shrink below its content's height and overflows
                    its parent instead of scrolling internally. */
  overflow-y: auto;
  padding: 0 20px 100px;
}

.screen { display: none; flex-direction: column; gap: 14px; padding-top: 18px; }
.screen.active { display: flex; }

/* ---------- Bottom tab bar ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10; /* any positioned element with an explicit z-index (even the
                  feed timeline markers at z-index:1) stacks above one with
                  the default z-index:auto, regardless of DOM order — the
                  tab bar needs its own explicit value to stay on top */
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  padding: 8px 6px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0 2px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink-faint);
  font-family: var(--font-body);
}

.tab svg { width: 22px; height: 22px; }
.tab svg * { stroke: currentColor; }

.tab .label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tab.active { color: var(--papaya); }

/* Live tab: the icon becomes orange whenever there's a session to show
   (live or in the post-chequered-flag grace period), but only pulses while
   actually racing — body.is-pulsing is only set for the genuine "live" state. */
body.is-live .tab#tab-live { color: var(--papaya); }
body.is-live.is-pulsing .tab#tab-live svg { animation: icon-pulse 1.6s ease-in-out infinite; }
@keyframes icon-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
@media (prefers-reduced-motion: reduce) { body.is-live.is-pulsing .tab#tab-live svg { animation: none; } }

.live-dot {
  display: none;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--papaya);
  margin-right: 3px;
}
body.is-pulsing .live-dot { animation: pulse 1.8s ease-out infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 130, 0, 0.55); }
  70%  { box-shadow: 0 0 0 6px rgba(255, 130, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 130, 0, 0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

/* ---------- Shared atoms ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--papaya);
}

.screen h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  letter-spacing: -0.02em;
  margin: 2px 0 0;
}

.state-note {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-dim);
  padding: 14px 0;
}

/* ---------- Home ---------- */

.next-race {
  background: linear-gradient(155deg, var(--papaya-wash), transparent 65%), var(--surface);
  border: 1px solid rgba(255, 130, 0, 0.35);
  border-radius: 18px;
  padding: 18px;
}
.next-race h3 { margin: 6px 0 2px; font-family: var(--font-display); font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }
.next-race .circuit { font-size: 13px; color: var(--ink-dim); }

.countdown { display: flex; gap: 10px; margin-top: 14px; }
.countdown .unit { flex: 1; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 10px 0; }
.countdown .unit b { display: block; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 19px; font-weight: 700; }
.countdown .unit span { font-size: 9px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.07em; }

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-dim);
}
.status-banner b { color: var(--ink); }
body.is-live .status-banner {
  background: var(--papaya-wash);
  border-color: rgba(255, 130, 0, 0.35);
  color: var(--ink);
}

.quick-result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.quick-result-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.quick-result .pos {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 26px;
  color: var(--papaya);
}
.quick-result .meta b { display: block; font-size: 14px; }
.quick-result .meta span { font-size: 12px; color: var(--ink-dim); }

.champ-standing { flex: none; text-align: right; }
.champ-standing b {
  display: block;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 18px;
  color: var(--ink);
}
.champ-standing span {
  display: block;
  font-size: 9.5px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
  white-space: nowrap;
}

/* ---------- Calendar ---------- */

.race-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
}
.race-row:last-child { border-bottom: none; }
.race-row .date-chip { width: 38px; text-align: center; font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim); line-height: 1.2; }
.race-row .date-chip b { display: block; font-size: 15px; color: var(--ink); }
.race-row .name { flex: 1; min-width: 0; }
.race-row .name b { display: block; font-weight: 600; font-size: 14px; }
.race-row .name span { color: var(--ink-faint); font-size: 12px; }
.result-chip-stack { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.result-chip { font-family: var(--font-mono); font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
.result-chip.p1 { background: rgba(255, 130, 0, 0.18); color: var(--papaya); }
.result-chip.podium { background: rgba(255, 204, 77, 0.15); color: var(--amber); }
.result-chip.plain { background: var(--surface-2); color: var(--ink-dim); }
.result-chip.next { background: rgba(53, 212, 140, 0.15); color: var(--green); }

/* ---------- Live ---------- */

.live-offair {
  margin-top: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  color: var(--ink-dim);
}
.live-offair .ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}
.live-offair h3 { margin: 8px 0 0; font-family: var(--font-display); font-size: 17px; color: var(--ink); }
.live-offair p { margin: 0; font-size: 13px; max-width: 34ch; }

.live-header {
  /* Sticky here is safe in the real app: the WebKit bug that broke this in
     the phone-frame mockup needed overflow:hidden + border-radius together
     on an ancestor. body has overflow:hidden but no border-radius. */
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -20px 0;
  padding: 0 20px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1; /* stretch to fill .app-topbar's row so space-between can push
              the clock/lap counter all the way to the right edge */
}
.session-bar .left { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 12.5px; color: var(--papaya); font-weight: 700; letter-spacing: 0.04em; }
.session-bar .lap { font-family: var(--font-mono); font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.podium-strip { display: flex; gap: 8px; }

.podium-chip {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 4px 7px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ink-faint);
  border-radius: 10px;
}

.podium-id { display: flex; align-items: baseline; gap: 5px; }
.podium-pos { font-family: var(--font-mono); font-weight: 700; font-size: 11px; color: var(--ink-dim); }
.podium-code { font-family: var(--font-display); font-weight: 800; font-size: 13.5px; letter-spacing: 0.01em; }
.podium-gap { font-family: var(--font-mono); font-size: 10px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.mclaren-list { display: flex; flex-direction: column; gap: 8px; }

.mclaren-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--papaya-wash);
  border: 1px solid rgba(255, 130, 0, 0.4);
}

.mclaren-pos {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 30px;
  flex: none;
}
.mclaren-pos .pos-num { font-family: var(--font-mono); font-weight: 800; font-size: 16px; color: var(--papaya); }
.mclaren-pos .pos-delta { font-family: var(--font-mono); font-weight: 700; font-size: 10px; line-height: 1; }
.mclaren-pos .pos-delta.up { color: var(--green); }
.mclaren-pos .pos-delta.down { color: #ff4d6d; }
.mclaren-pos .pos-delta.flat { color: var(--ink-faint); }

.mclaren-main { flex: 1; min-width: 0; }
.mclaren-main b { display: block; font-size: 14px; font-weight: 700; }
.mclaren-main span { display: block; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-dim); font-variant-numeric: tabular-nums; margin-top: 1px; }

/* Shown when the resolved driver isn't the regular seat-holder (acronym
   match failed and we fell back to "whichever McLaren car isn't Norris") —
   e.g. a reserve driver standing in. */
.mclaren-main .stand-in-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--amber);
  background: rgba(255, 204, 77, 0.15);
  border-radius: 5px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}

.mclaren-stats { display: flex; align-items: center; gap: 12px; flex: none; }
.mclaren-stats > div { text-align: center; }
.mclaren-stats b { display: block; font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.mclaren-stats > div span:not(.tyre) { display: block; font-size: 8.5px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.mclaren-stats .stint { font-family: var(--font-mono); }

.tyre { font-family: var(--font-mono); font-size: 10.5px; font-weight: 800; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.tyre.soft { background: #ff4d6d; color: #2a0410; }
.tyre.medium { background: #ffcc4d; color: #2a1e04; }
.tyre.hard { background: #eef0f2; color: #24272c; }
.tyre.intermediate { background: #3ecf5e; color: #06210c; }
.tyre.wet { background: #4fa8ff; color: #041b33; }

/* Race feed — vertical timeline with a marker + icon per event, color-coded
   by type/severity. See workers/mcl-mobile-frontend/README or the icon
   mapping reference for the full category → icon/color table. */

.timeline { position: relative; padding-left: 34px; }

.timeline::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: linear-gradient(var(--line), var(--line) 85%, transparent);
}

.feed-item { position: relative; padding: 0 0 18px; }
.feed-item:last-child { padding-bottom: 0; }

.feed-marker {
  position: absolute;
  left: -34px;
  top: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--line);
  z-index: 1;
}
.feed-marker svg { width: 13px; height: 13px; }

.feed-marker.mcl { border-color: var(--papaya); background: var(--papaya-wash); color: var(--papaya); }
.feed-marker.red { border-color: var(--red); background: rgba(255, 77, 77, 0.16); color: var(--red); }
.feed-marker.amber { border-color: var(--amber); background: rgba(255, 204, 77, 0.16); color: var(--amber); }
.feed-marker.blue { border-color: var(--blue); background: rgba(79, 168, 255, 0.16); color: var(--blue); }
.feed-marker.green { border-color: var(--green); background: rgba(53, 212, 140, 0.16); color: var(--green); }
.feed-marker.grey { color: var(--ink-faint); }

/* Session-state-changing moments worth catching the eye. */
.feed-marker.pulse-green { animation: feed-pulse-green 1.8s ease-out infinite; }
.feed-marker.pulse-red { animation: feed-pulse-red 1.8s ease-out infinite; }
.feed-marker.pulse-grey { animation: feed-pulse-grey 1.8s ease-out infinite; }
.feed-marker.pulse-amber { animation: feed-pulse-amber 1.8s ease-out infinite; }

@keyframes feed-pulse-green {
  0%   { box-shadow: 0 0 0 0 rgba(53, 212, 140, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(53, 212, 140, 0); }
  100% { box-shadow: 0 0 0 0 rgba(53, 212, 140, 0); }
}
@keyframes feed-pulse-red {
  0%   { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.55); }
  70%  { box-shadow: 0 0 0 7px rgba(255, 77, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}
@keyframes feed-pulse-grey {
  0%   { box-shadow: 0 0 0 0 rgba(242, 240, 234, 0.4); }
  70%  { box-shadow: 0 0 0 7px rgba(242, 240, 234, 0); }
  100% { box-shadow: 0 0 0 0 rgba(242, 240, 234, 0); }
}
@keyframes feed-pulse-amber {
  0%   { box-shadow: 0 0 0 0 rgba(255, 204, 77, 0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(255, 204, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 204, 77, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .feed-marker.pulse-green, .feed-marker.pulse-red, .feed-marker.pulse-grey, .feed-marker.pulse-amber { animation: none; }
}

.feed-body { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding-top: 2px; }
.feed-text { min-width: 0; }
.feed-text .msg { font-size: 12.5px; line-height: 1.45; color: var(--ink-dim); }
.feed-text .msg b { color: var(--ink); font-weight: 600; }
.feed-text .msg b.mcl { color: var(--papaya); }

.feed-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 5px;
  margin-top: 5px;
}
.feed-tag.mcl { background: var(--papaya-wash); color: var(--papaya); }
.feed-tag.red { background: rgba(255, 77, 77, 0.16); color: var(--red); }
.feed-tag.amber { background: rgba(255, 204, 77, 0.16); color: var(--amber); }
.feed-tag.blue { background: rgba(79, 168, 255, 0.16); color: var(--blue); }
.feed-tag.green { background: rgba(53, 212, 140, 0.16); color: var(--green); }
.feed-tag.grey { background: var(--surface-2); color: var(--ink-faint); }

.feed-time {
  flex: none;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  padding-top: 1px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Settings ---------- */

.settings-group { display: flex; flex-direction: column; }
.settings-group .group-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 0 2px 8px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.settings-row:first-of-type { border-radius: 14px 14px 0 0; }
.settings-row:last-of-type { border-radius: 0 0 14px 14px; }
.settings-row + .settings-row { border-top: none; }
.settings-row .label b { display: block; font-size: 13.5px; font-weight: 600; }
.settings-row .label span { font-size: 11.5px; color: var(--ink-dim); }

.settings-row.stacked { flex-direction: column; align-items: stretch; gap: 10px; }
.settings-row.stacked .driver-pick button { padding: 9px 0; font-size: 12px; }

.settings-switch {
  width: 40px;
  height: 24px;
  border-radius: 100px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  flex: none;
  cursor: pointer;
}
.settings-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink-dim);
}
.settings-switch.on { background: var(--papaya-wash); border-color: rgba(255, 130, 0, 0.45); }
.settings-switch.on::after { transform: translateX(16px); background: var(--papaya); }

.driver-pick { display: flex; gap: 8px; }
.driver-pick button {
  flex: 1;
  padding: 10px 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-dim);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.driver-pick button.selected { border-color: rgba(255, 130, 0, 0.5); background: var(--papaya-wash); color: var(--papaya); }

.push-hint {
  font-size: 11.5px;
  color: var(--ink-faint);
  margin: -4px 2px 0;
}

.about-row {
  display: flex;
  justify-content: space-between;
  padding: 11px 2px;
  font-size: 12.5px;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--line);
}
.about-row:last-child { border-bottom: none; }
.about-row b { color: var(--ink); font-weight: 500; }
