:root {
  --bg: #0c1013;
  --bg-2: #141a1f;
  --panel: #1a2127;
  --panel-2: #212a31;
  --line: #2b353d;
  --text: #e8edf1;
  --text-dim: #9aa7b2;
  --accent: #33d17a;
  --accent-dim: #1f6f47;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 700px at 50% -10%, #16211c 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.view {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.hidden {
  display: none !important;
}

/* ===================== Chooser ===================== */
.site-header {
  padding: 28px 32px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: radial-gradient(circle at 30% 30%, #2ecc71, #0b3d2e);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15), var(--shadow);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.tagline {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}

.chooser-main {
  padding: 32px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}
.section-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 0 0 18px;
}
.match-list {
  display: flex;
  flex-direction: column;
  gap: 36px;
}
.match-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.match-section-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 9px;
}
.match-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.loading {
  color: var(--text-dim);
}

.match-card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
  text-align: left;
  color: inherit;
  font: inherit;
}
.match-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent-dim);
  box-shadow: var(--shadow);
}
.match-card .comp {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 600;
}
.match-card .card-teams {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 18px;
  font-weight: 650;
  margin: 2px 0 8px;
  letter-spacing: -0.01em;
}
.match-card .card-teams .ct {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.match-card .card-flag {
  width: 24px;
  height: 17px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
  flex: none;
}
.match-card .card-teams .mid {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 14px;
}
.match-card .card-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 2px 0 8px;
}
.match-card .card-score .cs-dash {
  color: var(--text-dim);
  font-weight: 500;
  margin: 0 2px;
}
.match-card .card-score .cs-pen {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  align-self: center;
}
.match-card .card-sub {
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===================== Viewer ===================== */
#viewer {
  height: 100vh;
  overflow: hidden;
}
.viewer-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.back-btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  white-space: nowrap;
}
.back-btn:hover {
  background: var(--panel-2);
}
.match-title {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}
.teams {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 16px;
}
.team-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.team-chip .dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  flex: none;
}
.vs {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 13px;
}
.match-meta {
  color: var(--text-dim);
  font-size: 12.5px;
}
.event-badge {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(51, 209, 122, 0.12);
  border: 1px solid var(--accent-dim);
  padding: 6px 12px;
  border-radius: 20px;
  min-width: 90px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
}
.event-badge.show {
  opacity: 1;
}

.viewer-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: #05070a;
  display: flex;
}

/* ---- Event tray ---- */
.event-tray {
  width: 360px;
  flex: none;
  background: var(--bg-2);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  transition: width 0.25s ease, opacity 0.2s ease;
}
.event-tray.collapsed {
  width: 0;
  opacity: 0;
  overflow: hidden;
}
.tray-inner {
  padding: 18px 18px 20px;
  min-width: 360px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.open-video-btn {
  margin-top: auto;      /* pin to the bottom of the tray */
  padding: 11px 12px;
  background: var(--accent);
  color: #06231a;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  width: 100%;
}
.open-video-btn:hover { filter: brightness(1.08); }
.tray-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.tray-eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}
#tray-title {
  margin: 6px 0 4px;
  font-size: 20px;
  letter-spacing: -0.01em;
}
.tray-sub {
  color: var(--text-dim);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.team-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  margin-right: 2px;
  vertical-align: middle;
}
.tray-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.tray-empty {
  color: var(--text-dim);
  font-size: 13px;
}
.tray-section h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
}
.tray-section dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(96px, 40%) 1fr;
  gap: 5px 12px;
}
.tray-section .row {
  display: contents;
}
.tray-section dt {
  color: var(--text-dim);
  font-size: 12.5px;
}
.tray-section dd {
  margin: 0;
  font-size: 12.5px;
  color: var(--text);
  word-break: break-word;
}
.tray-section dd .code {
  display: inline-block;
  font-size: 10.5px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 5px;
  margin-left: 5px;
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
}
.tray-section dd .muted {
  color: var(--text-dim);
}

