/* Spectator scoreboard. Visual system = Securinets rCTF theme (same tokens as the portal); layout follows
   rCTF's /scores page: blurred header, leaderboard rows (64px, 4px gap, medal glow on the top three) with
   per-service cells under diagonal headers, and a side panel with the score graph and a live capture feed. */
@font-face { font-family: "Outfit"; src: url("/portal/static/fonts/Outfit-VariableFont_wght.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("/portal/static/fonts/GeistMonoVF.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  color-scheme: dark;
  --brand-red: #e5092a; --brand-red-hot: #ff203d; --brand-grid: #ff173012; --brand-glow: #e5092a2b;
  --l0: #050506; --l1: #0b0b0d; --l2: #141417; --l3: #202024; --l4: #2a2a30;
  --border: #3a3438; --border-soft: #2a2528;
  --fg0: #fffaf5; --fg1: #e0dadd; --fg2: #b9b0b5; --fg3: #91878c; --fg5: #575054;
  --accent-bg: #b0081f; --accent-fg: #ff3851;
  --ok: #76e69a; --warn: #ffca16; --bad: #ff3851;
  --gold-fg: #ffca16;   --gold-bg: color-mix(in oklab, #ffc53d 15%, transparent);
  --silver-fg: #b0b4ba; --silver-bg: color-mix(in oklab, #696e77 30%, transparent);
  --bronze-fg: #dbb594; --bronze-bg: color-mix(in oklab, #ad7f58 25%, transparent);
  --radius-sm: 0.25rem; --radius-md: 0.375rem; --radius-lg: 0.5rem;
  --header-height: 4.5rem;
  --row-gap: 4px; --row-h: 64px; --cell-w: 56px; --name-row: 112px;
  --sans: "Outfit", "Segoe UI", system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--fg1); font: 400 16px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden;
  background-color: var(--l0);
  background-image:
    radial-gradient(circle at 8% 3%, var(--brand-glow), transparent 30rem),
    radial-gradient(circle at 92% 21%, color-mix(in oklab, var(--brand-red) 7%, transparent), transparent 26rem),
    linear-gradient(var(--brand-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--brand-grid) 1px, transparent 1px);
  background-size: auto, auto, 2.75rem 2.75rem, 2.75rem 2.75rem;
  font-variant-numeric: tabular-nums;
}
::selection { color: #fff; background: var(--brand-red); }
a { color: inherit; }

/* ------------------------------------------------------------ header */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 10; height: var(--header-height);
  display: flex; align-items: center; justify-content: space-between; gap: 1.25rem; padding: 0.75rem 2.25rem;
  background: color-mix(in oklab, var(--l0) 86%, transparent);
  border-bottom: 1px solid color-mix(in oklab, var(--border) 70%, transparent);
  box-shadow: 0 0.5rem 2rem #00101412; backdrop-filter: blur(1rem) saturate(140%);
}
.brand { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; color: var(--fg0); }
.brand img { height: 2.6rem; width: auto; display: block; }
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand b { font-weight: 600; font-size: 1.05rem; }
.brand small { font-size: 0.8rem; color: var(--fg3); }
.hud { display: flex; align-items: center; gap: 0.5rem; }
.chip { display: inline-flex; align-items: center; gap: 0.5rem; height: 2.5rem; padding: 0 1rem; border-radius: var(--radius-lg); background: var(--l2); color: var(--fg2); font-size: 0.95rem; white-space: nowrap; }
.chip b { color: var(--fg0); font-weight: 500; }
.chip .dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--bad); }
.chip.open .dot { background: var(--ok); }
.round-chip { flex-direction: column; justify-content: center; align-items: flex-start; gap: 0.15rem; padding: 0 1rem; min-width: 9.5rem; }
.round-chip .lbl { font-size: 0.75rem; color: var(--fg3); line-height: 1; }
.round-chip b { font-size: 1rem; line-height: 1; }
.tick { width: 100%; height: 3px; border-radius: 2px; background: var(--l4); overflow: hidden; }
.tick > i { display: block; height: 100%; width: 0; background: var(--brand-red); transition: width .9s linear; }
.mode { font: 0.8rem var(--mono); color: var(--fg3); background: var(--l2); border: 0; border-radius: var(--radius-md); height: 2.5rem; padding: 0 0.85rem; cursor: pointer; }
.mode.live { color: var(--ok); }
.mode:hover { background: var(--l3); color: var(--fg0); }

/* ------------------------------------------------------------ layout */
.page { position: fixed; inset: var(--header-height) 0 0 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 30rem); gap: 1.25rem; padding: 1rem 2.25rem 1rem; }
.board { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.side { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) minmax(0, 1.1fr); gap: 1rem; }

