:root {
  --yellow: #fcb703;
  --yellow-soft: #ffe08a;
  --ink: #111111;
  --paper: #fff8e8;
  --paper-2: #f3ead8;
  --panel: rgba(255, 248, 232, 0.94);
  --line: rgba(17, 17, 17, 0.16);
  --muted: #706854;
  --green: #146b49;
  --red: #cd1b17;
  --red-soft: #ffd7d3;
  --blue: #0c4774;
  --blue-soft: #d8ebf5;
  --shadow: 0 18px 48px rgba(17, 17, 17, 0.18);
  --display: Impact, "Arial Black", system-ui, sans-serif;
  --body: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html {
  background: var(--ink);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(155deg, transparent 0 40%, rgba(255, 255, 255, 0.72) 40% 48%, transparent 48% 100%),
    linear-gradient(160deg, var(--yellow) 0 30%, var(--paper) 30% 58%, var(--blue) 58% 72%, var(--paper) 72% 83%, var(--red) 83% 100%);
  font-family: var(--body);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(17, 17, 17, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 17, 17, 0.04) 1px, transparent 1px);
  background-size: 100% 32px, 32px 100%;
}

button, a {
  font: inherit;
}

button {
  cursor: pointer;
}

#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.race-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 14px;
}

.race-hero {
  min-height: 68vh;
  display: grid;
  align-content: space-between;
  gap: 18px;
  padding: 10px 0 18px;
}

.race-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.race-nav a,
#sourceLink,
.hero-status button,
.stage-tabs button,
.radio-actions button {
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: 8px;
  background: rgba(255, 248, 223, 0.84);
  color: var(--ink);
  padding: 0 12px;
  text-decoration: none;
  font-weight: 900;
}

.race-nav a.active,
.hero-status button,
.stage-tabs button.active,
.radio-actions button:first-child {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.hero-board {
  display: grid;
  gap: 14px;
  grid-template-areas:
    "poster"
    "copy"
    "jersey";
}

.hero-copy {
  grid-area: copy;
  position: relative;
  z-index: 2;
  max-width: 760px;
}

.hero-poster {
  grid-area: poster;
  width: min(100%, 430px);
  margin: 0;
  justify-self: center;
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid rgba(17, 17, 17, 0.22);
  border-radius: 8px;
  box-shadow: 0 20px 0 rgba(17, 17, 17, 0.1), var(--shadow);
  background: var(--yellow);
}

.hero-poster img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center;
}

.eyebrow {
  margin: 0 0 6px;
  color: rgba(17, 17, 17, 0.66);
  font-size: 0.76rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-family: var(--display);
  font-size: clamp(4.8rem, 25vw, 10.8rem);
  line-height: 0.78;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 5px 5px 0 rgba(255, 255, 255, 0.42);
}

h2 {
  font-size: 1.08rem;
}

h3 {
  font-size: 0.98rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.subtitle {
  max-width: 560px;
  margin-top: 14px;
  color: #292512;
  font-size: 1.05rem;
  line-height: 1.38;
  font-weight: 750;
}

.yellow-jersey,
.radio-card,
.award-card,
.podium-card,
.board,
.stat-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.yellow-jersey {
  grid-area: jersey;
  min-height: 178px;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 16px;
  background:
    linear-gradient(90deg, transparent 0 20%, rgba(17, 17, 17, 0.08) 20% 28%, transparent 28% 72%, rgba(17, 17, 17, 0.08) 72% 80%, transparent 80%),
    var(--yellow);
  position: relative;
  overflow: hidden;
}

.yellow-jersey::before {
  content: "TDF";
  position: absolute;
  top: 12px;
  right: 14px;
  color: rgba(17, 17, 17, 0.12);
  font-family: var(--display);
  font-size: 4.6rem;
  line-height: 1;
}

.yellow-jersey span,
.award-card span {
  color: rgba(17, 17, 17, 0.68);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

.yellow-jersey strong {
  position: relative;
  font-family: var(--display);
  font-size: clamp(2rem, 11vw, 4rem);
  line-height: 0.9;
  overflow-wrap: anywhere;
}

.yellow-jersey small,
.award-card small {
  color: var(--muted);
  font-weight: 850;
}

.hero-status {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  color: var(--ink);
  font-weight: 900;
}

.hero-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.hero-buttons button {
  width: auto;
}

body.audio-off #audioToggleButton {
  background: rgba(17, 17, 17, 0.78);
  color: #fff;
}

.stage-strip {
  margin: -4px 0 14px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.stage-tabs {
  display: flex;
  gap: 7px;
  width: max-content;
  min-width: 100%;
  padding-bottom: 5px;
}

.stage-tabs button {
  width: auto;
  min-width: 43px;
  background: rgba(255, 248, 223, 0.9);
}

.podium-grid,
.award-grid,
.mood-grid,
.dashboard-grid {
  display: grid;
  gap: 12px;
}

.podium-grid {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.podium-card {
  min-height: 154px;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 14px;
  position: relative;
  overflow: hidden;
  background: var(--panel);
  animation: stageIn 520ms ease both;
}

.podium-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 213, 29, 0.42), transparent 52%),
    repeating-linear-gradient(-45deg, rgba(17, 17, 17, 0.05) 0 2px, transparent 2px 12px);
  pointer-events: none;
}