.tray-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  height: 34px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(20, 26, 31, 0.85);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  backdrop-filter: blur(6px);
  transition: background 0.15s;
}
.tray-toggle:hover {
  background: var(--panel-2);
}
#pitch {
  width: 100%;
  height: 100%;
  display: block;
}
.viewer-loading {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  backdrop-filter: blur(6px);
}

/* ---- 3D stage ---- */
.stage3d {
  position: absolute;
  inset: 0;
}
.stage3d canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- Broadcast scorebug ---- */
.scorebug {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 4;
  font-family: "Segoe UI", -apple-system, Roboto, sans-serif;
  color: #fff;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.5));
  user-select: none;
}
.sb-row {
  display: flex;
  align-items: stretch;
  height: 40px;
  background: linear-gradient(180deg, rgba(20, 26, 33, 0.96), rgba(10, 14, 18, 0.96));
  border-radius: 6px;
  overflow: hidden;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
}
.sb-team {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}
.sb-swatch {
  width: 16px;
  height: 22px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.sb-flag {
  width: 26px;
  height: 18px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
  display: none;
}
.sb-abbr { font-weight: 800; }
.sb-score {
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
  justify-content: center;
}
.sb-score.sep { padding: 0; opacity: 0.6; }
.sb-clock {
  display: flex;
  align-items: center;
  padding: 0 14px;
  margin-left: 4px;
  background: linear-gradient(180deg, #6395e3, #4a63a6);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

/* ---- Alien scorebug: static neon line-drawing ---- */
.scorebug.alien {
  filter: none;
  color: #7dfcff;
}
.scorebug.alien .sb-row {
  background: rgba(6, 10, 16, 0.35);
  border: 1.5px solid #37f5c8;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(55, 245, 200, 0.55), inset 0 0 8px rgba(55, 245, 200, 0.22);
  text-shadow: 0 0 6px rgba(125, 252, 255, 0.85);
}
.scorebug.alien .sb-swatch {
  border-color: #7dfcff;
  box-shadow: 0 0 6px rgba(125, 252, 255, 0.7);
}
/* Team flags rendered in green-scale to fit the Martian palette. */
.scorebug.alien .sb-flag {
  box-shadow: 0 0 0 1px #7dfcff;
  filter: grayscale(1) sepia(1) hue-rotate(70deg) saturate(3) brightness(0.95);
}
.scorebug.alien .sb-score { color: #5dff8a; }
.scorebug.alien .sb-clock {
  background: transparent;
  border-left: 1.5px solid #37f5c8;
  color: #37f5c8;
}

/* ---- 3D loading bar ---- */
.load3d {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(900px 500px at 50% 40%, #12303f, #05070a 75%);
}
.load3d-inner { width: min(420px, 78%); text-align: center; }
.load3d-title {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}
.load3d-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  min-height: 16px;
}
.load3d-track {
  height: 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.load3d-fill {
  height: 100%;
  width: 0%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.2s ease;
}

/* ---- Mute button ---- */
.mute-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 36px;
  flex: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mute-btn:hover { background: var(--panel-2); }
.mute-btn.muted { color: var(--text-dim); }

/* ---- Mode switch ---- */
.mode-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.mode-btn {
  background: var(--panel);
  color: var(--text-dim);
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active {
  background: var(--accent);
  color: #06120b;
}
.mode-alien { font-size: 15px; line-height: 1; padding: 8px 10px; }
.mode-alien.active {
  background: #1a3d1f;
  color: #7dff8a;
  box-shadow: inset 0 0 10px rgba(90, 255, 120, 0.5);
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
}
.play-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #06120b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: transform 0.12s, background 0.15s;
}
.play-btn:hover {
  transform: scale(1.06);
  background: #3ee089;
}
.play-btn svg {
  display: block;
}
.time {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text);
  min-width: 92px;
  white-space: nowrap;
}
.time.duration {
  color: var(--text-dim);
  text-align: right;
}

/* Custom range slider */
.seek {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 4px;
  background: var(--line);
  outline: none;
  cursor: pointer;
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06120b;
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}
.seek::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #06120b;
  cursor: pointer;
}

.speed select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}

@media (max-width: 640px) {
  .viewer-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .event-badge {
    order: 3;
  }
  .time.duration {
    display: none;
  }
}
