/* RN Analyzer – dark racing theme, iPhone first */
:root {
  /* Light theme (default) – Race Navigator look: white, graphite type, RN red */
  --bg: #f3f4f7;
  --bg2: #ffffff;
  --bg3: #e8eaef;
  --bg-gradient: radial-gradient(90% 60% at 50% -10%, #ffffff 0%, #f6f7f9 45%, #eceef2 100%) fixed;
  --panel: rgba(10, 12, 16, 0.035);
  --panel-grad: linear-gradient(180deg, #ffffff, #f7f8fa);
  --panel-border: rgba(10, 12, 16, 0.1);
  --text: #0e1014;
  --text-dim: #4d5563;
  --text-muted: #6b7380;
  --accent: #e5202b;
  --accent-2: #1d2027;
  --blue-soft: #0b6fb0;
  --yellow: #8a5e00;
  --red: #e5202b;
  --green: #15803d;
  --grey: #6b7380;
  --sector-default: #0b6fb0;
  --sector-custom: #8a5e00;
  --offline-fg: #b3141e;
  --purple: #7e22ce;
  --fg-025: rgba(10,12,16,0.025); --fg-04: rgba(10,12,16,0.04); --fg-05: rgba(10,12,16,0.05); --fg-06: rgba(10,12,16,0.06);
  --fg-08: rgba(10,12,16,0.08); --fg-10: rgba(10,12,16,0.1); --fg-12: rgba(10,12,16,0.12); --fg-16: rgba(10,12,16,0.16);
  --fg-20: rgba(10,12,16,0.2); --fg-25: rgba(10,12,16,0.25); --fg-30: rgba(10,12,16,0.3); --fg-35: rgba(10,12,16,0.35);
  --bar-bg: rgba(255, 255, 255, 0.88);
  --sheet-bg: #ffffff;
  --toast-bg: rgba(20, 22, 27, 0.96); --toast-fg: #fff;
  --chip-bg: rgba(255, 255, 255, 0.92); --chip-fg: #0e1014;
  --seg-on-bg: #0e1014; --seg-on-fg: #ffffff;
  --thead-bg: rgba(247, 248, 250, 0.98);
  --chart-grid: rgba(10, 12, 16, 0.08);
  --chart-axis: rgba(10, 12, 16, 0.35);
  --chart-text: #4d5563;
  --chart-cursor: #e5202b;
  --chart-marker: #0b6fb0;
  --chart-bg: rgba(10, 12, 16, 0.025);
  --map-bg: #e6e9ee;
  --tab-h: 56px;
  --top-h: 48px;
  --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);
  color-scheme: light;
}
:root[data-theme="dark"] {
  /* Dark theme – graphite black */
  --bg: #07080a;
  --bg2: #101216;
  --bg3: #181b21;
  --bg-gradient: radial-gradient(90% 60% at 50% -10%, #23262e 0%, #101216 40%, #07080a 100%) fixed;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-grad: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #f4f5f7;
  --text-dim: #aab0bb;
  --text-muted: #7d8591;
  --accent-2: #2a2e36;
  --blue-soft: #58c4ff;
  --yellow: #ffd23f;
  --green: #2ecc71;
  --grey: #8a9099;
  --sector-default: #6be5f6;
  --sector-custom: #ffe14d;
  --offline-fg: #ffb4ae;
  --purple: #c77dff;
  --fg-025: rgba(255,255,255,0.025); --fg-04: rgba(255,255,255,0.04); --fg-05: rgba(255,255,255,0.05); --fg-06: rgba(255,255,255,0.06);
  --fg-08: rgba(255,255,255,0.08); --fg-10: rgba(255,255,255,0.1); --fg-12: rgba(255,255,255,0.12); --fg-16: rgba(255,255,255,0.16);
  --fg-20: rgba(255,255,255,0.2); --fg-25: rgba(255,255,255,0.25); --fg-30: rgba(255,255,255,0.3); --fg-35: rgba(255,255,255,0.35);
  --bar-bg: rgba(7, 8, 10, 0.9);
  --sheet-bg: #14161b;
  --toast-bg: rgba(24, 26, 32, 0.97); --toast-fg: #fff;
  --chip-bg: rgba(24, 26, 32, 0.9); --chip-fg: #ffffff;
  --seg-on-bg: #ffffff; --seg-on-fg: #0a0a0c;
  --thead-bg: rgba(20, 22, 27, 0.98);
  --chart-grid: rgba(255, 255, 255, 0.08);
  --chart-axis: rgba(255, 255, 255, 0.3);
  --chart-text: #b8bec8;
  --chart-marker: #58c4ff;
  --chart-bg: rgba(255, 255, 255, 0.025);
  --map-bg: #0e1013;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-gradient);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea { -webkit-user-select: text; user-select: text; }
a { color: var(--blue-soft); }
canvas { display: block; touch-action: none; }
.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ---------- shell ---------- */
#app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  flex: 0 0 auto;
  height: calc(var(--top-h) + var(--sat));
  padding-top: var(--sat);
  display: flex; align-items: center; gap: 6px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--panel-border);
  padding-left: max(8px, var(--sal)); padding-right: max(8px, var(--sar));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.tbtn {
  background: transparent; border: 0; color: var(--text); padding: 6px 10px; border-radius: 8px;
  font-weight: 600; font-size: 14px; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tbtn:active, .tbtn.active { background: var(--fg-12); }
.tbtn.primary:active { background: #b8161f; }
.tbtn.primary { color: #fff; background: var(--accent); padding: 6px 12px; }
.tbtn.primary:active { background: #b8161f; }
.tbtn svg { width: 20px; height: 20px; fill: currentColor; }
.main { flex: 1 1 auto; min-height: 0; position: relative; display: flex; flex-direction: column; }
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }
/* children of a scrolling flex column must never shrink below their content (rows would overlap) */
.view.scroll > * { flex-shrink: 0; }

.tabbar {
  flex: 0 0 auto;
  order: 2;
  height: calc(var(--tab-h) + var(--sab));
  padding-bottom: var(--sab);
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--bar-bg);
  border-top: 1px solid var(--panel-border);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  z-index: 5;
}
.tabbar a {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-muted); text-decoration: none; font-size: 10.5px; font-weight: 600; letter-spacing: 0.2px;
}
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar a.active { color: var(--accent); }

/* wide screens: sidebar */
@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) and (min-aspect-ratio: 4/3) and (pointer: coarse) {
  #app { flex-direction: row; }
  .tabbar { order: 0; flex-direction: column; height: auto; width: 84px; justify-content: flex-start; padding-top: calc(var(--sat) + 8px); border-top: 0; border-right: 1px solid var(--panel-border); }
  .tabbar a { flex: 0 0 64px; }
  .content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
}
.content { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* ---------- generic ---------- */
.card {
  background: var(--panel-grad); border: 1px solid var(--panel-border); border-radius: 16px; padding: 14px; margin: 10px;
}
.btn {
  background: var(--accent-2); color: #fff; border: 1px solid var(--fg-08); border-radius: 12px; padding: 10px 14px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
}
.btn.accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn.ghost { background: var(--fg-10); color: var(--text); border-color: var(--fg-12); }
.btn.ghost:active { background: var(--fg-16); }
.btn.danger { background: rgba(229,32,43,0.12); color: var(--accent); border-color: rgba(229,32,43,0.4); }
.btn:disabled { opacity: 0.5; }
.btn.block { width: 100%; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-dim); }
.input, select.input {
  background: var(--fg-05); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px 12px; color: var(--text); width: 100%; min-height: 40px;
}
.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--fg-12); }
.badge.video { background: var(--accent); color: #fff; }
.badge.best { background: var(--yellow); color: #222; }
.empty { padding: 40px 24px; text-align: center; color: var(--text-dim); line-height: 1.5; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--sab) + 14px); transform: translateX(-50%);
  background: var(--toast-bg); color: var(--toast-fg); padding: 10px 16px; border-radius: 12px; border: 1px solid var(--panel-border);
  z-index: 50; max-width: 90vw; font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  animation: toastin 0.2s ease-out;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.progress { height: 6px; border-radius: 3px; background: var(--fg-12); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.15s linear; }

/* sheets / dialogs */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } }
.sheet {
  background: var(--sheet-bg); border: 1px solid var(--panel-border); border-radius: 18px 18px 0 0; width: 100%; max-width: 640px; max-height: 88vh;
  display: flex; flex-direction: column; padding-bottom: var(--sab); box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}
