:root {
  color-scheme: light;
  --bg: #f8f6f1;
  --paper: #fffefa;
  --surface: #f3f0ea;
  --ink: #242925;
  --muted: #535951;
  --line: #ded8ce;
  --accent: #89522c;
  --accent-fill: #89522c;
  --accent-hover: #6f4123;
  --accent-on: #fffaf4;
  --pale: #f1e5da;
  --pale-hover: #e9dacc;
  --dark: #2d3331;
  --nav-ink: #f6f3ed;
  --nav-muted: #cecac0;
  --nav-active: #4d3d32;
  --brand-chip: #e6c3a3;
  --brand-mark-bg: #171918;
  --positive: #245f48;
  --positive-bg: #e7f0e9;
  --negative: #942f31;
  --negative-bg: #faeded;
  --amber: #744c15;
  --amber-bg: #fbefd7;
  --blue: #315372;
  --blue-bg: #e6edf6;
  --warning-marker: #f5c542;
  --track-base: #367645;
  --track-light: #3e844d;
  --track-dark: #397c47;
  --sidebar-width: 220px;
  --dock-height: 52px;
  --radius: 15px;
  font-family: "PingFang HK", "Noto Sans HK", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101111;
  --paper: #1a1c1b;
  --surface: #222523;
  --ink: #f2eee7;
  --muted: #c1bbb0;
  --line: #3d3b36;
  --accent: #e5ad82;
  --accent-fill: #e5ad82;
  --accent-hover: #f2c19b;
  --accent-on: #271810;
  --pale: #36291f;
  --pale-hover: #463326;
  --dark: #171918;
  --nav-ink: #f6f3ed;
  --nav-muted: #c1bbb0;
  --nav-active: #473427;
  --brand-chip: #dca77e;
  --brand-mark-bg: #272321;
  --positive: #a1daba;
  --positive-bg: #24382f;
  --negative: #ffb0b0;
  --negative-bg: #40292b;
  --amber: #f0c878;
  --amber-bg: #3a2e1b;
  --blue: #b9d3fc;
  --blue-bg: #243245;
  --warning-marker: #f5c542;
  --track-base: #214a30;
  --track-light: #28583a;
  --track-dark: #245037;
}
* { box-sizing: border-box; }
html { scroll-padding: 14px 0 calc(var(--dock-height) + env(safe-area-inset-bottom) + 14px); }
body { margin: 0; color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, .scroll:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.layout { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; background: var(--dark);
  padding: 25px 16px; color: var(--nav-ink); display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; margin: 0 4px 12px; }
.sidebar .brand { align-self: flex-start; }
.brand-mark {
  position: relative; color: #edbf97; background: var(--brand-mark-bg);
  border-radius: .2em; font-size: 34px; width: 1em; height: 1em; flex: none;
}
.brand-track {
  position: absolute; inset: .29em .12em; border: .06em solid currentColor;
  border-radius: 1em; transform: rotate(-34deg);
}
.brand-track::after {
  content: ""; position: absolute; inset: .045em .035em;
  border: .027em solid currentColor; border-radius: 1em; opacity: .85;
}
.brand-finish {
  position: absolute; top: .39em; left: .48em; width: .045em; height: .22em;
  background: #fffaf4; transform: rotate(-34deg);
}
.brand strong, .brand small { display: block; white-space: nowrap; }
.brand strong { font-size: 15px; }
.brand small { color: var(--nav-muted); margin-top: 3px; font-size: 9px; letter-spacing: .13em; }
.archive-status { display: grid; gap: 4px; margin: 0 4px 20px; font-size: 11px; color: var(--nav-muted); }
.archive-status div { display: flex; flex-wrap: wrap; gap: 4px 8px; justify-content: space-between; }
.archive-status dd { margin: 0; color: var(--nav-ink); }
.archive-status a { color: inherit; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a {
  color: var(--nav-ink); font-size: 14px; font-weight: 650; text-decoration: none;
  padding: 11px 13px; border-radius: 8px;
}
.sidebar nav a[aria-current], .sidebar nav a:hover { background: var(--nav-active); color: #fff; }
.sidebar-foot { margin-top: auto; padding: 9px 10px; font-size: 12px; color: var(--nav-muted); }
.sidebar-foot span { display: inline-block; background: var(--brand-chip); width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; }
.site-actions {
  position: absolute; top: 12px; right: clamp(14px, 3vw, 45px); z-index: 2;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 28px);
}
.theme-toggle {
  position: absolute; top: 12px; right: clamp(14px, 3vw, 45px);
  padding: 4px 9px; min-height: 34px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--paper); color: var(--ink); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.site-actions .theme-toggle { position: static; flex: none; white-space: nowrap; }
.theme-toggle span { font-size: 15px; margin-right: 3px; }
.theme-toggle:hover, .theme-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
.account-signout {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 3px 4px 3px 10px; border-radius: 7px;
  background: var(--dark); color: var(--nav-ink); font-size: 12px;
}
.account-greeting { display: flex; align-items: center; gap: 4px; min-width: 0; max-width: 18rem; white-space: nowrap; }
.account-username { overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.account-signout button {
  flex: none; min-height: 28px; padding: 3px 7px; border: 1px solid var(--brand-chip);
  border-radius: 5px; background: var(--nav-active); color: var(--nav-ink);
  font: inherit; font-weight: 700; cursor: pointer;
}
.account-signout button:hover { background: var(--brand-chip); color: var(--brand-mark-bg); }
.bottom-nav {
  position: fixed; inset: auto 0 0 var(--sidebar-width); z-index: 10;
  border-top: 1px solid var(--line); background: var(--paper);
  padding: 3px 6px calc(3px + env(safe-area-inset-bottom));
}
.bottom-nav-inner { display: flex; gap: 4px; max-width: 420px; margin: auto; }
.bottom-nav a {
  flex: 1 1 0; display: grid; place-items: center; min-height: 45px; min-width: 0;
  padding: 4px; border-radius: 7px; color: var(--muted); text-decoration: none;
}
.bottom-nav svg { width: 23px; height: 23px; }
.bottom-nav a[aria-current="page"], .bottom-nav a:hover {
  background: var(--pale); color: var(--accent);
}
main { width: 100%; max-width: 1560px; margin-inline: auto; padding: 46px clamp(16px, 3vw, 45px) calc(45px + var(--dock-height) + env(safe-area-inset-bottom)); }
.page-head { margin-bottom: 22px; }
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .12em; font-weight: 800; margin: 0 0 7px; }
.eyebrow span { padding: 0 .3em; }
h1, h2, h3 { font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(33px, 4vw, 48px); letter-spacing: -.035em; }
h2 { font-size: 23px; }
h3 { font-size: 16px; }
.page-head > p:last-child, .muted { color: var(--muted); font-size: 14px; }
.page-head > p:last-child { margin: 7px 0 0; }
p { line-height: 1.5; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; min-width: 0; }
.meeting-picker { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; padding: 12px 16px; margin-bottom: 10px; }
.meeting-picker > span { margin-left: auto; padding-block: 8px; }
.filters { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
label { display: block; font-size: 12px; font-weight: 750; color: var(--ink); }
select, input[type=search], input[type=number], textarea {
  display: block; margin-top: 5px; padding: 8px 10px; min-height: 38px;
  border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 14px; color: var(--ink); background: var(--paper);
}
input[type=search] { width: min(58vw, 320px); }
.combinations-form input[type=number] { width: 110px; }
.combinations-form .source { align-self: center; }
.pagination { display: flex; gap: 8px; padding: 12px 18px; }
a.button { display: inline-flex; align-items: center; text-decoration: none; white-space: nowrap; }
textarea { width: 100%; resize: vertical; margin-bottom: 8px; }
.button {
  min-height: 38px; padding: 7px 13px; border: 1px solid var(--accent-fill);
  border-radius: 7px; background: var(--accent-fill); color: var(--accent-on); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.button:hover { background: var(--accent-hover); color: var(--accent-on); }
.button.secondary { background: var(--pale); color: var(--accent); border-color: var(--line); }
.button.secondary:hover { background: var(--pale-hover); }
.race-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.race-tabs a, .match-list a {
  display: inline-flex; align-items: center; gap: 4px; justify-content: center; min-width: 40px;
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px;
  background: var(--paper); font-size: 13px; font-weight: 750; text-decoration: none;
}
.race-tabs a[aria-current], .match-list a[aria-current] { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-on); }
.race-tabs a:hover:not([aria-current]), .match-list a:hover:not([aria-current]) { background: var(--pale); }
.race-tabs small, .match-list small { font-size: 10px; }
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 17px 18px 13px; }
.result-head .muted { margin: 5px 0 0; }
.race-media-links { display: flex; flex-wrap: wrap; gap: 6px; }
.race-media-links a[hidden] { display: none; }
.source-links { display: flex; flex-wrap: wrap; justify-content: end; gap: 4px 12px; }
.source { white-space: nowrap; font-weight: 700; font-size: 13px; text-decoration: none; padding-top: 4px; }
.source:hover, .horse-link:hover { text-decoration: underline; }
.scroll { overflow: auto; scrollbar-width: thin; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: 13px; }
th, td { padding: 7px 11px; text-align: left; border-top: 1px solid var(--line); }
th:first-child, td:first-child { padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
th { background: var(--surface); color: var(--muted); font-size: 11px; font-weight: 750; }
tbody tr:hover { background: var(--surface); }
tbody tr.selected { background: var(--pale); }
.horse-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.horse-code { margin-left: 6px; color: var(--muted); font-size: 10px; }
.winner { display: inline-grid; place-items: center; background: var(--positive-bg); color: var(--positive); border-radius: 6px; min-width: 23px; height: 23px; font-weight: 800; }
.code { font-size: 13px; font-weight: 650; color: var(--muted); }
.stat-strip {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); margin: 0 18px 16px; border-radius: 9px; overflow: hidden;
}
.stat-strip > div { padding: 9px 11px; background: var(--surface); }
.stat-strip span, .summary-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-strip strong { display: block; margin-top: 3px; font-size: 17px; overflow-wrap: anywhere; }
/* 表現分 → 補分 → 潛在表現分, framed like .stat-strip */
.credit-box {
  width: min(360px, calc(100% - 36px)); margin: 0 18px 16px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 9px; font-size: 13px;
}
.credit-row { display: grid; grid-template-columns: minmax(0, 1fr) 84px; }
.credit-box > * + *, .credit-fold > .credit-item { border-top: 1px solid var(--line); }
.credit-row > span { padding: 6px 10px; background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 600; }
.credit-row > strong { padding: 6px 10px; background: var(--paper); text-align: right; font-variant-numeric: tabular-nums; }
.credit-fold > summary { list-style: none; color: inherit; font-size: inherit; }
.credit-fold > summary::-webkit-details-marker { display: none; }
.credit-fold > summary > span::after {
  content: ''; display: inline-block; width: 5px; height: 5px; margin: 0 0 2px 8px;
  border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(-45deg);
}
.credit-fold[open] > summary > span::after { transform: rotate(45deg); }
.credit-item > span { padding-left: 24px; color: var(--muted); font-weight: 400; }
.credit-item > strong { color: var(--muted); font-weight: 400; }
.credit-item small { display: block; font-size: 11px; }
.credit-box > .credit-total { border-top-width: 2px; }
.credit-total > * { font-weight: 700; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(230px, 2fr); gap: 20px; padding: 0 18px 17px; }
.review { padding-left: 17px; border-left: 1px solid var(--line); }
.review p { margin: 6px 0 15px; font-size: 14px; }
figure { margin: 8px 0; }
.chart { display: block; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.chart text { fill: var(--muted); font-size: 11px; }
.grid-line { stroke: var(--line); stroke-dasharray: 3 3; }
.line { --series: var(--accent); }
.line-2 { --series: var(--blue); }
.line polyline { stroke: var(--series); stroke-width: 2.7; fill: none; }
.line-2 polyline { stroke-dasharray: 5 4; }
.line circle { fill: var(--series); }
figcaption { display: flex; gap: 12px; padding: 5px 2px; font-size: 12px; color: var(--muted); }
.legend::before { content: ''; display: inline-block; width: 10px; height: 3px; margin: 0 5px 3px 0; background: var(--accent); }
.legend-2::before { background: var(--blue); }
.splits td:first-child, .splits th:first-child { padding-left: 8px; }
.splits td, .splits th { padding: 6px 8px; }
.splits .num { text-align: right; font-variant-numeric: tabular-nums; }
.comparison { margin-top: 9px; }
.split-note { display: flex; flex-wrap: wrap; align-items: start; gap: 6px; margin-top: 12px; color: var(--muted); font-size: 12px; }
.split-note > strong { padding-block: 3px; }
.split-time { display: grid; justify-items: center; gap: 2px; background: var(--surface); border-radius: 5px; padding: 3px 5px; }
.split-time small { font-size: 10px; white-space: nowrap; }
.form-heading { margin-bottom: 10px; }
.season-row th { background: var(--pale); color: var(--accent); font-size: 13px; }
.season-row small { font-weight: 500; margin-left: 5px; }
.empty, .search-panel, .inset { padding: 16px 18px; }
.empty { color: var(--muted); }
.inset { padding-top: 0; }
.match-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.summary-card { padding: 16px 18px; }
.summary-card strong { display: block; font-size: clamp(22px, 3vw, 34px); margin-top: 5px; }
.notice { background: var(--pale); color: var(--accent); padding: 9px 12px; margin: 0 0 12px; border-radius: 8px; }
.issue-list { padding-left: 20px; font-size: 13px; }
.issue-list li { margin: 8px 0; overflow-wrap: anywhere; }
.issue-list span { display: block; color: var(--muted); }
summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.racecard-meeting { display: grid; gap: 4px; margin-right: auto; }
.entrant-overview {
  display: grid; grid-template-columns: minmax(150px, 1fr) minmax(0, 4fr) auto;
  grid-template-areas: 'identity fields pricing';
  align-items: start; gap: 12px; padding: 16px 18px 12px;
}
.entrant-identity { grid-area: identity; display: flex; align-items: center; gap: 8px; min-width: 0; }
.entrant-identity h3 { overflow-wrap: anywhere; }
.entrant-identity small { font-size: 11px; }
.entrant-silks { flex: none; object-fit: contain; }
.entrant-number {
  display: grid; place-items: center; min-width: 32px; min-height: 32px; padding: 4px 7px;
  border-radius: 8px; background: var(--pale); color: var(--accent); font-size: 12px; font-weight: 750;
}
.entrant-fields { grid-area: fields; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin: 0; }
.entrant-fields dt { margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.entrant-fields dd { margin: 0; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.entrant-tools { padding: 0 18px 14px; }
.entrant-actions { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.entrant-actions .button { padding-inline: 9px; }
.entrant-actions .button::before {
  display: inline-block; content: ''; width: 0; height: 0; margin-right: 5px;
  border-block: 4px solid transparent; border-left: 6px solid currentColor;
}
.entrant-actions .button[aria-expanded='true'] { border-color: var(--accent); }
.entrant-actions .button[aria-expanded='true']::before { transform: rotate(90deg); }
.entrant-actions .work-latest { font-size: 11px; }
.entrant-history { margin-top: 10px; }
.entrant-history textarea { width: 100%; }
.card-form-scroll { container-type: inline-size; }
.card-form-table th[scope=row] { text-align: left; font-weight: 600; }
.card-form-table small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.report-toggle {
  display: block; margin-top: 5px; padding: 4px 7px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px; color: var(--accent);
  font: inherit; cursor: pointer;
}
.report-toggle[aria-expanded=true] { background: var(--pale); }
.card-report-row td { padding: 0 12px; background: var(--surface); }
.card-report-content {
  width: min(780px, calc(100cqw - 24px)); padding: 12px 0;
  white-space: normal; overflow-wrap: anywhere;
}
.card-report-content p { margin: 0 0 8px; }
.card-report-text { display: grid; gap: 10px; margin: 0; }
.card-report-text dt { color: var(--accent); font-weight: 750; }
.card-report-text dd { margin: 3px 0 0; line-height: 1.5; }
.card-report-links { display: flex; flex-wrap: wrap; gap: 5px 14px; margin-top: 10px; font-size: 12px; }
@media (max-width: 1150px) {
  .entrant-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 950px) {
  :root { --sidebar-width: 176px; }
  .sidebar { padding-inline: 11px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .review { padding: 0; border: 0; }
  .entrant-overview {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'identity pricing' 'fields fields';
  }
}
@media (max-width: 650px) {
  :root { --sidebar-width: 0px; }
  .layout { display: block; }
  .sidebar { position: static; height: auto; padding: 11px 14px; }
  .brand { margin: 0 0 9px; }
  .theme-toggle { top: 11px; }
  .site-actions { top: 11px; right: 14px; }
  .account-greeting { max-width: 150px; }
  .archive-status { display: flex; flex-wrap: wrap; gap: 5px 12px; margin: 0 0 8px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 5px; }
  .sidebar nav a { padding: 7px 9px; }
  .sidebar-foot { display: none; }
  main { padding-top: 18px; }
  .result-head { flex-wrap: wrap; }
  .stat-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-strip > :last-child { grid-column: span 2; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 500px) {
  .signed-in-layout .site-actions { top: 54px; }
  .signed-in-layout .sidebar .brand { margin-bottom: 52px; }
}

/* Official replay links share the boxed look of the report toggle. */
.replay-link {
  display: inline-block; margin-left: 8px; padding: 3px 7px; background: var(--paper);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; font-weight: 700; white-space: nowrap; text-decoration: none;
}
.replay-link:hover { background: var(--pale); text-decoration: none; }
.card-form-table .replay-link {
  display: block; width: fit-content; margin: 5px 0 0; padding: 4px 7px; font-size: inherit; font-weight: inherit;
}
.card-form-table td.num, .history-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.score-chip, .credit-open {
  display: inline-block;
  padding: 2px 7px; background: var(--paper); border: 1px solid var(--line); border-radius: 6px;
  color: var(--accent); font: inherit; font-weight: 700; cursor: pointer;
}
.score-chip:not(button) { cursor: default; }
.credit-open:hover { background: var(--pale); }
.credit-popover {
  width: min(320px, calc(100vw - 32px)); margin: auto; padding: 12px; white-space: normal;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 18%); text-align: left;
}
.credit-popover::backdrop { background: rgb(0 0 0 / 18%); }
.credit-popover-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 13px; }
.credit-popover-head button { padding: 0 6px; background: none; border: 0; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.credit-popover .credit-box { width: 100%; margin: 0; }
.form-runs-popover { width: min(420px, calc(100vw - 32px)); }
.form-runs { overflow: hidden; border: 1px solid var(--line); border-radius: 9px; border-collapse: separate; border-spacing: 0; }
.form-runs th, .form-runs td { padding: 6px 9px; }
.form-runs thead th { border-top: 0; }
.form-runs td { text-align: right; font-variant-numeric: tabular-nums; }
.form-runs tbody th { color: var(--ink); font-size: 12px; font-weight: 600; }
.form-runs tfoot th { text-align: right; color: var(--ink); font-size: 12px; font-weight: 600; }
.form-runs .form-runs-total > * { border-top-width: 2px; font-weight: 700; }

/* Race-card form tags */
.tag-basis { margin: -4px 0 12px; font-size: 12px; }
.entrant-tags { display: flex; flex-wrap: wrap; align-items: start; gap: 6px; list-style: none; margin: 0; padding: 0 18px 12px; }
.tag, .tag summary {
  border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 700; line-height: 1.5;
  border: 1px solid var(--line); background: var(--pale); color: var(--accent);
}
.tag[title] { cursor: help; }
details.tag { padding: 0; border: 0; background: none; }
details.tag summary { display: list-item; width: fit-content; }
details.tag[open] { flex-basis: 100%; }
details.tag p { margin: 6px 0 0; font-size: 13px; font-weight: 400; color: var(--ink); overflow-wrap: anywhere; }
.tag-up { background: var(--positive-bg); border-color: var(--line); color: var(--positive); }
.tag-down { background: var(--negative-bg); border-color: var(--line); color: var(--negative); }
.tag-muted { background: var(--surface); color: var(--muted); }
.tag-alert, .tag-alert summary { background: var(--amber-bg); border-color: var(--line); color: var(--amber); }

/* Running style and pace forecast */
.tag-style { background: var(--blue-bg); border-color: var(--line); color: var(--blue); }
.tag-leader { background: var(--blue-bg); border-color: var(--blue); color: var(--blue); }
.pace { margin: 8px 0 0; font-size: 14px; }
.pace strong { padding: 1px 8px; border-radius: 999px; background: var(--pale); color: var(--accent); }
.pace-2 strong, .pace-3 strong { background: var(--amber-bg); color: var(--amber); }

/* Horse career records */
.record { padding: 14px 18px; }
.record summary { display: list-item; }
.record summary h3 { display: inline; }
.record-note { margin: 8px 0 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.record-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.record-table table { width: 100%; }
.record-table caption { text-align: left; font-weight: 750; font-size: 13px; padding-bottom: 6px; }
.record-table th[scope="row"] { text-align: left; white-space: nowrap; font-weight: 600; background: none; color: var(--ink); font-size: 13px; }
.record-table td { text-align: right; font-variant-numeric: tabular-nums; }
.record-table .record-best th, .record-table .record-best td { font-weight: 800; background: var(--pale); }
.record-table th, .record-table td { padding: 6px 7px; }
.record-table th:first-child, .record-table td:first-child { padding-left: 10px; }
.record-table th:last-child, .record-table td:last-child { padding-right: 10px; }

/* Trackwork records */
.trackwork-panel summary h3 { display: inline; }
.trackwork-content { font-size: 13px; }
.trackwork-links { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.trackwork-links a { white-space: nowrap; font-size: 12px; font-weight: 700; }
.trackwork-links .trackwork-action {
  min-height: 32px; padding: 4px 8px; gap: 4px;
  background: var(--work-bg); color: var(--work-fg); border-color: var(--line);
}
.trackwork-links .trackwork-action:hover { border-color: var(--work-fg); }
[data-work-tone="swim"] { --work-bg: #e0f0fc; --work-fg: #244c69; }
[data-work-tone="trot"] { --work-bg: var(--amber-bg); --work-fg: var(--amber); }
[data-work-tone="gallop"] { --work-bg: #45494d; --work-fg: #fffefa; }
[data-work-tone="trial"] { --work-bg: #fae398; --work-fg: #62480d; }
.work-latest:not(:empty) { margin-left: 8px; font-weight: 500; }
.trackwork-meta { margin: 7px 0; font-size: 12px; }
.trackwork-filter { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.trackwork-filter select { width: auto; margin: 0; }
.trackwork-month { margin-top: 6px; border-top: 1px solid var(--line); }
.trackwork-month summary { padding: 8px 0; font-weight: 700; }
.trackwork-month summary small { margin-left: 6px; }
.trackwork-table th, .trackwork-table td { padding: 6px 9px; }
.trackwork-table td:first-child, .trackwork-table td:nth-child(2) { white-space: nowrap; }
.trackwork-table td .trackwork-links { margin-top: 3px; }
.trackwork-content [hidden] { display: none; }
.trackwork-player { width: min(100%, 840px); margin: 0 auto; padding: 20px 16px; }
.trackwork-player video { display: block; width: 100%; aspect-ratio: 16 / 9; background: #111; margin: 12px 0; }
.work-calendar { margin-top: 10px; }
.work-calendar-nav { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin-bottom: 6px; }
.work-calendar-range { flex-basis: 100%; margin: 0; font-weight: 700; }
.work-calendar-nav label { display: flex; gap: 4px; align-items: center; }
.work-calendar-nav select { width: auto; margin: 0; }
.work-calendar-key { font-size: 11px; color: var(--muted); }
.work-calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.work-calendar-weekday { color: var(--muted); text-align: center; font-size: 12px; padding: 3px 0; }
.work-calendar-day {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 56px; min-width: 0; padding: 3px 1px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--paper);
  color: var(--ink); cursor: pointer; font: inherit;
}
.work-calendar-day time { font-weight: 750; font-variant-numeric: tabular-nums; }
.work-calendar-date { display: flex; align-items: center; justify-content: center; gap: 2px; }
.work-calendar-key span, .work-calendar-video { color: var(--accent); font-size: 10px; }
.work-calendar-day.is-empty { color: var(--muted); background: var(--surface); }
.work-calendar-day:hover, .work-calendar-day[aria-pressed="true"] { background: var(--pale); border-color: var(--accent); }
.work-calendar-day:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.work-calendar-marks { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 100%; font-size: 10px; line-height: 1.3; }
.work-calendar-marks span {
  max-width: 100%; padding: 1px 3px; border-radius: 4px; overflow-wrap: anywhere;
  color: var(--work-fg, var(--muted)); background: var(--work-bg, var(--surface));
}
.work-calendar-results { margin-top: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; }
.work-calendar-results h4 { margin: 0 0 3px; }
.work-calendar-results p { margin: 6px 0 0; }
.work-day-list { margin: 0; padding: 0; list-style: none; }
.work-day-list li { display: flex; align-items: baseline; gap: 6px 10px; padding: 6px 0; }
.work-day-list li + li { border-top: 1px solid var(--line); }
.work-day-list li strong { flex: 0 0 auto; }
.work-day-list .trackwork-links { margin-top: 2px; }

/* Collapsible tools below the racecard */
.racecard-fold { scroll-margin-top: 12px; }
.racecard-fold > summary {
  display: flex; align-items: center; gap: 10px; min-height: 46px;
  padding: 10px 18px; border-radius: var(--radius); list-style: none;
}
.racecard-fold > summary::-webkit-details-marker { display: none; }
.racecard-fold > summary::before {
  content: ''; flex: 0 0 7px; height: 7px;
  border: solid var(--accent); border-width: 0 2px 2px 0; transform: rotate(-45deg);
}
.racecard-fold[open] > summary::before { transform: rotate(45deg); }
.racecard-fold > summary:hover { background: var(--surface); }
.racecard-fold-title { flex: 1; color: var(--ink); font-size: 16px; font-weight: 600; white-space: nowrap; }
.racecard-fold > summary .muted { font-size: 12px; text-align: end; }
.reserve-fold[open] { padding: 0 12px 12px; }
.reserve-fold[open] > summary { margin-inline: -12px; }
.reserve-fold .racecard-entrant:last-child { margin-bottom: 0; }

/* Editable early-position map */
.speed-map { padding-inline: 18px; }
.speed-map[open] { padding-bottom: 14px; }
.speed-map [hidden] { display: none !important; }
.speed-map > summary { margin-inline: -18px; }
.speed-map > summary .pace { margin: 0; }
.speed-map-editor-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.speed-map-status {
  width: fit-content; margin: 0 0 8px; padding: 4px 8px; border-left: 2px solid var(--accent);
  border-radius: 4px; background: var(--surface); color: var(--muted); font-size: 12px;
}
.speed-map-editor-controls .button { padding: 6px 10px; min-height: 34px; font-size: 12px; }
.speed-map-editor-controls .button:disabled { opacity: .5; cursor: default; }
.speed-map-mode { font-size: 12px; padding: 5px 8px; color: var(--accent); background: var(--pale); border-radius: 5px; }
.speed-map-mode.is-personal { color: var(--blue); background: var(--blue-bg); }
.speed-map-selection { font-size: 12px; color: var(--muted); margin: 8px 0; }
.speed-map-selection-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.speed-map-selection-row .button { padding: 5px 9px; font-size: 12px; min-height: 32px; }
.speed-map-selection-row .button:disabled { opacity: .5; cursor: default; }
.speed-map-frame { display: grid; grid-template-columns: 44px minmax(0, 1fr); background: var(--track-base); border-radius: 10px 10px 0 0; overflow: hidden; }
.speed-map-lane-window { height: var(--map-height); overflow: hidden; position: relative; }
.speed-map-lane-list { position: relative; }
.speed-map-lane { position: absolute; left: 4px; padding: 2px 5px; border-radius: 5px; background: rgba(0,0,0,.22); color: #fff; font-size: 10px; font-weight: 750; max-width: 38px; text-align: center; }
.speed-map-scroll { height: var(--map-height); overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; }
.speed-map-track {
  position: relative; isolation: isolate;
  background:
    repeating-linear-gradient(0deg, transparent 0 75px, rgba(255,255,255,.17) 75px 76px),
    repeating-linear-gradient(90deg, transparent 0 55px, rgba(255,255,255,.09) 55px 56px),
    repeating-linear-gradient(90deg, var(--track-light) 0 112px, var(--track-dark) 112px 224px);
}
.speed-map-track::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: repeating-linear-gradient(90deg, #fff 0 26px, #dfe7df 26px 30px); pointer-events: none; }
.speed-map-runner { position: absolute; width: 90px; height: 70px; padding: 0; margin: 0; display: grid; justify-items: center; align-content: start; gap: 0; border: 0; border-radius: 6px; background: transparent; font: inherit; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; z-index: 1; }
.speed-map-runner:hover, .speed-map-runner:focus-visible { z-index: 3; }
.speed-map-runner[aria-pressed="true"] { outline: 2px solid #b5e6ff; outline-offset: 1px; z-index: 4; background: rgba(24,65,69,.15); }
.speed-map-runner.is-dragging { cursor: grabbing; z-index: 6; filter: drop-shadow(0 3px 3px rgba(0,0,0,.35)); }
.speed-map-figure { position: relative; display: block; width: 84px; height: 43px; color: #f0eee2; --horse-detail: #294d37; pointer-events: none; }
.speed-map-figure svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.speed-map-straight .speed-map-figure svg { transform: scaleX(-1); }
.speed-map-number { position: absolute; left: 0; top: 0; min-width: 18px; height: 18px; padding: 0 3px; border-radius: 5px; display: grid; place-items: center; background: var(--paper); color: var(--ink); font-size: 10px; font-weight: 800; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.is-leader .speed-map-number { background: var(--warning-marker); color: #282116; }
.speed-map-caption { display: grid; justify-items: center; padding: 1px 4px; border-radius: 4px; background: var(--paper); color: var(--ink); line-height: 1.15; width: max-content; max-width: 88px; pointer-events: none; }
.speed-map-name { display: block; max-width: 80px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-weight: 750; }
.speed-map-caption small { display: block; max-width: 80px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10px; color: var(--muted); }
.is-picked .speed-map-caption { outline: 1px dashed var(--warning-marker); outline-offset: 1px; }
.is-manual .speed-map-caption { background: var(--blue-bg); box-shadow: 0 0 0 1px var(--blue); }
.speed-map-axis { text-align: center; color: #fff; background: var(--track-base); font-size: 11px; font-weight: 700; padding: 6px 8px; border-radius: 0 0 10px 10px; }
.speed-map-waiting { border: 1px dashed var(--line); border-radius: 8px; padding: 8px; margin: 8px 0; background: var(--surface); }
.speed-map-waiting h4 { margin: 0 0 8px; font-size: 12px; }
.speed-map-tray { display: flex; flex-wrap: wrap; gap: 8px; }
.speed-map-tray .speed-map-runner { position: relative; flex: 0 0 90px; }
.speed-map-tray .speed-map-figure { color: var(--muted); --horse-detail: var(--surface); }
.speed-map-picks fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 12px 0 0; padding: 10px 12px 12px; }
.speed-map-picks legend { font-size: 13px; font-weight: 750; padding: 0 4px; }
.speed-map-pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px; margin-bottom: 10px; }
.speed-map-pick-list select { margin-top: 4px; width: 100%; }

/* Ratings and pricing: projected score, personal adjustment and model price */
.ratings[open] { padding-bottom: 12px; }
.ratings > p { margin: 0 18px 10px; }
.ratings th.num, .ratings td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ratings td { vertical-align: middle; }
.ratings input[type=number] { width: 72px; margin: 0 0 0 auto; min-height: 32px; padding: 4px 8px; text-align: right; }
.ratings input:invalid { border-color: var(--negative); }
.ratings tr.is-positive td { background: var(--pale); }
.ratings tr.is-positive [data-cell="pm"] { color: var(--accent); font-weight: 750; }
.ratings thead th { vertical-align: bottom; }
.ratings thead tr + tr th:first-child { padding-left: 11px; }
.ratings th.ratings-group { text-align: center; border-bottom: 1px solid var(--line); }
.ratings .ratings-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.ratings td.ratings-total { font-weight: 700; }
.ratings .ratings-flag { display: inline-block; margin-left: 4px; padding: 0 5px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--amber-bg); color: var(--amber); font-size: 11px; font-weight: 700; cursor: help; }
.ratings-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 18px 0; font-size: 13px; }
.ratings-help { margin: 10px 18px 0; font-size: 13px; }
.ratings-help summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.ratings-help ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.6; }
.entrant-rating { grid-area: pricing; display: flex; align-items: flex-start; gap: 8px; }
.entrant-rating table {
  width: auto; min-width: 116px; border-collapse: separate; border-spacing: 0;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: 12px;
}
.entrant-rating th, .entrant-rating td { padding: 3px 8px; }
.entrant-rating th { border-right: 1px solid var(--line); font-weight: 600; }
.entrant-rating td { text-align: right; font-weight: 700; }
.entrant-rating tbody tr:first-child > * { border-top: 0; }
.entrant-odds tbody th { background: var(--pale); color: var(--accent); }
.entrant-odds tfoot td { text-align: center; white-space: normal; color: var(--muted); font-size: 10px; font-weight: 400; }
@media (max-width: 480px) {
  .entrant-overview:has(.entrant-rating) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'identity' 'pricing' 'fields';
  }
  .entrant-rating table { min-width: 0; flex: 1; }
}

.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 76px 20px 36px;
}
.login-card {
  width: min(100%, 400px);
  padding: clamp(22px, 6vw, 34px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-card .brand { margin: 0 0 26px; }
.login-card .brand small { color: var(--muted); }
.login-card h1 { margin: 0 0 18px; font-size: 28px; }
.login-card form { display: grid; gap: 8px; }
.login-card label { font-weight: 650; }
.login-card input { min-width: 0; width: 100%; min-height: 44px; margin-bottom: 8px; }
.login-card button {
  min-height: 44px;
  margin-top: 8px;
  background: var(--accent-fill);
  color: var(--accent-on);
  border-color: var(--accent-fill);
}
.login-card button:hover { background: var(--accent-hover); }
.login-error { margin: 0; color: var(--negative); }