.podium-card.place-1 {
  min-height: 205px;
  background: var(--yellow-soft);
}

.podium-card.place-2 {
  background: #f4f1e9;
}

.podium-card.place-3 {
  background: #f5d8c3;
}

.podium-card .badge {
  position: relative;
  width: max-content;
  max-width: 100%;
  border: 1px solid rgba(17, 17, 17, 0.2);
  border-radius: 8px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.55);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

.podium-rank {
  position: absolute;
  top: 9px;
  right: 12px;
  font-family: var(--display);
  font-size: 5rem;
  line-height: 1;
  color: rgba(17, 17, 17, 0.12);
}

.podium-card h2 {
  position: relative;
  font-family: var(--display);
  font-size: clamp(1.8rem, 8vw, 3.2rem);
  line-height: 0.92;
  overflow-wrap: anywhere;
}

.podium-card strong {
  position: relative;
  font-size: 2.3rem;
  line-height: 1;
}

.podium-card p {
  position: relative;
  color: var(--muted);
  font-weight: 900;
}

.radio-card {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px;
  background: #161616;
  color: #fff8df;
  position: relative;
  overflow: hidden;
}

.radio-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, rgba(255, 213, 29, 0.14) 0 3px, transparent 3px 16px);
  pointer-events: none;
}

.radio-card > * {
  position: relative;
}

.radio-card .eyebrow {
  color: var(--yellow);
}

.radio-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.ai-status {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: 7px;
  border: 1px solid rgba(255, 248, 223, 0.22);
  border-radius: 8px;
  background: rgba(255, 248, 223, 0.08);
  color: #fff8df;
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
  white-space: nowrap;
}

.ai-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #bdb7a2;
  box-shadow: 0 0 0 3px rgba(189, 183, 162, 0.16);
}

.ai-status.is-live .ai-status-dot {
  background: #20d47b;
  box-shadow: 0 0 0 3px rgba(32, 212, 123, 0.18), 0 0 18px rgba(32, 212, 123, 0.68);
}

.ai-status.is-fallback .ai-status-dot {
  background: #ff453a;
  box-shadow: 0 0 0 3px rgba(255, 69, 58, 0.18), 0 0 18px rgba(255, 69, 58, 0.55);
}

.ai-status.is-loading .ai-status-dot {
  animation: statusPulse 1s ease-in-out infinite;
}

.radio-card h2 {
  font-family: var(--display);
  font-size: 2rem;
  line-height: 0.95;
}

#radioText {
  color: #fff8df;
  font-size: 1rem;
  line-height: 1.45;
  font-weight: 760;
}

.radio-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.radio-actions button {
  min-width: 0;
  background: rgba(255, 248, 223, 0.1);
  color: #fff8df;
  border-color: rgba(255, 248, 223, 0.24);
}

.radio-actions button:first-child {
  grid-column: 1 / -1;
  background: var(--yellow);
  color: var(--ink);
  border-color: var(--yellow);
}

.radio-actions .horn-button {
  min-height: 54px;
  background: var(--red);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
  font-family: var(--display);
  font-size: 1.55rem;
  line-height: 1;
  text-shadow: 2px 2px 0 rgba(17, 17, 17, 0.24);
}