@media (min-width: 700px) { .sheet { border-radius: 18px; max-height: 80vh; } }
.sheet header { padding: 14px 16px 8px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--panel-border); flex-shrink: 0; }
.sheet > *:not(.body) { flex-shrink: 0; }
.sheet header h2 { margin: 0; font-size: 16px; flex: 1; }
.sheet .body { overflow-y: auto; padding: 8px 0; -webkit-overflow-scrolling: touch; touch-action: pan-y; flex: 1 1 auto; min-height: 0; }
.sheet .item {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 16px; border-bottom: 1px solid var(--fg-06); min-height: 48px;
}
.sheet .item .lbl { flex: 1 1 150px; min-width: 0; }
.sheet .item .lbl .sub, .settings .item .lbl .sub { overflow-wrap: anywhere; }
.sheet .item > .seg, .settings .item > .seg { margin-left: auto; max-width: 100%; overflow-x: auto; }
.sheet .item:active { background: var(--fg-06); }
.sheet .item.selected { background: var(--fg-10); }
.sheet .item .lbl { flex: 1; }
.sheet .group { padding: 10px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); }
.check {
  width: 24px; height: 24px; border: 2px solid var(--fg-35); border-radius: 7px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.check.disabled { opacity: 0.3; }
.switch { position: relative; width: 50px; height: 30px; border-radius: 15px; background: var(--fg-20); border: 0; flex: 0 0 auto; transition: background 0.15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; transition: left 0.15s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; }
.seg { display: inline-flex; background: var(--fg-10); border-radius: 10px; padding: 2px; }
.seg button { background: transparent; border: 0; padding: 6px 12px; border-radius: 8px; color: var(--text-dim); font-weight: 600; font-size: 13px; }
.seg button.on { background: var(--seg-on-bg); color: var(--seg-on-fg); }

/* ---------- laps list ---------- */
.laps-toolbar { display: flex; gap: 8px; padding: 8px 10px; align-items: center; }
.laps-toolbar .input { flex: 1; min-height: 36px; padding: 6px 10px; }
.event-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--fg-06); border-top: 1px solid var(--panel-border); border-bottom: 1px solid var(--panel-border);
  position: sticky; top: 0; z-index: 2; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.event-head .title { font-weight: 800; letter-spacing: -0.2px; }