/* ------------------------------------------------------------ leaderboard */
.lb-head { display: flex; align-items: flex-end; height: var(--name-row); flex: none; }
.lb-head .team-col { flex: 0 1 38rem; min-width: 20rem; padding: 0 1rem 0.5rem; display: flex; justify-content: space-between; color: var(--fg3); font-size: 0.85rem; }
.svc-names { flex: 1; display: flex; gap: var(--row-gap); align-items: flex-end; height: 100%; padding-left: 0.25rem; }
.svc-name { position: relative; flex: 1 1 var(--cell-w); min-width: var(--cell-w); height: 100%; }
.svc-name span {
  position: absolute; bottom: 0.4rem; left: calc(50% - 0.4rem); max-width: 8rem; transform-origin: bottom left; rotate: -45deg;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--accent-fg); font-size: 1rem;
}
.lb-scroll { flex: 1; min-height: 0; overflow: auto; scrollbar-width: none; }
.lb-scroll::-webkit-scrollbar { display: none; }
.lb-row { display: flex; height: var(--row-h); margin-bottom: var(--row-gap); }
@keyframes row-in { from { opacity: 0; } }
.row-team {
  --rank-fg0: var(--fg0); --rank-fg1: var(--fg3); --rank-glow: transparent;
  position: relative; z-index: 0; flex: 0 1 38rem; min-width: 20rem; height: 100%;
  display: flex; align-items: center; gap: 0.75rem; padding: 0 1rem;
}
.row-team::before, .row-team::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: var(--radius-lg); }
.row-team::before { background: var(--l2); }
.row-team.ranked::after { width: min(24rem, 100%); background: linear-gradient(to right, var(--rank-glow), transparent); }
.row-team.first  { --rank-fg0: var(--gold-fg);   --rank-fg1: color-mix(in oklab, var(--gold-fg) 70%, transparent);   --rank-glow: var(--gold-bg); }
.row-team.second { --rank-fg0: var(--silver-fg); --rank-fg1: color-mix(in oklab, var(--silver-fg) 70%, transparent); --rank-glow: var(--silver-bg); }
.row-team.third  { --rank-fg0: var(--bronze-fg); --rank-fg1: color-mix(in oklab, var(--bronze-fg) 70%, transparent); --rank-glow: var(--bronze-bg); }
.lb-row.hit .row-team::before { animation: hit 1.1s ease-out; }
@keyframes hit { 0% { background: color-mix(in oklab, var(--brand-red) 35%, var(--l2)); } 100% { background: var(--l2); } }