.radio-actions .horn-button:active {
  transform: translateY(2px) scale(0.98);
}

.radio-actions button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.award-grid {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.mood-grid {
  grid-template-columns: 1fr;
  margin-bottom: 12px;
}

.award-card {
  min-height: 116px;
  display: grid;
  align-content: end;
  gap: 6px;
  padding: 12px;
  background: var(--panel);
}

.award-card strong {
  font-size: 1.25rem;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.award-card.yellow {
  background: var(--yellow-soft);
}

.award-card.red {
  background: var(--red-soft);
}

.award-card.blue {
  background: var(--blue-soft);
}

.panic-card,
.quote-card {
  min-height: 132px;
  display: grid;
  align-content: end;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  background: var(--panel);
}

.panic-card {
  background:
    linear-gradient(135deg, rgba(255, 213, 29, 0.44), transparent 58%),
    #fff8df;
}

.quote-card {
  background:
    repeating-linear-gradient(-35deg, rgba(17, 17, 17, 0.05) 0 2px, transparent 2px 12px),
    #171717;
  color: #fff8df;
}

.panic-card span,
.quote-card span {
  color: rgba(17, 17, 17, 0.68);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

.quote-card span {
  color: var(--yellow);
}

.panic-card strong {
  font-size: 1.45rem;
  line-height: 1;
}

.panic-card small {
  color: var(--muted);
  font-weight: 850;
}

.panic-track {
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(17, 17, 17, 0.14);
}

.panic-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width 520ms ease;
}

.quote-card blockquote {
  margin: 0;
  color: #fff8df;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.2rem;
  line-height: 1.22;
  font-weight: 800;
}

.dashboard-grid {
  grid-template-columns: 1fr;
  align-items: start;
}

.board,
.stat-panel {
  padding: 12px;
  background: var(--panel);
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

#sourceLink {
  min-width: 72px;
}

.ranking-list {
  display: grid;
  gap: 8px;
}

.ranking-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.82);
}

.ranking-row.is-leader {
  border-color: rgba(255, 213, 29, 0.95);
  box-shadow: inset 5px 0 0 var(--yellow);
}

.ranking-row.is-lantern {
  border-color: rgba(185, 54, 45, 0.45);
  box-shadow: inset 5px 0 0 var(--red);
}

.rank-badge {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-weight: 950;
  font-size: 0.9rem;
}

.ranking-row.is-leader .rank-badge {
  background: var(--yellow);
  color: var(--ink);
}

.ranking-row.is-lantern .rank-badge {
  background: var(--red);
}

.ranking-main {
  min-width: 0;
}

.ranking-main p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.mini-tag {
  border: 1px solid rgba(17, 17, 17, 0.12);
  border-radius: 8px;
  padding: 3px 6px;
  background: rgba(255, 248, 223, 0.72);
  font-size: 0.7rem;
  font-weight: 900;
  text-transform: uppercase;
}

.ranking-score {
  display: grid;
  gap: 2px;
  justify-items: end;
  min-width: 78px;
}

.ranking-score strong {
  font-size: 1.24rem;
}

.gap {
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 950;
}

.gap.leader {
  color: var(--green);
}

.side-rail {
  display: grid;
  gap: 12px;
}

.stat-panel {
  display: grid;
  gap: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.stat-row span {
  color: var(--muted);
}

.stat-row strong {
  text-align: right;
}

.empty {
  min-height: 86px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@keyframes stageIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes statusPulse {
  0%, 100% { opacity: 0.45; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

@media (min-width: 720px) {
  .race-shell {
    padding: 22px;
  }

  .race-hero {
    min-height: 64vh;
  }

  .hero-board {
    grid-template-columns: minmax(0, 0.95fr) minmax(260px, 0.78fr);
    grid-template-areas:
      "copy poster"
      "jersey poster";
    align-items: end;
    column-gap: 22px;
  }

  .hero-poster {
    width: min(100%, 430px);
    aspect-ratio: 2 / 3;
    justify-self: end;
  }

  .podium-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
  }

  .award-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mood-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr) 330px;
  }

  .radio-card {
    grid-template-columns: 230px minmax(0, 1fr);
    align-items: center;
  }

  .radio-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .radio-actions button:first-child {
    grid-column: auto;
  }
}
