:root {
  --bg: hsl(222 40% 7%);
  --glass: hsla(222 40% 12% / 0.55);
  --glass-border: hsla(200 80% 80% / 0.15);
  --text: hsl(210 30% 95%);
  --muted: hsl(215 15% 65%);
  --accent: hsl(186 95% 55%);
  --accent-2: hsl(268 90% 66%);
  --good: hsl(150 75% 55%);
  --bad: hsl(350 85% 62%);
  --radius: 18px;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'Outfit', sans-serif; }

#world-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px hsla(222 60% 3% / 0.5);
}

.screen { position: fixed; inset: 0; display: none; pointer-events: none; }
.screen.active { display: flex; }
#menu, #summary { align-items: center; justify-content: center; pointer-events: auto; }

.menu-card { width: min(520px, 92vw); padding: 2.2rem; animation: rise .6s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.98); } }

.logo { font-size: 3rem; font-weight: 800; letter-spacing: -1px; }
.logo span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); margin-bottom: 1.6rem; }

.menu-group { margin-bottom: 1.2rem; }
.menu-group h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin-bottom: .5rem; display: flex; justify-content: space-between; align-items: center; }
.menu-group small { color: var(--accent); font-family: var(--mono); letter-spacing: 0; }

.ghost-pill {
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--glass-border);
  background: hsla(220 30% 20% / .6);
  color: var(--muted);
  transition: all 0.2s ease;
}
.ghost-pill.active {
  background: hsla(268 90% 60% / 0.28);
  border-color: var(--accent-2);
  color: #f5d0fe;
  box-shadow: 0 0 12px hsla(268 90% 66% / 0.35);
}

.choice-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.choice {
  flex: 1; padding: .7rem .8rem; border-radius: 12px; cursor: pointer;
  background: hsla(220 30% 20% / .5); color: var(--text); border: 1px solid transparent;
  font: inherit; font-weight: 600; transition: all .2s;
}
.choice:hover { transform: translateY(-2px); border-color: var(--glass-border); }
.choice.selected { border-color: var(--accent); background: hsla(186 95% 55% / .15); box-shadow: 0 0 20px hsla(186 95% 55% / .25); }

input[type=range] { width: 100%; accent-color: var(--accent); transition: opacity 0.2s; }
input[type=range].disabled { opacity: 0.35; pointer-events: none; }

.primary-btn {
  width: 100%; margin-top: .8rem; padding: 1rem; border: 0; border-radius: 14px; cursor: pointer;
  font: inherit; font-size: 1.15rem; font-weight: 800; color: hsl(222 40% 8%);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: transform .2s, box-shadow .2s;
}
.primary-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 30px hsla(268 90% 66% / .45); }
.error { color: var(--bad); margin-top: .6rem; min-height: 1.2em; font-size: .9rem; }

/* HUD */
#hud { flex-direction: column; align-items: center; padding: 1rem; }
.hud-top { display: flex; gap: 1.6rem; padding: .9rem 1.6rem; align-items: flex-end; }
.metric { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.metric label { font-size: .7rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); }
.metric span { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; transition: color .3s; }
.metric.big span { font-size: 2.6rem; color: var(--accent); }
#m-ghost.ahead { color: var(--good); }
#m-ghost.behind { color: var(--bad); }
#m-ghost.off { color: var(--muted); opacity: 0.6; }

.progress { width: min(700px, 90vw); height: 10px; margin-top: .8rem; padding: 0; overflow: hidden; }
#progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s linear; }

#stroke-pulse { position: fixed; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 hsla(186 95% 55% / 0); }
#stroke-pulse.pulse { animation: pulse .5s ease-out; }
@keyframes pulse { 0% { box-shadow: inset 0 0 80px 0 hsla(186 95% 55% / .25); } 100% { box-shadow: inset 0 0 0 0 hsla(186 95% 55% / 0); } }

.sim-panel { position: fixed; right: 1rem; bottom: 1rem; width: 240px; padding: 1rem; pointer-events: auto; }
.sim-panel h3 { font-size: .8rem; letter-spacing: 2px; text-transform: uppercase; color: var(--accent-2); margin-bottom: .5rem; }
.sim-panel label { display: flex; justify-content: space-between; font-size: .85rem; margin-top: .4rem; }
.sim-panel b { font-family: var(--mono); color: var(--accent); }
.hint { font-size: .7rem; color: var(--muted); margin-top: .6rem; }