.event-head .sub { font-size: 12px; color: var(--text-dim); }
.event-head .chev { transition: transform 0.15s; color: var(--text-dim); }
.event-head.collapsed .chev { transform: rotate(-90deg); }
.lap-row {
  display: grid; grid-template-columns: 6px 44px 1fr auto 34px; gap: 10px; align-items: center; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--fg-06);
  position: relative;
}
.lap-row:active { background: var(--fg-05); }
.lap-row .bar { width: 6px; align-self: stretch; border-radius: 0 3px 3px 0; background: transparent; }
.lap-row.selected .bar { background: var(--lap-color); }
.lap-row.selected { background: color-mix(in srgb, var(--lap-color) 26%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--lap-color) 70%, transparent); }
.lap-row.selected .avatar { box-shadow: 0 0 0 3px var(--lap-color); }
.lap-row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.lap-row .selmark { width: 24px; height: 24px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.35); }
.lap-row .selmark svg { width: 15px; height: 15px; fill: currentColor; }
.lap-row .avatar { width: 44px; height: 44px; border-radius: 8px; background: var(--fg-08); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--text-dim); font-weight: 700; }
.lap-row .avatar img { width: 100%; height: 100%; object-fit: cover; }
.lap-row .info { min-width: 0; }
.lap-row .time { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.2px; }
.lap-row.incomplete .time, .lap-row.incomplete .l1 { color: var(--grey); }
.lap-row.best .time { color: var(--yellow); }
.lap-row .l1 { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lap-row .l2 { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lap-row .right { text-align: right; font-size: 12px; color: var(--text-dim); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.lap-row .more { background: transparent; border: 0; color: var(--text-dim); width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.lap-row .more svg { width: 20px; height: 20px; fill: currentColor; }
.sel-summary { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 13px; color: var(--text-dim); border-bottom: 1px solid var(--panel-border); }
.sel-summary .dots { display: flex; gap: 4px; }
.sel-summary .dots i { width: 12px; height: 12px; border-radius: 6px; display: inline-block; }

/* ---------- analyzer ---------- */
.analyzer { display: flex; flex-direction: column; flex: 1 1 auto; height: 100%; min-height: 0; }
.right-col { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel { position: relative; min-height: 60px; display: flex; flex-direction: column; overflow: hidden; }
.panel .panel-body { flex: 1; min-height: 0; position: relative; }
.panel .panel-body > canvas, .panel .panel-body > .table-wrap { position: absolute; inset: 0; }
/* channel strips: the canvas grows with the strip count, the body scrolls */
.panel .panel-body.scroll-y { overflow-y: auto; overflow-x: hidden; }
.panel .panel-body.scroll-y > canvas { position: relative; inset: auto; display: block; touch-action: pan-y; } /* one finger up/down scrolls the strips, sideways moves the cursor */
.panel-tools { position: absolute; right: 8px; top: 6px; display: flex; gap: 4px; z-index: 2; }
.chip {
  min-height: 40px; min-width: 40px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--fg-12); background: var(--chip-bg); color: var(--chip-fg);
  font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.panel-tools button svg { width: 16px; height: 16px; fill: currentColor; }
.panel-title { position: absolute; right: 8px; top: 6px; z-index: 2; display: flex; gap: 4px; }
.panel-title { max-width: calc(100% - 16px); }
/* the title is a block so text-overflow can truncate it; the row shrinks it before the Channels and maximise chips */
.panel-title .chip:not(.icon) { display: block; line-height: 34px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.panel-title .chip:not(.icon):not(.chan) { flex: 0 1 auto; max-width: 60vw; }
.panel-title .chip.chan { flex: none; }
.divider { flex: 0 0 14px; display: flex; align-items: center; justify-content: center; cursor: row-resize; touch-action: none; background: var(--fg-04); }
.divider::after { content: ""; width: 44px; height: 4px; border-radius: 2px; background: var(--fg-35); }
/* touch: a divider you can grab with a gloved thumb */
@media (pointer: coarse) {
  .divider { flex-basis: 24px; }
  .divider::after { width: 60px; height: 5px; }
}
/* one panel maximised: videos, dividers and the other panels step aside (the panel keeps its chart, only the layout changes) */
.analyzer.panel-max .video-panel, .analyzer.panel-max .divider { display: none !important; }
.analyzer.panel-max.has-video { display: flex; flex-direction: column; }
.analyzer.panel-max .right-col { flex: 1 1 0; }
.panel-title .chip.icon { min-width: 34px; padding: 0 8px; }
.panel-title .chip.icon svg { width: 18px; height: 18px; fill: currentColor; }
.videos { display: grid; gap: 4px; padding: 4px; height: 100%; grid-auto-rows: 1fr; grid-template-columns: repeat(auto-fit, minmax(45%, 1fr)); }
.videos.one { grid-template-columns: 1fr; }
/* graphite instead of pure black: the cell is sized to 16:9 by fitVideoCells(), so the colour only shows while a frame loads */
.vcell { position: relative; background: #101216; border-radius: 8px; overflow: hidden; border: 2px solid var(--lap-color, transparent); min-height: 0; place-self: center; max-width: 100%; max-height: 100%; }
.vcell video { width: 100%; height: 100%; object-fit: contain; display: block; background: #101216; }
.vcell .vlabel { position: absolute; left: 6px; top: 4px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; background: rgba(0, 0, 0, 0.45); padding: 2px 6px; border-radius: 6px; }
.vcell .vlabel b { color: var(--lap-color); }
.vcell .vmissing { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 12px; text-align: center; padding: 8px; }
.play-bar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; min-height: 56px; background: var(--fg-06); border-top: 1px solid var(--panel-border); flex: 0 0 auto; }
.play-bar .tbtn.primary { width: 48px; height: 48px; border-radius: 24px; padding: 0; justify-content: center; }
.play-bar .tbtn.primary svg { width: 26px; height: 26px; }
.play-bar .gaps { display: flex; gap: 10px; flex-wrap: wrap; font-weight: 800; font-size: 15px; }
.play-bar .pos { font-variant-numeric: tabular-nums; }
.play-bar .tbtn { min-height: 32px; padding: 4px 8px; }
.play-bar .pos { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-dim); }
.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--fg-08); text-align: right; white-space: nowrap; }
table.data th { text-align: left; font-weight: 600; color: var(--text-dim); background: var(--fg-05); position: sticky; left: 0; }
table.data thead th { position: sticky; top: 0; z-index: 1; text-align: right; background: var(--thead-bg); }
table.data thead th:first-child { left: 0; z-index: 2; }
table.data td .v { display: inline-block; padding: 1px 8px; border: 2px solid transparent; border-radius: 999px; }
table.data td .v.best { border-color: var(--red); }
table.data td .v.best2 { border-color: var(--blue-soft); }
table.data td.label { text-align: left; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; padding: 6px 10px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

/* ---------- landscape phone: video left, panels right ---------- */
@media (orientation: landscape) and (max-height: 500px) and (min-aspect-ratio: 4/3) and (pointer: coarse) {
  /* phone landscape: touch device, clearly wider than tall (a zoomed desktop window with a mouse never matches):
     videos left (42 %) stacked on top of each other, charts right – a grid so the play bar cannot steal width */
  .analyzer.has-video .videos:not(.max) { grid-template-columns: 1fr; }
  .analyzer.has-video { display: grid; grid-template-columns: 42% minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .analyzer.has-video .play-bar { grid-column: 1 / -1; grid-row: 2; }
  .analyzer.has-video .video-panel { grid-column: 1; grid-row: 1; flex: none !important; min-height: 0; }
  .analyzer.has-video .divider.d0 { display: none; }
  .analyzer.has-video .right-col { grid-column: 2; grid-row: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
}

/* ---------- devices ---------- */
.device-card { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; }
.device-card .logo { display: flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 800; font-size: 11px; letter-spacing: 1px; color: var(--text-muted); }
.device-card .logo img { width: 56px; height: auto; display: block; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; }
.kv .k { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.dl-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--fg-06); }
.dl-row .t { font-weight: 700; font-variant-numeric: tabular-nums; }
.dl-row .s { font-size: 12px; color: var(--text-dim); }
.dl-row .progress { grid-column: 1 / -1; }

/* ---------- settings ---------- */
.settings .item { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 12px 14px; border-bottom: 1px solid var(--fg-06); min-height: 52px; }
.settings .item .lbl { flex: 1 1 150px; min-width: 0; }
.settings .item .sub { font-size: 12px; color: var(--text-dim); }
.settings h3 { margin: 18px 14px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); }

/* ---------- video player view ---------- */
.player { display: flex; flex-direction: column; height: 100%; }
.player .stage { flex: 1; min-height: 0; background: #000; display: flex; align-items: center; justify-content: center; position: relative; }
.player video { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; }
.player .hud { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 12px; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px #000; }
.player .hud b { font-size: 22px; }
.player .controls { padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--panel-border); }
.player input[type=range] { width: 100%; accent-color: var(--accent); }
.rbtn { width: 44px; height: 44px; border-radius: 22px; background: var(--fg-12); border: 0; color: var(--text); display: inline-flex; align-items: center; justify-content: center; }
.rbtn.big { width: 56px; height: 56px; border-radius: 28px; background: var(--accent); color: #fff; }
.rbtn svg { width: 22px; height: 22px; fill: currentColor; }

.offline-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(229, 32, 43, 0.14); color: var(--offline-fg); font-weight: 600; }
.update-banner { background: var(--accent); color: #fff; padding: 8px 14px; text-align: center; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: calc(8px + var(--sat)); }
.update-banner.hidden { display: none; }
.update-banner .banner-close { background: rgba(255,255,255,0.2); color: #fff; border: 0; border-radius: 12px; width: 24px; height: 24px; font-size: 16px; line-height: 1; flex: 0 0 auto; }

/* ---------- device control (RN Connect) ---------- */
.logo-rn { width: 48px; height: 44px; border-radius: 10px; background: var(--fg-08); display: flex; align-items: center; justify-content: center; }
.logo-rn img { width: 36px; height: auto; display: block; }
.about-row { display: flex; align-items: center; gap: 14px; }
.about-logo { width: 54px; height: auto; flex: 0 0 auto; }
.rec-btn { width: 72px; height: 72px; border-radius: 36px; border: 3px solid var(--fg-25); background: var(--fg-06); color: var(--text); display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-weight: 800; font-size: 12px; letter-spacing: 1px; flex: 0 0 auto; }
.rec-btn .rec-dot { width: 16px; height: 16px; border-radius: 8px; background: var(--fg-35); }
.rec-btn.on { border-color: var(--red); background: rgba(255,59,48,0.2); }
.rec-btn.on .rec-dot { background: var(--red); animation: recblink 1.2s ease-in-out infinite; }
@keyframes recblink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip.stat { height: auto; padding: 6px 10px; background: var(--fg-08); border-color: var(--fg-12); color: var(--text-dim); }
.chip.stat b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.stat { color: var(--text-dim); }
.chip.stat.warn { border-color: var(--yellow); color: var(--yellow); }
.chip.stat.warn b { color: var(--yellow); }
.ctl-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--fg-06); cursor: pointer; }
.ctl-row:last-child { border-bottom: 0; }
.ctl-row:active { background: var(--fg-06); }
.ctl-icon { width: 32px; height: 32px; border-radius: 8px; background: var(--fg-08); display: inline-flex; align-items: center; justify-content: center; color: var(--blue-soft); flex: 0 0 auto; }
.ctl-icon svg { width: 18px; height: 18px; fill: currentColor; }
.avatar-sm { width: 36px; height: 36px; border-radius: 8px; background: var(--fg-08); display: inline-flex; align-items: center; justify-content: center; overflow: hidden; font-weight: 700; font-size: 12px; color: var(--text-dim); flex: 0 0 auto; }
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.cam-stage { position: relative; background: #000; aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; }
.cam-img { width: 100%; height: 100%; object-fit: contain; }
.cam-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text-dim); }
@media (max-width: 420px) { .tabbar a span { font-size: 9.5px; } }

/* brand */
.tabbar a.active svg { filter: drop-shadow(0 0 6px rgba(229,32,43,0.55)); }
input.input:focus, textarea.input:focus { outline: none; border-color: rgba(229,32,43,0.6); box-shadow: 0 0 0 3px rgba(229,32,43,0.15); }
.topbar h1 { letter-spacing: -0.2px; font-weight: 700; }
.topbar h1 .rn { color: var(--accent); font-weight: 900; font-style: italic; margin-right: 4px; }

/* ---------- 4-tab navigation: mode switch in the top bar, Race Navigator page ---------- */
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.seg button .ico { display: none; line-height: 0; }
.seg button .ico svg { width: 18px; height: 18px; fill: currentColor; display: block; }
.topbar h1 .seg.title-seg { vertical-align: middle; }
.topbar .title-seg button { padding: 5px 11px; font-size: 12.5px; }
/* mode switch stays centred regardless of how many buttons sit left/right (it must not jump between modes) */
.topbar { position: relative; }
.topbar:has(.title-seg) h1 { position: absolute; left: 50%; top: var(--sat); height: var(--top-h); display: flex; align-items: center; transform: translateX(-50%); flex: none; overflow: visible; margin: 0; }
.topbar:has(.title-seg) #top-right { margin-left: auto; }
/* table panels: keep the header row clear of the panel title chip */
.panel:has(> .panel-body > .table-wrap table.data) .table-wrap { top: 34px; }
/* narrow phones: mode switch as icons, top-bar buttons icon-only so nothing gets clipped */
@media (max-width: 600px) {
  .topbar .title-seg button .lbl { display: none; }
  .topbar .title-seg button .ico { display: inline-flex; }
  .topbar .title-seg button { padding: 6px 14px; }
  .topbar:has(.title-seg) .tbtn .tlabel { display: none; }
  .topbar:has(.title-seg) .tbtn { padding: 6px 9px; }
  .topbar:has(.title-seg) #top-left, .topbar:has(.title-seg) #top-right { flex: 0 0 auto; }
}
.device-page h3 { margin: 18px 14px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); }
.device-page .view, .device-page .view.scroll { flex: none; min-height: 0; overflow: visible; display: block; }
.rbtn.small { width: 34px; height: 34px; }
.rbtn.small svg { width: 18px; height: 18px; }

/* ---------- session analysis in the lap list ---------- */
.filter-bar { display: flex; gap: 6px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; align-items: center; flex: 0 0 auto; }
.filter-bar::-webkit-scrollbar { display: none; }
/* mouse and trackpad: no touch scrolling and the scrollbar is hidden, so the chips wrap instead */
@media (hover: hover) and (pointer: fine) { .filter-bar { flex-wrap: wrap; overflow-x: visible; row-gap: 6px; } }
.filter-bar .chip { flex: 0 0 auto; white-space: nowrap; }
.filter-bar .chip.on { background: var(--seg-on-bg); color: var(--seg-on-fg); border-color: transparent; }
.filter-bar .sep { flex: 0 0 1px; width: 1px; height: 18px; background: var(--fg-16); margin: 0 2px; }
.lap-row .time-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.lap-row .delta { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.lap-row.outlier .time { color: var(--grey); }
.lap-row .secs { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 11.5px; color: var(--text-dim); }
.lap-row .sec b { font-weight: 600; color: var(--text-muted); margin-right: 3px; }
.lap-row .sec.best { color: var(--purple); font-weight: 700; }
.lap-row .sec.best b { color: var(--purple); }
.event-head .stats { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.event-head .stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.event-head .suggest { flex: 0 0 auto; align-self: center; }

/* ---------- guided tour ---------- */
.tour-root { position: fixed; inset: 0; z-index: 90; pointer-events: none; }
.tour-block { position: absolute; inset: 0; pointer-events: auto; }
.tour-root:has(.tour-spot.hidden) .tour-block { background: rgba(0, 0, 0, 0.62); }
.tour-spot { position: fixed; border-radius: 12px; box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.62), 0 0 0 2px var(--accent); transition: left 0.25s, top 0.25s, width 0.25s, height 0.25s; pointer-events: none; }
.tour-card {
  position: fixed; left: 12px; right: 12px; max-width: 480px; margin: 0 auto; bottom: calc(var(--tab-h) + var(--sab) + 12px);
  background: var(--sheet-bg); color: var(--text); border: 1px solid var(--panel-border); border-radius: 16px; padding: 12px 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); pointer-events: auto;
}
.tour-card.top { bottom: auto; top: calc(var(--top-h) + var(--sat) + 12px); }
.tour-card.center { bottom: auto; top: 50%; transform: translateY(-50%); }
@media (min-width: 900px) { .tour-card { left: calc(84px + 12px); } }
.tour-head { display: flex; align-items: center; justify-content: space-between; }
.tour-dots { display: flex; gap: 5px; align-items: center; }
.tour-dots i { width: 7px; height: 7px; border-radius: 4px; background: var(--fg-16); transition: width 0.2s; }
.tour-dots i.on { background: var(--accent); width: 18px; }
.tour-dots i.done { background: var(--fg-35); }
.tour-text { font-size: 15px; line-height: 1.45; margin: 10px 0 12px; }
.tour-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.tour-offer { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 20px; text-align: center; }

/* ---------- session weather ---------- */
.event-head .weather { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.badge.hr { background: rgba(229, 32, 43, 0.15); color: var(--accent); font-size: 12px; }

/* ---------- answer-first redesign ---------- */
.sel-summary .compare { min-height: 40px; padding: 0 16px; font-size: 14px; }
.sel-summary .tbtn.small { font-size: 12px; opacity: 0.8; }
.panel-title .chip { min-height: 34px; padding: 0 12px; font-size: 13px; }
.filter-bar .chip { min-height: 40px; }
.event-head .suggest { min-height: 40px; }
.more-row .lbl { color: var(--text-dim); }
.more-wrap.hidden { display: none; }
.tour-offer .btn.block { max-width: 320px; }
@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) and (min-aspect-ratio: 4/3) and (pointer: coarse) {
  .tabbar { padding-left: var(--sal); width: calc(84px + var(--sal)); } /* the notch's safe area comes on top of the rail, not out of it */
}

/* ---------- one Analyze screen: video cells ---------- */
.vcell .vhud { position: absolute; right: 6px; bottom: 6px; font-size: 12px; font-weight: 700; color: #fff; background: rgba(0, 0, 0, 0.5); padding: 2px 7px; border-radius: 6px; pointer-events: none; }
.vcell .vsound { position: absolute; right: 6px; top: 4px; width: 32px; height: 32px; border-radius: 16px; border: 0; background: rgba(0, 0, 0, 0.45); color: #fff; display: inline-flex; align-items: center; justify-content: center; }
.vcell .vsound svg { width: 18px; height: 18px; fill: currentColor; }
.videos.max { grid-template-columns: 1fr; }
.videos.max .vcell:not(.big) { display: none; }
.videos.max .vcell.big .vhud { font-size: 15px; }
.play-bar .rewind { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 700; }
.play-bar .rewind svg { width: 18px; height: 18px; }
@media (max-width: 700px) { .play-bar .small { display: none; } .play-bar .rewind span:last-child { display: none; } }

/* big video: keep the picture's shape, no black bars */
.videos.max { display: flex; justify-content: center; height: 100%; }
.videos.max .vcell.big { height: 100%; aspect-ratio: 16 / 9; width: auto; max-width: 100%; min-height: 0; } /* the inline aspect-ratio set from the video's metadata overrides 16:9 */
.videos.max .vcell.big video { object-fit: contain; }
/* selection bar on phones: the dots say how many, the button says what next */
.sel-summary .count { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) { .sel-summary .count { display: none; } .sel-summary .dots { margin-right: auto; } .sel-summary .compare { flex: 1; } }

/* ---------- floating glass tab bar (data-glass on <html>; phones/portrait only, the side rail keeps its shape) ---------- */
:root { --glass-bg: rgba(255, 255, 255, 0.78); --glass-border: rgba(255, 255, 255, 0.65); --glass-hi: rgba(255, 255, 255, 0.85); --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.18); --tabspace: calc(var(--tab-h) + var(--sab) + 22px); }
:root[data-theme="dark"] { --glass-bg: rgba(22, 24, 30, 0.72); --glass-border: rgba(255, 255, 255, 0.14); --glass-hi: rgba(255, 255, 255, 0.12); --glass-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); }
:root[data-glass] .tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--sab) + 10px); height: var(--tab-h); padding: 0 6px;
  border-radius: 30px; border: 1px solid var(--glass-border); border-top-color: var(--glass-hi);
  background: var(--glass-bg); backdrop-filter: blur(22px) saturate(160%); -webkit-backdrop-filter: blur(22px) saturate(160%);
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--glass-shadow); z-index: 30;
}
:root[data-glass] .tabbar a { position: relative; z-index: 1; border-radius: 22px; margin: 6px 2px; }
.tabbar .pill { position: absolute; top: 6px; height: calc(100% - 12px); left: 0; width: 0; border-radius: 22px; background: var(--fg-12); opacity: 0; pointer-events: none;
  transition: left 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), width 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.18s ease, background 0.18s ease; }