.rank { width: 2.5rem; display: flex; flex-direction: column; align-items: center; flex: none; }
.rank strong { color: var(--rank-fg0); font-weight: 400; font-size: 1.3rem; }
.rank small { font-size: 0.8rem; color: var(--fg3); line-height: 1; }
.rank small.up { color: var(--ok); } .rank small.dn { color: var(--bad); }
.avatar { width: 3rem; height: 3rem; flex: none; border-radius: var(--radius-lg); object-fit: cover; background: var(--l4); display: grid; place-items: center; color: var(--fg2); font-weight: 500; }
.tname { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tname b { color: var(--rank-fg0); font-weight: 400; font-size: 1.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tname small { color: var(--rank-fg1); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.points { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.points strong { color: var(--fg1); font-weight: 400; font-size: 1.3rem; white-space: nowrap; }
.points small { color: var(--fg3); font-size: 0.8rem; white-space: nowrap; }
.points small.pos { color: var(--ok); } .points small.neg { color: var(--bad); }

.cells { flex: 1; display: flex; gap: var(--row-gap); padding-left: 0.25rem; height: 100%; }
.cell { position: relative; flex: 1 1 var(--cell-w); min-width: var(--cell-w); display: grid; place-items: center; border-radius: var(--radius-sm); }
.cell:nth-child(odd) { background: color-mix(in oklab, var(--fg0) 4%, transparent); }
.cell i { width: 1.25rem; height: 1.25rem; border-radius: 50%; box-sizing: border-box; }
.cell i.s101 { border: 2.5px solid color-mix(in oklab, var(--ok) 85%, transparent); background: color-mix(in oklab, var(--ok) 18%, transparent); }
.cell i.s102, .cell i.s103 { border: 2.5px solid var(--warn); }
.cell i.s104, .cell i.s110 { border: 2.5px solid var(--bad); background: color-mix(in oklab, var(--bad) 18%, transparent); }
.cell i.s0 { border: 2px dashed var(--fg5); }
.cell small { position: absolute; bottom: 0.3rem; font-size: 0.7rem; color: var(--fg3); }

/* ------------------------------------------------------------ side panels (rCTF ui-section) */
.sec { min-height: 0; display: flex; flex-direction: column; overflow: clip; background: var(--l1); border: 2px solid var(--border); border-radius: var(--radius-lg); }
.sec > h2 { margin: 0; padding: 0.4rem 1rem; font-size: 0.95rem; font-weight: 400; color: var(--fg3); background: var(--l3); display: flex; justify-content: space-between; }
.sec > h2 span { color: var(--fg3); font-size: 0.85rem; }
.chart { flex: 1; min-height: 0; position: relative; padding: 0.5rem; }
.chart svg { width: 100%; height: 100%; display: block; }
.chart .grid line { stroke: var(--border-soft); }
.chart .axis text { fill: var(--fg3); font: 11px var(--mono); }
.chart path { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--fg5); stroke-dasharray: 3 3; }
.tip { position: absolute; display: none; pointer-events: none; z-index: 2; min-width: 11rem; padding: 0.5rem 0.75rem; background: var(--l3); border-radius: var(--radius-md); font-size: 0.85rem; }
.tip h4 { margin: 0 0 0.25rem; font-weight: 400; color: var(--fg3); font-size: 0.8rem; }
.tip .r { display: flex; justify-content: space-between; gap: 1rem; }
.tip .r i { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 2px; margin-right: 0.4rem; }

.feed { list-style: none; margin: 0; padding: 0.25rem 0; overflow: hidden; flex: 1; min-height: 0; }
.feed li { display: grid; grid-template-columns: 4.2rem 1fr; gap: 0.6rem; padding: 0.45rem 1rem; font-size: 0.95rem; border-top: 1px solid var(--border-soft); animation: row-in .3s ease-out; }
.feed li:first-child { border-top: 0; }
.feed .t { font: 0.8rem var(--mono); color: var(--fg3); padding-top: 0.15rem; }
.feed .k { font-weight: 500; margin-right: 0.35rem; }
.k.blood { color: var(--bad); } .k.steal { color: var(--accent-fg); } .k.down { color: var(--warn); } .k.up { color: var(--ok); } .k.net, .k.lead { color: var(--fg0); }
.feed b { color: var(--fg0); font-weight: 500; }
.feed .svc { color: var(--fg3); }
.empty { flex: 1; display: grid; place-items: center; color: var(--fg3); font-size: 0.95rem; padding: 1rem; text-align: center; }
[hidden] { display: none !important; }

/* toast-style callout for first blood / lead change */
.callout { position: fixed; top: calc(var(--header-height) + 1rem); left: 50%; translate: -50% 0; z-index: 20; pointer-events: none; }
.callout > div { padding: 0.75rem 1.5rem; border-radius: var(--radius-lg); background: var(--l3); box-shadow: inset 0 0 0 1px var(--brand-red), 0 0.75rem 2rem #0009; font-size: 1.3rem; color: var(--fg0); animation: callout 4s ease forwards; }
.callout > div span { color: var(--fg2); }
@keyframes callout { 0% { opacity: 0; translate: 0 -8px; } 8%, 85% { opacity: 1; translate: 0 0; } 100% { opacity: 0; } }

@media (max-width: 64rem) {
  body { overflow: auto; }
  .top { position: static; height: auto; flex-wrap: wrap; padding: 0.75rem 1rem; }
  .page { position: static; grid-template-columns: 1fr; padding: 1rem; }
  .board { min-height: 70vh; }
  .side { grid-template-rows: 16rem 20rem; }
  .lb-head .team-col span:last-child { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------ views: all | teams | graph | feed */
.views { display: flex; gap: 0.375rem; }
.views a { display: inline-flex; align-items: center; height: 2.5rem; padding: 0 1rem; border-radius: var(--radius-lg); background: var(--l2); color: var(--fg2); text-decoration: none; font-size: 1rem; }
.views a:hover { background: var(--l3); color: var(--fg0); }
.views a.on { color: var(--accent-fg); background: color-mix(in oklab, var(--accent-bg) 45%, var(--l1)); }
body[data-view="teams"] .page { grid-template-columns: minmax(0, 1fr); }
body[data-view="teams"] .side { display: none; }
body[data-view="teams"] { --row-h: 76px; }
body[data-view="teams"] .tname b { font-size: 1.45rem; }
body[data-view="teams"] .points strong, body[data-view="teams"] .rank strong { font-size: 1.6rem; }
body[data-view="graph"] .page, body[data-view="feed"] .page { grid-template-columns: minmax(0, 1fr); }
body[data-view="graph"] .board, body[data-view="feed"] .board { display: none; }
body[data-view="graph"] .side, body[data-view="feed"] .side { grid-template-rows: minmax(0, 1fr); }
body[data-view="graph"] .sec.feed-sec, body[data-view="feed"] .sec.graph-sec { display: none; }
body[data-view="graph"] .chart .axis text { font-size: 13px; }
body[data-view="graph"] #legend { font-size: 1rem !important; gap: .5rem 1.4rem !important; }
body[data-view="feed"] .feed li { font-size: 1.35rem; padding: 0.75rem 1.5rem; grid-template-columns: 6rem 1fr; }
body[data-view="feed"] .feed .t { font-size: 1rem; }

.mode { display: inline-flex; align-items: center; }
.waiting { padding: 3rem 1rem; text-align: center; color: var(--fg3); font-size: 1.05rem; }
