:root {
  --yellow: #f4c542;
  --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-deep: #6f0d0b;
  --red-soft: #ffd7d3;
  --blue: #0c4774;
  --blue-soft: #d8ebf5;
  --cream-text: #fff8e8;
  --cream-muted: #ffe1ad;
  --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(--red) 0 30%, var(--paper) 30% 58%, var(--ink) 58% 72%, var(--paper) 72% 83%, var(--yellow) 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: auto;
  display: grid;
  gap: 9px;
  padding: 6px 0 10px;
}

.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 {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

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

.hero-copy {
  grid-area: copy;
  position: relative;
  z-index: 2;
  max-width: 760px;
  color: var(--cream-text);
}

.hero-poster {
  grid-area: poster;
  width: 100%;
  margin: 0;
  justify-self: center;
  position: relative;
  aspect-ratio: 1.42 / 1;
  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(--red);
}

.hero-poster picture,
.hero-poster img {
  width: 100%;
  height: 100%;
  display: block;
}

.hero-poster img {
  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(3.3rem, 16vw, 8.2rem);
  line-height: 0.78;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--cream-text);
  text-shadow: 5px 5px 0 rgba(17, 17, 17, 0.44), 0 16px 36px rgba(17, 17, 17, 0.28);
}

h2 {
  font-size: 1.08rem;
}

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

.subtitle {
  max-width: 560px;
  margin-top: 8px;
  color: var(--cream-text);
  font-size: 0.98rem;
  line-height: 1.38;
  font-weight: 750;
  text-shadow: 0 2px 12px rgba(17, 17, 17, 0.32);
}

.hero-copy .eyebrow {
  color: var(--cream-muted);
  text-shadow: 0 2px 10px rgba(17, 17, 17, 0.32);
}

.yellow-jersey,
.radio-card,
.stage-detail-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: 146px;
  display: grid;
  align-content: end;
  gap: 8px;
  padding: 16px 128px 16px 16px;
  background:
    radial-gradient(circle at 82% 42%, rgba(255, 248, 232, 0.16), transparent 30%),
    linear-gradient(90deg, rgba(17, 17, 17, 0.2) 0 19%, rgba(255, 248, 232, 0.08) 19% 27%, rgba(17, 17, 17, 0.1) 27% 72%, rgba(255, 248, 232, 0.08) 72% 80%, rgba(17, 17, 17, 0.16) 80%),
    linear-gradient(135deg, var(--red-deep), var(--red) 54%, #9f1310);
  color: var(--cream-text);
  position: relative;
  overflow: hidden;
}

.yellow-jersey::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(17, 17, 17, 0.26), rgba(255, 248, 232, 0.1) 58%, rgba(17, 17, 17, 0.16)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 55%);
  pointer-events: none;
}

.yellow-jersey img {
  position: absolute;
  right: -12px;
  bottom: -24px;
  width: 138px;
  max-width: 39%;
  filter: hue-rotate(-58deg) saturate(1.6) drop-shadow(0 16px 24px rgba(17, 17, 17, 0.26));
  pointer-events: none;
}

.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 span {
  color: var(--cream-muted);
}

.yellow-jersey strong {
  position: relative;
  font-family: var(--display);
  font-size: clamp(2rem, 9vw, 4.4rem);
  line-height: 0.9;
  overflow-wrap: anywhere;
  color: var(--cream-text);
  text-shadow: 4px 4px 0 rgba(17, 17, 17, 0.5), 0 12px 28px rgba(17, 17, 17, 0.28);
}

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

.yellow-jersey small {
  color: var(--cream-muted);
  text-shadow: 0 2px 10px rgba(17, 17, 17, 0.28);
}

.hero-status {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  color: var(--cream-text);
  font-weight: 900;
  text-shadow: 0 2px 10px rgba(17, 17, 17, 0.28);
}

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

.hero-buttons button {
  width: auto;
}

.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);
}

.stage-detail-card {
  display: grid;
  gap: 0;
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--panel);
  animation: stageIn 520ms ease both;
}

.stage-detail-card[hidden] {
  display: none;
}

.stage-profile {
  margin: 0;
  min-height: 190px;
  background:
    linear-gradient(160deg, rgba(252, 183, 3, 0.92), rgba(255, 248, 232, 0.34)),
    var(--yellow);
}

.stage-profile img {
  width: 100%;
  height: 100%;
  min-height: 190px;
  display: block;
  object-fit: contain;
  object-position: center;
  background: #fff;
}

