:root {
  --bg: #06070d; --fg: #e6e8f0; --dim: #8b90a3; --line: rgba(255, 255, 255, .08); --red: #ff3b5c; --gold: #ffc53d;
  --title: clamp(44px, 4.6vh, 110px); --rail: clamp(360px, 23vw, 820px); --feed: clamp(160px, 22vh, 500px);
  --fs-feed: clamp(16px, 1.8vh, 40px); --fs-board: clamp(14px, 1.6vh, 36px); --fs-small: clamp(11px, 1.15vh, 26px);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;
  --display: "Avenir Next Condensed", "DIN Alternate", "Bahnschrift", "Futura", "Helvetica Neue", system-ui, sans-serif;
}

html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.4 var(--sans); overflow: hidden; }
#map, #labels, #vignette { position: fixed; top: var(--title); left: 0; right: var(--rail); bottom: var(--feed); display: block; }
#labels, #vignette { pointer-events: none; overflow: hidden; }
#vignette { background: radial-gradient(ellipse at 50% 52%, transparent 55%, rgba(0, 0, 0, .55) 100%); }

.label {
  position: absolute; left: 0; top: 0; text-align: center; width: max-content; will-change: transform;
  font: 600 clamp(16px, min(calc(var(--map-h, 73vh) * .06), 2.3vw), 64px)/1 var(--display); text-transform: uppercase; letter-spacing: .08em;
}
.crown { font-size: .62em; margin-left: .3em; text-shadow: 0 0 10px currentColor; }
.label .n { display: block; margin-top: 4px; font: var(--fs-small) var(--mono); letter-spacing: 0; text-transform: none; color: var(--dim); text-shadow: 0 0 2px #000, 0 0 8px #000; }

#titlebar {
  position: fixed; top: 0; left: 0; right: var(--rail); height: var(--title); box-sizing: border-box;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  border-bottom: 1px solid var(--line); background: rgba(6, 7, 13, .6);
}
#name { font: 700 clamp(16px, 1.9vh, 44px) var(--display); letter-spacing: .14em; text-transform: uppercase; }
#count, #status, #queue { color: var(--dim); font: var(--fs-small) var(--mono); }
#queue { color: var(--fg); }
#status { margin-left: auto; }
#settings { background: none; border: 1px solid var(--line); border-radius: 4px; color: var(--dim); font: var(--fs-small) var(--sans); padding: .3em .8em; cursor: pointer; }
#settings:hover { color: var(--fg); border-color: var(--dim); }
:focus-visible { outline: 2px solid #e6e8f0; outline-offset: 2px; }

#rail {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--rail); box-sizing: border-box; padding: 14px 12px;
  border-left: 1px solid var(--line); background: rgba(6, 7, 13, .75); overflow: hidden;
}
#rail h2 { margin: 0 0 10px; font-size: var(--fs-small); font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--dim); }
#board { width: 100%; border-collapse: collapse; table-layout: auto; }
#board th { text-align: right; font: 500 calc(var(--fs-small) * .88) var(--sans); letter-spacing: .03em; text-transform: uppercase; color: var(--dim); padding: 4px 3px 6px; border-bottom: 1px solid var(--line); }
#board td { padding: .5em .2em; text-align: right; font: var(--fs-board) var(--mono); border-bottom: 1px solid var(--line); white-space: nowrap; }
#board th:nth-child(n+2), #board td:nth-child(n+2) { width: 1%; font-variant-numeric: tabular-nums; }   /* width 1%: auto layout keeps the numbers at their content width and leaves the rest to the team name */
#board th:nth-child(n+2) { min-width: 3.4em; }   /* on the header only: 3.4em of the 15 px cell font would be wider than the headers and squeeze the names out of the rail */
#board th:first-child, #board td:first-child { text-align: left; padding-left: 0; }
#board th:last-child, #board td:last-child, #board th:has(+ [hidden]) { padding-right: 0; }   /* :has: the hidden penalty th is still the last child, so the depth th would keep its padding and sit 3px left of its numbers */
#board td:first-child { font: 600 var(--fs-board) var(--sans); overflow: hidden; text-overflow: ellipsis; max-width: 0; }   /* max-width 0 in auto layout: the name column takes what the numbers leave and ellipsises, instead of its min-content pushing them out of the rail */
.swatch { display: inline-block; width: .62em; height: .62em; border-radius: 50%; margin-right: .45em; background: currentColor; box-shadow: 0 0 8px currentColor; vertical-align: -1px; }
.broken { color: var(--red); text-shadow: 0 0 8px currentColor; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: .45em; margin-top: .3em; }
.combo { display: inline-flex; align-items: center; gap: .28em; }
.combo i { width: .42em; height: .42em; border-radius: 50%; background: currentColor; box-shadow: 0 0 .5em currentColor; }
.combo .x { font: var(--fs-small) var(--mono); }
.badge {
  font: 700 calc(var(--fs-small) * .95)/1 var(--mono); font-style: normal; letter-spacing: .06em; padding: .22em .35em;
  border: 1px solid currentColor; border-radius: 3px; text-shadow: 0 0 .5em currentColor; opacity: .85;
}
#board tr.pulse td { animation: rowpulse .9s ease-out; }
@keyframes rowpulse {
  0% { background: color-mix(in srgb, var(--tc, #fff) 55%, transparent); }
  100% { background: color-mix(in srgb, var(--tc, #fff) 0%, transparent); }
}

#legend { position: fixed; left: 0; right: var(--rail); bottom: var(--feed); margin: 0; padding: 6px 18px; font: var(--fs-feed) var(--sans); color: var(--fg); background: rgba(6, 7, 13, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#map { cursor: grab; }
#map:active { cursor: grabbing; }
#zoom { position: fixed; z-index: 3; right: calc(var(--rail) + 12px); bottom: calc(var(--feed) + 12px); display: flex; gap: 4px; }
#zoom button { min-width: 2.2em; background: rgba(6, 7, 13, .75); border: 1px solid var(--line); border-radius: 4px; color: var(--dim); font: var(--fs-small) var(--sans); padding: .35em .7em; cursor: pointer; }
#zoom button:hover:not(:disabled) { color: var(--fg); border-color: var(--dim); }
#zoom button:disabled { opacity: .4; cursor: default; }

/* The feed's top edge: a 12 px strip to drag, with a short bar that shows on hover and focus. */
#feed-grip { position: fixed; z-index: 3; left: 0; right: var(--rail); bottom: calc(var(--feed) - 6px); height: 12px; cursor: ns-resize; touch-action: none; }
#feed-grip::after { content: ""; position: absolute; left: 50%; top: 4px; width: 56px; height: 4px; margin-left: -28px; border-radius: 2px; background: var(--dim); opacity: .35; transition: opacity .15s; }
#feed-grip:hover::after, #feed-grip:focus-visible::after, #feed-grip:active::after { opacity: 1; }

#feedbar {
  position: fixed; left: 0; right: var(--rail); bottom: 0; height: var(--feed); box-sizing: border-box;
  padding: clamp(8px, 1vh, 22px) 18px;
  border-top: 1px solid var(--line); background: rgba(6, 7, 13, .75);
  overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; overscroll-behavior: contain;
}
#feed .line { white-space: normal; overflow-wrap: anywhere; font-size: var(--fs-feed); line-height: 1.5; padding: .3em 0; border-bottom: 1px solid var(--line); }
#feed .line:first-child { font-size: calc(var(--fs-feed) * 1.08); }
#feed .line:last-child { border-bottom: 0; }

#banner {
  position: fixed; z-index: 4; top: var(--title); left: 0; right: var(--rail); pointer-events: none;
  padding: clamp(8px, 1.3vh, 26px) 18px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font: 700 clamp(22px, 3.3vh, 80px)/1.1 var(--display); letter-spacing: .12em; text-transform: uppercase;
  text-shadow: 0 0 .3em currentColor, 0 0 1em currentColor;
  border-top: 1px solid currentColor; border-bottom: 1px solid currentColor;
  background: linear-gradient(90deg, transparent, rgba(6, 7, 13, .92) 14%, rgba(6, 7, 13, .92) 86%, transparent);
}
#banner.in { animation: banner var(--banner-ms, 2800ms) ease-out both; }
@keyframes banner {
  0% { opacity: 0; transform: translateY(-12px) scaleY(.75); }
  7% { opacity: 1; transform: none; }
  86% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-6px); }
}
@keyframes bannerfade { 0%, 100% { opacity: 0; } 7%, 86% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #banner.in { animation-name: bannerfade; }
  #board tr.pulse td { animation: none; }
}
body.power #titlebar { border-bottom-color: var(--gold); box-shadow: 0 0 2em rgba(255, 197, 61, .3); }
body.power #name { color: var(--gold); text-shadow: 0 0 .4em currentColor; }

#tip {
  position: fixed; z-index: 3; max-width: clamp(380px, 26vw, 620px); padding: 10px 12px; pointer-events: none;
  background: rgba(10, 12, 20, .94); border: 1px solid var(--line); border-radius: 6px; font-size: clamp(12px, 1.25vh, 28px);
}
#tip .h { font-weight: 700; margin-bottom: 6px; text-shadow: 0 0 8px currentColor; }
#tip .row { display: grid; grid-template-columns: 8.5em 1fr; gap: 8px; }
#tip .k { color: var(--dim); }

#debug { position: fixed; left: 12px; top: calc(var(--title) + 8px); font: 11px var(--mono); color: var(--dim); }
#error { position: fixed; top: 0; left: 0; right: 0; z-index: 9; padding: 10px 18px; background: var(--red); color: #fff; font-weight: 600; }

dialog#explainer {
  position: fixed; inset: var(--title) auto 0 0; margin: 0; width: 560px; max-width: calc(100vw - var(--rail)); height: auto; max-height: none; box-sizing: border-box;   /* height: auto beats the UA's fit-content, so top/bottom size the panel and it scrolls */
  padding: 28px 32px; overflow-y: auto; border: 0; border-right: 1px solid var(--line);
  background: #0b0d16; color: #e6e8f0; font: 16px/1.55 var(--sans);
}
dialog#explainer::backdrop { background: rgba(0, 0, 0, .6); }
dialog#explainer h1 { margin: 0 0 18px; font: 700 28px var(--display); letter-spacing: .06em; text-transform: uppercase; }
dialog#explainer h2 { margin: 22px 0 6px; font: 12px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: #a9b0bd; }
dialog#explainer p, dialog#explainer ul { margin: 0 0 10px; padding: 0; }
dialog#explainer li { list-style: none; margin: 0 0 8px; }
dialog#explainer em { font-style: normal; font-weight: 600; }
dialog#explainer .hint { color: #a9b0bd; }
dialog#explainer form { margin-top: 18px; }
dialog#explainer form button { background: none; border: 1px solid #a9b0bd; border-radius: 4px; color: #e6e8f0; font: 14px var(--sans); padding: 6px 14px; cursor: pointer; }
dialog#settings-panel {
  position: fixed; inset: var(--title) auto auto 0; margin: 0; width: 320px; max-width: calc(100vw - var(--rail)); box-sizing: border-box;
  padding: 22px 26px 24px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: #0b0d16; color: #e6e8f0; font: 15px/1.5 var(--sans);
}
dialog#settings-panel::backdrop { background: rgba(0, 0, 0, .6); }
dialog#settings-panel h1 { margin: 0 0 18px; font: 700 20px var(--display); letter-spacing: .06em; text-transform: uppercase; }
dialog#settings-panel form { margin: 0; }
dialog#settings-panel button { display: block; width: 100%; margin-top: 14px; text-align: left; background: none; border: 1px solid #a9b0bd; border-radius: 4px; color: #e6e8f0; font: 14px var(--sans); padding: 6px 14px; cursor: pointer; }
dialog#settings-panel button:hover { border-color: #e6e8f0; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; width: 38px; height: 20px; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 10px; background: #171a26; cursor: pointer;
}
.switch input::after { content: ""; display: block; width: 14px; height: 14px; margin: 2px; border-radius: 50%; background: var(--dim); transition: transform .15s, background .15s; }
.switch input:checked { background: rgba(255, 43, 214, .22); border-color: #ff2bd6; }
.switch input:checked::after { transform: translateX(18px); background: #ff2bd6; box-shadow: 0 0 8px #ff2bd6; }
.switch + .switch, .slider { margin-top: 12px; }
.slider { display: flex; align-items: center; gap: 12px; }
.slider input { flex: 1; accent-color: #ff2bd6; cursor: pointer; }

.g { display: inline-block; vertical-align: middle; margin-right: 10px; border-radius: 50%; }
.g-ghost { width: 7px; height: 7px; background: #a9b0bd; }
.g-lit { width: 18px; height: 18px; background: #ff2bd6; box-shadow: 0 0 10px 2px #ff2bd6; }
.g-big { width: 26px; height: 26px; background: #ff2bd6; box-shadow: 0 0 12px 3px #ff2bd6; }
.g-faded { width: 18px; height: 18px; background: #ff2bd6; opacity: .4; }
.g-ring { width: 14px; height: 14px; box-sizing: border-box; border: 1.5px solid #ff2bd6; background: radial-gradient(circle, #ff2bd6 3px, transparent 4px); }
.g-line { width: 40px; height: 1px; border-radius: 0; background: rgba(255, 43, 214, .35); vertical-align: middle; }

body.sandbox { --rail: clamp(440px, 28vw, 820px); }
body.sandbox .label { font-size: clamp(16px, 1.6vw, 32px); }
body.sandbox #titlebar { border-bottom-color: #00f0ff; }
body.sandbox #status { color: #00f0ff; }
#sandbox-toggle { position: fixed; z-index: 5; top: 8px; right: 12px; }
#sandbox-panel {
  position: fixed; z-index: 5; right: 10px; bottom: 10px; width: calc(var(--rail) - 20px);
  max-width: 410px; max-height: calc(100vh - 255px); box-sizing: border-box; overflow-y: auto;
  padding: 14px; border: 1px solid #365268; border-radius: 8px; background: #0b101c;
  color: var(--fg); font: 12px/1.45 var(--sans); box-shadow: 0 12px 40px #0008;
}
#sandbox-panel[hidden] { display: none; }
#sandbox-panel header { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
#sandbox-panel header button { width: auto; margin: 0; padding: 0 8px; font-size: 20px; }
#sandbox-panel label { display: block; color: #abb8ca; margin-top: 8px; }
#sandbox-panel select, #sandbox-panel input:not([type=checkbox]) {
  display: block; width: 100%; min-width: 0; box-sizing: border-box; margin-top: 4px;
  padding: 6px 8px; border: 1px solid #354157; border-radius: 4px; background: #141c2b; color: var(--fg); font: inherit;
}
#sandbox-panel button, #sandbox-toggle {
  border: 1px solid #40536c; border-radius: 4px; background: #17283a; color: #e6e8f0; padding: 6px 8px;
  font: 12px/1.4 var(--sans); cursor: pointer;
}
#sandbox-panel button { width: 100%; margin-top: 8px; }
#sandbox-panel button:hover, #sandbox-toggle:hover { background: #223a52; border-color: #00bfd0; }
#sandbox-panel fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
#sandbox-panel fieldset:disabled { opacity: .45; }
#sandbox-panel fieldset:disabled button { cursor: default; }
#sandbox-panel .sandbox-row { display: flex; gap: 8px; }
#sandbox-panel .sandbox-row > * { flex: 1; min-width: 0; }
#sandbox-panel .sandbox-check { display: flex; gap: 7px; align-items: start; }
#sandbox-panel input[type=checkbox] { accent-color: #00bfd0; }
#sandbox-panel details { margin-top: 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
#sandbox-panel summary { cursor: pointer; color: #b8d7ef; }
#sandbox-panel .sandbox-hint { color: #889cb4; margin: 6px 0; font-size: 11px; }
#demo-feedback { color: #9febe4; margin: 12px 0 4px; }
@media (max-height: 650px) { #sandbox-panel { max-height: calc(100vh - 180px); } }
