/* RACE page: live race-engineer dashboard. Shares the tokens, header and
   card look of style.css; laid out as one row of panels on very wide
   screens (Xeneon Edge 2560×720) and as a wrapping grid elsewhere. */

body.race-page { background: var(--bg); }
.race-page a.chip { text-decoration: none; }
.rv-who { font-size: 12px; color: var(--dim); font-weight: 600; }
.rv-who b { color: var(--text); }
#rv-sender {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; font-family: inherit; font-size: 12px; padding: 3px 8px;
}

/* safety car / VSC / pit banner */
.rv-flag {
  text-align: center; font-weight: 800; font-style: italic;
  letter-spacing: 4px; font-size: 15px; padding: 3px 0;
}
.rv-flag.sc { background: #facc15; color: #1a1400; }
.rv-flag.pit { background: #1d4ed8; color: #fff; }

/* Panels are switchable (header chips, remembered). Wide screens: one
   row, each panel's share set by --w so the tyres get the most room.
   16:9: tyres on the left at full height, the rest stacked on the right.
   Narrow: one scrolling column. */
#rv-grid {
  flex: 1; min-height: 0; gap: 12px; padding: 16px 14px 12px;
  display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr); overflow: auto;
}
#rv-grid > .rv-panel { grid-column: 2; }
#rv-standing, #rv-fuel { justify-content: space-between; }
#rv-grid > #rv-tyres { grid-column: 1; }
#rv-grid.solo { grid-template-columns: minmax(0, 1fr); }
#rv-grid.no-tyres { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
#rv-grid.no-tyres > .rv-panel { grid-column: auto; }
.rv-panel.off { display: none !important; }
#rv-standing { --w: 1; }
#rv-tyres { --w: 2.6; }
#rv-fuel { --w: 1; }
#rv-damage { --w: 1; }
#rv-drive { --w: .8; }
@media (min-aspect-ratio: 12/5) {
  #rv-grid, #rv-grid.no-tyres, #rv-grid.solo { display: flex; overflow: hidden; }
  #rv-grid > .rv-panel { flex: var(--w) 1 0; }
}
@media (max-width: 1100px) and (max-aspect-ratio: 12/5) {
  #rv-grid, #rv-grid.no-tyres { grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; }
  #rv-grid > .rv-panel { grid-column: 1 !important; grid-row: auto !important; }
  #rv-tyres { min-height: 520px; }
  #rv-drive { min-height: 260px; }
}

/* panel switches in the header */
.rv-panels button { padding: 6px 12px; }

