:root {
  --ink: #14211f;
  --muted: #52625f;
  --evergreen: #123d34;
  --turf: #1f6f54;
  --turf-dark: #15513d;
  --cream: #f6f1e4;
  --paper: #fffdf8;
  --rust: #a94f32;
  --gold: #c7953e;
  --line: #d8dfda;
  --focus: #f0b429;
  --positive: #157347;
  --negative: #a43d2d;
  --shadow: 0 16px 44px rgba(20, 33, 31, .10);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: #f2f5f1;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}
button, select, input { font: inherit; }
button, select { min-height: 44px; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.skip-link { position: fixed; left: 1rem; top: -100px; z-index: 100; padding: .75rem 1rem; background: white; color: var(--evergreen); }
.skip-link:focus { top: 1rem; }

.site-header { position: sticky; top: 0; z-index: 20; background: rgba(255,253,248,.95); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.header-inner { max-width: 1440px; margin: auto; padding: .75rem clamp(1rem, 3vw, 2rem); display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--evergreen); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--evergreen); color: white; font-family: Georgia, serif; font-weight: 800; }
.brand strong, .brand small { display: block; line-height: 1.1; }
.brand strong { font-family: Georgia, serif; font-size: 1.25rem; }
.brand small { margin-top: .25rem; color: var(--muted); font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.virtual-badge { padding: .45rem .7rem; border-radius: 999px; background: #e8f4ee; color: var(--turf-dark); font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.virtual-badge span { color: var(--positive); }
.quiet-button, .text-button { border: 0; background: transparent; color: var(--turf-dark); font-weight: 800; text-decoration: underline; text-underline-offset: .2em; }

main { max-width: 1440px; margin: auto; padding: clamp(1rem, 3vw, 2rem); }
h1, h2, h3 { color: var(--evergreen); font-family: Georgia, "Times New Roman", serif; line-height: 1.14; letter-spacing: -.018em; }
h1 { max-width: 900px; margin: .35rem 0 .75rem; font-size: clamp(2.25rem, 5vw, 4.75rem); }
h2 { margin: .2rem 0 .6rem; font-size: clamp(1.4rem, 2.4vw, 2.1rem); }
h3 { margin: 0 0 .35rem; font-size: 1.15rem; }
p { margin-top: 0; }
.eyebrow { margin: 0 0 .25rem; color: var(--gold); font-size: .76rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.lede { max-width: 780px; color: #dbe9e3; font-family: Georgia, serif; font-size: clamp(1.05rem, 2vw, 1.35rem); }

.lab-intro { position: relative; overflow: hidden; display: grid; grid-template-columns: 1fr auto; gap: 2rem; align-items: end; padding: clamp(1.5rem, 4vw, 3.75rem); border-bottom: 7px solid var(--gold); border-radius: var(--radius); background: linear-gradient(135deg, var(--evergreen), #1a5547); box-shadow: var(--shadow); color: white; }
.lab-intro::after { content: ""; position: absolute; right: -85px; top: -100px; width: 310px; height: 310px; border: 35px solid rgba(255,255,255,.05); border-radius: 50%; }
.lab-intro h1 { color: white; }
.session-strip { position: relative; z-index: 1; display: grid; min-width: 250px; margin: 0; border: 1px solid rgba(255,255,255,.2); background: rgba(0,0,0,.12); }
.session-strip div { display: flex; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; border-bottom: 1px solid rgba(255,255,255,.15); }
.session-strip div:last-child { border-bottom: 0; }
.session-strip dt { color: #cce0d8; font-size: .8rem; text-transform: uppercase; letter-spacing: .07em; }
.session-strip dd { margin: 0; font-weight: 850; }
.session-strip div:last-child dd { color: #dfeae5; font-size: .72rem; letter-spacing: .03em; }

.mode-switcher { display: grid; grid-template-columns: minmax(240px, .75fr) minmax(460px, 1.25fr); gap: 1.25rem; align-items: center; margin-top: 1.25rem; padding: 1rem 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 8px 24px rgba(20,33,31,.06); }
.mode-switcher h2 { margin-bottom: 0; font-size: clamp(1.25rem, 2vw, 1.65rem); }
.mode-switcher fieldset { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; min-width: 0; margin: 0; padding: 0; border: 0; }
.mode-option { position: relative; display: block; margin: 0; cursor: pointer; }
.mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.mode-option span { display: block; min-height: 78px; padding: .8rem .9rem; border: 2px solid var(--line); border-radius: 12px; background: #f8faf7; transition: border-color .16s ease, background .16s ease, box-shadow .16s ease; }
.mode-option strong, .mode-option small { display: block; }
.mode-option strong { color: var(--evergreen); font-size: .9rem; }
.mode-option small { margin-top: .2rem; color: var(--muted); font-size: .74rem; line-height: 1.35; }
.mode-option input:checked + span { border-color: var(--turf); background: #e8f4ee; box-shadow: inset 0 0 0 1px var(--turf); }
.mode-option input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.mode-option input:disabled + span { cursor: not-allowed; opacity: .58; }
body[data-mode="test"] .mode-switcher { border-left: 6px solid var(--rust); }
body[data-mode="test"]:not(.test-unlocked) .model-only { display: none; }

.lab-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.25rem; align-items: start; margin-top: 1.25rem; }
.primary-column { min-width: 0; display: grid; gap: 1.25rem; }
.lesson-card, .racecard-panel, .track-panel, .analysis-panel, .betting-desk, .learning-notes, .history-panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: 0 8px 24px rgba(20,33,31,.06); }
.lesson-card { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; padding: 1.15rem 1.35rem; border-left: 6px solid var(--gold); }
.lesson-card p:not(.eyebrow) { margin-bottom: 0; color: var(--muted); }
.lesson-number { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--cream); color: var(--rust); font-family: Georgia, serif; font-weight: 800; }
.model-details { grid-column: 2 / -1; display: grid; grid-template-columns: repeat(5, 1fr); gap: .75rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.model-details[hidden] { display: none; }
.model-details div { padding: .7rem; background: var(--cream); text-align: center; }
.model-details strong, .model-details span { display: block; }
.model-details strong { color: var(--evergreen); font-size: 1.2rem; }
.model-details span { color: var(--muted); font-size: .78rem; }
.model-details p { grid-column: 1 / -1; font-size: .9rem; }

.racecard-panel, .track-panel, .analysis-panel { overflow: hidden; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; padding: 1.2rem 1.35rem; border-bottom: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; color: var(--muted); font-size: .75rem; }
.racecard-key { display: grid; justify-items: end; gap: .45rem; }
.scenario-chip { display: inline-flex; align-items: center; min-height: 28px; padding: .25rem .55rem; border: 1px solid #d5c18f; border-radius: 999px; background: var(--cream); color: var(--rust); font-size: .7rem; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }
.form-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.form-dot.strong { background: var(--positive); }
.form-dot.steady { background: var(--gold); }
.form-dot.watch { background: var(--rust); }
.table-wrap, .analysis-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 830px; }
th, td { padding: .8rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #edf3ef; color: var(--evergreen); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; }
td { font-size: .88rem; }
tbody tr:hover { background: #f8f5eb; }
.runner { display: grid; grid-template-columns: 30px 1fr; gap: .55rem; align-items: center; min-width: 150px; }
.silk { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; color: white; font-weight: 900; box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.runner strong, .runner small { display: block; }
.runner small { color: var(--muted); }
.rating { display: inline-flex; align-items: center; gap: .35rem; font-variant-numeric: tabular-nums; }
.probability-cell strong { display: block; color: var(--evergreen); }
.probability-bar { width: 62px; height: 4px; margin-top: .25rem; overflow: hidden; border-radius: 4px; background: var(--line); }
.probability-bar span { display: block; height: 100%; background: var(--turf); }
.odds-pill { display: inline-block; padding: .3rem .48rem; border: 1px solid #c9d8d0; border-radius: 6px; background: #f4faf7; color: var(--turf-dark); font-weight: 850; }
.table-note { margin: 0; padding: .85rem 1.35rem; background: var(--cream); color: var(--muted); font-size: .82rem; }

.track-heading { align-items: center; }
.race-status { max-width: 360px; margin: 0; color: var(--muted); font-size: .86rem; text-align: right; }
.track { position: relative; min-height: 390px; overflow: hidden; padding: 24px 6% 18px 2%; background: linear-gradient(rgba(18,61,52,.18),rgba(18,61,52,.18)), url("assets/licensed/track.jpg") center/cover; }
.track::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(20,33,31,.38), transparent 22%, transparent 80%, rgba(255,255,255,.12)); pointer-events: none; }
#track-lanes { position: relative; z-index: 1; }
.track-lane { position: relative; height: 56px; border-bottom: 1px dashed rgba(255,255,255,.42); }
.lane-number { position: absolute; left: 0; top: 14px; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: rgba(255,255,255,.88); font-weight: 900; }
.track-horse { position: absolute; left: 32px; top: 1px; width: 70px; height: 54px; background-image: var(--sheet); background-size: 287px 287px; background-position: 0 0; background-repeat: no-repeat; filter: drop-shadow(0 4px 3px rgba(0,0,0,.35)); transform: translateX(0); }
.track-horse.racing { transition-property: transform; transition-duration: var(--duration); transition-timing-function: cubic-bezier(.2,.65,.32,1); transition-delay: var(--delay); }
.track-horse.finished { transform: translateX(calc(var(--track-distance) + var(--finish-offset))); }
.finish-line { position: absolute; z-index: 2; right: 7%; top: 0; bottom: 0; width: 13px; background: repeating-conic-gradient(#fff 0 25%, #111 0 50%) 0/13px 13px; box-shadow: 0 0 0 2px rgba(255,255,255,.7); }
.finish-line span { position: absolute; top: 7px; left: 50%; padding: .2rem .4rem; transform: translateX(-50%); background: var(--paper); color: var(--evergreen); font-size: .66rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }

.betting-desk { position: sticky; top: 84px; padding: 1.25rem; }
.desk-note { padding: .75rem; border-left: 4px solid var(--gold); background: var(--cream); color: var(--muted); font-size: .82rem; }
label { display: block; margin: .8rem 0 .3rem; color: var(--evergreen); font-size: .78rem; font-weight: 850; }
select, input { width: 100%; min-height: 46px; border: 1px solid #aab9b3; border-radius: 8px; background: white; color: var(--ink); padding: .62rem .7rem; }
.selection-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stake-row { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.stake-presets { display: flex; }
.stake-presets button { min-width: 42px; border: 1px solid var(--line); background: var(--cream); color: var(--evergreen); font-weight: 850; }
.estimate-field { margin-top: .9rem; padding: .8rem; border: 1px solid #d7c8a7; border-radius: 10px; background: var(--cream); }
.estimate-field label { margin-top: 0; }
.estimate-field p { margin: .35rem 0 0; color: var(--muted); font-size: .74rem; }
.percent-input { position: relative; }
.percent-input input { padding-right: 2.25rem; background: white; }
.percent-input span { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 850; }
.price-card { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 1rem; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: var(--line); }
.price-card div { padding: .65rem; background: #f8faf7; }
.price-card span, .price-card strong { display: block; }
.price-card span { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; }
.price-card strong { margin-top: .12rem; font-variant-numeric: tabular-nums; }
.value-positive { color: var(--positive) !important; }
.value-negative { color: var(--negative) !important; }
.formula-note { margin: .5rem 0 0; color: var(--muted); font-size: .74rem; }
.form-error { min-height: 1.2em; margin: .35rem 0; color: var(--negative); font-size: .78rem; }
.primary-button, .race-button { width: 100%; min-height: 48px; border: 0; border-radius: 9px; background: var(--turf-dark); color: white; font-weight: 900; }
.primary-button:hover, .race-button:hover { background: var(--rust); }
.primary-button:disabled, .race-button:disabled { cursor: not-allowed; opacity: .48; }
.bet-slip { margin-top: 1.15rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.slip-heading { display: flex; justify-content: space-between; align-items: center; }
.empty-slip { padding: 1rem; border: 1px dashed #b7c3be; border-radius: 9px; color: var(--muted); font-size: .82rem; text-align: center; }
#slip-list { display: grid; gap: .55rem; margin: 0; padding: 0; list-style: none; }
.slip-item { display: grid; grid-template-columns: 1fr auto; gap: .5rem; padding: .7rem; border: 1px solid var(--line); border-radius: 9px; background: #fafbf8; }
.slip-item strong, .slip-item small { display: block; }
.slip-item small { color: var(--muted); }
.remove-bet { min-width: 34px; min-height: 34px; border: 0; background: transparent; color: var(--rust); font-size: 1.1rem; }
.risk-meter { margin: 1rem 0; }
.risk-meter > div:first-child { display: flex; justify-content: space-between; font-size: .82rem; }
.meter-track { height: 7px; margin: .35rem 0; overflow: hidden; border-radius: 99px; background: var(--line); }
.meter-track span { display: block; width: 0; height: 100%; background: var(--positive); transition: width .2s ease; }
.risk-meter p { margin: 0; color: var(--muted); font-size: .74rem; }
.slip-total { display: flex; justify-content: space-between; margin: .75rem 0; }

.finish-order { display: flex; flex-wrap: wrap; gap: .5rem; padding: 1rem 1.35rem; }
.finish-card { display: flex; align-items: center; gap: .45rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.finish-card:first-child { border-color: var(--gold); background: var(--cream); }
.place-number { color: var(--rust); font-family: Georgia, serif; font-size: 1.15rem; font-weight: 900; }
.analysis-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; padding: 0 1.35rem 1rem; }
.analysis-summary div { padding: .9rem; border-radius: 10px; background: #edf3ef; }
.analysis-summary span, .analysis-summary strong { display: block; }
.analysis-summary span { color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.analysis-summary strong { margin-top: .2rem; font-size: 1.15rem; }
.analysis-table-wrap table { min-width: 650px; }
.seed-chip { padding: .35rem .55rem; border-radius: 6px; background: var(--cream); color: var(--muted); font-size: .7rem; }
.analysis-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: .55rem; }
.analysis-tools .quiet-button { padding-inline: .5rem; }
.coach-note { margin: 1rem 1.35rem 1.35rem; padding: 1rem; border-left: 5px solid var(--gold); background: var(--cream); }
.coach-note strong { color: var(--evergreen); }

.learning-notes { margin-top: 1.25rem; padding: clamp(1.25rem, 3vw, 2.2rem); }
.notes-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.notes-grid article { padding: 1rem; border-top: 4px solid var(--turf); background: #f8faf7; }
.notes-grid article > span { color: var(--gold); font-weight: 900; }
.notes-grid p { margin: 0; color: var(--muted); font-size: .86rem; }
.history-panel { margin-top: 1.25rem; overflow: hidden; }
.history-panel .section-heading > p { max-width: 430px; margin: 0; color: var(--muted); font-size: .82rem; text-align: right; }
.history-empty { margin: 0; padding: 1.4rem; color: var(--muted); text-align: center; }
.history-wrap { overflow-x: auto; }
.history-wrap table { min-width: 780px; }
.history-wrap td small { display: block; color: var(--muted); }

footer { display: block; margin-top: 2rem; padding: 2rem max(1rem, calc((100vw - 1380px)/2)); background: var(--evergreen); color: #e5eee9; }
footer strong { color: white; font-family: Georgia, serif; font-size: 1.3rem; }
footer p { max-width: 620px; margin: .35rem 0 0; font-size: .82rem; }

@media (max-width: 1080px) {
  .lab-grid { grid-template-columns: 1fr; }
  .primary-column { display: contents; }
  .lesson-card { order: 1; }
  .racecard-panel { order: 2; }
  .betting-desk { position: static; order: 3; }
  .track-panel { order: 4; }
  .analysis-panel { order: 5; }
  .notes-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .header-inner { align-items: flex-start; }
  .header-actions { align-items: flex-end; flex-direction: column; gap: .2rem; }
  .virtual-badge { font-size: .65rem; }
  .quiet-button { min-height: 44px; display: inline-flex; align-items: center; font-size: .78rem; }
  .lab-intro { grid-template-columns: 1fr; }
  .session-strip { min-width: 0; }
  .mode-switcher { grid-template-columns: 1fr; }
  .mode-switcher fieldset { grid-template-columns: 1fr; }
  .lesson-card { grid-template-columns: auto 1fr; }
  .lesson-card > .text-button { grid-column: 1 / -1; justify-self: start; }
  .model-details { grid-column: 1 / -1; grid-template-columns: repeat(2, 1fr); }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .legend { justify-content: flex-start; }
  .racecard-key { justify-items: start; }
  .race-status { text-align: left; }
  .analysis-tools { justify-content: flex-start; }
  .history-panel .section-heading > p { text-align: left; }
  .track { min-height: 340px; padding-left: 0; }
  .track-lane { height: 48px; }
  .track-horse { top: -2px; transform: scale(.84); transform-origin: left center; }
  .track-horse.finished { transform: translateX(calc(var(--track-distance) + var(--finish-offset))) scale(.84); }
  .analysis-summary, .notes-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .track-horse.racing { transition-duration: .01ms !important; transition-delay: 0ms !important; }
}
