:root {
  color-scheme: dark;
  /* Stage: the TV-draw set, from deepest to brightest */
  --stage-0: #240105;
  --stage-1: #3d0409;
  --stage-2: #56060e;
  --stage-3: #7a0911;
  --red: #e62619;
  --red-hot: #ff4a3d;
  --paper: #fff6f4;
  --paper-line: #f3d9d5;
  --ink: #2a0206;
  --ink-2: #6b3a3e;
  --gold: #ffc83d;
  --text: #ffffff;
  --text-2: rgb(255 255 255 / 0.8);
  --text-3: rgb(255 255 255 / 0.66);
  --line: rgb(255 255 255 / 0.14);
  --bar: #ff8f84;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Barlow Condensed", "Barlow", system-ui, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;
  --space-6: 72px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--stage-1);
  color: var(--text);
  font: 17px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1; }
h2 {
  font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: clamp(2rem, 4.5vw, 3rem); letter-spacing: -0.01em;
}
p { margin: 0; }
a { color: inherit; text-underline-offset: 3px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--space-3); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- Balls ---------- */
.balls { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; margin: 0; padding: 0; }
.ball {
  --size: 52px;
  flex-shrink: 0;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 34% 28%, #fff 0 20%, #f2eeee 50%, #cbc3c3 100%);
  box-shadow: inset -4px -6px 10px rgb(0 0 0 / 0.14), 0 4px 10px rgb(0 0 0 / 0.28);
  color: var(--red);
  font-family: var(--display); font-weight: 800; font-size: calc(var(--size) * 0.44);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.ball-bonus {
  background: radial-gradient(circle at 34% 28%, #ffe7a3 0 16%, var(--gold) 50%, #d99a00 100%);
  color: var(--ink);
}
.ball-xs { --size: 30px; }
.balls-sm { gap: 8px; align-items: center; }
.balls-sm .ball { --size: 40px; }
.balls-sm .plus { color: var(--text-3); font-weight: 700; }

/* ---------- Stage (hero) ---------- */
.stage {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(ellipse 60% 70% at 50% -10%, rgb(255 90 70 / 0.55), transparent 70%),
    radial-gradient(ellipse 40% 50% at 100% 100%, rgb(230 38 25 / 0.35), transparent 70%),
    linear-gradient(180deg, var(--stage-3) 0%, var(--stage-1) 100%);
  padding-bottom: var(--space-5);
}
/* Light beams from the rig */
.stage::before {
  content: ""; position: absolute; inset: -20% 0 auto 0; height: 140%; z-index: -1;
  background:
    conic-gradient(from 160deg at 50% -5%, transparent 0 8deg, rgb(255 255 255 / 0.07) 8deg 13deg, transparent 13deg 22deg, rgb(255 255 255 / 0.05) 22deg 26deg, transparent 26deg 36deg, rgb(255 255 255 / 0.06) 36deg 40deg, transparent 40deg);
  pointer-events: none;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; }
.topbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.update-status { margin-left: auto; max-width: 60ch; text-align: right; color: var(--text); font-weight: 600; font-size: 0.9375rem; }
.update-status:empty { display: none; }
.btn-light { background: var(--text); color: var(--stage-1); }
.btn-light:hover { background: var(--gold); color: var(--ink); }
.btn-light:disabled { cursor: progress; opacity: 0.85; }
.btn-light.is-loading svg { animation: nudge 800ms ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(3px); } }
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-style: italic; font-size: 1.375rem; }

.stage-body { padding: var(--space-6) 0 var(--space-5); }
.stage-kicker { font-size: 1.125rem; font-weight: 600; color: var(--text-2); margin-bottom: var(--space-2); }
.stage h1 {
  font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: clamp(3.25rem, 11vw, 7.5rem); line-height: 0.88; letter-spacing: -0.025em;
  text-shadow: 0 6px 30px rgb(0 0 0 / 0.35);
}
.stage h1::first-letter { text-transform: uppercase; }
.stage-sub { margin-top: var(--space-4); max-width: 52ch; color: var(--text-2); font-size: 1.125rem; }

