:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --plane: #f7f7f5;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #ecebe6;
  --axis: #c3c2b7;
  --line: rgba(11, 11, 11, 0.09);
  --accent: #2a78d6;
  --red: #e34948;
  --blue: #2a78d6;
  --orange: #eb6834;
  --warn: #b7791f;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
a.link { color: var(--accent); }
a.link:hover { text-decoration: underline; }
.tnum, td, th { font-variant-numeric: tabular-nums; }

/* top bar */
header.top { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
header.top .in { max-width: 1240px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.brand { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(90deg, var(--blue) 50%, var(--red) 50%); }
.brand small { color: var(--muted); font-weight: 450; }
nav.main { display: flex; gap: 4px; }
nav.main a { padding: 6px 10px; border-radius: 8px; color: var(--ink-2); }
nav.main a:hover { background: var(--plane); color: var(--ink); }
nav.main a.on { background: var(--plane); color: var(--ink); font-weight: 550; }
.spacer { flex: 1; }
select, input[type=search], button { font: inherit; color: inherit; }
select, input[type=search] { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 10px; }
input[type=search] { width: 150px; }
button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 12px; cursor: pointer; }
button:hover { background: var(--plane); }
button.on { background: var(--ink); color: #fff; border-color: var(--ink); }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 64px; }
h1 { font-size: 24px; line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 6px; font-weight: 680; }
h2 { font-size: 18px; letter-spacing: -0.01em; margin: 0 0 4px; font-weight: 640; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 620; }
.sub { color: var(--ink-2); margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
section { margin-top: 28px; }
section > .head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
section > .head p { margin: 0; color: var(--muted); font-size: 13px; flex: 1 1 320px; }

.notice { margin-top: 10px; padding: 8px 12px; border-radius: var(--radius); background: var(--plane); color: var(--ink-2); font-size: 13px; }
.notice b { color: var(--ink); }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; margin-top: 14px; }
.tile { border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; background: var(--surface); }
.tile .k { color: var(--muted); font-size: 12px; }
.tile .v { font-size: 20px; font-weight: 640; letter-spacing: -0.02em; margin-top: 2px; }
.tile .v small { font-size: 13px; color: var(--muted); font-weight: 450; margin-left: 2px; }
.tile .d { color: var(--ink-2); font-size: 12px; margin-top: 2px; }

/* grids of cards */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); min-width: 0; }
.card .cap { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }

/* tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 5px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-weight: 560; color: var(--ink-2); font-size: 12px; background: #fff; position: sticky; top: 0; cursor: default; user-select: none; }
th.sort { cursor: pointer; }
th.sort:hover { color: var(--ink); }
th.sorted::after { content: " \2193"; color: var(--accent); }
th.sorted.asc::after { content: " \2191"; }
td.l, th.l { text-align: left; }
tbody tr:hover { background: #fafaf8; }
tbody tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
.team-a { font-weight: 600; }
.pill { display: inline-block; padding: 0 7px; border-radius: 99px; font-size: 11px; line-height: 18px; background: var(--plane); color: var(--ink-2); }
.pill.low { background: #fdf3e1; color: #8a5a00; }
.pill.red { background: #fdecec; color: #a82727; }
.pill.blue { background: #e9f1fc; color: #1c5cab; }
.pill.vid { background: #eef7ee; color: #1f6b1f; }
.al { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.al.red { background: var(--red); } .al.blue { background: var(--blue); }
.bar-in { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); opacity: 0.85; vertical-align: middle; }

/* charts */
svg { display: block; overflow: visible; }
svg text { font-family: var(--font); fill: var(--muted); font-size: 11px; }
svg .gridl { stroke: var(--grid); stroke-width: 1; }
svg .axisl { stroke: var(--axis); stroke-width: 1; }
svg .lbl { fill: var(--ink-2); }
svg .hit { fill: transparent; cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); margin: 0 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.legend i.sq { border-radius: 2px; }
.legend i.ring { background: #fff !important; border: 2px solid var(--ink); width: 10px; height: 10px; }
#tip { position: fixed; z-index: 50; pointer-events: none; background: #fff; border: 1px solid var(--line); box-shadow: 0 6px 24px rgba(0,0,0,0.08); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.45; max-width: 280px; display: none; color: var(--ink); }
#tip b { font-weight: 620; }

/* field */
.field svg .turf { fill: #fbfbfa; stroke: var(--axis); }
.field svg .zone { fill: rgba(42,120,214,0.045); }
.field svg .zone.r { fill: rgba(227,73,72,0.045); }
.field svg .zl { stroke: var(--axis); stroke-dasharray: 4 4; }
.fieldbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.player { display: flex; gap: 12px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.player input[type=range] { flex: 1 1 300px; accent-color: var(--ink); }
.player .clock { font-variant-numeric: tabular-nums; min-width: 64px; font-weight: 600; }

/* match header */
.scoreline { display: grid; grid-template-columns: 1fr auto 1fr; gap: 24px; align-items: center; margin-top: 24px; }
.scoreline .side { border-radius: var(--radius); padding: 16px 20px; border: 1px solid var(--line); }
.scoreline .side.red { border-top: 3px solid var(--red); }
.scoreline .side.blue { border-top: 3px solid var(--blue); }
.scoreline .big { font-size: 36px; font-weight: 700; letter-spacing: -0.03em; }
.scoreline .vs { color: var(--muted); }
@media (max-width: 700px) { .scoreline { grid-template-columns: 1fr; } .scoreline .vs { display: none; } }
.robots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.robot { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12px; }
.robot .t { font-size: 15px; font-weight: 640; display: flex; justify-content: space-between; align-items: center; }
.robot .n { font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.robot .row { display: flex; justify-content: space-between; color: var(--ink-2); }
@media (max-width: 520px) { .robots { grid-template-columns: 1fr; } }
video { width: 100%; border-radius: var(--radius); background: #000; }
.empty { padding: 40px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 16px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--muted); }
footer { max-width: 1240px; margin: 0 auto; padding: 24px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }
@media (max-width: 600px) { main { padding: 20px 16px 64px; } header.top .in { padding: 10px 16px; gap: 10px; } h1 { font-size: 24px; } }
@media (max-width: 600px) { header.top { position: static; } }

/* auto routines */
.routines { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-top: 16px; }
.routine .rt, .autoteam .rt { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.routine .rn { font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.routine .kv { margin-top: 10px; }
.rk { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 6px; color: #fff; font-size: 12px; font-weight: 600; align-self: center; }
.rk.sm { width: 16px; height: 16px; font-size: 10px; border-radius: 4px; margin-right: 6px; vertical-align: -3px; }
.autogrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-top: 12px; }
.autoteam .rt { justify-content: space-between; }
.autoteam .rl { font-size: 12px; color: var(--ink-2); display: grid; gap: 3px; margin-top: 8px; }
#autofilter { width: 160px; }

/* time legend */
.tleg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); margin-right: 14px; }
.tleg .mk { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--ink-2); background: #fff; }
.tleg .mk.dash { border-style: dashed; }
.tleg .mk.fill { background: var(--ink-2); }
/* planner */
.slot { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.slot:first-of-type { border-top: 0; }
.slot .st { width: 84px; }
.slot .sr { flex: 1 1 200px; min-width: 0; max-width: 100%; }
.slot .si { flex-basis: 100%; padding-left: 20px; }
.dotc { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.card.ok { color: #137a52; background: #f2fbf6; border-color: #cdeedc; }
.pill.bad { background: #fde8e8; color: #b42323; border-color: #f7c6c6; }

/* segmented toggle */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; background: #fff; }
.seg button { border: 0; border-radius: 7px; padding: 4px 12px; }
/* account */
.acct { display: inline-flex; align-items: center; gap: 8px; }
.acct .av { width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.modal-bg { position: fixed; inset: 0; background: rgba(20, 20, 18, 0.28); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 22px 24px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.18); }
.modal h3 { margin: 0 0 6px; font-size: 18px; }
.fl { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); margin-top: 14px; }
.fl input { font: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
tr.mine td { background: #f3f8fe; }
/* layout editing */
.crumbs { display: flex; align-items: center; gap: 12px; }
.crumbs p { margin: 0; }
.laybar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px solid var(--line); background: var(--plane, #f6f6f3); border-radius: 12px; padding: 10px 14px; margin: 12px 0; position: sticky; top: 64px; z-index: 5; }
.chip { padding: 2px 10px; border-radius: 999px; font-size: 12px; }
section.w-hidden { display: none; }
main.editing > section { outline: 1.5px dashed var(--axis); outline-offset: 8px; border-radius: 6px; margin-top: 40px; }
.wtools { display: flex; align-items: center; gap: 8px; margin: -4px 0 10px; font-size: 12px; color: var(--ink-2); }
.wtools .grip { cursor: grab; font-size: 16px; padding: 0 4px; user-select: none; }
.wtools .wt { font-weight: 600; }
.wtools button { padding: 2px 9px; font-size: 12px; }
section.dragging { opacity: 0.4; }

/* compact: cap chart and field heights so pages need less scrolling */
.card svg[role=img] { max-height: 250px; display: block; margin: 0 auto; }
.field svg[role=img] { max-height: 400px; }
.routines .field svg[role=img], .autogrid .field svg[role=img] { max-height: 190px; }
#planfield { max-height: 520px !important; }

/* matches table: robot chips (team + balls scored) per alliance, one score column */
.mtable td, .mtable th { padding: 6px 10px; }
.mtable th.c, .mtable td.c { text-align: center; }
.mtable td.mq { font-weight: 600; }
.mchips { display: flex; gap: 6px; }
.mchip { display: inline-flex; align-items: stretch; border-radius: 7px; overflow: hidden; font-size: 13px; text-decoration: none; border: 1px solid transparent; }
.mchip b { padding: 3px 8px; font-weight: 560; color: var(--ink); min-width: 3.4em; }
.mchip span { padding: 3px 8px; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 2.6em; text-align: right; color: #fff; }
.mchip.red { background: #fdf0f0; border-color: #f6d6d6; } .mchip.red span { background: #d9534f; }
.mchip.blue { background: #eef4fc; border-color: #d3e2f6; } .mchip.blue span { background: #3a7bd5; }
.mchip:hover { filter: brightness(0.97); }
.mchip.me b { text-decoration: underline; }
.msc { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 15px; }
.msc .ms { display: inline-block; min-width: 2.6em; color: var(--muted); }
.msc .ms.red { text-align: right; } .msc .ms.blue { text-align: left; }
.msc .ms.win.red { color: #c23a39; font-weight: 700; } .msc .ms.win.blue { color: #2366b8; font-weight: 700; }
.msc .dash { color: var(--axis); margin: 0 6px; }
.speed .big { font-size: 34px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.1; }
.speed .big small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.speed { margin-bottom: 8px; }

.ytwrap { max-width: 880px; }
.ytwrap iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 10px; display: block; background: #000; }

.clipmodal { width: min(900px, 100%); }
.clipmodal .ytwrap { max-width: none; }
.clipbtn { padding: 3px 10px; font-size: 12px; white-space: nowrap; }
button:disabled { opacity: 0.4; cursor: default; }

/* team tabs */
.keystats .tiles { margin-top: 12px; }
.tabs { position: sticky; top: 57px; z-index: 10; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; background: rgba(255,255,255,0.95); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); margin: 18px -4px 0; padding: 8px 4px; }
.tabs button { border: 0; background: transparent; border-radius: 8px; padding: 6px 14px; font-weight: 560; color: var(--ink-2); }
.tabs button:hover { background: var(--plane, #f6f6f3); color: var(--ink); }
.tabs button.on { background: var(--ink); color: #fff; }
main > section.tab-off { display: none; }
main > section { margin-top: 22px; }
details.more { margin-top: 14px; }
details.more summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 6px 0; }
details.more[open] summary { margin-bottom: 8px; }

/* expandable stat cards */
.tile.x { cursor: pointer; transition: border-color .15s, box-shadow .15s; position: relative; }
.tile.x::after { content: "⌄"; position: absolute; right: 10px; bottom: 4px; color: var(--muted); font-size: 13px; }
.tile.x:hover { border-color: var(--axis); box-shadow: 0 1px 6px rgba(0,0,0,0.05); }
.tile.open { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink) inset; }
.tile.open::after { content: "⌃"; color: var(--ink); }
.tilepanel { margin-top: 10px; position: relative; }
.tilepanel .tp-x { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 8px; }
.tilepanel .tp-x:hover { color: var(--ink); }

.provbar { background: #fff8e6; border-bottom: 1px solid #f3e2b3; color: #6b5310; font-size: 13px; padding: 8px 24px; text-align: center; }

.no-raw .raw { display: none !important; }

/* HIDE_TRACKS events: no full-match robot tracks (the replay keeps running invisibly so video / chart sync still works) */
main > section.tracks-off { display: none !important; }
