/* ═══════════════════════════════════════════════════════════════
   THE NAME DERBY — vintage race-day program
   Cream paper · racing green · jockey silks · gold foil
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* palette (oklch, neutrals tinted toward warm paper) */
  --paper:        oklch(0.955 0.018 90);
  --paper-deep:   oklch(0.92 0.025 88);
  --ink:          oklch(0.28 0.03 130);
  --ink-soft:     oklch(0.42 0.025 120);
  --green:        oklch(0.38 0.09 152);
  --green-deep:   oklch(0.30 0.075 152);
  --green-bright: oklch(0.52 0.12 150);
  --gold:         oklch(0.78 0.12 88);
  --gold-deep:    oklch(0.66 0.115 80);
  --red:          oklch(0.54 0.19 27);
  --red-deep:     oklch(0.45 0.17 27);
  --cream-line:   oklch(0.86 0.03 88);

  /* type */
  --f-display: "Alfa Slab One", serif;
  --f-label:   "Graduate", serif;
  --f-body:    "Zilla Slab", serif;

  /* spacing */
  --space-xs: 4px;  --space-sm: 8px;  --space-md: 16px;
  --space-lg: 24px; --space-xl: 40px; --space-2xl: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--f-body);
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink);
  background-color: var(--paper);
  /* subtle paper grain */
  background-image:
    radial-gradient(oklch(0.35 0.03 120 / 0.045) 1px, transparent 1px),
    radial-gradient(oklch(0.35 0.03 120 / 0.03) 1px, transparent 1px);
  background-size: 7px 7px, 11px 11px;
  background-position: 0 0, 3px 5px;
  min-height: 100dvh;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

.scene { min-height: 100dvh; display: flex; flex-direction: column; }
.scene[hidden] { display: none !important; }

/* ─────────────────────────── masthead ─────────────────────────── */

.masthead {
  text-align: center;
  padding: clamp(28px, 6vh, 72px) var(--space-lg) 0;
  animation: rise 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.masthead-eyebrow {
  font-family: var(--f-label);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: var(--space-md);
}

.masthead-title {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 5.8rem);
  line-height: 1.02;
  color: var(--green-deep);
  text-transform: uppercase;
  letter-spacing: 0.01em;
  text-shadow: 3px 3px 0 var(--gold), 6px 6px 0 oklch(0.35 0.03 120 / 0.12);
}

.masthead-sub {
  font-style: italic;
  font-size: clamp(1rem, 2.6vw, 1.25rem);
  color: var(--ink-soft);
  margin-top: var(--space-md);
}

.masthead-rule {
  display: flex; align-items: center; gap: var(--space-md);
  max-width: 520px;
  margin: var(--space-lg) auto 0;
  color: var(--gold-deep);
}
.masthead-rule::before,
.masthead-rule::after {
  content: ""; flex: 1; height: 3px;
  border-block: 1px solid var(--gold-deep);
}

/* ─────────────────────────── program body ─────────────────────────── */

.program {
  width: min(100% - 2 * var(--space-lg), 1060px);
  margin-inline: auto;
  padding-block: var(--space-xl) var(--space-2xl);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-xl);
  align-items: start;
}
@media (min-width: 880px) {
  .program:has(#winners-board:not([hidden])) {
    grid-template-columns: minmax(0, 1.7fr) minmax(240px, 1fr);
  }
}

.entry-panel { animation: rise 0.7s 0.08s cubic-bezier(0.16, 1, 0.3, 1) both; }

.panel-heading {
  font-family: var(--f-label);
  font-weight: 400;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green-deep);
  display: flex; align-items: baseline; gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.panel-no {
  color: var(--paper);
  background: var(--red);
  font-size: 0.7rem;
  padding: 3px 8px 2px;
  letter-spacing: 0.1em;
  white-space: nowrap;
  flex: none;
}

/* add form */
#add-form { display: flex; gap: var(--space-sm); }

#name-input {
  flex: 1; min-width: 0;
  font: 600 1.15rem var(--f-body);
  color: var(--ink);
  padding: 12px 16px;
  background: oklch(0.985 0.012 92);
  border: 2px solid var(--ink);
  border-radius: 2px;
  box-shadow: 3px 3px 0 oklch(0.35 0.03 120 / 0.18);
  transition: box-shadow 0.15s ease-out, translate 0.15s ease-out;
}
#name-input::placeholder { color: oklch(0.62 0.02 100); font-weight: 400; font-style: italic; }
#name-input:focus-visible {
  outline: none;
  translate: -1px -1px;
  box-shadow: 4px 4px 0 var(--gold-deep);
}