.cam-toggle-btn {
  position: fixed;
  bottom: 1.2rem;
  left: 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  background: hsla(222, 45%, 9%, 0.8);
  border: 1px solid var(--glass-border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  pointer-events: auto;
  transition: all 0.2s ease;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.cam-toggle-btn:hover {
  background: hsla(222, 45%, 15%, 0.9);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px hsla(186, 95%, 55%, 0.25);
}
.cam-toggle-btn kbd {
  background: hsla(220, 20%, 30%, 0.6);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
}
.ghost-hud-btn {
  left: 11.4rem;
}
.ghost-hud-btn.off {
  opacity: 0.65;
}

.paused { display: none; position: fixed; top: 45%; left: 50%; transform: translate(-50%,-50%); font-size: 4rem; font-weight: 800; letter-spacing: 8px; opacity: .85; }
.paused.show { display: block; }

/* Summary */
.summary-title { font-size: 2rem; margin-bottom: 1rem; }
.summary-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-bottom: 1rem; }
.summary-stats div { background: hsla(220 30% 20% / .5); border-radius: 12px; padding: .7rem; text-align: center; }
.summary-stats label { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.summary-stats span { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; }
.splits { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: .9rem; max-height: 200px; }
.splits th { color: var(--muted); font-weight: 500; text-align: left; padding: .3rem; border-bottom: 1px solid var(--glass-border); }
.splits td { padding: .3rem; }

/* TV Broadcast & Zwift Style Live Standings Board */
.standings-board {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  width: 285px;
  max-width: calc(100vw - 2.4rem);
  z-index: 10;
  pointer-events: auto;
  padding: 0;
  overflow: hidden;
  background: hsla(222, 45%, 9%, 0.82);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  box-shadow: 0 12px 35px hsla(222, 60%, 3%, 0.6), 0 0 1px hsla(200, 80%, 80%, 0.25);
}

.standings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(90deg, #0f1c33 0%, #172c4c 100%);
  padding: 0.5rem 0.85rem 0.5rem 0.5rem;
}

.standings-badge {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  clip-path: polygon(0 0, 100% 0, 84% 100%, 0 100%);
  padding: 0.35rem 1.15rem 0.35rem 0.65rem;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.standings-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  line-height: 1.2;
}

#standings-event {
  font-weight: 700;
  font-size: 0.8rem;
  color: #f8fafc;
  letter-spacing: 0.3px;
}

#standings-sub {
  font-size: 0.68rem;
  color: #38bdf8;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.standings-accent-bar {
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, #38bdf8 0%, #818cf8 60%, transparent 100%);
}

.standings-list {
  padding: 0.2rem 0;
  max-height: 420px;
  overflow-y: auto;
}

.standings-list .row {
  display: grid;
  grid-template-columns: 24px 22px 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.85rem;
  border-bottom: 1px solid hsla(215, 25%, 35%, 0.14);
  transition: background 0.2s, transform 0.2s;
}

.standings-list .row:last-child {
  border-bottom: none;
}

.standings-list .rank {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: #94a3b8;
  text-align: center;
}

.standings-list .flag {
  width: 20px;
  height: 13px;
  display: inline-flex;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.standings-list .flag svg {
  width: 100%;
  height: 100%;
  display: block;
}

.standings-list .name {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standings-list .delta {
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: #cbd5e1;
}

.standings-list .delta.leader {
  color: #fde047;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  background: hsla(48, 96%, 53%, 0.14);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid hsla(48, 96%, 53%, 0.28);
}

.standings-list .row.is-you {
  background: linear-gradient(90deg, hsla(186, 95%, 55%, 0.2) 0%, hsla(186, 95%, 55%, 0.06) 100%);
  border-left: 3px solid var(--accent);
  padding-left: calc(0.85rem - 3px);
}

.standings-list .row.is-you .name {
  color: var(--accent);
  font-weight: 900;
}

.standings-list .row.is-you .rank {
  color: var(--accent);
}

.standings-list .row.is-ghost {
  background: hsla(268, 90%, 66%, 0.1);
  border-left: 3px solid var(--accent-2);
  padding-left: calc(0.85rem - 3px);
}

.standings-list .row.is-ghost .name {
  color: #c084fc;
}

@media (max-width: 960px) {
  .standings-board {
    top: auto;
    bottom: 1rem;
    left: 1rem;
    right: auto;
    width: 250px;
  }
}

@media (max-width: 700px) {
  .hud-top { gap: .7rem; padding: .6rem; flex-wrap: wrap; justify-content: center; }
  .metric span { font-size: 1.1rem; }
  .metric.big span { font-size: 1.8rem; }
  .sim-panel { width: calc(100% - 2rem); }
  .standings-board { display: none; }
}
