:root {
  --ink: #1b2420;
  --muted: #6a675c;
  --paper: #f3eee1;
  --card: #fffdf7;
  --line: #ddd5c0;
  --green: #12412f;
  --green-2: #1c5a41;
  --green-soft: #e4eee4;
  --gold: #c8a43a;
  --gold-soft: #f6ecc8;
  --red: #b3261e;
  --blue: #1f5fa8;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.45 var(--sans); font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--green); color: #f5f1e6;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 50% 50%, var(--green) 0 34%, #f5f1e6 35% 48%, var(--red) 49% 100%);
  box-shadow: 0 0 0 2px #f5f1e6;
}
.brand h1 { font: 700 22px/1.1 var(--serif); letter-spacing: 0.01em; }
.brand p { font-size: 12px; opacity: 0.75; letter-spacing: 0.08em; text-transform: uppercase; }
.meet { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; flex: 1; min-width: 240px; font-size: 14px; }
.meet strong { font: 600 18px var(--serif); }
.meet b { color: #e6cf85; font-weight: 600; }
.meet-note { opacity: 0.65; font-style: italic; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ghost {
  background: transparent; border: 1px solid rgba(245, 241, 230, 0.35); color: inherit;
  padding: 6px 12px; border-radius: 6px; font-size: 13px;
}
.ghost:hover { background: rgba(245, 241, 230, 0.12); }
.ghost.dark { border-color: var(--line); color: var(--ink); background: var(--card); }
.ghost.dark:hover { background: #f1ebda; }
.wallet {
  display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-radius: 8px;
  background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(200, 164, 58, 0.5);
}
.wallet-label { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.75; }
.wallet strong { font: 700 20px var(--serif); color: #f0d77f; }
.mini { background: var(--gold); border: 0; color: #1c1600; padding: 4px 10px; border-radius: 5px; font-size: 12px; font-weight: 600; }

/* ---------- race bar ---------- */
.racebar { background: var(--card); border-bottom: 1px solid var(--line); padding: 0 24px; }
.race-tabs { display: flex; gap: 4px; overflow-x: auto; padding-top: 10px; }
.tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 132px;
  padding: 7px 12px 8px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0;
  background: #f1ebda; text-align: left; white-space: nowrap;
}
.tab-time { font: 700 15px var(--serif); }
.tab-sub { font-size: 11.5px; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--green); color: #f5f1e6; border-color: var(--green); }
.tab.on .tab-sub { color: rgba(245, 241, 230, 0.8); }
.tab.done:not(.on) { background: var(--card); }
.tab:disabled { opacity: 0.5; }
.race-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 14px 0; border-top: 2px solid var(--green); }
.race-head h2 { font: 700 22px/1.2 var(--serif); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips span { background: var(--green-soft); color: var(--green); padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; }
.chips.light span { background: #f1ebda; color: var(--ink); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; padding: 20px 24px 28px; max-width: 1560px; margin: 0 auto; align-items: start; }
.stage { min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.panel h2 { font: 700 15px var(--serif); letter-spacing: 0.02em; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }

.steps { list-style: none; display: flex; gap: 0; margin: 0 0 14px; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.steps li { flex: 1; display: flex; align-items: center; gap: 8px; padding: 9px 14px; font-size: 13.5px; color: var(--muted); border-right: 1px solid var(--line); white-space: nowrap; }
.steps li:last-child { border-right: 0; }
.steps li span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #e7e0cd; font-size: 11.5px; font-weight: 700; color: var(--ink); }
.steps li.on { background: var(--green); color: #f5f1e6; font-weight: 600; }
.steps li.on span { background: var(--gold); }
.steps li.past { color: var(--ink); }
.steps li.go { cursor: pointer; }
.steps li.go:hover { background: #f1ebda; }

.view-actions { display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.view-actions .hint { flex: 1; min-width: 220px; color: var(--muted); font-size: 13.5px; }
.spacer { flex: 1; }
.primary { background: var(--green); color: #f5f1e6; border: 0; padding: 11px 20px; border-radius: 8px; font-weight: 600; font-size: 15px; }
.primary:hover { background: var(--green-2); }
.primary.wide { width: 100%; margin-top: 10px; }
.muted { color: var(--muted); font-size: 13.5px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table.card { border-collapse: collapse; width: 100%; font-size: 14px; }
table.card th {
  text-align: left; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600;
  padding: 9px 10px; border-bottom: 2px solid var(--green); white-space: nowrap; background: var(--card); position: sticky; top: 0;
}
table.card td { padding: 9px 10px; border-bottom: 1px solid #ebe5d3; vertical-align: middle; white-space: nowrap; }
table.card tbody tr:last-child td { border-bottom: 0; }
#cardTable tbody tr { cursor: pointer; }
#cardTable tbody tr:hover { background: #faf5e6; }
table.card tr.sel { background: var(--gold-soft) !important; box-shadow: inset 3px 0 0 var(--gold); }
.c-no b { font: 700 18px var(--serif); margin-right: 3px; }
.c-no small { color: var(--muted); }
.c-silk { width: 40px; padding-right: 0 !important; }
.c-silk svg, .silk { display: block; }
td.c-horse { white-space: normal !important; min-width: 220px; }
.link { background: none; border: 0; padding: 0; font-weight: 700; font-size: 15px; color: var(--ink); text-align: left; }
.link:hover { text-decoration: underline; color: var(--green-2); }
.link.th { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.link.th.on { color: var(--green); text-decoration: underline; }
.gear { font-size: 11px; font-weight: 700; color: var(--blue); text-decoration: none; border: 1px solid currentColor; border-radius: 3px; padding: 0 3px; vertical-align: 2px; }
.sub { font-size: 12.5px; color: var(--muted); }
.spot { font-size: 12.5px; color: #4a4a40; font-style: italic; margin-top: 1px; }
.c-form { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.06em; font-weight: 600; }
.up { color: #1c6b3f; font-weight: 600; }
.down { color: var(--red); font-weight: 600; }
.fav { color: var(--muted); margin-left: 3px; }
.tag { background: var(--gold); color: #1c1600; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.05em; vertical-align: 1px; }
table.result tr.placed td:first-child { box-shadow: inset 3px 0 0 var(--green); }
table.result tr.backed { background: var(--gold-soft); }
table.card tr.won { background: #edf5ea; }

.odds {
  min-width: 62px; padding: 6px 10px; border-radius: 6px; border: 1px solid #0c2f22; background: var(--green); color: #f5efd8;
  font: 700 14.5px var(--serif); text-align: center;
}
.odds:hover:not(:disabled) { background: var(--gold); color: #1c1600; border-color: #8f7320; }
.odds:disabled { background: #e7e0cd; color: var(--ink); border-color: var(--line); }
.odds.big { font-size: 18px; padding: 8px 16px; margin-left: auto; }

/* ---------- canvases ---------- */
.canvas-frame { border-radius: 10px; overflow: hidden; border: 1px solid #0c2f22; background: #6a9f50; line-height: 0; }
.parade-canvas { width: 100%; aspect-ratio: 5 / 2; display: block; }
.race-canvas { width: 100%; aspect-ratio: 5 / 2.1; display: block; }
.inspect { display: grid; grid-template-columns: minmax(300px, 46%) 1fr; gap: 14px; margin-top: 14px; }
.close-frame { min-height: 290px; }
.close-canvas { width: 100%; height: 100%; min-height: 290px; display: block; }
.inspect-info { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.inspect-info h3, .dlg-head h2 { font: 700 19px var(--serif); }
.inspect-info h4, #dlgBody h4 { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 14px 0 6px; }
.insp-head { display: flex; align-items: center; gap: 12px; }
.facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 0; }
.facts div { background: #f4eedd; border-radius: 6px; padding: 5px 10px; min-width: 62px; }
.facts dt { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; font-size: 15px; }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: 14px; }
.notes li { padding-left: 22px; position: relative; }
.notes li::before { content: "•"; position: absolute; left: 6px; color: var(--muted); }
.notes li.good::before { content: "+"; color: #1c6b3f; font-weight: 800; left: 4px; }
.notes li.bad::before { content: "−"; color: var(--red); font-weight: 800; left: 4px; }
.notes.plain li { padding-left: 0; font-size: 13.5px; color: #3c3c34; }
.notes.plain li::before { content: none; }

.commentary {
  margin-top: 10px; min-height: 46px; padding: 11px 16px; background: var(--green); color: #f5f1e6; border-radius: 8px;
  font: italic 600 17px/1.35 var(--serif);
}
.speed { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.speed button { border: 0; background: none; padding: 8px 14px; font-weight: 600; }
.speed button.on { background: var(--green); color: #f5f1e6; }

/* ---------- sidebar ---------- */
.mrow { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; }
.mrow[data-row] { cursor: pointer; }
.mrow[data-row]:hover { background: #faf5e6; }
.mrow.sel { background: var(--gold-soft); }
.mrow.mine { background: var(--gold-soft); }
.mrow.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #f2c94c; } to { background: transparent; } }
.num { display: inline-grid; place-items: center; min-width: 24px; height: 22px; padding: 0 4px; border-radius: 4px; font-weight: 700; font-size: 12.5px; border: 1px solid rgba(0, 0, 0, 0.35); flex: none; }
.mname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.move { font-size: 11px; }
.move.in { color: var(--blue); }
.move.out { color: #b0651a; }
.pos { width: 34px; font: 700 13px var(--serif); color: var(--muted); flex: none; }
.sp { font-weight: 600; font-size: 13.5px; }
.board-note { margin-top: 8px; font-size: 12px; color: var(--muted); }
.board-note b { color: var(--ink); }

.slip-sel { display: flex; align-items: center; gap: 10px; }
.slip-sel div { flex: 1; min-width: 0; }
.slip-sel b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slip-sel small, .bet small { display: block; color: var(--muted); font-size: 12.5px; }
.slip-odds { font: 700 20px var(--serif); color: var(--green); }
.seg { display: grid; grid-template-columns: 1fr 1fr; margin: 12px 0 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #f4eedd; padding: 8px; font-weight: 600; }
.seg button.on { background: var(--green); color: #f5f1e6; }
.seg button:disabled { opacity: 0.45; }
.stake-row { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.stake-row input { flex: 1; min-width: 0; font: 700 18px var(--serif); padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); text-align: right; }
.quick { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.quick button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 5px 0; font-size: 12.5px; font-weight: 600; min-width: 42px; }
.quick button:hover { background: #f1ebda; }
.slip-sum { margin-top: 10px; font-size: 13.5px; color: #3c3c34; min-height: 20px; }
.slip-msg { margin-top: 8px; font-size: 13.5px; font-weight: 600; color: var(--green-2); }
.bet { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #ebe5d3; }
.bet:last-child { border-bottom: 0; padding-bottom: 0; }
.bet div { flex: 1; min-width: 0; }
.bet-amt { font-weight: 700; white-space: nowrap; }
.bet.won .bet-amt { color: #1c6b3f; }
.bet.lost .bet-amt { color: var(--red); font-weight: 600; font-size: 13.5px; }

/* ---------- result ---------- */
.winner { display: flex; align-items: center; gap: 16px; padding: 16px 20px; margin-bottom: 14px; background: var(--green); color: #f5f1e6; border-radius: 10px; }
.winner h3 { font: 700 26px/1.15 var(--serif); }
.winner p { opacity: 0.85; font-size: 14px; }
.eyebrow { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #e6cf85; display: block; }
.win-time { margin-left: auto; text-align: right; }
.win-time b { font: 700 22px var(--serif); }
.settle { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; padding: 13px 18px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.settle strong { margin-left: auto; font: 700 19px var(--serif); }
.settle.won { background: #e6f2e2; border-color: #a9cba0; }
.settle.won strong { color: #1c6b3f; }
.settle.lost strong { color: var(--red); }

/* ---------- dialog ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(920px, 94vw); max-height: 88vh; background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(10, 25, 18, 0.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
#dlgBody { padding: 16px 20px 22px; overflow-y: auto; }
#dlgBody .table-wrap { margin-top: 10px; }
#dlgBody > p { margin-top: 12px; }
.help p { margin-bottom: 4px; max-width: 70ch; }

.foot { padding: 0 24px 26px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Christmas advertising banner ---------- */
.ad-slot { max-width: 1560px; margin: 0 auto; padding: 16px 24px 0; }
.xmas-ad {
  position: relative; display: flex; align-items: center; gap: 22px; overflow: hidden;
  min-height: 118px; padding: 28px 28px 18px; border-radius: 14px;
  border: 6px solid transparent; color: #fff; text-decoration: none;
  background:
    linear-gradient(105deg, #dc2a3f 0%, #b3111f 60%, #0f8a45 60.2%, #0a5c2f 100%) padding-box,
    repeating-linear-gradient(135deg, #fff 0 10px, #e63946 10px 20px) border-box;
  box-shadow: 0 3px 12px rgba(60, 10, 14, 0.25);
}
.xmas-ad:focus-visible { outline: 3px solid #ffd23f; outline-offset: 3px; }
.xmas-snow {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.75;
  background-image:
    radial-gradient(circle, #fff 0 1.6px, transparent 2.2px),
    radial-gradient(circle, #fff 0 2.4px, transparent 3px),
    radial-gradient(circle, rgba(255, 255, 255, 0.7) 0 1.2px, transparent 1.8px);
  background-size: 90px 90px, 140px 140px, 60px 60px;
  background-position: 0 0, 40px 60px, 20px 30px;
  animation: xmas-snow 9s linear infinite;
}
@keyframes xmas-snow { to { background-position: 0 90px, 40px 200px, 20px 150px; } }
.xmas-lights {
  position: absolute; left: 0; right: 0; top: 0; height: 24px; pointer-events: none;
  background: linear-gradient(#0b3d24, #0b3d24) 0 5px / 100% 2px no-repeat;
}
.xmas-lights::before, .xmas-lights::after {
  content: ""; position: absolute; inset: 0; background-size: 120px 24px; background-repeat: repeat-x;
  filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.75));
  animation: xmas-twinkle 1.6s ease-in-out infinite alternate;
}
.xmas-lights::before {
  background-image:
    radial-gradient(circle at 15px 12px, #ffd23f 0 5px, transparent 6px),
    radial-gradient(circle at 75px 12px, #ff70a6 0 5px, transparent 6px);
}
.xmas-lights::after {
  background-image:
    radial-gradient(circle at 45px 14px, #4cc9f0 0 5px, transparent 6px),
    radial-gradient(circle at 105px 14px, #9ef01a 0 5px, transparent 6px);
  animation-delay: -1.6s; animation-direction: alternate-reverse;
}
@keyframes xmas-twinkle { from { opacity: 1; } to { opacity: 0.35; } }
.xmas-art { position: relative; flex: none; height: 88px; width: auto; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.25)); }
.xmas-copy { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.xmas-kicker { font: 700 12px var(--sans); letter-spacing: 0.2em; text-transform: uppercase; color: #ffe9a8; }
.xmas-name {
  font: 800 clamp(26px, 3.6vw, 46px)/1.05 var(--serif); letter-spacing: 0.01em;
  text-shadow: 0 2px 0 #7d0a16, 0 5px 12px rgba(0, 0, 0, 0.35);
}
.xmas-name span { color: #ffd23f; }
.xmas-tag { font: italic 700 clamp(16px, 2vw, 24px)/1.2 var(--serif); color: #ffd23f; text-shadow: 0 1px 0 #7d0a16; }
.xmas-cta {
  position: relative; flex: none; padding: 11px 24px; border-radius: 999px;
  background: #ffd23f; color: #7d0a16; font: 800 15px var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  box-shadow: 0 3px 0 #b8860b; transition: transform 0.15s, background 0.15s;
}
.xmas-ad:hover .xmas-cta { transform: translateY(-2px); background: #ffe680; }
.xmas-label {
  position: absolute; right: 10px; bottom: 3px; font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: rgba(255, 255, 255, 0.75);
}
@media (max-width: 900px) { .xmas-art-r { display: none; } }
@media (max-width: 760px) {
  .ad-slot { padding: 14px 14px 0; }
  .xmas-ad { flex-wrap: wrap; gap: 10px 14px; padding: 28px 16px 20px; background:
    linear-gradient(105deg, #dc2a3f 0%, #b3111f 100%) padding-box,
    repeating-linear-gradient(135deg, #fff 0 10px, #e63946 10px 20px) border-box; }
  .xmas-art { height: 62px; }
  .xmas-copy { flex: 1 1 240px; }
  .xmas-name { font-size: 24px; }
}
@media (max-width: 520px) { .xmas-art { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .xmas-snow, .xmas-lights::before, .xmas-lights::after { animation: none; }
}

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .inspect { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .top, .racebar { padding-left: 14px; padding-right: 14px; }
  .layout { padding: 14px; }
  .c-jock, .spot { display: none; }
  .steps li { padding: 8px; font-size: 12px; gap: 5px; }
  .parade-canvas, .race-canvas { aspect-ratio: 16 / 10; }
}
@media (prefers-reduced-motion: reduce) { .mrow.flash { animation: none; } }
