:root {
  --bg: #090c11;
  --panel: #10151c;
  --panel-2: #151b24;
  --panel-3: #1b2330;
  --line: #222b37;
  --line-2: #2c3746;
  --text: #e9eef4;
  --muted: #8d99a8;
  --dim: #5b6676;
  --accent: #ff3b30;
  --green: #30d158;
  --purple: #c26bff;
  --yellow: #ffd60a;
  --orange: #ff9f0a;
  --blue: #0a84ff;
  --cyan: #64d2ff;
  --cold: #4aa8ff;
  --font: "Titillium Web", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.hidden { display: none !important; }
a { color: var(--cyan); }
small { font-size: 0.82em; }

/* ------------------------------------------------------------------ buttons */
.btn {
  background: var(--panel-3);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: #222c3a; border-color: #3a4757; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff554b; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.on { background: rgba(48, 209, 88, 0.16); border-color: var(--green); color: var(--green); }
.btn.box { background: rgba(255, 59, 48, 0.18); border-color: var(--accent); color: #ff8a82; }
.btn.push { border-color: var(--purple); color: #dcb3ff; }
.btn.save { border-color: var(--cyan); color: var(--cyan); }
.btn.warn { border-color: var(--yellow); color: var(--yellow); }

input[type=text], input[type=password], input[type=number], select {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 7px 10px;
  outline: none;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--blue); }
input[type=range] { accent-color: var(--accent); }

/* ------------------------------------------------------------------ join page */
.join-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.join-card { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: 0.04em; }
.brand .mark { width: 28px; height: 28px; border-radius: 6px; background: linear-gradient(135deg, var(--accent), #ff7a59); display: grid; place-items: center; }
.brand .mark svg { width: 18px; height: 18px; }
.join-card h1 { font-size: 15px; font-weight: 400; color: var(--muted); margin: 8px 0 22px; }
.role-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 18px; }
.role-tabs button { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 6px; cursor: pointer; text-align: center; }
.role-tabs button b { display: block; font-size: 14px; }
.role-tabs button span { font-size: 11px; color: var(--muted); }
.role-tabs button.active { border-color: var(--accent); background: rgba(255, 59, 48, 0.1); }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.field input { width: 100%; }
.join-card .hint { font-size: 12.5px; color: var(--muted); margin-top: 14px; }
.join-card .hint code { background: var(--panel-3); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.err { color: #ff7b72; font-size: 13px; min-height: 18px; margin-top: 8px; }

/* ------------------------------------------------------------------ app shell */
body.app { display: grid; grid-template-rows: auto 1fr; height: 100vh; overflow: hidden; }
.top {
  display: flex; align-items: center; gap: 14px; padding: 0 12px; height: 48px;
  background: var(--panel); border-bottom: 1px solid var(--line); min-width: 0; overflow-x: auto; scrollbar-width: none;
}
.top::-webkit-scrollbar { display: none; }
.top .brand { font-size: 15px; }
.top .brand .mark { width: 22px; height: 22px; }
.top .sep { width: 1px; height: 22px; background: var(--line-2); flex: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 13px; }
.chip .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.chip b { font-weight: 700; }
.team-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--panel-3); font-weight: 600; font-size: 13px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--dim); }
.dot.live { background: var(--green); box-shadow: 0 0 0 3px rgba(48, 209, 88, 0.18); }
.dot.warn { background: var(--yellow); }
.dot.off { background: var(--dim); }
.spacer { flex: 1; }
.flag-chip { padding: 2px 8px; border-radius: 4px; font-weight: 700; font-size: 12px; letter-spacing: 0.06em; }
.flag-1 { background: #0a5bd6; color: #fff; }
.flag-2 { background: var(--yellow); color: #000; }
.flag-3 { background: #000; color: #fff; border: 1px solid #fff; }
.flag-4 { background: #fff; color: #000; }
.flag-5 { background: repeating-conic-gradient(#fff 0 25%, #000 0 50%) 0 0 / 10px 10px; color: transparent; width: 34px; }
.flag-6 { background: #000; color: var(--orange); border: 1px solid var(--orange); }

.grid {
  display: grid; gap: 8px; padding: 8px; min-height: 0;
  grid-template-columns: minmax(370px, 430px) minmax(400px, 1fr) minmax(330px, 380px);
  grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
  grid-template-areas: "timing map car" "radio pace strategy";
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.panel-h { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-height: 38px; flex: none; }
.panel-h h2 { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.panel-h .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.panel-b { padding: 10px 12px; overflow: auto; min-height: 0; flex: 1; }
#timing { grid-area: timing; }
#mapPanel { grid-area: map; }
#carPanel { grid-area: car; }
#radioPanel { grid-area: radio; }
#pacePanel { grid-area: pace; }
#strategyPanel { grid-area: strategy; }

@media (max-width: 1250px) {
  body.app { height: auto; overflow: auto; }
  .grid { grid-template-columns: 1fr 1fr; grid-template-rows: none; grid-auto-rows: minmax(380px, auto);
    grid-template-areas: "map map" "timing car" "radio strategy" "pace pace"; }
  #mapPanel { min-height: 460px; }
}
@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; grid-template-areas: "map" "timing" "car" "strategy" "radio" "pace"; padding: 6px; }
  #mapPanel { min-height: 360px; }
}

/* listener mode: radio scanner only */
body.listener .grid { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "radio"; max-width: 760px; margin: 0 auto; width: 100%; }
body.listener #timing, body.listener #mapPanel, body.listener #carPanel, body.listener #pacePanel, body.listener #strategyPanel,
body.listener .team-only { display: none !important; }

/* ------------------------------------------------------------------ timing tower */
.tower { font-size: 13px; }
.tower-head, .trow {
  display: grid; align-items: center; gap: 5px;
  grid-template-columns: 20px 3px minmax(84px, 1fr) 34px 22px 48px 46px 60px 16px;
  padding: 0 8px;
}
.tower-head { color: var(--dim); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; height: 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.trow { height: 30px; border-bottom: 1px solid rgba(34, 43, 55, 0.6); cursor: pointer; }
.trow:hover { background: var(--panel-2); }
.trow.me { background: rgba(255, 59, 48, 0.12); box-shadow: inset 3px 0 0 var(--accent); }
.trow.sel { background: rgba(10, 132, 255, 0.12); }
.trow.inpit { opacity: 0.62; }
.trow .pos { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.trow .stripe { width: 3px; height: 18px; border-radius: 2px; background: var(--line-2); }
.trow .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; }
.trow .name small { color: var(--dim); font-weight: 400; margin-left: 5px; }
.trow .tyre { display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.trow .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trow .int.close { color: var(--green); font-weight: 700; }
.trow .last.pb { color: var(--green); }
.trow .last.fl { color: var(--purple); font-weight: 700; }
.trow .ico { color: var(--dim); display: grid; place-items: center; }
.trow .ico.team { color: var(--muted); }
.trow .ico.tuned { color: var(--green); }
.trow .ico svg { width: 14px; height: 14px; }
.badge { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 3px; letter-spacing: 0.04em; }
.badge.pit { background: var(--yellow); color: #000; }
.badge.fin { background: #fff; color: #000; }

/* tyre compound ring */
.cmp { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--muted); font-size: 9px; font-weight: 800; font-style: normal; color: var(--text); flex: none; }
.cmp.lg { width: 30px; height: 30px; font-size: 12px; border-width: 4px; }

/* ------------------------------------------------------------------ map */
#mapPanel .panel-b { padding: 0; position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.live-strip { display: flex; align-items: center; gap: 14px; padding: 6px 12px; border-bottom: 1px solid var(--line); flex: none; overflow-x: auto; scrollbar-width: none; }
.live-strip::-webkit-scrollbar { display: none; }
.ls { display: grid; line-height: 1.1; white-space: nowrap; }
.ls .k { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; }
.ls .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ls .v small { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.ls.gear .v { font-size: 26px; width: 22px; text-align: center; }
.pedals { display: flex; gap: 3px; height: 34px; align-items: flex-end; }
.pedals .bar { width: 8px; height: 100%; background: var(--panel-3); border-radius: 2px; position: relative; overflow: hidden; }
.pedals .bar i { position: absolute; left: 0; right: 0; bottom: 0; height: 0; }
.pedals .thr i { background: var(--green); }
.pedals .brk i { background: var(--accent); }
.rpm { width: 110px; height: 6px; background: var(--panel-3); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.rpm i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green) 0 70%, var(--yellow) 70% 88%, var(--accent) 88%); }
.delta.pos { color: var(--accent); }
.delta.neg { color: var(--green); }
.map-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); text-align: center; padding: 20px; pointer-events: none; }
.map-legend { position: absolute; left: 10px; bottom: 8px; font-size: 11px; color: var(--dim); pointer-events: none; }

/* ------------------------------------------------------------------ car panel */
.tyres { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tyre-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: grid; gap: 5px; }
.tyre-card .row1 { display: flex; justify-content: space-between; align-items: baseline; }
.tyre-card .corner { font-size: 10.5px; color: var(--dim); letter-spacing: 0.1em; font-weight: 700; }
.tyre-card .core { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tyre-card .core small { font-size: 12px; color: var(--muted); }
.imo { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.imo span { height: 18px; border-radius: 3px; font-size: 10.5px; display: grid; place-items: center; color: #061018; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.kv b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.lifebar { height: 5px; background: var(--panel-3); border-radius: 3px; overflow: hidden; }
.lifebar i { display: block; height: 100%; background: var(--green); }
.section-t { font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; margin: 12px 0 6px; display: flex; align-items: center; gap: 8px; }
.section-t:first-child { margin-top: 0; }
.section-t .r { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
.stat .k { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; }
.stat .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 11px; color: var(--muted); font-weight: 400; }
.stat.good .v { color: var(--green); }
.stat.bad .v { color: var(--accent); }
.stat.warn .v { color: var(--yellow); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.echip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 8px; font-size: 12px; color: var(--muted); }
.echip b { color: var(--text); font-variant-numeric: tabular-nums; }
.echip.active { border-color: var(--yellow); color: var(--yellow); }
.damage { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.damage div { font-size: 10.5px; color: var(--dim); text-align: center; }
.damage .bar { height: 5px; background: var(--panel-3); border-radius: 3px; margin-top: 3px; overflow: hidden; }
.damage .bar i { display: block; height: 100%; width: 0; background: var(--orange); }

/* ------------------------------------------------------------------ strategy */
.callout { border-radius: 8px; padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--line); margin-bottom: 8px; }
.callout .t { font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.callout .big { font-size: 18px; font-weight: 700; margin-top: 2px; }
.callout.alert { border-color: rgba(255, 59, 48, 0.6); background: rgba(255, 59, 48, 0.08); }
.callout.ok { border-color: rgba(48, 209, 88, 0.5); background: rgba(48, 209, 88, 0.06); }
.rival { display: grid; grid-template-columns: 52px 1fr auto; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.rival:last-child { border-bottom: 0; }
.rival .lbl { font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
.rival .nm { font-weight: 600; }
.rival .sub { font-size: 12px; color: var(--muted); }
.rival .gapv { font-size: 18px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.good { color: var(--green); }
.bad { color: var(--accent); }
.warn { color: var(--yellow); }
details.cfg summary { cursor: pointer; color: var(--muted); font-size: 12.5px; margin-top: 10px; }
.cfg-grid { display: grid; grid-template-columns: 1fr 90px; gap: 6px 10px; align-items: center; margin-top: 8px; font-size: 12.5px; color: var(--muted); }
.cfg-grid input { width: 100%; padding: 4px 8px; }

/* ------------------------------------------------------------------ pace */
.pace-wrap { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; height: 100%; min-height: 0; }
.chart-box { position: relative; min-height: 180px; }
.chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.laps-table { overflow: auto; min-height: 0; }
table.laps { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.laps th { text-align: right; color: var(--dim); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 6px; position: sticky; top: 0; background: var(--panel); }
table.laps td { text-align: right; padding: 4px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
table.laps td:first-child, table.laps th:first-child { text-align: left; }
table.laps tr.invalid td { color: var(--dim); text-decoration: line-through; }
table.laps tr.pit td:first-child::after { content: " PIT"; color: var(--yellow); font-size: 10px; font-weight: 700; }
td.sb { color: var(--purple); font-weight: 700; }
td.best { color: var(--green); font-weight: 700; }
@media (max-width: 1250px) { .pace-wrap { grid-template-columns: 1fr; } .chart-box { min-height: 220px; } }

/* ------------------------------------------------------------------ radio */
.radio-top { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }
.ptt {
  user-select: none; -webkit-user-select: none; touch-action: none;
  border: 1px solid var(--line-2); border-radius: 10px; background: var(--panel-2);
  padding: 12px; text-align: center; cursor: pointer; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  transition: background 0.1s, border-color 0.1s;
}
.ptt small { display: block; font-weight: 400; color: var(--muted); letter-spacing: 0; text-transform: none; font-size: 12px; }
.ptt.tx { background: rgba(255, 59, 48, 0.22); border-color: var(--accent); }
.ptt.disabled { opacity: 0.6; }
.meter { height: 4px; background: var(--panel-3); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.06s; }
.channels { display: grid; gap: 4px; margin-bottom: 10px; }
.chan { display: grid; grid-template-columns: 10px minmax(0, 1fr) 70px auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); }
.chan .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 13px; }
.chan .nm small { color: var(--dim); font-weight: 400; margin-left: 4px; }
.chan.talking { border-color: var(--green); box-shadow: 0 0 0 1px rgba(48, 209, 88, 0.3) inset; }
.chan.talking .nm::after { content: " ● LIVE"; color: var(--green); font-size: 10px; font-weight: 700; }
.chan input[type=range] { width: 100%; }
.pitboard { display: grid; gap: 6px; margin-bottom: 10px; }
.pitboard .quick { display: flex; flex-wrap: wrap; gap: 5px; }
.pitboard form { display: flex; gap: 6px; }
.pitboard form input { flex: 1; text-transform: uppercase; }
.log { display: grid; gap: 3px; }
.log-item { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 5px; font-size: 12.5px; }
.log-item:hover { background: var(--panel-2); }
.log-item .bar { width: 4px; height: 26px; border-radius: 2px; }
.log-item .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-item .who b { font-weight: 600; }
.log-item .who small { color: var(--dim); display: block; }
.log-item .play { background: none; border: 1px solid var(--line-2); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; cursor: pointer; padding: 0; }
.log-item .play svg { width: 10px; height: 10px; }
.log-item.pb .bar { background: var(--yellow) !important; }
.empty { color: var(--dim); font-size: 12.5px; padding: 8px 0; }

.banner {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 50;
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px);
}
.toast-area { position: fixed; right: 14px; top: 58px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--panel-3); border: 1px solid var(--line-2); border-left: 3px solid var(--blue); border-radius: 8px; padding: 8px 12px; font-size: 13px; max-width: 320px; animation: fadein 0.2s; }
.toast.err { border-left-color: var(--accent); }
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; } }

/* ------------------------------------------------------------------ driver page */
body.driver { display: grid; grid-template-rows: auto 1fr; height: 100vh; overflow: hidden; }
.drv { display: grid; grid-template-rows: auto 1fr auto; gap: 12px; padding: 14px; min-height: 0; max-width: 820px; width: 100%; margin: 0 auto; }
.drv-status { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.drv-main { display: grid; gap: 12px; align-content: start; min-height: 0; overflow: auto; }
.eng-light {
  border-radius: 14px; border: 1px solid var(--line); background: var(--panel); padding: 22px; text-align: center;
  font-size: 15px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--dim); font-weight: 700; transition: all 0.1s;
}
.eng-light.on { background: rgba(48, 209, 88, 0.15); border-color: var(--green); color: var(--green); }
.board { border-radius: 14px; background: #000; border: 1px solid var(--line); padding: 18px; text-align: center; min-height: 110px; display: grid; place-items: center; }
.board .txt { font-size: clamp(26px, 7vw, 54px); font-weight: 800; letter-spacing: 0.04em; color: #fff; line-height: 1.05; }
.board.box .txt { color: var(--accent); animation: blink 0.8s steps(2) infinite; }
.board .when { font-size: 12px; color: var(--dim); margin-top: 6px; }
@keyframes blink { 50% { opacity: 0.35; } }
.dash { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dash .stat .v { font-size: 22px; }
.drv-ptt { padding: 26px 12px; font-size: 18px; border-radius: 16px; }
.drv-controls { display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--panel-2); padding: 3px; border-radius: 8px; }
.seg button { background: none; border: 0; border-radius: 6px; padding: 7px 4px; cursor: pointer; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--panel-3); color: var(--text); font-weight: 600; }
.ctl-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); }
@media (max-width: 560px) { .dash { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .top .brand-text, .top .sep { display: none; } .top { gap: 10px; } }

/* ------------------------------------------------------------------ sectors / delta / grip */
.secbar { display: flex; gap: 2px; align-items: center; }
.secbar i { width: 6px; height: 12px; border-radius: 1.5px; background: #222b37; }
td.sg { color: var(--green); font-weight: 700; }
td.lp { color: var(--purple); font-weight: 700; }
td.lg { color: var(--green); font-weight: 700; }

.ls.limit canvas { width: 64px; height: 34px; display: block; }
.ls .v.delta { min-width: 74px; }

.map-modes { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px; background: rgba(16, 21, 28, 0.9); border: 1px solid var(--line); border-radius: 7px; padding: 2px; z-index: 2; }
.map-modes button { background: none; border: 0; border-radius: 5px; padding: 4px 10px; font-size: 12px; color: var(--muted); cursor: pointer; }
.map-modes button.active { background: var(--panel-3); color: var(--text); font-weight: 600; }
.map-heat-legend { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; pointer-events: none; }
.map-heat-legend .grad { width: 110px; height: 6px; border-radius: 3px; }

.tabs { display: flex; gap: 2px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 4px 8px 5px; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); cursor: pointer; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
#refBar select { padding: 3px 6px; font-size: 12px; max-width: 170px; }
#pacePanel .panel-b { display: flex; flex-direction: column; }
.tab { flex: 1; min-height: 0; }

.delta-wrap { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; height: 100%; }
.delta-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.delta-big { display: grid; line-height: 1.1; min-width: 150px; }
.delta-big .k { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; }
.delta-big .v { font-size: 30px; font-weight: 800; }
.delta-big .muted { font-size: 12px; }
.delta-big .v.pos, .sec-cmp .pos { color: var(--accent); }
.delta-big .v.neg, .sec-cmp .neg { color: var(--green); }
table.sec-cmp { border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; flex: 1; min-width: 300px; }
table.sec-cmp th { color: var(--dim); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right; padding: 2px 8px; }
table.sec-cmp td { text-align: right; padding: 2px 8px; border-top: 1px solid var(--line); white-space: nowrap; }
table.sec-cmp td:first-child, table.sec-cmp th:first-child { text-align: left; color: var(--muted); }
table.sec-cmp td.st-p { color: var(--purple); font-weight: 700; }
table.sec-cmp td.st-g { color: var(--green); font-weight: 700; }
table.sec-cmp td.st-y { color: var(--yellow); }
table.sec-cmp td.live { font-style: italic; }
#tab-delta .chart-box { min-height: 220px; }

.grip-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; height: 100%; }
.grip-col { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 8px; min-height: 0; }
.arc-box { min-height: 150px; }
.gg-box { min-height: 200px; }
.grip-stats { grid-template-columns: repeat(3, 1fr); }
.grip-help { margin: 0; font-size: 11.5px; color: var(--dim); line-height: 1.45; }
@media (max-width: 1250px) { .grip-wrap { grid-template-columns: 1fr; } #pacePanel { min-height: 520px; } }

/* ------------------------------------------------------------------ pit plan */
.pit-plan { display: grid; gap: 6px; }
.stop { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; display: grid; gap: 6px; font-size: 12.5px; }
.stop.next { border-color: rgba(255, 159, 10, 0.7); }
.stop.boxnow { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(255, 59, 48, 0.35) inset; }
.stop.done { opacity: 0.72; }
.stop-h { display: flex; align-items: center; gap: 6px; }
.stop-h b { font-size: 13px; }
.stop-h .when { margin-left: auto; color: var(--muted); }
.stop-h .x { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 14px; padding: 0 2px; }
.stop-h .x:hover { color: var(--accent); }
.stop input[type=number] { width: 58px; padding: 3px 6px; }
.stop select { padding: 3px 6px; }
.stop-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); }
.stop-row .res { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.stop-row label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.stop-status { font-size: 12px; }
.stop-status.ok { color: var(--green); }
.stop-status.bad { color: var(--accent); }
.stop-status.warn { color: var(--yellow); }
.plan-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.auto-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.auto-toggle.disabled { opacity: 0.5; cursor: not-allowed; }
.badge.exp { background: rgba(255, 214, 10, 0.15); color: var(--yellow); border: 1px solid rgba(255, 214, 10, 0.4); }
.plan-note { font-size: 12px; color: var(--dim); margin-top: 4px; }
.plan-note.warn { color: var(--yellow); }
.next-stop { border-radius: 14px; border: 1px solid var(--line); background: var(--panel); padding: 12px 16px; display: grid; gap: 2px; }
.next-stop .t { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }
.next-stop .v { font-size: 20px; font-weight: 700; }
.next-stop.boxnow { border-color: var(--accent); background: rgba(255, 59, 48, 0.12); }
.next-stop.boxnow .v { color: #ff8a82; }

/* ------------------------------------------------------------------ map zoom + racing line */
.map-zoom { position: absolute; top: 44px; right: 8px; display: grid; gap: 2px; background: rgba(16, 21, 28, 0.9); border: 1px solid var(--line); border-radius: 7px; padding: 2px; z-index: 2; }
.map-zoom button { width: 28px; height: 26px; background: none; border: 0; border-radius: 5px; color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; }
.map-zoom button:hover { background: var(--panel-3); color: var(--text); }
.map-zoom button.active { background: var(--panel-3); color: var(--cyan); }
.map-line-bar { position: absolute; left: 8px; top: 8px; right: 210px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 11.5px; color: var(--muted); background: rgba(16, 21, 28, 0.88); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; z-index: 2; width: fit-content; max-width: calc(100% - 230px); }
.map-line-bar .lk { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.map-line-bar .lk i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.map-line-bar .lk.pin { color: var(--text); }
.map-line-bar .lk .x { background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 14px; padding: 0 2px; line-height: 1; }
.map-line-bar .lk .x:hover { color: var(--accent); }
.map-line-bar #linePins { display: contents; }
.map-line-bar .btn:disabled { opacity: 0.4; cursor: default; }
.map-edge { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: rgba(9, 12, 17, 0.88); border: 1px solid var(--line-2); border-radius: 18px; padding: 4px 14px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; z-index: 2; pointer-events: none; }
.map-edge b { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.map-edge .close { color: var(--yellow); }
.map-edge .over { color: var(--accent); }
.corner-toast { position: absolute; left: 10px; bottom: 30px; max-width: min(360px, 60%); display: flex; gap: 10px; align-items: center; background: rgba(9, 12, 17, 0.92); border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 12px; z-index: 3; font-size: 12.5px; }
.corner-toast > b { font-size: 26px; font-variant-numeric: tabular-nums; min-width: 38px; text-align: center; }
.corner-toast span { display: grid; gap: 1px; color: var(--muted); }
.corner-toast span b { color: var(--text); }
#map { cursor: grab; }
#map:active { cursor: grabbing; }

/* ------------------------------------------------------------------ corners tab */
.corners-wrap { display: grid; grid-template-rows: auto 1fr; gap: 10px; height: 100%; min-height: 0; }
.corners-head { display: grid; grid-template-columns: repeat(3, minmax(90px, 140px)) 1fr; gap: 6px; align-items: center; }
.corners-note { font-size: 11.5px; margin: 0 0 0 8px; }
.corners-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 12px; min-height: 0; }
.corners-table-box { overflow: auto; min-height: 0; }
table.corners { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.corners th { color: var(--dim); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right; padding: 3px 6px; position: sticky; top: 0; background: var(--panel); }
table.corners th:first-child { text-align: left; }
table.corners td { padding: 3px 6px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.corners td.cn { text-align: left; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
table.corners td.cn .dir { color: var(--dim); }
table.corners tbody tr { cursor: pointer; }
table.corners tbody tr:hover { background: var(--panel-2); }
table.corners tbody tr.sel { background: var(--panel-3); }
table.corners .score { font-weight: 700; }
.corner-detail { min-width: 0; overflow: auto; }
.cd-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
table.cd { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.cd th { color: var(--dim); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; text-align: right; padding: 2px 6px; }
table.cd td { padding: 3px 6px; border-top: 1px solid var(--line); text-align: right; }
table.cd td:first-child, table.cd th:first-child { text-align: left; color: var(--muted); }
table.cd td.verdict { font-size: 11.5px; color: var(--text); text-align: left; vertical-align: top; }
table.cd .pos { color: var(--accent); }
table.cd .neg { color: var(--green); }
.cd-parts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px; margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.cd-parts .part { display: grid; grid-template-columns: 64px 1fr 30px; align-items: center; gap: 6px; text-transform: capitalize; }
.cd-parts .part i { height: 5px; border-radius: 3px; background: var(--panel-3); overflow: hidden; display: block; }
.cd-parts .part i b { display: block; height: 100%; }
.cd-parts .part em { font-style: normal; text-align: right; color: var(--text); }
@media (max-width: 1250px) { .corners-grid { grid-template-columns: 1fr; } }

/* live gap to the selected driver (live strip) */
.ls.selgap { padding-left: 12px; border-left: 1px solid var(--line); min-width: 120px; }
.ls.selgap.active .k { color: var(--blue); }
.ls.selgap .v { display: flex; align-items: baseline; gap: 8px; }
.ls.selgap .ahead { color: var(--orange); }
.ls.selgap .behind { color: var(--cyan); }
.ls.selgap .tr { font-size: 11px; font-weight: 600; color: var(--muted); }
.ls.selgap .tr.good { color: var(--green); }
.ls.selgap .tr.bad { color: var(--accent); }
.ghost-t { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; text-transform: none; letter-spacing: 0; }
.ghost-t input { margin: 0; accent-color: var(--accent); }

/* ------------------------------------------------------------------ car systems: trail modes, battery, engine, damage, events */
.map-line-bar .trail-modes { display: inline-flex; gap: 2px; background: var(--panel-2); border-radius: 6px; padding: 2px; }
.map-line-bar .trail-modes button { background: none; border: 0; border-radius: 4px; padding: 2px 7px; font-size: 11px; color: var(--muted); cursor: pointer; }
.map-line-bar .trail-modes button.active { background: var(--panel-3); color: var(--text); font-weight: 600; }
.map-line-bar #trailKeys { display: contents; }
.echip.open { border-color: var(--green); color: var(--green); }
.echip.off { opacity: 0.6; }
.toast.warn { border-left-color: var(--yellow); }
.ebar { position: relative; height: 22px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; display: flex; align-items: center; gap: 8px; padding: 0 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.ebar > i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--green); opacity: 0.35; transition: width 0.2s; }
.ebar .lbl, .ebar .st { position: relative; }
.ebar .lbl { font-weight: 700; }
.ebar .st { margin-left: auto; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ebar .st.dep { color: var(--yellow); }
.ebar .st.chg { color: var(--green); }
.ebar.thin { height: 18px; margin-top: 5px; }
.ebar.thin > i { background: var(--yellow); opacity: 0.3; }
.ebar.thin .lbl { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.elaps { margin-top: 6px; display: grid; gap: 2px; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.elaps b { color: var(--text); font-weight: 600; }
.elaps .trend { color: var(--text); }
.elaps .trend.neg { color: var(--yellow); }
.susp { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 6px; }
.susp div { font-size: 10.5px; color: var(--dim); text-align: center; }
.susp .bar { height: 5px; background: var(--panel-3); border-radius: 3px; margin-top: 3px; overflow: hidden; }
.susp .bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.dmg-hint { margin-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--yellow); background: rgba(255, 214, 10, 0.07); border: 1px solid rgba(255, 214, 10, 0.3); border-radius: 6px; padding: 6px 8px; }
.dmg-hint .btn { margin-left: auto; }
.sys-log { display: grid; gap: 3px; font-size: 12px; }
.sys-log .ev { display: grid; grid-template-columns: 30px 1fr; gap: 6px; color: var(--muted); }
.sys-log .ev.warn { color: var(--text); }
.sys-log .ev .lap { color: var(--dim); font-variant-numeric: tabular-nums; }
.sys-log .ev.warn .lap { color: var(--yellow); }

/* ------------------------------------------------------------------ penalties */
.ls.pen .k { color: var(--accent); }
.ls.pen .v { color: var(--accent); }
.dt-tag, .pen-tag { display: inline-block; margin-left: 5px; padding: 0 4px; border-radius: 3px; font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em; line-height: 14px; vertical-align: 1px; background: rgba(255, 59, 48, 0.16); color: #ff8a82; border: 1px solid rgba(255, 59, 48, 0.4); }

/* ------------------------------------------------------------------ team cars and seats */
.car-seg { grid-template-columns: 1fr 1fr; }
.field small { font-size: 11.5px; }
.car-switch { display: inline-flex; gap: 2px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.car-switch button { display: inline-flex; align-items: center; gap: 5px; background: none; border: 0; border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.car-switch button:hover { color: var(--text); }
.car-switch button.active { background: var(--panel-3); color: var(--text); }
.car-switch button i { font-style: normal; font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em; padding: 0 4px; border-radius: 3px; background: var(--panel-3); color: var(--muted); }
.car-switch button i.you { background: rgba(100, 210, 255, 0.15); color: var(--cyan); }
.car-switch button i.pen { background: rgba(255, 59, 48, 0.18); color: #ff8a82; }
.car-switch .dot { width: 7px; height: 7px; }
.view-chip { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.view-chip.locked { background: rgba(255, 214, 10, 0.1); color: var(--yellow); border: 1px solid rgba(255, 214, 10, 0.35); }
.view-chip.cover { background: rgba(48, 209, 88, 0.1); color: var(--green); border: 1px solid rgba(48, 209, 88, 0.35); }
/* looking at the other car while it has its own engineer: controls that would change it are off */
body.readonly .pitboard, body.readonly .pit-plan, body.readonly .plan-actions, body.readonly #cfgForm, body.readonly .dmg-hint .btn { opacity: 0.45; pointer-events: none; }
.talk-to { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.talk-to .k { font-size: 10.5px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; margin-right: 4px; }
.talk-to button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; }
.talk-to button.active { border-color: var(--accent); color: var(--text); background: rgba(255, 59, 48, 0.1); }
.chan.own { border-color: var(--line-2); }
.invited { background: rgba(48, 209, 88, 0.08); border: 1px solid rgba(48, 209, 88, 0.35); color: var(--text); border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; }

/* ------------------------------------------------------------------ invite dialog */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; z-index: 80; padding: 16px; }
.modal-card { width: 100%; min-width: 0; max-width: 620px; overflow-x: hidden; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; }
.modal-h { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-h h2 { margin: 0; font-size: 15px; }
.modal-h .x { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-b { padding: 14px 16px; display: grid; gap: 12px; font-size: 13px; }
.modal-b p { margin: 0; }
.inv-car { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; background: var(--panel-2); }
.inv-car h3 { margin: 0; font-size: 13px; }
.inv-row { display: grid; gap: 4px; }
.inv-k { font-size: 12px; color: var(--muted); }
.inv-k small { margin-left: 6px; color: var(--dim); overflow-wrap: anywhere; }
.inv-car, .inv-row, .inv-v { min-width: 0; }
.inv-v .btn { flex: none; }
.inv-warn { overflow-wrap: anywhere; }
.inv-v { display: flex; gap: 6px; }
.inv-val { flex: 1; min-width: 0; font-family: var(--mono); font-size: 11.5px; }
.inv-warn { background: rgba(255, 214, 10, 0.08); border: 1px solid rgba(255, 214, 10, 0.35); color: var(--yellow); border-radius: 8px; padding: 8px 10px; }
.inv-foot { color: var(--muted); }
.inv-foot a { color: var(--cyan); }