.rv-panel {
  position: relative; min-width: 0; min-height: 0;
  padding: 16px 14px 12px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.022) 0 2px, transparent 2px 5px),
    linear-gradient(168deg, rgba(40,48,64,.7), rgba(10,12,17,.95) 58%);
  border: 1px solid #2c3444; border-radius: 3px 14px 3px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.rv-panel::before {
  content: ""; position: absolute; left: 0; top: 0; height: 2px; width: 62%;
  background: linear-gradient(90deg, var(--f1red), rgba(225,6,0,0));
}
.rv-k {
  font-size: 10px; font-weight: 700; letter-spacing: 1.5px; color: var(--dim);
}
.rv-panel b { font-variant-numeric: tabular-nums; }
.rv-purple { color: #c084fc; }
.rv-good { color: var(--green); }
.rv-bad { color: var(--red); }

/* ---------- standing ---------- */
.rv-pos-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.rv-pos { display: flex; align-items: baseline; font-style: italic; }
.rv-pos span { font-size: 28px; font-weight: 700; color: var(--f1red); }
.rv-pos b { font-size: clamp(44px, 9vh, 76px); line-height: .9; font-weight: 700; }
.rv-pos small, .rv-lap small { font-size: 14px; color: var(--dim); margin-left: 4px; font-weight: 600; }
.rv-lap { text-align: right; }
.rv-lap b { display: block; font-size: 28px; font-weight: 700; font-style: italic; line-height: 1; }
.rv-gaps, .rv-times, .rv-kv {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px;
}
.rv-gap, .rv-times > div, .rv-kv > div {
  background: rgba(0,0,0,.25); border: 1px solid #222a38; border-radius: 6px;
  padding: 5px 8px; display: flex; flex-direction: column; min-width: 0;
}
.rv-gap b { font-size: 19px; font-style: italic; }
.rv-times b, .rv-kv b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.rv-tag {
  font-size: 10px; font-weight: 700; letter-spacing: 1px; padding: 3px 8px;
  border-radius: 4px; background: #1d2230; color: var(--dim);
}
.rv-tag.warn { background: #3a2410; color: var(--yellow); }
.rv-tag.bad { background: #3b1111; color: var(--red); }

/* ---------- tyres ---------- */
.rv-tyre-grid {
  flex: 1; min-height: 0; display: grid; gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(70px, .42fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
}
.rv-car {
  grid-column: 2; grid-row: 1 / 3; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.rv-tyre-grid .rv-corner[data-i="0"] { grid-column: 1; grid-row: 1; }
.rv-tyre-grid .rv-corner[data-i="1"] { grid-column: 3; grid-row: 1; }
.rv-tyre-grid .rv-corner[data-i="2"] { grid-column: 1; grid-row: 2; }
.rv-tyre-grid .rv-corner[data-i="3"] { grid-column: 3; grid-row: 2; }
.rv-car-svg { flex: 1; min-height: 0; width: 100%; max-height: 100%; }
.rv-body { fill: #1f2532; stroke: #3a4354; stroke-width: 1.5; }
.rv-wing { fill: #2a3242; }
.rv-halo { fill: none; stroke: #4a5568; stroke-width: 3; }
.rv-wheel { fill: #2a3242; stroke: #0b0c0f; stroke-width: 1.5; transition: fill .3s; }
.rv-compound {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 50%; border: 5px solid #94a3b8;
  font-weight: 900; font-size: 22px; background: #0b0d13; flex: none;
}
.rv-age { font-size: 11px; font-weight: 700; letter-spacing: 1px; color: var(--dim); text-align: center; line-height: 1.1; }
.rv-age b { display: block; color: var(--text); font-size: 22px; font-style: italic; }

/* one corner: numbers scale with the card (container query units) */
.rv-corner {
  --tc: #4a5568;
  container-type: size; min-width: 0; min-height: 0;
  border-radius: 10px; padding: 8px 12px 10px;
  border: 2px solid color-mix(in srgb, var(--tc) 60%, #222a38);
  background: linear-gradient(180deg, color-mix(in srgb, var(--tc) 16%, transparent), rgba(0,0,0,.35) 70%);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto auto; gap: 4px;
  transition: border-color .3s;
}
.rv-corner .c-head { display: flex; justify-content: space-between; align-items: baseline; }
.rv-corner .c-name {
  font-size: clamp(11px, 7cqh, 20px); font-weight: 800; letter-spacing: 2px; color: var(--text);
}
.rv-corner .c-psi { font-size: clamp(11px, 7cqh, 20px); font-weight: 700; color: #aab2bf; font-variant-numeric: tabular-nums; }
.rv-corner .c-psi small { font-size: .6em; color: var(--dim); margin-left: 3px; letter-spacing: 1px; }
.rv-corner .c-surf {
  display: flex; align-items: baseline; align-content: center; flex-wrap: wrap; justify-content: center; gap: .15em;
  font-size: clamp(28px, min(36cqh, 30cqw), 120px); font-weight: 700; font-style: italic;
  line-height: 1; color: var(--tc); font-variant-numeric: tabular-nums; transition: color .3s;
}
.rv-corner .c-surf small {
  font-size: clamp(9px, 5cqh, 14px); font-style: normal; font-weight: 700;
  letter-spacing: 1.5px; color: var(--dim);
}
.rv-corner .c-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.rv-corner .c-stats > div {
  display: flex; flex-direction: column; align-items: center; min-width: 0;
  background: rgba(0,0,0,.3); border-radius: 6px; padding: 3px 2px;
}
.rv-corner .c-stats span {
  font-size: clamp(8px, 4.5cqh, 12px); font-weight: 700; letter-spacing: 1px; color: var(--dim);
}
.rv-corner .c-stats b { font-size: clamp(13px, min(11cqh, 9cqw), 34px); font-weight: 700; line-height: 1.1; }
.rv-corner .c-wear { height: clamp(5px, 3cqh, 10px); border-radius: 5px; background: #1c2331; overflow: hidden; }
.rv-corner .c-wear i { display: block; height: 100%; width: 0; transition: width .4s, background .4s; }

/* ---------- fuel / energy ---------- */
.rv-big-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.rv-big { display: flex; align-items: baseline; gap: 6px; }
.rv-big b { font-size: clamp(30px, 6vh, 46px); font-weight: 700; font-style: italic; line-height: 1; }
.rv-big span { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: var(--dim); }
.rv-surplus { font-size: 18px; font-weight: 800; font-style: italic; }
.rv-mode {
  font-size: 11px; font-weight: 800; letter-spacing: 1.5px; padding: 3px 9px;
  border-radius: 4px; border: 1px solid currentColor;
}
.rv-bar { height: 9px; border-radius: 5px; background: #1c2331; overflow: hidden; }
.rv-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.rv-bar.ers i { background: #f59e0b; }
.rv-sep { border-top: 1px solid #222a38; margin: 2px 0; }

/* ---------- damage ---------- */
.rv-dmg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: 1; min-height: 0; }
.rv-dmg { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.rv-dmg h4 { font-size: 10px; letter-spacing: 1.5px; color: var(--dim); margin-bottom: 2px; }
.rv-dmg .d-row { display: grid; grid-template-columns: 1fr auto; gap: 1px 8px; font-size: 11px; }
.rv-dmg .d-row span { color: #aab2bf; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rv-dmg .d-row b { font-size: 12px; }
.rv-dmg .d-bar { grid-column: 1 / 3; height: 4px; border-radius: 2px; background: #1c2331; overflow: hidden; }
.rv-dmg .d-bar i { display: block; height: 100%; transition: width .4s; }
.rv-faults { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- driver ---------- */
.rv-drive { flex: 1; min-height: 0; display: flex; align-items: stretch; gap: 12px; }
.rv-pedal {
  width: 26px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.rv-pedal i {
  flex: 1; width: 100%; border-radius: 5px; background: #1c2331; position: relative; overflow: hidden;
  display: block;
}
.rv-pedal i::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0;
  height: var(--v, 0%); background: var(--green);
}
.rv-pedal.brk i::after { background: var(--red); }
.rv-pedal span { font-size: 9px; font-weight: 700; letter-spacing: 1px; color: var(--dim); }
.rv-speedo {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.rv-gear {
  font-size: clamp(30px, 7vh, 52px); font-weight: 800; color: var(--yellow);
  border: 1px solid #2a3242; background: #171d29; border-radius: 10px;
  min-width: 1.6em; text-align: center; line-height: 1.2;
}
.rv-speed { font-size: clamp(38px, 9vh, 64px); font-weight: 700; font-style: italic; line-height: 1; font-variant-numeric: tabular-nums; }
.rv-rpm { width: 100%; height: 8px; border-radius: 4px; background: #1c2331; overflow: hidden; }
.rv-rpm i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--yellow) 70%, var(--red)); }
.rv-rpm-txt { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }

/* ---------- waiting overlay ---------- */
.rv-wait {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; text-align: center; z-index: 20;
}
.rv-wait h2 { font-size: 15px; }
.rv-wait p { font-size: 12px; color: var(--dim); }
.rv-wait.hide { display: none; }
body.stale #rv-grid { opacity: .45; }

/* one-row layout: spread each panel over the full height, bigger numbers */
@media (min-aspect-ratio: 12/5) {
  #rv-standing, #rv-fuel { justify-content: space-between; }
  .rv-gap b { font-size: clamp(19px, 3.6vh, 28px); }
  .rv-times b, .rv-kv b { font-size: clamp(16px, 3vh, 22px); }
  .rv-gap, .rv-times > div, .rv-kv > div { padding: 8px 10px; gap: 2px; }
  .rv-dmg { justify-content: space-between; }
  .rv-dmg .d-row { font-size: 12px; }
  .rv-dmg .d-bar { height: 6px; }
  .rv-tags { margin-top: 0; }
}

/* race engineer radio: header switch + subtitle of the last call */
#rv-radio.on { background: #16a34a; border-color: #16a34a; color: #fff; }
#rv-radio.talking { animation: rv-talk .6s ease-in-out infinite alternate; }
@keyframes rv-talk { to { box-shadow: 0 0 0 4px rgba(22,163,74,.45); } }
.rv-sub {
  position: fixed; left: 50%; bottom: 14px; transform: translate(-50%, 20px);
  max-width: min(900px, calc(100vw - 32px)); z-index: 20;
  display: flex; gap: 10px; align-items: center;
  padding: 8px 16px; border-radius: 10px;
  background: rgba(10, 14, 20, .92); border: 1px solid #16a34a;
  font-size: 18px; font-weight: 700; color: #f1f5f9;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.rv-sub.show { opacity: 1; transform: translate(-50%, 0); }
.rv-sub.p3 { border-color: #f87171; }
#rv-mic.on { background: #dc2626; border-color: #dc2626; color: #fff; }
#rv-mic.hearing { animation: rv-hear .5s ease-in-out infinite alternate; }
@keyframes rv-hear { to { box-shadow: 0 0 0 4px rgba(220,38,38,.5); } }
.rv-sub.me { border-color: #64748b; color: #cbd5e1; font-weight: 600; }
.rv-sub.me.miss { opacity: .55; }
#rv-mic.follow { background: #f59e0b; border-color: #f59e0b; color: #111; }
#rv-radio.locked { background: #f59e0b; border-color: #f59e0b; color: #111;
  animation: rv-talk .8s ease-in-out infinite alternate; }
#rv-usage { font-variant-numeric: tabular-nums; }
.rv-usage-pop {
  position: fixed; top: 52px; right: 16px; z-index: 30;
  max-width: calc(100vw - 32px); padding: 12px 14px; border-radius: 10px;
  background: rgba(10, 14, 20, .97); border: 1px solid #334155;
  font-size: 13px; color: #cbd5e1; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.rv-usage-pop table { border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rv-usage-pop th, .rv-usage-pop td { padding: 3px 10px; text-align: right; }
.rv-usage-pop th:first-child, .rv-usage-pop td:first-child { text-align: left; color: #94a3b8; }
.rv-usage-pop thead th { color: #f1f5f9; border-bottom: 1px solid #334155; }
.rv-usage-pop tr.sum td { color: #f1f5f9; font-weight: 700; border-top: 1px solid #334155; }
.rv-usage-pop p { margin: 8px 0 0; font-size: 11px; color: #64748b; }
