:root {
  --ui: "Titillium Web", "DejaVu Sans Condensed", "Segoe UI", system-ui, sans-serif;
  --num: "Roboto Mono", "DejaVu Sans Mono", ui-monospace, monospace;
  --bg: #07090c;
  --panel: #0e1116;
  --glass: rgba(10, 13, 18, .78);
  --line: #1e242c;
  --line2: #2b323c;
  --fg: #eef1f5;
  --dim: #8b93a0;
  --dim2: #626a76;
  --hot: #ffd23f;
  --purple: #b26bff;
  --green: #23d18b;
  --red: #ff3b52;
  --hdr: 54px;
  --strip: 140px;
  --tower: 344px;
  --focus: 384px;
  --row: 30px;
}
@media (max-width: 1600px) { :root { --tower: 300px; --focus: 340px; --strip: 124px; } }
@media (max-height: 860px)  { :root { --hdr: 46px; --strip: 116px; } }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 13px/1.35 var(--ui); -webkit-font-smoothing: antialiased; }
button, select, input { font: inherit; color: inherit; }
b, .num { font-variant-numeric: tabular-nums; }

#app { display: grid; grid-template-rows: var(--hdr) 1fr var(--strip); height: 100%; }

/* ------------------------------------------------------------------ header */
#hdr { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px;
  padding: 0 14px; background: linear-gradient(180deg, #12161d 0%, #0a0d12 100%); border-bottom: 1px solid var(--line2); }
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand .mark { font-weight: 900; font-size: 21px; letter-spacing: .01em; color: var(--fg); }
.brand .mark b { color: var(--hot); font-weight: 900; }
.brand .circuit { font-size: 11px; letter-spacing: .22em; color: var(--dim); text-transform: uppercase; }

.session { display: flex; align-items: center; gap: 14px; justify-self: center; }
.session .kind { font-weight: 700; font-size: 13px; letter-spacing: .16em; padding: 3px 10px; border-radius: 3px;
  background: var(--hot); color: #10131a; text-transform: uppercase; }
.session .kind.train { background: #4aa8ff; }
.session .kind.idle { background: #5d6570; color: #e6e8eb; }
.session .sn { font-size: 11px; letter-spacing: .16em; color: var(--dim); }
.session .clock { font-family: var(--num); font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 5px; }
.session .clock b { font-size: 17px; font-weight: 500; letter-spacing: -.01em; }
.session .clock span { font-size: 11px; color: var(--dim2); }
.session .tbar { width: 160px; height: 3px; background: #222831; border-radius: 2px; overflow: hidden; }
.session .tbar i { display: block; height: 100%; width: 0; background: var(--hot); transition: width .4s linear; }
.session .lapbox { display: flex; align-items: baseline; gap: 6px; }
.session .lapbox span { font-size: 10px; letter-spacing: .18em; color: var(--dim); }
.session .lapbox b { font-family: var(--num); font-size: 17px; font-weight: 500; }

.hright { display: flex; align-items: center; gap: 12px; justify-self: end; }
.hright .song, .hright .rt, .hright .films { font-size: 11px; color: var(--dim); letter-spacing: .04em;
  max-width: 260px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hright .films a { color: var(--dim); text-decoration: none; border-bottom: 1px solid var(--line2); margin-left: 8px; }
.hright .films a:hover { color: var(--fg); }
.hright .rt { font-family: var(--num); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .18em; color: #fff; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: pulse 2s ease-in-out infinite; }
.live.stale i { background: var(--dim2); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

button.ghost { background: transparent; border: 1px solid var(--line2); color: var(--dim); border-radius: 3px;
  padding: 4px 9px; font-size: 10px; letter-spacing: .14em; font-weight: 600; cursor: pointer; }
button.ghost:hover { color: var(--fg); border-color: #47505d; }
button.ghost.on { background: var(--hot); border-color: var(--hot); color: #10131a; }

main { display: grid; grid-template-columns: var(--tower) minmax(0, 1fr) var(--focus); min-height: 0; }

/* ------------------------------------------------------------------ timing tower */
#tower { display: grid; grid-template-rows: 20px 1fr auto; min-height: 0; min-width: 0; background: var(--panel);
  border-right: 1px solid var(--line2); }
.towerhead, .trow { display: grid; align-items: center;
  grid-template-columns: 20px 3px 24px 1fr 48px 44px 44px 38px; gap: 4px; padding: 0 6px 0 0; }
.towerhead { font-size: 9px; letter-spacing: .14em; color: var(--dim2); border-bottom: 1px solid var(--line2); }
#tower > * { min-width: 0; }
#focus > *, #strip > *, #hdr > * { min-width: 0; }
.fcard > *, .ftel > *, .fstats > *, .flearn > *, .lgrid > *, .fstats div > *, #briefs > div { min-width: 0; }
.fname, .fteam { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.towerhead > *, .trow > * { min-width: 0; overflow: hidden; white-space: nowrap; }
.towerhead .c-name { padding-left: 4px; }
.towerhead .c-gap, .towerhead .c-lap { text-align: right; background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; letter-spacing: .14em; color: var(--dim2); }
.towerhead .c-gap:hover { color: var(--fg); }
.towerhead .c-chip { text-align: center; }
.towerhead .c-p { text-align: right; }

#rows { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.trow { position: absolute; left: 0; right: 0; top: 0; cursor: pointer; border-bottom: 1px solid #12161c;
  overflow: hidden; background: #0c1015; transition: transform .2s cubic-bezier(.4,0,.2,1); }
.trow:nth-child(even) { background: #10141a; }
.trow:hover { background: #171d25; }
.trow.sel { background: #1b232e; }
.trow.sel::before { content: ""; position: absolute; inset: 0; border: 1px solid currentColor; opacity: .5; pointer-events: none; }
.trow .c-p { font-family: var(--num); font-size: 13px; font-weight: 500; text-align: right; color: var(--fg); }
.trow.p1 .c-p { color: var(--hot); }
.trow .c-bar { height: 100%; }
.trow .c-no { font-family: var(--num); font-size: 12px; font-weight: 700; text-align: center; }
.trow .c-name { color: var(--fg); font-weight: 700; font-size: 11.5px; letter-spacing: .01em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: clip; padding-left: 4px; }
.trow.out .c-name { color: var(--dim); }
.trow .c-gap, .trow .c-last, .trow .c-best { font-family: var(--num); font-size: 11px; text-align: right; color: #cdd3db; }
.trow .c-gap.lead { color: var(--dim2); }
.trow .c-best.purple { color: var(--purple); }
.trow .c-gap.off { color: var(--red); }
.trow.out .c-no { opacity: .55; }
.trow .c-chip { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.chip { position: relative; width: 17px; height: 17px; border-radius: 3px; border: 1.5px solid; display: grid;
  place-items: center; font-size: 9px; font-weight: 700; line-height: 1; }
.chip i { position: absolute; left: 1px; right: 1px; bottom: 1px; height: 2px; background: currentColor; opacity: .85;
  transform-origin: left; }
.chip.n { color: var(--purple); } .chip.b { color: #27f4d2; } .chip.r { color: var(--hot); } .chip.x { color: #6b7480; }
.rcount { font-family: var(--num); font-size: 9.5px; color: var(--dim2); min-width: 18px; text-align: right; }
.rcount.hit { color: #ff8f5c; }
.act { position: absolute; left: 0; bottom: 0; height: 2px; opacity: .55; transition: width .2s linear; }

.towerfoot { border-top: 1px solid var(--line2); padding: 6px 8px; background: #0b0e13; }
.towerfoot .fl { font-size: 10.5px; letter-spacing: .1em; color: var(--purple); font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.towerfoot .st { font-size: 9.5px; letter-spacing: .04em; color: var(--dim2); margin-top: 3px; font-family: var(--num);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ stage */
#stage { position: relative; min-width: 0; overflow: hidden; background: #05070a; }
#stage canvas#stage3d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.vign { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 45%, rgba(0,0,0,.55) 100%); }
.glass { background: var(--glass); border: 1px solid var(--line2); border-radius: 4px;
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px); }

.stagetop { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; pointer-events: none; }
.viewbtns { display: flex; gap: 4px; pointer-events: auto; }
.viewbtns button { background: var(--glass); border: 1px solid var(--line2); color: var(--dim); border-radius: 3px;
  padding: 4px 10px; font-size: 10px; letter-spacing: .14em; font-weight: 700; cursor: pointer;
  backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px); }
.viewbtns button.on { background: var(--fg); border-color: var(--fg); color: #0a0d12; }
.following { font-size: 10px; letter-spacing: .16em; font-weight: 700; color: var(--dim);
  background: var(--glass); border: 1px solid var(--line2); border-radius: 3px; padding: 4px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.following b { color: var(--fg); }
#mapbox[hidden] { display: none; }

.banner[hidden] { display: none; }
.banner { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); display: flex; align-items: center;
  gap: 12px; padding: 8px 20px 8px 12px; background: rgba(10,13,18,.92); border: 1px solid var(--line2);
  border-radius: 4px; font-size: 15px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  animation: drop .35s ease-out; }
.banner i { width: 6px; align-self: stretch; border-radius: 2px; background: var(--hot); }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -14px) } to { opacity: 1; transform: translate(-50%, 0) } }

#rc { position: absolute; left: 12px; bottom: 12px; width: 340px; padding: 7px 9px 8px; }
#rc .rchead { font-size: 9px; letter-spacing: .22em; color: var(--dim2); margin-bottom: 5px; }
.rcmsg { display: grid; grid-template-columns: 5px 42px 1fr; gap: 7px; align-items: baseline; padding: 2.5px 0;
  font-size: 11px; letter-spacing: .04em; }
.rcmsg i { height: 10px; border-radius: 1px; background: var(--dim); position: relative; top: 2px; }
.rcmsg time { font-family: var(--num); font-size: 9.5px; color: var(--dim2); }
.rcmsg span { text-transform: uppercase; color: #d6dbe2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rcmsg.old { opacity: .5; }

#mapbox { position: absolute; right: 12px; bottom: 12px; width: 252px; padding: 6px 7px 7px; }
#mapbox .ilabel { font-size: 9px; letter-spacing: .2em; color: var(--dim2); margin-bottom: 4px; display: flex;
  justify-content: space-between; }
#mapbox canvas { width: 100%; height: 152px; display: block; }
@media (max-width: 1600px) { #mapbox { width: 210px; } #mapbox canvas { height: 128px; } #rc { width: 296px; } }
@media (max-width: 1600px) {
  .towerhead, .trow { grid-template-columns: 18px 3px 23px 1fr 50px 44px 38px; gap: 3px; }
  .c-last { display: none; }
  .trow .c-name { font-size: 11.5px; }
}

/* ------------------------------------------------------------------ focus panel */
#focus { min-width: 0; overflow: hidden; background: var(--panel); border-left: 1px solid var(--line2);
  display: grid; grid-template-rows: auto auto auto 1fr auto; }
.fcard { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); border-left: 4px solid var(--dim2); }
.fcard .fno { font-family: var(--num); font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.fcard .fname { font-size: 17px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fcard .fteam { font-size: 10px; letter-spacing: .1em; color: var(--dim); text-transform: uppercase; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fcard .fpos { text-align: right; }
.fcard .fpos span { display: block; font-size: 9px; letter-spacing: .18em; color: var(--dim2); }
.fcard .fpos b { font-family: var(--num); font-size: 24px; font-weight: 500; line-height: 1; }

.ftel { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; padding: 9px 12px;
  border-bottom: 1px solid var(--line); }
.ftel .speed { display: flex; align-items: baseline; gap: 5px; }
.ftel .speed b { font-family: var(--num); font-size: 34px; font-weight: 500; line-height: 1; letter-spacing: -.03em; }
.ftel .speed span { font-size: 9px; letter-spacing: .14em; color: var(--dim2); }
.pedals { display: grid; gap: 4px; min-width: 0; }
.pedal { display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 7px; }
.pedal span { font-size: 9px; letter-spacing: .12em; color: var(--dim2); }
.pbar { position: relative; height: 6px; background: #1a1f27; border-radius: 2px; overflow: hidden; }
.pbar i { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 2px; transition: width .1s linear; }
.pbar i.thr { background: var(--green); } .pbar i.brk { background: var(--red); }
.pbar.centre::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #39414c; }
.pbar i.str { background: #7fb2ff; left: 50%; transition: none; }

.fstats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.fstats div { padding: 6px 4px 7px 8px; border-right: 1px solid var(--line); border-top: 1px solid var(--line); }
.fstats div:nth-child(5n) { border-right: 0; }
.fstats div:nth-child(-n+5) { border-top: 0; }
.fstats span { display: block; font-size: 8.5px; letter-spacing: .12em; color: var(--dim2); white-space: nowrap; }
.fstats b { display: block; font-family: var(--num); font-size: 12px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.fstats b.up { color: var(--red); } .fstats b.down { color: var(--green); }

.fbrain { position: relative; min-height: 0; display: grid; grid-template-rows: 22px 1fr auto auto;
  border-bottom: 1px solid var(--line); }
.phead { font-size: 9px; letter-spacing: .2em; color: var(--dim2); padding: 7px 12px 0; }
.phead span { color: var(--fg); letter-spacing: .1em; font-weight: 700; }
#gl { width: 100%; height: 100%; display: block; min-height: 0; }
.scalebar { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; padding: 0 12px 4px;
  font-family: var(--num); font-size: 8.5px; color: var(--dim2); }
.scalebar i { height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #1a1e26 0%, #7a5a1e 45%, #ffea9e 100%); }
.pfoot { font-size: 9.5px; letter-spacing: .06em; color: var(--dim); padding: 0 12px 7px; font-family: var(--num); }

.flearn { padding: 7px 12px 9px; }
.flearn .phead { padding: 0 0 5px; }
.lrow { display: grid; grid-template-columns: 84px 1fr 40px; gap: 8px; align-items: center; }
.lrow span { font-size: 9px; letter-spacing: .12em; color: var(--dim2); }
.lrow b { font-family: var(--num); font-size: 11px; text-align: right; }
.lrow .pbar i { background: var(--purple); }
.lgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 7px; }
.lgrid div { background: #12161d; border: 1px solid var(--line); border-radius: 3px; padding: 4px 6px; }
.lgrid span { display: block; font-size: 8.5px; letter-spacing: .1em; color: var(--dim2); }
.lgrid b { font-family: var(--num); font-size: 12px; }

/* ------------------------------------------------------------------ field brain strip */
#strip { position: relative; border-top: 1px solid var(--line2); background: #06080b; display: grid;
  grid-template-rows: 16px 1fr 20px; min-height: 0; }
.striphead { font-size: 9px; letter-spacing: .22em; color: var(--dim2); padding: 5px 12px 0; }
.striphead span { letter-spacing: .06em; color: #5a626e; }
#brains { width: 100%; height: 100%; display: block; min-height: 0; cursor: pointer; }
#briefs { display: grid; align-items: center; padding: 0 2px 3px; }
#briefs div { position: relative; display: flex; align-items: center; gap: 3px; padding: 0 3px 2px; font-size: 9px;
  color: var(--dim); white-space: nowrap; overflow: hidden; cursor: pointer; }
#briefs div.sel { color: var(--fg); }
#briefs b { width: 3px; height: 9px; border-radius: 1px; flex: none; }
#briefs em { font-style: normal; font-family: var(--num); color: #b9c0c9; }
#briefs u { text-decoration: none; overflow: hidden; text-overflow: clip; letter-spacing: .02em; }
#briefs s { position: absolute; left: 3px; bottom: 0; height: 2px; width: 0; opacity: .7; transition: width .2s linear; }

/* ------------------------------------------------------------------ admin drawer */
#admin { position: fixed; right: 12px; top: calc(var(--hdr) + 8px); width: 392px; max-height: calc(100% - var(--hdr) - 24px);
  overflow: auto; padding: 10px 12px 14px; z-index: 20; }
#admin[hidden] { display: none; }
.ahead { display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: .2em;
  color: var(--dim); margin-bottom: 8px; }
.ahead button { background: transparent; border: 1px solid var(--line2); color: var(--dim); border-radius: 3px;
  padding: 2px 8px; font-size: 9px; letter-spacing: .14em; cursor: pointer; }
.ahead2 { font-size: 9px; letter-spacing: .18em; color: var(--dim2); margin: 12px 0 6px; }
.arow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#admin button:not(.ahead button) { background: #171c24; border: 1px solid var(--line2); color: var(--fg); border-radius: 3px;
  padding: 5px 10px; font-size: 10px; letter-spacing: .1em; font-weight: 600; cursor: pointer; }
#admin button.on { background: var(--hot); border-color: var(--hot); color: #10131a; }
#admin select, #admin input[type=number] { background: #171c24; border: 1px solid var(--line2); border-radius: 3px;
  padding: 4px 6px; font-size: 11px; max-width: 160px; }
#admin input[type=number] { width: 62px; }
.gains label { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; color: var(--dim); }
.ahint { font-size: 10px; color: var(--dim2); margin: 6px 0 0; line-height: 1.4; white-space: pre-wrap; }
#chart { display: block; width: 100%; height: 88px; background: #0b0e13; border: 1px solid var(--line); border-radius: 3px; }
#weightlist { max-height: 150px; overflow: auto; font-family: var(--num); font-size: 10px; }

/* ------------------------------------------------------------------ compact desktop */
@media (max-width: 1440px) { :root { --tower: 268px; --focus: 300px; }
  .brand .mark { font-size: 18px; } .brand .circuit { display: none; }
  #hdr { gap: 10px; padding: 0 10px; }
  .session { gap: 9px; } .session .tbar { width: 92px; } .session .sn { font-size: 10px; }
  .hright { gap: 9px; } .hright .films { display: none; } .hright .song { max-width: 150px; }
  .towerhead, .trow { grid-template-columns: 17px 3px 21px 1fr 44px 36px 42px; gap: 3px; }
  .rcount { min-width: 15px; font-size: 9px; }
  .trow .c-name { font-size: 11px; }
  .towerhead { font-size: 8px; letter-spacing: .04em; }
  .fstats span { font-size: 7.5px; letter-spacing: .06em; }
  .fstats b { font-size: 11px; } .fstats div { padding: 4px 5px; }
  #rc { max-width: 250px; } #mapbox { width: 190px; }
}

/* race-only broadcast layout (?ui=race): stage + timing tower, nothing else */
body.ui-race #app { grid-template-rows: var(--hdr) 1fr; }
body.ui-race main { grid-template-columns: var(--tower) minmax(0, 1fr); }
body.ui-race #focus, body.ui-race #strip, body.ui-race #rc, body.ui-race #films, body.ui-race #song, body.ui-race #rtx,
body.ui-race #tower .c-chip, body.ui-race #tower .chip, body.ui-race .trow > :nth-child(n+8), body.ui-race #sessionstats { display: none !important; }
body.ui-race { --tower: 330px; }
body.ui-race .towerhead, body.ui-race .trow { grid-template-columns: 22px 3px 26px 1fr 58px 50px 50px; }
body.ui-race #tower .c-name, body.ui-race #tower .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ stage-only (the server-side renderer behind the live page) */
body.ui-stage #hdr, body.ui-stage #tower, body.ui-stage #focus, body.ui-stage #strip, body.ui-stage .stagetop, body.ui-stage #banner,
body.ui-stage #rc, body.ui-stage #mapbox, body.ui-stage #admin, body.ui-stage .vign { display: none !important; }
body.ui-stage #app { grid-template-rows: 1fr; }
body.ui-stage main { grid-template-columns: minmax(0, 1fr); }