:root[data-glass] .tabbar.pressing .pill { transform: scale(1.06, 1.1); background: var(--fg-20); }
:root[data-glass] .tabbar.pressing a { transition: transform 0.18s ease; }
.tabbar { touch-action: none; }
/* content runs behind the floating bar: scrolling views get room at the end, fixed layouts stop above it */
:root[data-glass] .view.scroll, :root[data-glass] .scroll.grow { padding-bottom: var(--tabspace); }
:root[data-glass] .analyzer { margin-bottom: calc(var(--tab-h) + var(--sab) + 18px); }
:root[data-glass] .toast { bottom: calc(var(--tabspace) + 6px); }
:root[data-glass] .tour-card:not(.top):not(.center) { bottom: calc(var(--tabspace) + 4px); }
:root[data-glass] .update-banner { position: relative; }
}

/* ---------- corner coach ---------- */
.coach { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.coach-head { font-size: 13px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.coach-head .gap { margin-left: auto; font-size: 15px; }
.panel .coach-head { padding-right: 120px; }
.vlabel .vtime { font-weight: 400; opacity: 0.85; }
.diag-pre { margin: 0; padding: 8px 16px; font-size: 11px; line-height: 1.4; white-space: pre-wrap; word-break: break-all; max-height: 55vh; overflow: auto; user-select: text; } /* the floating panel title chip sits top right */
.event-head .session-delete { color: var(--text-dim); flex: 0 0 auto; }
.coach .lost { color: var(--accent); } .coach .gained { color: var(--green); }
.coach-narrative { font-size: 14px; line-height: 1.45; padding: 10px 12px; border-radius: 12px; background: var(--fg-06); }
.coach-note { min-height: 14px; }
.coach-list { display: flex; flex-direction: column; gap: 4px; }
.coach-row { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--fg-08); cursor: pointer; }
.coach-row:active { background: var(--fg-06); }
.coach-row .whatif { margin-top: 3px; color: var(--green); }
.sel-hint { padding: 4px 10px 6px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--panel-border); }
.coach-row.current { border-color: var(--accent); background: rgba(229, 32, 43, 0.08); }
.coach-row .row.between { font-size: 14px; }
