:root {
  --font-display: "Cormorant Garamond", Georgia, serif;
  --font-body: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #0a1117;
  --surface: #111b23;
  --surface-2: #17242d;
  --surface-3: #1b2b35;
  --text: #edf3f2;
  --muted: #9aabb0;
  --accent: #83dcc7;
  --accent-strong: #3db99f;
  --positive: #75d6a1;
  --negative: #ff9290;
  --line: rgba(151, 190, 190, .18);
  --line-soft: rgba(151, 190, 190, .1);
  --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: .005em;
}
button, select, textarea { font: inherit; font-variant-numeric: tabular-nums; }
button { cursor: pointer; }
#gold-dust { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .12; }
#modern-shell { position: relative; z-index: 1; max-width: 1680px; margin: 0 auto; }

/* Brand and the track photography are intentionally kept in the same layout. */
.mast { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 2.2rem .7rem; }
.brand { display: flex; gap: .85rem; align-items: center; }
.emblem { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1px var(--accent), 0 0 26px rgba(131, 220, 199, .18); }
.eyebrow { margin: 0; color: var(--accent); font-size: .67rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: .1rem 0 0; font-size: 1.55rem; line-height: 1.1; font-weight: 750; letter-spacing: -.025em; }

/* Option A: elegant Cormorant display type with highly legible Inter data/body text. */
h1, h2, h3, h4, h5, h6,
.hero-copy h2, .track-chip b, .panel-head h3, .horse,
.race-title h4, .agent-race h4, .agent-perf h4,
.wager-stats h4, .wager-stats .wager-card h5, .ticket .rn {
  font-family: var(--font-display);
  font-variant-numeric: lining-nums;
}
table, th, td, .stat, .meta, .pill, .status-pill, .tier, .status-badge,
.race-title span, .race-title strong, .wager-table, .result-grid {
  font-variant-numeric: tabular-nums;
}
h1 span { color: var(--accent); }
.mast-meta { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.pill, .status-pill { display: inline-flex; align-items: center; min-height: 28px; padding: .25rem .62rem; border: 1px solid rgba(131, 220, 199, .35); border-radius: 999px; color: var(--accent); background: rgba(131, 220, 199, .08); font-size: .7rem; font-weight: 700; letter-spacing: .06em; }

.hero { position: relative; height: 38vh; min-height: 240px; margin: .6rem 1.4rem 0; overflow: hidden; border-radius: 22px; background: #0a1117; box-shadow: var(--shadow); }
.hero-photo { position: absolute; inset: 0; z-index: 0; width: 100%; height: 100%; object-fit: cover; animation: ken 28s ease-in-out infinite alternate; }
@keyframes ken { from { transform: scale(1.02); } to { transform: scale(1.12) translate(-1.4%, -.8%); } }
.hero-veil { position: absolute; inset: 0; z-index: 1; background: linear-gradient(90deg, rgba(7, 14, 20, .83) 0%, rgba(7, 14, 20, .15) 55%, rgba(7, 14, 20, .55) 100%), linear-gradient(180deg, transparent 40%, rgba(7, 14, 20, .78)); }
.hero-copy { position: absolute; z-index: 2; left: 2.2rem; bottom: 1.8rem; }
.hero-copy h2 { margin: .15rem 0; font-size: clamp(2.3rem, 5vw, 4.6rem); line-height: .95; font-weight: 750; letter-spacing: -.055em; }
.hero-copy p:last-child { margin: .45rem 0 0; color: #d0dcda; font-size: .92rem; }

.track-rail { display: grid; grid-template-columns: repeat(5, 1fr); gap: .7rem; padding: 1rem 1.4rem .2rem; }
.track-chip { position: relative; height: 118px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; color: var(--text); background: var(--surface); text-align: left; }
.track-chip img { position: absolute; inset: 0; z-index: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.track-chip .shade { position: absolute; inset: 0; z-index: 1; background: linear-gradient(180deg, rgba(7, 14, 20, .04), rgba(7, 14, 20, .58) 55%, rgba(7, 14, 20, .9)); }
.track-chip b, .track-chip small { position: relative; z-index: 2; display: block; padding: 0 .8rem; }
.track-chip b { margin-top: 3.4rem; font-size: 1rem; font-weight: 700; }
.track-chip small { color: var(--accent); font-size: .62rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.track-chip.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 10px 28px rgba(131, 220, 199, .14); }
.track-chip.live::before { content: "LIVE"; position: absolute; top: .45rem; right: .5rem; z-index: 2; padding: .12rem .38rem; border-radius: 999px; color: var(--bg); background: var(--accent); font-size: .57rem; font-weight: 800; letter-spacing: .12em; }

.nav { display: flex; gap: .2rem; margin: 1rem 1.4rem 0; padding: .25rem; width: fit-content; border: 1px solid var(--line); border-radius: 12px; background: rgba(17, 27, 35, .82); }
.nav button { min-height: 38px; padding: .45rem 1rem; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: .84rem; font-weight: 700; }
.nav button:hover { color: var(--text); background: rgba(131, 220, 199, .08); }
.nav button.active { color: var(--bg); background: var(--accent); }

main { padding: .8rem 1.4rem 3.5rem; }
.panel { padding: 1.35rem; border: 1px solid var(--line); border-radius: 16px; background: rgba(17, 27, 35, .88); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding-bottom: 1.05rem; border-bottom: 1px solid var(--line-soft); }
.panel-head > div:first-child { min-width: min(100%, 28rem); }
.panel-head h3 { margin: 0; font-size: 1.25rem; line-height: 1.2; font-weight: 750; letter-spacing: -.02em; }
.panel-head p { max-width: 50rem; margin: .3rem 0 0; color: var(--muted); font-size: .84rem; }
.panel-actions, .view-toolbar { display: flex; align-items: end; gap: .7rem; flex-wrap: wrap; }
.view-toolbar { margin-left: auto; }

.select-field, .inline-select { display: grid; gap: .3rem; min-width: 15rem; color: var(--muted); font-size: .67rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.select-field select, .inline-select select, .card-select select { width: 100%; min-height: 40px; appearance: none; padding: .55rem 2.2rem .55rem .75rem; border: 1px solid rgba(151, 190, 190, .28); border-radius: 9px; outline: none; color: var(--text); background-color: var(--surface-2); background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(135deg, var(--accent) 50%, transparent 50%); background-position: calc(100% - 15px) 17px, calc(100% - 10px) 17px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.select-field select:hover, .inline-select select:hover, .card-select select:hover { border-color: rgba(131, 220, 199, .62); }
.select-field select:focus, .inline-select select:focus, .card-select select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(131, 220, 199, .16); }
.card-select { display: flex; align-items: end; gap: .65rem; margin: 0 0 1rem; }
.card-select label { color: var(--muted); font-size: .67rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.card-select select { min-width: 17rem; }
.gold, .ghost { min-height: 40px; padding: .5rem .9rem; border-radius: 9px; font-weight: 700; }
.gold { border: 1px solid var(--accent); color: var(--bg); background: var(--accent); }
.ghost { border: 1px solid var(--line); color: var(--text); background: transparent; }
.gold:hover { background: #a0ead8; }
.gold:disabled { opacity: .55; cursor: wait; }

/* Shared cards, stat blocks and tables */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { padding: .85rem 1rem; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.stat b { display: block; font-size: 1.25rem; line-height: 1.2; font-weight: 750; overflow-wrap: anywhere; }
.stat span { display: block; margin-top: .2rem; color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.ribbon { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin: 0 0 1.1rem; padding: 0; list-style: none; }
.ribbon li { padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: .86rem; }
.ribbon span { display: block; margin-bottom: .15rem; color: var(--muted); font-size: .66rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.ribbon li.done { border-color: rgba(131, 220, 199, .5); }
.ribbon li.fail { border-color: rgba(255, 146, 144, .55); }
.two-col, .chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.file-list { max-height: 280px; margin: 0 0 1rem; padding: 0; overflow: auto; list-style: none; }
.file-list li { display: flex; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--line-soft); font-size: .84rem; }
.board, .tickets { display: grid; gap: .75rem; margin-top: 1rem; }
.race-row, .ticket, .agent-race, .results-race, .wager-race { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.race-row { padding: .8rem 1rem; }
.ticket { position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 1rem; padding: .8rem 1rem; }
.ticket .rn { color: var(--accent); font-size: 1.8rem; font-weight: 750; }
.ticket::before, .ticket::after { content: ""; position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); transform: translateY(-50%); }
.ticket::before { left: -8px; } .ticket::after { right: -8px; }
.horse { margin: 0; font-size: 1.15rem; font-weight: 700; }
.meta { color: var(--muted); font-size: .82rem; }
.tier, .status-badge { display: inline-flex; align-items: center; padding: .16rem .45rem; border: 1px solid rgba(131, 220, 199, .45); border-radius: 999px; color: var(--accent); font-size: .64rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.tier.HIGH { color: var(--bg); background: var(--accent); }
.tier.LOW { opacity: .7; }
.bars { display: grid; gap: .25rem; margin-top: .45rem; }
.bars i { display: block; height: 4px; border-radius: 99px; background: rgba(255,255,255,.08); }
.bars i::after { content: ""; display: block; width: var(--w, 40%); height: 100%; border-radius: inherit; background: var(--accent); }

.results-race, .wager-race { margin-top: 1rem; padding: 1rem; overflow-x: auto; }
.race-title { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: .65rem; }
.race-title h4 { margin: 0; font-size: .98rem; font-weight: 750; }
.race-title span, .race-title strong { color: var(--muted); font-size: .76rem; }
.exotic-line { margin: .6rem 0; }
.empty-state { padding: 1.2rem; border: 1px dashed var(--line); border-radius: 10px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th { color: var(--muted); font-size: .67rem; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
th, td { padding: .68rem .65rem; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(131, 220, 199, .035); }
.wps { min-width: 660px; margin-top: .65rem; }
.wps th:nth-child(2n), .wps td:nth-child(2n), .wager-table th:nth-child(n+4), .wager-table td:nth-child(n+4) { text-align: right; }
.result-grid { min-width: 760px; }
.result-grid td:nth-child(n+3) { color: #cfe0dc; }
.result-grid small { color: var(--muted); font-weight: 500; }
.wager-table { min-width: 680px; }
.wager-card-total { margin: 1rem 0 .4rem; padding: .8rem 1rem; border: 1px solid rgba(131, 220, 199, .25); border-radius: 10px; background: rgba(131, 220, 199, .06); }
.wager-card-total strong, .wager-race strong { color: var(--accent); }

.wager-stats { margin-top: 1rem; }
.wager-stats h4 { margin: 0 0 .35rem; font-size: .9rem; }
.wager-stats .wager-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; margin: .75rem 0 1rem; }
.wager-stats .wager-card { padding: .9rem 1rem; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.wager-stats .wager-card h5 { margin: 0 0 .45rem; color: var(--accent); font-size: .85rem; font-weight: 750; }
.wager-stats .wager-card .big { font-size: 1.35rem; font-weight: 750; }
.wager-stats .wager-card .meta-line { margin-top: .25rem; color: var(--muted); font-size: .76rem; }
.agent-perf { margin-top: 1rem; }
.agent-perf h4 { margin: 0 0 .55rem; font-size: .95rem; }
.agent-perf th.sub, .agent-perf td.sub { font-size: .74rem; }
.agent-perf .pos { color: var(--positive); }
.agent-perf .neg { color: var(--negative); }
.agent-perf tr.house td { color: var(--accent); background: rgba(131, 220, 199, .05); }
.agent-race { margin: 1rem 0; padding: .85rem 1rem; }
.agent-race h4 { margin: 0 0 .45rem; font-size: 1rem; }
.agent-row { display: grid; grid-template-columns: 148px 1fr; gap: .6rem; padding: .48rem 0; border-top: 1px solid var(--line-soft); font-size: .82rem; }
.agent-row.chief, .agent-row.house { padding: .55rem .45rem; border-radius: 7px; background: rgba(131, 220, 199, .06); }
.agent-row b { color: var(--accent); }

.chart-grid figure, .stub-card, .pdf-links a { padding: .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.chart-grid figure { margin: 0; }
.chart-grid figcaption { margin-bottom: .35rem; color: var(--muted); font-size: .68rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.chart-grid canvas { width: 100% !important; max-height: 240px; }
.prompt { display: grid; gap: .6rem; }
.prompt textarea { width: 100%; padding: .75rem; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--surface); resize: vertical; }
.answer { margin-top: 1rem; color: var(--text); line-height: 1.6; white-space: pre-wrap; }
.pdf-links { display: flex; gap: .6rem; flex-wrap: wrap; }
.pdf-links a { color: var(--accent); text-decoration: none; }
.log { min-height: 4rem; padding: .8rem 1rem; border-radius: 9px; color: var(--muted); background: #091016; font-size: .78rem; white-space: pre-wrap; }

#toast { position: fixed; right: 1rem; bottom: 1rem; z-index: 9; max-width: 28rem; padding: .7rem .9rem; border: 1px solid var(--accent); border-radius: 9px; color: var(--text); background: var(--surface-3); box-shadow: var(--shadow); }

/* Delayed data loads only: keep fast interactions visually quiet. */
.refresh-indicator { position: fixed; inset: 0; z-index: 20; opacity: 0; pointer-events: none; transition: opacity .18s ease; }
.refresh-indicator.is-visible { opacity: 1; pointer-events: auto; }
.refresh-dimmer { position: absolute; inset: 0; background: rgba(6, 14, 20, .28); backdrop-filter: blur(1px); }
.refresh-progress { position: absolute; top: 0; left: 0; z-index: 2; width: 100%; height: 2px; overflow: hidden; background: rgba(131, 220, 199, .18); }
.refresh-progress::after { content: ""; display: block; width: 42%; height: 100%; border-radius: 99px; background: var(--accent); box-shadow: 0 0 14px rgba(131, 220, 199, .8); animation: refresh-sweep 1.25s ease-in-out infinite; }
@keyframes refresh-sweep { from { transform: translateX(-110%); } to { transform: translateX(250%); } }
.refresh-message { position: absolute; top: 1.35rem; left: 50%; z-index: 3; display: inline-flex; align-items: center; gap: .55rem; transform: translateX(-50%); padding: .55rem .85rem; border: 1px solid rgba(131, 220, 199, .28); border-radius: 999px; color: var(--text); background: rgba(17, 27, 35, .92); box-shadow: 0 12px 30px rgba(0, 0, 0, .22); font-family: var(--font-body); font-size: .8rem; font-weight: 600; letter-spacing: .02em; }
.refresh-spinner { width: 14px; height: 14px; border: 2px solid rgba(131, 220, 199, .25); border-top-color: var(--accent); border-radius: 50%; animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
  .track-rail, .ribbon, .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .hero { height: 28vh; margin: .5rem; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .mast { align-items: flex-start; padding: .9rem 1rem .55rem; }
  .emblem { width: 46px; height: 46px; }
  .mast-meta .pill { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hero { min-height: 220px; margin: .4rem; border-radius: 15px; }
  .hero-copy { left: 1.1rem; bottom: 1.15rem; }
  .hero-copy h2 { font-size: 2.45rem; }
  .track-rail, .ribbon, .stat-grid, .two-col, .chart-grid { grid-template-columns: 1fr; }
  .track-rail { padding: .7rem .4rem .1rem; gap: .45rem; }
  .track-chip { height: 92px; }
  .track-chip b { margin-top: 2.45rem; font-size: .92rem; }
  .nav { width: calc(100% - .8rem); margin: .75rem .4rem 0; }
  .nav button { flex: 1; padding-inline: .45rem; }
  main { padding: .7rem .4rem 2.5rem; }
  .panel { padding: .9rem; border-radius: 13px; }
  .panel-head { gap: .75rem; }
  .view-toolbar, .panel-actions { width: 100%; margin-left: 0; }
  .inline-select, .select-field, .card-select { width: 100%; min-width: 0; }
  .card-select { display: block; }
  .card-select label { display: block; margin-bottom: .3rem; }
  .card-select select { min-width: 0; }
  .panel-actions .gold { width: 100%; }
  .result-grid, .wager-table, .wps { font-size: .74rem; }
  th, td { padding: .58rem .45rem; }
  .agent-row { grid-template-columns: 112px 1fr; }
}
