:root {
  --hot: #ff8a1f;
  --gold: #ffc23a;
  --fire: #ff4d0a;
  --ink: #f4f1ea;
  --dim: #b7b2c4;
  --panel: rgba(40, 36, 38, 0.92);
  --panel-2: rgba(22, 20, 24, 0.9);
  --ui: min(0.62vw, 1.1vh);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #07070a;
  color: var(--ink);
  font-family: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
#stage { position: fixed; inset: 0; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud, #screens { position: absolute; inset: 0; pointer-events: none; }
#screens > * { pointer-events: auto; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ scoreboard */
#scoreboard {
  position: absolute;
  top: calc(var(--ui) * 1.2);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: calc(var(--ui) * 21) calc(var(--ui) * 9) calc(var(--ui) * 16) calc(var(--ui) * 9) calc(var(--ui) * 21);
  grid-template-rows: auto auto;
  background: var(--panel);
  border: calc(var(--ui) * 0.3) solid var(--hot);
  box-shadow: 0 calc(var(--ui) * 0.6) calc(var(--ui) * 2) rgba(0, 0, 0, 0.45);
  font-weight: 700;
  text-transform: uppercase;
}
.sb-team {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--ui) * 0.6) 0;
  line-height: 1;
  border-bottom: calc(var(--ui) * 0.5) solid var(--team-2, #000);
}
.sb-abbr { font-size: calc(var(--ui) * 4.6); font-weight: 800; letter-spacing: 0.02em; }
.sb-name { font-size: calc(var(--ui) * 1.7); font-weight: 700; margin-top: calc(var(--ui) * 0.4); }
.sb-score {
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--ui) * 6.2); font-weight: 800; font-variant-numeric: tabular-nums;
}
.sb-score.bump { animation: bump 0.45s ease-out; }
@keyframes bump { 0% { transform: scale(1.5); color: var(--gold); } 100% { transform: scale(1); } }
.sb-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.sb-quarter { font-size: calc(var(--ui) * 1.9); color: var(--gold); }
.sb-clock { font-size: calc(var(--ui) * 5); font-weight: 800; font-variant-numeric: tabular-nums; }
.sb-clock.low { color: #ff5a3a; }
.sb-shot {
  grid-column: 3; grid-row: 2; justify-self: center;
  margin-bottom: calc(var(--ui) * -4.4);
  background: rgba(10, 10, 10, 0.92);
  padding: calc(var(--ui) * 0.2) calc(var(--ui) * 1.5);
  font-size: calc(var(--ui) * 3.4); font-weight: 800; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.sb-shot.low span { color: #ff4d33; }

/* ------------------------------------------------------------------ player cards */
#cards { position: absolute; inset: auto 0 calc(var(--ui) * 2.2) 0; display: flex; justify-content: space-between; padding: 0 calc(var(--ui) * 1.2); }
.cards-side { display: flex; flex-direction: column; gap: calc(var(--ui) * 0.7); width: calc(var(--ui) * 36); }
.card {
  background: var(--panel);
  border-left: calc(var(--ui) * 0.9) solid var(--team, #888);
  padding: calc(var(--ui) * 0.7) calc(var(--ui) * 1.6) calc(var(--ui) * 0.8);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: baseline;
  column-gap: calc(var(--ui) * 1);
  font-weight: 700;
  text-transform: uppercase;
  position: relative;
}
.card .who { font-size: calc(var(--ui) * 2.3); color: var(--dim); font-weight: 600; }
.card.human .who { color: var(--gold); }
.card.human.p2 .who { color: #4cc3ff; }
.card .nm { font-size: calc(var(--ui) * 2.3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .pts { font-size: calc(var(--ui) * 1.6); color: var(--ink); }
.card .tb { grid-column: 1 / 4; display: flex; align-items: center; gap: calc(var(--ui) * 0.8); margin-top: calc(var(--ui) * 0.5); }
.card .bar { flex: 1; height: calc(var(--ui) * 0.9); background: rgba(255, 255, 255, 0.18); position: relative; overflow: hidden; }
.card .bar i { position: absolute; inset: 0 auto 0 0; background: #4ee06b; width: 100%; transition: background 0.2s; }
.card .bar i.low { background: #ff5a3a; }
.card .tl { font-size: calc(var(--ui) * 1.25); color: var(--dim); }
.card .heat { width: calc(var(--ui) * 1.2); height: calc(var(--ui) * 1.2); background: rgba(255, 255, 255, 0.15); }
.card .heat.warm { background: var(--hot); }
.card.fire { box-shadow: 0 0 calc(var(--ui) * 1.6) rgba(255, 90, 10, 0.75), inset 0 0 calc(var(--ui) * 2) rgba(255, 80, 0, 0.35); }
.card.fire .heat { background: var(--fire); animation: flick 0.25s infinite alternate; }
@keyframes flick { from { opacity: 0.6; } to { opacity: 1; } }

/* ------------------------------------------------------------------ popups + meter */
#popups { position: absolute; inset: 0; }
.popup {
  position: absolute; left: 50%; transform: translate(-50%, -50%);
  text-align: center; white-space: nowrap; line-height: 0.95;
  font-weight: 800; font-style: italic; letter-spacing: 0.01em;
  -webkit-text-stroke: calc(var(--ui) * 0.18) rgba(0, 0, 0, 0.55);
  text-shadow: 0 calc(var(--ui) * 0.5) 0 rgba(0, 0, 0, 0.45), 0 0 calc(var(--ui) * 3) currentColor;
  will-change: transform, opacity;
}
.popup small {
  display: block; font-size: calc(var(--ui) * 2.8); font-style: normal; color: #fff;
  -webkit-text-stroke: 0; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7); margin-top: calc(var(--ui) * 0.6);
}
#meter {
  position: absolute; width: calc(var(--ui) * 1.6); height: calc(var(--ui) * 12);
  background: rgba(0, 0, 0, 0.8); border: calc(var(--ui) * 0.25) solid rgba(0, 0, 0, 0.8);
}
.meter-win { position: absolute; left: 0; right: 0; top: 0; height: 16%; background: rgba(50, 255, 80, 0.45); }
.meter-fill { position: absolute; left: 0; right: 0; bottom: 0; background: var(--gold); }
#tags .tag {
  position: absolute; transform: translate(-50%, -100%);
  font-weight: 800; font-size: calc(var(--ui) * 2); color: var(--gold);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.8);
}
#tags .tag.p2 { color: #4cc3ff; }
#tags .tag::after { content: '▼'; display: block; text-align: center; font-size: 0.6em; margin-top: -0.2em; }
#fps { position: absolute; right: 8px; top: 8px; font: 600 12px/1 ui-monospace, monospace; background: rgba(0, 0, 0, 0.6); padding: 4px 6px; }

/* ------------------------------------------------------------------ screens */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-transform: uppercase; font-weight: 700;
}
.screen.dim { background: radial-gradient(ellipse at center, rgba(8, 6, 10, 0.55), rgba(8, 6, 10, 0.86)); }
.screen h1, .screen h2 {
  margin: 0; font-weight: 800; color: var(--gold); letter-spacing: 0.01em;
  text-shadow: 0 calc(var(--ui) * 0.4) 0 rgba(0, 0, 0, 0.5);
}
.screen h2 { font-size: calc(var(--ui) * 6); }
.title-logo { width: min(60vw, 110vh); max-width: 1100px; filter: drop-shadow(0 1vh 3vh rgba(0, 0, 0, 0.6)); animation: logo-in 0.8s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes logo-in { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.press {
  margin-top: calc(var(--ui) * 3); font-size: calc(var(--ui) * 4.2); font-weight: 800; color: #fff;
  animation: blink 1.1s steps(2) infinite; text-shadow: 0 0 calc(var(--ui) * 2) rgba(255, 140, 30, 0.8);
  cursor: pointer; background: none; border: 0; font-family: inherit; text-transform: uppercase;
}
@keyframes blink { 50% { opacity: 0.35; } }
.hint { margin-top: calc(var(--ui) * 2.5); text-align: center; font-size: calc(var(--ui) * 1.9); color: #dcd7e6; line-height: 1.5; font-weight: 600; }
.hint b { color: var(--hot); font-weight: 700; }
.foot { position: absolute; bottom: calc(var(--ui) * 2.5); left: 0; right: 0; text-align: center; font-size: calc(var(--ui) * 2.1); color: #e8e4ef; }
.foot span { margin: 0 calc(var(--ui) * 1.5); white-space: nowrap; }
.foot a { color: var(--gold); text-decoration: none; pointer-events: auto; }

.menu { margin-top: calc(var(--ui) * 2.5); display: flex; flex-direction: column; gap: calc(var(--ui) * 0.5); min-width: calc(var(--ui) * 52); }
.menu button {
  all: unset; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 1em;
  padding: calc(var(--ui) * 0.9) calc(var(--ui) * 2.2);
  font-size: calc(var(--ui) * 3); font-weight: 700; color: #d9d4e2;
  background: rgba(30, 28, 32, 0.72); border-left: calc(var(--ui) * 0.6) solid transparent;
}
.menu button .arrows { opacity: 0; color: var(--hot); }
.menu button.sel { color: #fff; background: linear-gradient(90deg, rgba(255, 138, 31, 0.32), rgba(30, 28, 32, 0.8)); border-left-color: var(--hot); }
.menu button.sel .arrows { opacity: 1; }
.menu button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.ts { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: calc(var(--ui) * 1.5); width: min(94vw, 170vh); margin-top: calc(var(--ui) * 2); }
.ts-vs { font-size: calc(var(--ui) * 9); font-weight: 800; color: var(--gold); font-style: italic; }
.ts-card {
  background: rgba(40, 36, 38, 0.94); border: calc(var(--ui) * 0.35) solid rgba(255, 255, 255, 0.15);
  border-top: calc(var(--ui) * 1) solid var(--team); padding: calc(var(--ui) * 1.6) calc(var(--ui) * 3);
  display: flex; flex-direction: column; align-items: center; position: relative;
}
.ts-card.sel { border-color: var(--hot); border-top-color: var(--team); }
.ts-who { font-size: calc(var(--ui) * 3); color: #fff; }
.ts-badge-row { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.ts-badge { height: calc(var(--ui) * 22); width: calc(var(--ui) * 22); object-fit: contain; margin: calc(var(--ui) * 1) 0; }
.ts-arrow { all: unset; cursor: pointer; font-size: calc(var(--ui) * 6); font-weight: 800; color: #fff; padding: 0 calc(var(--ui) * 1); }
.ts-arrow:hover { color: var(--hot); }
.ts-city { font-size: calc(var(--ui) * 3.2); color: #fff; }
.ts-name { font-size: calc(var(--ui) * 6.5); font-weight: 800; color: var(--team-text); line-height: 1; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45); }
.ts-player { width: 100%; margin-top: calc(var(--ui) * 2); }
.ts-player .pn { font-size: calc(var(--ui) * 3); color: #fff; }
.ts-player .nick { font-size: calc(var(--ui) * 2.1); color: var(--gold); }
.ts-stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: calc(var(--ui) * 1.2); margin-top: calc(var(--ui) * 0.8); }
.ts-stats div { font-size: calc(var(--ui) * 1.5); color: #eee; }
.ts-stats i { display: block; height: calc(var(--ui) * 0.7); background: rgba(255, 255, 255, 0.2); margin-top: calc(var(--ui) * 0.4); position: relative; }
.ts-stats i b { position: absolute; inset: 0 auto 0 0; background: var(--gold); }
.ts-stats i b.lo { background: var(--hot); }

.panel { background: rgba(28, 25, 30, 0.95); border: calc(var(--ui) * 0.3) solid var(--hot); padding: calc(var(--ui) * 2.5) calc(var(--ui) * 4); min-width: calc(var(--ui) * 70); max-width: 94vw; max-height: 88vh; overflow: auto; }
.box { border-collapse: collapse; width: 100%; margin-top: calc(var(--ui) * 1.5); font-size: calc(var(--ui) * 2.1); }
.box th { color: var(--gold); font-weight: 700; text-align: right; padding: calc(var(--ui) * 0.4) calc(var(--ui) * 0.9); }
.box td { text-align: right; padding: calc(var(--ui) * 0.35) calc(var(--ui) * 0.9); border-top: 1px solid rgba(255, 255, 255, 0.08); font-variant-numeric: tabular-nums; }
.box th:first-child, .box td:first-child { text-align: left; }
.box tr.teamrow td { color: #fff; font-weight: 800; background: rgba(255, 255, 255, 0.05); }
.qs { display: flex; justify-content: center; gap: calc(var(--ui) * 3); font-size: calc(var(--ui) * 3); margin-top: calc(var(--ui) * 1); }
.winner { font-size: calc(var(--ui) * 7); color: var(--gold); text-shadow: 0 0 calc(var(--ui) * 3) rgba(255, 140, 20, 0.8); }

.opt-tabs { display: flex; gap: calc(var(--ui) * 1); margin: calc(var(--ui) * 1.4) 0; }
.opt-tabs button { all: unset; cursor: pointer; font-size: calc(var(--ui) * 2.6); padding: calc(var(--ui) * 0.4) calc(var(--ui) * 2); background: rgba(255, 255, 255, 0.08); }
.opt-tabs button.on { background: var(--hot); color: #160c02; }
.opt-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: calc(var(--ui) * 3); padding: calc(var(--ui) * 0.8) calc(var(--ui) * 1.5); font-size: calc(var(--ui) * 2.6); background: rgba(255, 255, 255, 0.04); margin-bottom: calc(var(--ui) * 0.4); cursor: pointer; border-left: calc(var(--ui) * 0.5) solid transparent; }
.opt-row.sel { border-left-color: var(--hot); background: rgba(255, 138, 31, 0.18); }
.opt-row .val { display: flex; align-items: center; gap: calc(var(--ui) * 1.2); color: var(--gold); }
.opt-row .val button { all: unset; cursor: pointer; color: #fff; font-size: 1.1em; padding: 0 0.3em; }
.opt-row .slider { width: calc(var(--ui) * 16); height: calc(var(--ui) * 0.9); background: rgba(255, 255, 255, 0.2); position: relative; }
.opt-row .slider b { position: absolute; inset: 0 auto 0 0; background: var(--gold); }
.help { font-size: calc(var(--ui) * 2.2); font-weight: 600; text-transform: none; line-height: 1.45; }
.help table { border-collapse: collapse; width: 100%; margin: calc(var(--ui) * 1) 0 calc(var(--ui) * 1.6); }
.help th { text-align: left; color: var(--gold); text-transform: uppercase; font-weight: 700; padding: 0.25em 0.6em; }
.help td { padding: 0.25em 0.6em; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.help ul { margin: 0; padding-left: 1.2em; }
.help li { margin: 0.2em 0; }
.help b { color: var(--hot); }
.intro-banner { position: absolute; bottom: 12vh; left: 0; right: 0; display: flex; justify-content: center; gap: calc(var(--ui) * 4); align-items: center; pointer-events: none; }
.intro-team { display: flex; align-items: center; gap: calc(var(--ui) * 1.5); font-size: calc(var(--ui) * 5); font-weight: 800; animation: slide-in 0.6s cubic-bezier(.2, 1.3, .4, 1) both; }
.intro-team img { height: calc(var(--ui) * 14); }
.intro-team.right { animation-delay: 1.4s; }
.intro-vs { font-size: calc(var(--ui) * 6); color: var(--gold); font-style: italic; font-weight: 800; animation: slide-in 0.5s 0.8s both; }
@keyframes slide-in { from { opacity: 0; transform: translateY(4vh) scale(0.8); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ loading */
#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #2a1308 0%, #0a0708 60%, #050506 100%);
  transition: opacity 0.6s; z-index: 10;
}
#loading.done { opacity: 0; pointer-events: none; }
.load-logo { width: min(70vw, 720px); filter: drop-shadow(0 1vh 3vh rgba(0, 0, 0, 0.6)); }
.load-bar { width: min(60vw, 520px); height: 10px; background: rgba(255, 255, 255, 0.12); margin-top: 4vh; overflow: hidden; }
.load-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--fire), var(--gold)); transition: width 0.2s; }
.load-text { margin-top: 1.6vh; font-size: 20px; letter-spacing: 0.08em; color: var(--dim); font-weight: 700; }
.load-error { color: #ff8a6a; font-size: 20px; text-align: center; max-width: 80vw; text-transform: none; }
.load-error a { color: var(--gold); }

#rotate { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: #07070a; font-size: 28px; font-weight: 800; color: var(--gold); text-align: center; }
#rotate small { font-size: 16px; color: var(--dim); font-weight: 600; }

/* ------------------------------------------------------------------ touch */
#touch { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.tc-stick {
  position: absolute; left: calc(env(safe-area-inset-left) + 4vh); bottom: 5vh;
  width: 30vh; height: 30vh; max-width: 190px; max-height: 190px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.07); border: 2px solid rgba(255, 255, 255, 0.22);
  pointer-events: auto; touch-action: none; display: grid; place-items: center;
}
.tc-knob { width: 40%; height: 40%; border-radius: 50%; background: rgba(255, 200, 120, 0.5); border: 2px solid rgba(255, 255, 255, 0.5); }
.tc-buttons {
  position: absolute; right: calc(env(safe-area-inset-right) + 3vh); bottom: 4vh;
  display: grid; grid-template-columns: repeat(2, 15vh); grid-template-rows: repeat(2, 15vh); gap: 2.4vh;
  max-width: 260px;
}
.tc-btn {
  all: unset; pointer-events: auto; touch-action: none; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: clamp(11px, 2.6vh, 16px); letter-spacing: 0.04em;
  background: rgba(30, 28, 32, 0.6); border: 2px solid rgba(255, 255, 255, 0.35); color: #fff;
}
.tc-btn.on { transform: scale(0.92); background: rgba(255, 138, 31, 0.6); }
.tc-shoot { background: rgba(255, 110, 20, 0.55); border-color: #ffb066; }
.tc-turbo { background: rgba(60, 200, 90, 0.4); }
.tc-pause { all: unset; pointer-events: auto; position: absolute; top: 2vh; right: calc(env(safe-area-inset-right) + 2vh); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.5); border: 2px solid rgba(255, 255, 255, 0.3); font-weight: 800; }
body.touch .hint.kb, body.touch .foot.kb { display: none; }
body:not(.touch) .touch-only { display: none; }

/* touch layout: player cards move to the top corners, pause to the bottom centre */
body.touch #cards { inset: calc(env(safe-area-inset-top) + 6px) 0 auto 0; padding: 0 calc(env(safe-area-inset-left) + 8px); }
body.touch .cards-side { width: calc(var(--ui) * 30); gap: 3px; }
body.touch .tc-pause { top: auto; bottom: 2vh; right: auto; left: 50%; transform: translateX(-50%); }