.btn-add {
  font-family: var(--f-label);
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  padding: 12px 22px;
  color: var(--paper);
  background: var(--green);
  border: 2px solid var(--green-deep);
  border-radius: 2px;
  box-shadow: 3px 3px 0 oklch(0.35 0.03 120 / 0.18);
  cursor: pointer;
  transition: translate 0.12s ease-out, box-shadow 0.12s ease-out, background 0.12s;
}
.btn-add:hover { background: var(--green-bright); }
.btn-add:active { translate: 2px 2px; box-shadow: 1px 1px 0 oklch(0.35 0.03 120 / 0.18); }

.entry-hint {
  font-size: 0.85rem; font-style: italic;
  color: var(--ink-soft);
  margin-top: var(--space-sm);
}

/* field list */
#field-wrap { margin-top: var(--space-xl); }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-count {
  font-family: var(--f-label);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}

#field-list { list-style: none; display: grid; gap: var(--space-sm); }

.runner {
  display: flex; align-items: center; gap: var(--space-md);
  background: oklch(0.985 0.012 92);
  border: 1.5px solid var(--cream-line);
  border-radius: 3px;
  padding: 8px 12px;
  animation: slide-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.runner.leaving { animation: slide-out 0.22s ease-in both; }

.saddle-cloth {
  flex: none;
  width: 40px; height: 32px;
  display: grid; place-items: center;
  font-family: var(--f-label);
  font-size: 1rem;
  color: white;
  border-radius: 3px 3px 8px 8px;
  box-shadow: inset 0 -4px 0 oklch(0 0 0 / 0.18), 1px 2px 3px oklch(0.3 0.03 120 / 0.25);
  text-shadow: 0 1px 2px oklch(0 0 0 / 0.4);
}

.runner-name {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 1.1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.runner-odds {
  font-family: var(--f-label);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.btn-scratch {
  flex: none;
  font-family: var(--f-body); font-size: 1.15rem; line-height: 1;
  width: 30px; height: 30px;
  color: var(--ink-soft);
  background: transparent;
  border: none; border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn-scratch:hover { background: oklch(0.54 0.19 27 / 0.12); color: var(--red-deep); }

.field-empty {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  border: 2px dashed var(--cream-line);
  border-radius: 4px;
  color: var(--ink-soft);
  font-style: italic;
}
.field-empty p { margin-bottom: var(--space-sm); }

.field-actions {
  display: flex; gap: var(--space-md); flex-wrap: wrap;
  margin-top: var(--space-md);
}

/* buttons */
.btn-ghost {
  font-family: var(--f-label);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  padding: 8px 14px;
  color: var(--ink-soft);
  background: transparent;
  border: 1.5px solid var(--cream-line);
  border-radius: 2px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.btn-ghost:hover { border-color: var(--ink-soft); color: var(--ink); }

.btn-link {
  font: italic 600 0.95rem var(--f-body);
  color: var(--green);
  background: none; border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.btn-link:hover { color: var(--green-bright); }

/* the ticket (start button) */
.ticket {
  display: flex; align-items: stretch;
  width: 100%;
  margin-top: var(--space-xl);
  background: var(--red);
  border: 2px solid var(--red-deep);
  border-radius: 6px;
  box-shadow: 0 4px 0 var(--red-deep), 0 8px 18px oklch(0.3 0.05 27 / 0.3);
  cursor: pointer;
  overflow: hidden;
  transition: translate 0.12s ease-out, box-shadow 0.12s ease-out, filter 0.2s;
}
.ticket:hover:not(:disabled) { filter: brightness(1.07); }
.ticket:active:not(:disabled) { translate: 0 4px; box-shadow: 0 0 0 var(--red-deep), 0 2px 8px oklch(0.3 0.05 27 / 0.3); }
.ticket:disabled { cursor: not-allowed; filter: saturate(0.25) brightness(1.1); box-shadow: 0 4px 0 oklch(0.6 0.03 27); }

.ticket-stub {
  display: grid; place-items: center;
  padding-inline: 20px;
  font-size: 1.7rem;
  background: var(--red-deep);
  /* perforation */
  border-right: 2px dashed oklch(0.95 0.02 90 / 0.55);
  animation: bell-sway 2.4s ease-in-out infinite;
}
.ticket:disabled .ticket-stub { animation: none; }

.ticket-body {
  flex: 1;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 14px 20px;
  text-align: left;
}
.ticket-action {
  font-family: var(--f-display);
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: oklch(0.97 0.015 90);
}
.ticket-note {
  font-style: italic;
  font-size: 0.9rem;
  color: oklch(0.88 0.05 40);
}
.ticket-compact { width: auto; margin-top: 0; }
.ticket-compact .ticket-body { padding: 10px 18px; justify-content: center; }

.fairness-note {
  margin-top: var(--space-md);
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-soft);
  text-align: center;
}

/* winners board */
.winners-board {
  background: var(--green-deep);
  color: oklch(0.93 0.03 95);
  border-radius: 4px;
  padding: var(--space-lg);
  box-shadow: 0 6px 20px oklch(0.3 0.06 152 / 0.35);
  animation: rise 0.7s 0.15s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.winners-board .panel-heading { color: var(--gold); }
.winners-board .panel-no { background: var(--gold-deep); color: var(--green-deep); }

#winners-list { list-style: none; display: grid; gap: var(--space-sm); }
#winners-list li {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid oklch(0.93 0.03 95 / 0.18);
  font-size: 0.98rem;
}
#winners-list .w-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#winners-list .w-when { font-family: var(--f-label); font-size: 0.62rem; letter-spacing: 0.08em; color: oklch(0.93 0.03 95 / 0.55); flex: none; }
.winners-board .btn-link { color: var(--gold); margin-top: var(--space-md); }

.racecard-status {
  margin-top: var(--space-sm);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--green);
  min-height: 1.3em;
  opacity: 0;
  transition: opacity 0.25s ease-out;
}
.racecard-status.shown { opacity: 1; }
.racecard-status.error { color: var(--red-deep); }

/* vintage program advert */
.sponsor-ad {
  width: min(100% - 2 * var(--space-lg), 560px);
  margin: 0 auto var(--space-lg);
  padding: var(--space-lg) var(--space-xl);
  text-align: center;
  border: 3px double var(--gold-deep);
  outline: 1.5px solid var(--cream-line);
  outline-offset: 5px;
  background: oklch(0.97 0.015 92);
}
.sponsor-eyebrow {
  font-family: var(--f-label);
  font-size: 0.66rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.sponsor-name {
  display: inline-block;
  margin-top: var(--space-sm);
  font-family: var(--f-display);
  font-size: 1.7rem;
  text-transform: uppercase;
  color: var(--green-deep);
  text-decoration: none;
}
.sponsor-name:hover { color: var(--green-bright); }
.sponsor-blurb {
  margin-top: var(--space-sm);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.sponsor-cta {
  margin-top: var(--space-sm);
  font-family: var(--f-label);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}
.sponsor-cta a { color: var(--red-deep); text-decoration: none; }
.sponsor-cta a:hover { text-decoration: underline; text-underline-offset: 3px; }

.colophon {
  margin-top: auto;
  padding: var(--space-lg);
  text-align: center;
  font-size: 0.78rem;
  font-style: italic;
  color: oklch(0.55 0.02 100);
}

/* ─────────────────────────── racecourse ─────────────────────────── */

#racecourse {
  background: var(--green-deep);
  gap: 0;
}

.course-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px clamp(12px, 3vw, 28px);
}
.course-title { display: flex; align-items: baseline; gap: var(--space-md); flex: 1 1 auto; min-width: 0; overflow: hidden; }
.course-title > * { white-space: nowrap; }
.course-controls { flex: none; }
.course-name {
  font-family: var(--f-display);
  font-size: 1.05rem;
  color: var(--gold);
  text-transform: uppercase;
}
.course-race {
  font-family: var(--f-label);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: oklch(0.93 0.03 95 / 0.65);
}
.course-controls { display: flex; gap: var(--space-sm); }

.btn-round {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 1rem;
  color: oklch(0.93 0.03 95);
  background: oklch(0.93 0.03 95 / 0.1);
  border: 1.5px solid oklch(0.93 0.03 95 / 0.3);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-round:hover { background: oklch(0.93 0.03 95 / 0.22); }
.btn-round[aria-pressed="true"] { opacity: 0.45; }

#canvas-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 clamp(8px, 2vw, 20px);
  border: 3px solid var(--gold-deep);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 0 60px oklch(0 0 0 / 0.15), 0 10px 30px oklch(0 0 0 / 0.3);
  background: oklch(0.8 0.06 230);
}
#race-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

#countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--f-display);
  font-size: clamp(4rem, 16vw, 9rem);
  color: oklch(0.97 0.015 90);
  text-shadow: 0 4px 0 var(--green-deep), 0 8px 30px oklch(0 0 0 / 0.45);
  pointer-events: none;
}
#countdown.tick { animation: count-pop 0.9s cubic-bezier(0.16, 1, 0.3, 1) both; }

#photo-flash {
  position: absolute; inset: 0;
  background: white;
  pointer-events: none;
  animation: flash 0.5s ease-out both;
}

.course-bottom {
  display: flex; align-items: center; gap: var(--space-lg);
  padding: 10px clamp(12px, 3vw, 28px) 14px;
  min-height: 58px;
}

.commentary {
  flex: 1; min-width: 0;
  font-style: italic;
  font-size: clamp(0.95rem, 2.5vw, 1.2rem);
  color: oklch(0.95 0.02 92);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.commentary.pop { animation: comment-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both; }

.tote {
  flex: none;
  list-style: none;
  display: flex; gap: var(--space-sm);
}
.tote li {
  display: flex; align-items: center; gap: 6px;
  font-family: var(--f-label);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  color: oklch(0.93 0.03 95);
  background: oklch(0 0 0 / 0.25);
  padding: 5px 9px;
  border-radius: 3px;
  max-width: 150px;
}
.tote .t-pos { color: var(--gold); }
.tote .t-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tote .t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) {
  .course-bottom { flex-direction: column; align-items: stretch; gap: var(--space-sm); }
  .commentary { white-space: normal; line-height: 1.3; min-height: 2.6em; }
  .tote { flex-wrap: wrap; }
  .tote li { max-width: 110px; }
}

/* ─────────────────────────── winner's circle ─────────────────────────── */

#ceremony {
  position: relative;
  background: var(--green-deep);
  background-image: radial-gradient(ellipse 90% 70% at 50% 20%, oklch(0.46 0.1 152 / 0.9), transparent 65%);
  display: grid; place-items: center;
  overflow: hidden;
  padding: var(--space-lg);
}
#confetti-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.ceremony-card {
  position: relative;
  text-align: center;
  max-width: 640px;
  width: 100%;
  background: var(--paper);
  border: 3px solid var(--gold-deep);
  border-radius: 6px;
  padding: clamp(28px, 6vw, 56px) clamp(20px, 5vw, 48px);
  box-shadow: 0 0 0 8px var(--green-deep), 0 0 0 10px var(--gold-deep), 0 30px 80px oklch(0 0 0 / 0.5);
  animation: card-in 0.6s 0.1s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.ceremony-eyebrow {
  font-family: var(--f-label);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.rosette { position: relative; width: 96px; margin: var(--space-lg) auto var(--space-md); }
.rosette-disc {
  position: relative; z-index: 1;
  width: 96px; height: 96px;
  display: grid; place-items: center;
  font-family: var(--f-display);
  font-size: 1.6rem;
  color: oklch(0.97 0.015 90);
  background:
    repeating-conic-gradient(var(--red) 0deg 15deg, var(--red-deep) 15deg 30deg);
  border-radius: 50%;
  box-shadow: inset 0 0 0 7px var(--red), inset 0 0 0 9px oklch(0.97 0.015 90), 0 4px 12px oklch(0 0 0 / 0.3);
  animation: rosette-spin 1s 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.rosette-disc sup { font-size: 0.7rem; margin-left: 1px; }
.rosette-ribbons i {
  position: absolute; top: 70px;
  width: 22px; height: 62px;
  background: var(--red);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%);
}
.rosette-ribbons i:first-child { left: 20px; rotate: 12deg; background: var(--red-deep); }
.rosette-ribbons i:last-child { right: 20px; rotate: -12deg; }

.winner-name {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: clamp(2rem, 7vw, 3.6rem);
  line-height: 1.05;
  color: var(--green-deep);
  text-transform: uppercase;
  overflow-wrap: break-word;
  margin-top: var(--space-lg);
}

.winner-margin {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin-top: var(--space-sm);
}

.ceremony-actions {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-md);
  margin-top: var(--space-xl);
}

.ceremony-sponsor {
  margin-top: var(--space-lg);
  font-family: var(--f-label);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.ceremony-sponsor a { color: var(--green); }

/* ─────────────────────────── animation ─────────────────────────── */

@keyframes rise { from { opacity: 0; translate: 0 22px; } to { opacity: 1; translate: 0 0; } }
@keyframes slide-in { from { opacity: 0; translate: -14px 0; } to { opacity: 1; translate: 0 0; } }
@keyframes slide-out { to { opacity: 0; translate: 18px 0; } }
@keyframes bell-sway { 0%, 100% { rotate: -6deg; } 50% { rotate: 6deg; } }
@keyframes count-pop {
  0% { opacity: 0; scale: 1.8; }
  25% { opacity: 1; scale: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; scale: 0.92; }
}
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes comment-in { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
@keyframes card-in { from { opacity: 0; scale: 0.9; translate: 0 30px; } to { opacity: 1; scale: 1; translate: 0 0; } }
@keyframes rosette-spin { from { scale: 0; rotate: -180deg; } to { scale: 1; rotate: 0deg; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