.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-5); }
.strategy { border: 0; padding: 0; margin: 0; }
.segmented {
  display: inline-flex; gap: var(--space-1);
  background: rgb(0 0 0 / 0.28); padding: 5px; border-radius: 999px;
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.3);
}
.segmented label {
  position: relative; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  padding: 0 20px; border-radius: 999px; cursor: pointer;
  color: var(--text-2); font-weight: 600;
  transition: background-color 180ms, color 180ms;
}
.segmented label:hover { color: var(--text); background: rgb(255 255 255 / 0.08); }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented label:has(input:checked) { background: var(--text); color: var(--stage-1); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--gold); outline-offset: 2px; }
.hint { margin-top: var(--space-3); color: var(--text-3); font-size: 0.9375rem; }

.last-draw {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3);
  padding-top: var(--space-4); border-top: 1px solid var(--line);
}
.last-draw p { color: var(--text-2); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 20px; border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: transform 150ms, box-shadow 150ms, background-color 150ms;
}
.btn:active { transform: scale(0.97); }
.btn-cta {
  min-height: 56px; padding: 0 30px;
  background: var(--gold); color: var(--ink);
  font-family: var(--display); font-size: 1.375rem; font-weight: 800; font-style: italic;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.35), inset 0 -3px 0 rgb(0 0 0 / 0.14);
}
.btn-cta:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgb(0 0 0 / 0.4), inset 0 -3px 0 rgb(0 0 0 / 0.14); }
.btn-cta svg { transition: transform 450ms; }
.btn-cta:hover svg { transform: rotate(-120deg); }
.btn-ghost { color: var(--text); border-color: rgb(255 255 255 / 0.4); background: transparent; }
.btn-ghost:hover { background: rgb(255 255 255 / 0.1); border-color: var(--text); }
.file-btn:focus-within { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- Tickets ---------- */
main { background: linear-gradient(180deg, var(--stage-1), var(--stage-0) 900px); }
.tickets-section { padding-top: var(--space-5); }
.section-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.section-actions { display: flex; align-items: center; gap: var(--space-3); }
.status { color: var(--text-2); font-size: 0.9375rem; }

.tickets {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 470px), 1fr));
}
.ticket {
  position: relative;
  background: var(--paper); color: var(--ink);
  border-radius: 6px;
  padding: var(--space-4) var(--space-4) 20px;
  box-shadow: 0 18px 40px rgb(0 0 0 / 0.4);
  /* perforated top edge */
  -webkit-mask: radial-gradient(circle 6px at 12px 0, transparent 5.5px, #000 6px) top / 24px 100% repeat-x;
          mask: radial-gradient(circle 6px at 12px 0, transparent 5.5px, #000 6px) top / 24px 100% repeat-x;
}
.ticket:nth-child(odd) { transform: rotate(-0.6deg); }
.ticket:nth-child(even) { transform: rotate(0.5deg); }

.ticket-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: 20px; }
.ticket h3 {
  font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: 2rem; color: var(--red); letter-spacing: -0.01em;
}
.ticket .balls { gap: 6px; }
.ticket .ball { --size: 44px; box-shadow: inset -3px -5px 8px rgb(0 0 0 / 0.12), 0 2px 5px rgb(42 2 6 / 0.25); }

.bulletin {
  display: grid; grid-template-columns: repeat(9, 1fr);
  border-top: 2px solid var(--red); border-left: 1px solid var(--paper-line);
}
.cell {
  position: relative; aspect-ratio: 1.25;
  display: grid; place-items: center;
  border-right: 1px solid var(--paper-line); border-bottom: 1px solid var(--paper-line);
  font-family: var(--display); font-weight: 600; font-size: 1rem; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.cell.is-marked { color: var(--ink); font-weight: 800; }
.cell-num { position: relative; z-index: 1; }
.cell.is-marked .cell-num { text-shadow: 0 0 3px var(--paper), 0 0 6px var(--paper); }
.cell svg { position: absolute; z-index: 0; opacity: 0.85; inset: 8% 14%; width: 72%; height: 84%; overflow: visible; }
.cell svg path {
  fill: none; stroke: var(--red); stroke-width: 3.2; stroke-linecap: round;
  stroke-dasharray: 40; stroke-dashoffset: 0;
}

.grid-meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin: var(--space-3) 0 0; font-size: 0.9375rem; color: var(--ink-2); }
.grid-meta dt { display: inline; }
.grid-meta dd { display: inline; margin: 0 0 0 6px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }

/* One orchestrated moment: balls drop in, then the pen marks the ticket. */
.tickets.is-fresh .ball { animation: drop 520ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.tickets.is-fresh .ball:nth-child(2) { animation-delay: 50ms; }
.tickets.is-fresh .ball:nth-child(3) { animation-delay: 100ms; }
.tickets.is-fresh .ball:nth-child(4) { animation-delay: 150ms; }
.tickets.is-fresh .ball:nth-child(5) { animation-delay: 200ms; }
.tickets.is-fresh .ball:nth-child(6) { animation-delay: 250ms; }
.tickets.is-fresh .cell svg path { animation: ink 260ms ease-out both; animation-delay: calc(380ms + var(--i, 0) * 70ms); }
.tickets.is-fresh .cell svg path + path { animation-delay: calc(480ms + var(--i, 0) * 70ms); }
@keyframes drop { from { transform: translateY(-18px) scale(0.6) rotate(-50deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes ink { from { stroke-dashoffset: 40; } to { stroke-dashoffset: 0; } }

/* ---------- Method ---------- */
.method {
  display: grid; gap: var(--space-5); align-items: start;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  padding: var(--space-6) 0;
}
.big-odds {
  font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: clamp(3.5rem, 9vw, 6.5rem); line-height: 0.9; letter-spacing: -0.02em;
  color: var(--text); margin-bottom: var(--space-3);
  font-variant-numeric: tabular-nums;
}
.big-odds span { display: block; font-size: 0.42em; color: var(--red-hot); letter-spacing: 0; }
.method-odds p:not(.big-odds) { color: var(--text-2); max-width: 38ch; }
.method-text h2 { margin-bottom: var(--space-4); }
.method-list { margin: 0; }
.method-list dt { font-weight: 700; font-size: 1.125rem; padding-top: var(--space-3); border-top: 1px solid var(--line); }
.method-list dd { margin: var(--space-1) 0 var(--space-3); color: var(--text-2); max-width: 62ch; }

details { margin-top: var(--space-3); }
summary { cursor: pointer; font-weight: 700; min-height: 44px; display: inline-flex; align-items: center; color: var(--gold); }
summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.filters ul { margin: var(--space-2) 0 0; padding-left: 1.2em; color: var(--text-2); }
.filters li + li { margin-top: var(--space-1); }

/* ---------- Stats ---------- */
.stats { padding-bottom: var(--space-6); }
.stats h2 { margin-bottom: var(--space-4); }
.stat-row {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin-bottom: var(--space-4);
}
.stat-tile { padding: 20px 20px 20px 0; }
.stat-tile + .stat-tile { padding-left: 20px; border-left: 1px solid var(--line); }
.stat-tile .label { color: var(--text-3); font-size: 0.9375rem; }
.stat-tile .value { font-family: var(--display); font-weight: 800; font-size: 2.5rem; line-height: 1; margin: 10px 0; }
.stat-tile .value .balls { gap: 6px; }
.stat-tile .value .ball { --size: 42px; }
.stat-tile .sub { color: var(--text-2); font-size: 0.875rem; }

.chart-figure {
  position: relative; margin: 0;
  background: rgb(0 0 0 / 0.22); border: 1px solid var(--line); border-radius: 14px;
  padding: var(--space-4);
}
.chart-figure figcaption { display: flex; flex-direction: column; gap: 2px; margin-bottom: var(--space-3); }
.chart-figure figcaption span { color: var(--text-3); font-size: 0.9375rem; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .bar { fill: var(--bar); transition: fill 120ms; }
.chart .bar.is-active { fill: var(--gold); }
.chart .axis-text { fill: var(--text-3); font-size: 12px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .expected { stroke: var(--text); stroke-width: 1.5; }
.chart .expected-label { fill: var(--text); font-size: 12px; font-weight: 700; stroke: var(--stage-0); stroke-width: 4px; paint-order: stroke; stroke-linejoin: round; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--paper); color: var(--ink);
  border-radius: 8px; padding: var(--space-2) 12px; font-size: 0.875rem;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.4); white-space: nowrap;
}
.tooltip strong { display: block; font-family: var(--display); font-size: 1.125rem; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 12px var(--space-3); }
#stats-table { margin-top: var(--space-2); }
#stats-table th { color: var(--text-3); font-weight: 600; font-size: 0.875rem; border-bottom: 1px solid var(--line); }
#stats-table td { border-bottom: 1px solid var(--line); color: var(--text-2); }
#stats-table td:first-child { font-family: var(--display); font-weight: 800; color: var(--text); font-size: 1.125rem; }

/* ---------- Odds (ticket stub) ---------- */
.odds { padding-bottom: var(--space-6); }
.odds h2 { margin-bottom: var(--space-3); }
.odds-intro { color: var(--text-2); max-width: 70ch; margin-bottom: var(--space-4); }
.stub { background: var(--paper); color: var(--ink); border-radius: 6px; box-shadow: 0 18px 40px rgb(0 0 0 / 0.4); }
.stub th { color: var(--ink-2); font-weight: 600; font-size: 0.875rem; border-bottom: 2px solid var(--red); }
.stub td { border-bottom: 1px dashed var(--paper-line); }
.stub tbody tr:last-child td { border-bottom: 0; background: #fde9e6; font-weight: 700; }
.stub td:first-child { font-family: var(--display); font-weight: 800; font-style: italic; font-size: 1.375rem; color: var(--red); width: 4.5em; }
.stub tbody tr:first-child td { font-weight: 700; }

/* ---------- Misc ---------- */
.alert { margin-top: var(--space-4); padding: var(--space-3); border-radius: 10px; background: var(--paper); color: var(--ink); border-left: 5px solid var(--gold); }

.site-footer { background: var(--stage-0); border-top: 1px solid var(--line); padding: var(--space-5) 0; font-size: 0.9375rem; }
.site-footer p + p { margin-top: var(--space-2); }
.footer-sources { color: var(--text-3); }

@media (max-width: 860px) {
  .method { grid-template-columns: 1fr; gap: var(--space-4); }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-tile:nth-child(3) { padding-left: 0; border-left: 0; }
  .stat-tile:nth-child(n + 3) { border-top: 1px solid var(--line); }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .stage-body { padding-top: var(--space-5); }
  .controls { flex-direction: column; align-items: stretch; }
  .topbar { flex-wrap: wrap; }
  .topbar-actions { width: 100%; justify-content: stretch; }
  .topbar-actions .btn { flex: 1 1 auto; }
  .update-status { text-align: left; margin-left: 0; }
  .segmented { display: grid; grid-template-columns: repeat(3, 1fr); }
  .segmented label { padding: 0 8px; }
  .btn-cta { width: 100%; }
  .ticket { padding: 20px 14px 16px; transform: none !important; }
  .ticket .ball { --size: 40px; }
  .ticket h3 { font-size: 1.75rem; }
  .cell { font-size: 0.9375rem; }
  .balls-sm .ball { --size: 36px; }
  .stat-tile .value { font-size: 2rem; }
  .chart-figure { padding: var(--space-3); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