.stage-detail-copy {
  display: grid;
  gap: 10px;
  padding: 14px;
  background:
    linear-gradient(145deg, rgba(252, 183, 3, 0.2), transparent 48%),
    rgba(255, 248, 232, 0.96);
}

.stage-detail-copy h2 {
  font-family: var(--display);
  font-size: clamp(2rem, 9vw, 3.8rem);
  line-height: 0.92;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.stage-route {
  color: #292512;
  font-size: 1.04rem;
  font-weight: 900;
}

.stage-facts,
.stage-times {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.stage-poule-preview {
  display: grid;
  gap: 5px;
  border-left: 5px solid var(--red);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(12, 71, 116, 0.1), transparent 52%),
    rgba(255, 255, 255, 0.62);
  padding: 10px 11px;
}

.stage-poule-preview span {
  color: rgba(17, 17, 17, 0.68);
  font-size: 0.72rem;
  font-weight: 950;
  text-transform: uppercase;
}

.stage-poule-preview p {
  color: #292512;
  font-size: 0.94rem;
  line-height: 1.36;
  font-weight: 850;
}

.stage-facts span,
.stage-times span,
#stageOfficialLink {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 950;
}

.stage-facts span {
  border: 1px solid rgba(17, 17, 17, 0.16);
  background: #fff8df;
  color: var(--ink);
  padding: 0 9px;
}

.stage-times span {
  border: 1px solid rgba(12, 71, 116, 0.24);
  background: var(--blue);
  color: #fff8df;
  padding: 0 9px;
}

#stageOfficialLink {
  width: max-content;
  max-width: 100%;
  border: 1px solid rgba(17, 17, 17, 0.22);
  background: var(--ink);
  color: #fff8df;
  padding: 0 10px;
  text-decoration: none;
}

.stage-detail-card.is-loading .stage-profile {
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.26) 0 14px, transparent 14px 28px),
    var(--yellow);
}

.podium-grid,
.award-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-style-tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.radio-style-tabs button {
  min-height: 34px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 248, 223, 0.24);
  border-radius: 8px;
  background: rgba(255, 248, 223, 0.08);
  color: #fff8df;
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 950;
}

.radio-style-tabs button.active {
  background: var(--yellow);
  color: var(--ink);
  border-color: var(--yellow);
}

.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 .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;
}

.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);
}

.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;
}

.admin-shell {
  max-width: 1180px;
}

.admin-hero {
  display: grid;
  gap: 26px;
  padding: 10px 0 18px;
}

.admin-grid {
  display: grid;
  gap: 12px;
  align-items: start;
}

.admin-panel {
  margin-bottom: 0;
}

.admin-form {
  display: grid;
  gap: 10px;
}

.admin-form label {
  display: grid;
  gap: 6px;
  color: #fff8df;
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.admin-form input,
.admin-form select,
.admin-form textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 248, 223, 0.26);
  border-radius: 8px;
  background: rgba(255, 248, 223, 0.94);
  color: var(--ink);
  padding: 9px 10px;
  font: inherit;
  font-weight: 800;
}

.admin-form textarea {
  min-height: 260px;
  resize: vertical;
  line-height: 1.35;
  text-transform: none;
}

.admin-actions {
  grid-template-columns: 1fr 1fr;
}

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

.share-card-panel {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px;
  background: var(--panel);
}

.share-card-mode {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 950;
  text-transform: uppercase;
}

.share-card-mode select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 223, 0.94);
  color: var(--ink);
  padding: 0 10px;
  font: inherit;
  font-weight: 900;
}

#shareCardCanvas {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid rgba(17, 17, 17, 0.18);
  border-radius: 8px;
  background: var(--yellow);
}

.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 {
    gap: 14px;
    padding-bottom: 16px;
  }

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

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

  .hero-poster img {
    object-fit: cover;
    object-position: center 52%;
  }

  .yellow-jersey {
    min-height: 164px;
    padding: 18px 190px 18px 18px;
  }

  .yellow-jersey img {
    right: -20px;
    bottom: -30px;
    width: 190px;
  }

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

  .podium-card.place-1 {
    order: 2;
  }

  .podium-card.place-2 {
    order: 1;
  }

  .podium-card.place-3 {
    order: 3;
  }

  .stage-detail-card {
    grid-template-columns: minmax(280px, 0.92fr) minmax(0, 1fr);
    align-items: stretch;
  }

  .stage-profile,
  .stage-profile img {
    min-height: 300px;
    max-height: 620px;
  }

  .stage-detail-copy {
    align-content: center;
    padding: 22px;
  }

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

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

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

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

  .admin-form-wide {
    grid-column: 1 / -1;
  }

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

  .radio-actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr;
  }
}
