/* DearDerby — race card on white paper: black ink, one red, condensed type, racing silks. */
:root {
  --paper: #fbfaf6;
  --card: #ffffff;
  --ink: #151515;
  --muted: #6b6a64;
  --soft: #e8e5dc;
  --soft2: #f3f1ea;
  --red: #c8102e;
  --tint: #fdeff0;
  --pos: #0b7a45;
  --neg: #c8102e;
  --sweat: #3fa9f5;
  --row-h: 58px;
  --bar-max: 0.5;
  --top-h: 56px;
  --cond: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --sans: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --gutter: 24px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body.loading { cursor: progress; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
h1, h2, h3, h4 { font-family: var(--cond); font-weight: 800; text-transform: uppercase; letter-spacing: 0.2px; line-height: 1; margin: 0; text-wrap: balance; }
.eyebrow { margin: 0 0 6px; font-family: var(--cond); font-weight: 700; font-size: 14px; letter-spacing: 2px; text-transform: uppercase; color: var(--red); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(var(--gutter), env(safe-area-inset-right, 0px)) 0 max(var(--gutter), env(safe-area-inset-left, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border-bottom: 3px solid var(--ink);
}
.brand { background: none; border: 0; padding: 0; cursor: pointer; }
.brand-word { font-family: var(--cond); font-weight: 800; font-size: 28px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--ink); }
.brand-word b { color: var(--red); font-weight: 800; }
.brand-word.big { font-size: 40px; }
.top-right { display: flex; align-items: center; gap: 14px; }
.me-btn { width: 38px; height: 38px; border: 2px solid var(--ink); border-radius: 50%; background: var(--soft2); padding: 2px; cursor: pointer; display: grid; place-items: center; }
.me-btn .face { width: 30px; height: 30px; }
.sound-btn { width: 38px; height: 38px; border: 2px solid var(--ink); border-radius: 50%; background: transparent; color: var(--ink); padding: 0; cursor: pointer; display: grid; place-items: center; }
.sound-btn svg { width: 22px; height: 22px; }
.sound-btn[aria-pressed="false"] { color: var(--muted, #777); border-color: var(--muted, #777); }
.bank { display: flex; align-items: baseline; gap: 8px; }
.bank-label { color: var(--muted); font-size: 14px; }
.bank b { font-family: var(--mono); font-size: 20px; font-weight: 700; }
.bank.flash-up b { animation: flash 1.2s ease; }
@keyframes flash { 0% { color: var(--pos); } 100% { color: var(--ink); } }

.leave-bar {
  position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); z-index: 29;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 10px max(var(--gutter), env(safe-area-inset-right, 0px)) 10px max(var(--gutter), env(safe-area-inset-left, 0px));
  background: var(--ink); color: #fff; font-weight: 600;
}
.leave-bar span { flex: 1 1 220px; }
.leave-bar .btn:not(.danger) { background: #fff; }

main {
  max-width: 1280px; margin: 0 auto;
  padding: 24px max(var(--gutter), env(safe-area-inset-right, 0px)) max(40px, env(safe-area-inset-bottom, 0px)) max(var(--gutter), env(safe-area-inset-left, 0px));
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 42px;
  border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  font-family: var(--cond); font-weight: 700; font-size: 17px; letter-spacing: 0.6px; text-transform: uppercase;
  cursor: pointer; border-radius: 0; transition: background 0.15s, color 0.15s;
}
.btn:hover:not(:disabled) { background: var(--ink); color: #fff; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #a00d25; border-color: #a00d25; }
.btn.big { min-height: 52px; font-size: 20px; padding: 10px 22px; }
.btn.small { min-height: 34px; font-size: 15px; padding: 4px 12px; }
.btn.wide { width: 100%; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 600; font-size: 13px; }
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.btn:focus-visible, .topic:focus-visible, .link-btn:focus-visible, .av:focus-visible, .sheet-tabs button:focus-visible, .file-tabs button:focus-visible, .me-btn:focus-visible, .sound-btn:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }

.card { background: var(--card); border: 2px solid var(--ink); padding: 18px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h3 { font-size: 22px; }
.pill { font-family: var(--mono); font-size: 12px; font-weight: 700; padding: 2px 8px; border: 1.5px solid var(--ink); white-space: nowrap; }
.tag { display: inline-block; font-family: var(--cond); font-weight: 700; font-size: 14px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--red); }
.tag.ghost { color: var(--muted); }

/* ---------- racing silks (pattern + two colours, so racers differ beyond colour) ---------- */
.silk {
  display: inline-block; flex: none; width: 26px; height: 26px; border: 2px solid var(--ink);
  background-color: var(--c); vertical-align: middle;
}
.silk.big { width: 34px; height: 34px; }
.pat-hoops { background: repeating-linear-gradient(0deg, var(--c) 0 5px, var(--c2) 5px 9px); }
.pat-stripes { background: repeating-linear-gradient(90deg, var(--c) 0 5px, var(--c2) 5px 9px); }
.pat-quarters { background: conic-gradient(var(--c2) 0 25%, var(--c) 0 50%, var(--c2) 0 75%, var(--c) 0); }
.pat-sash { background: linear-gradient(135deg, var(--c) 0 36%, var(--c2) 36% 64%, var(--c) 64%); }
.pat-check { background: repeating-conic-gradient(var(--c) 0 25%, var(--c2) 0 50%) 0 0 / 10px 10px; }
.pat-spots { background: radial-gradient(circle, var(--c2) 0 2.6px, transparent 3.1px) 0 0 / 9px 9px, var(--c); }
.pat-chevron { background: linear-gradient(135deg, transparent 0 40%, var(--c2) 40% 60%, transparent 60%) 0 0 / 12px 12px, var(--c); }
.pat-cross { background: linear-gradient(var(--c2), var(--c2)) center / 100% 28% no-repeat, linear-gradient(var(--c2), var(--c2)) center / 28% 100% no-repeat, var(--c); }

/* ---------- lobby ---------- */
.hero { margin: 8px 0 22px; max-width: 760px; }
.hero h1 { font-size: clamp(40px, 7vw, 72px); }
.lede { font-size: 17px; margin: 12px 0 0; max-width: 64ch; }
.lobby-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.daily { display: flex; flex-direction: column; gap: 10px; }
.daily-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.daily h2 { font-size: clamp(32px, 4.4vw, 46px); }
.daily .muted { margin: 0; }
.streak { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.daily-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.daily-meta span { font-size: 13px; padding: 3px 8px; border: 1.5px solid var(--soft); background: var(--soft2); }
.daily-meta .done { border-color: var(--pos); color: var(--pos); font-weight: 600; }
.daily .btn { align-self: flex-start; margin-top: 4px; }
.daily p.small { margin: 0; }
.week { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.week .day { width: 30px; height: 30px; display: grid; place-items: center; border: 2px solid var(--ink); font-family: var(--mono); font-size: 12px; font-weight: 700; }
.week .day.done { background: var(--ink); color: #fff; }
.week .day.today:not(.done) { border-style: dashed; }
.week-note { font-size: 13px; color: var(--muted); margin-left: 6px; }

.jockey { display: flex; flex-direction: column; gap: 10px; }
.jockey p { margin: 0; }
.jockey-stage { height: 128px; display: flex; align-items: flex-end; justify-content: center; background: repeating-linear-gradient(90deg, var(--soft2) 0 40px, var(--card) 40px 80px); border-bottom: 3px solid var(--ink); overflow: hidden; animation: track-move 0.8s linear infinite; }
@keyframes track-move { from { background-position: 0 0; } to { background-position: -80px 0; } }
.avatar-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.av { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; background: var(--card); border: 2px solid var(--soft); cursor: pointer; font-size: 12px; font-weight: 600; }
.av .face { width: 40px; height: 40px; }
.av.on { border-color: var(--ink); background: var(--tint); }
.face { display: block; }

.quick { margin-bottom: 18px; }
.quick-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.quick h2 { font-size: 30px; margin-top: 4px; }
.topic-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.topic-tools input, .topic-tools select {
  flex: 1 1 200px; min-width: 0; padding: 10px 12px; border: 2px solid var(--ink); background: var(--card); font: inherit; border-radius: 0;
}
.topic-tools select { flex: 0 1 220px; }
.topic-count { font-size: 13px; margin: 8px 0; }
.topic-chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.topic { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: var(--card); border: 1.5px solid var(--soft); cursor: pointer; min-width: 0; }
.topic:hover { border-color: var(--ink); background: var(--soft2); }
.topic em { font-style: normal; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--red); font-weight: 600; }
.topic b { font-family: var(--cond); font-size: 19px; text-transform: uppercase; line-height: 1.1; }
.topic span { font-size: 13px; color: var(--muted); }
#topicMore { margin-top: 10px; }

.how { margin-bottom: 18px; }
.how h3 { font-size: 24px; margin-bottom: 12px; }
.how-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; counter-reset: s; }
.how-steps li { counter-increment: s; display: flex; flex-direction: column; gap: 4px; border-top: 3px solid var(--ink); padding-top: 8px; }
.how-steps li::before { content: '0' counter(s); font-family: var(--mono); font-weight: 700; color: var(--red); font-size: 13px; }
.how-steps b { font-family: var(--cond); font-size: 20px; text-transform: uppercase; }
.how-steps span { font-size: 14px; color: var(--muted); }
.stats-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { border: 2px solid var(--ink); padding: 10px 12px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; }
.stat b { font-family: var(--mono); font-size: 22px; color: var(--ink); }
.fineprint { font-size: 12px; color: var(--muted); margin: 18px 0 0; }

/* ---------- race screen ---------- */
.race-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.race-titles { min-width: 0; }
.race-title { font-size: clamp(30px, 4.4vw, 50px); }
.race-head .muted { margin: 4px 0 0; }
.controls { display: flex; gap: 8px; }

.race-layout { max-width: 980px; margin: 0 auto; }
.track-card { position: relative; background: var(--card); border: 2px solid var(--ink); padding: 14px 16px 0; min-width: 0; }
.progress-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.y-end { font-family: var(--mono); font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; }
.ybar { position: relative; flex: 1; height: 6px; background: var(--soft); margin: 30px 26px 4px; }
.yfill { position: relative; height: 100%; width: 0; background: var(--red); }
.ynow { position: absolute; right: 0; bottom: 10px; transform: translateX(50%); font-family: var(--mono); font-weight: 700; font-size: 22px; line-height: 1; color: var(--ink); }
.ynow::after { content: ''; position: absolute; left: 50%; top: 100%; width: 2px; height: 10px; background: var(--ink); }

.track-cols, .row { display: grid; grid-template-columns: 40px 30px 170px minmax(0, 1fr); gap: 10px; align-items: center; }
.track-cols {
  font-family: var(--cond); font-weight: 700; font-size: 13px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted);
  padding: 0 4px 6px; border-bottom: 3px solid var(--ink);
}
.track-cols span:first-child { grid-column: 1 / span 3; padding-left: 32px; }
.track { position: relative; }
.row {
  position: absolute; left: 0; right: 0; top: 0; height: var(--row-h);
  padding: 0 4px; border-bottom: 1px solid var(--soft); cursor: pointer;
  transition: transform 0.5s cubic-bezier(0.3, 0.8, 0.3, 1), background 0.2s;
}
.row:hover { background: var(--soft2); }
.row.selected { box-shadow: inset 4px 0 0 var(--ink); }
.row.mine { background: var(--tint); }
.row.unmask { animation: unmask 1.4s ease; }
.row.unmask .name b { color: var(--red); }
@keyframes unmask { 0% { background: #ffe680; } 100% { background: transparent; } }
.rank { font-family: var(--mono); font-weight: 700; font-size: 15px; text-align: left; white-space: nowrap; }
.name { min-width: 0; display: flex; flex-direction: column; }
.name b { font-family: var(--cond); font-weight: 800; font-size: 21px; text-transform: uppercase; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name .sub { font-size: 12px; color: var(--muted); }
.row.solved .name .sub { color: var(--pos); font-weight: 600; }
.lane { position: relative; display: flex; align-items: center; min-width: 0; height: 100%; }
.bar { height: 26px; background: var(--c); flex: none; transition: width 0.12s linear; }
.val { font-family: var(--mono); font-weight: 700; font-size: 14px; margin-left: 8px; white-space: nowrap; }
.slot { flex: none; display: flex; align-items: flex-end; }
.slot:empty { display: none; }
.fans { display: flex; margin-left: 8px; }
.fan { width: 22px; height: 22px; margin-left: -4px; border: 1.5px solid var(--ink); border-radius: 50%; background: var(--card); display: grid; place-items: center; }
.fan .face { width: 18px; height: 18px; }
.hint { font-size: 13px; line-height: 1.3; min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hint i { font-style: normal; font-family: var(--mono); font-weight: 700; font-size: 11px; color: var(--red); margin-right: 4px; }
.rowguess { display: flex; min-width: 0; }
.rowguess input { flex: 1; min-width: 0; padding: 7px 8px; border: 2px solid var(--ink); border-right: 0; font: inherit; font-size: 14px; background: var(--card); border-radius: 0; }
.rowguess button { padding: 0 10px; border: 2px solid var(--ink); background: var(--ink); color: #fff; font-family: var(--cond); font-weight: 700; text-transform: uppercase; cursor: pointer; }
.rowguess input:disabled, .rowguess button:disabled { opacity: 0.45; cursor: not-allowed; }
.shake { animation: shake 0.35s; border-color: var(--red) !important; }

/* ---------- race card: before the start, starting order and two hints, no bars ---------- */
.card-hints { display: none; }
.card-cap { display: none; margin: 0 0 4px; padding: 0 4px 10px; border-bottom: 3px solid var(--ink); font-family: var(--cond); font-weight: 800; font-size: 32px; line-height: 1.05; text-transform: uppercase; letter-spacing: 0.3px; }
body.prerace .card-cap { display: block; }
.card-cap small { display: block; margin-top: 4px; font-family: var(--mono); font-weight: 700; font-size: 16px; letter-spacing: 0; text-transform: none; color: var(--red); }
body.prerace .progress-row { display: none; }
body.prerace { --row-h: 74px; }
body.prerace .track-cols, body.prerace .lane { display: none; }
body.prerace .card-hints { display: flex; flex-direction: column; gap: 3px; min-width: 0; font-size: 13.5px; line-height: 1.3; }
body.prerace .card-hints span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
body.prerace .card-hints i { font-style: normal; font-family: var(--mono); font-weight: 700; font-size: 11px; color: var(--red); margin-right: 6px; }
body.prerace .row { border-bottom: 1px solid var(--soft); }
body.prerace .row.mine { box-shadow: inset 4px 0 0 var(--red); }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ---------- the runner: your jockey on a hobby horse ---------- */
.runner { --pace: 0.45s; width: 56px; height: 50px; margin: -18px 0 0 -6px; position: relative; z-index: 2; pointer-events: none; }
.runner.big { width: 150px; height: 134px; margin: 0; }
.runner-svg { width: 100%; height: 100%; overflow: visible; display: block; }
.runner-svg * { transform-box: view-box; }
.runner .bob { animation: bob var(--pace) ease-in-out infinite; }
.runner .legs.front { transform-origin: 31px 44px; animation: legA var(--pace) ease-in-out infinite alternate; }
.runner .legs.back { transform-origin: 30px 44px; animation: legA var(--pace) ease-in-out infinite alternate-reverse; }
.runner .horse { transform-origin: 20px 58px; animation: gallop calc(var(--pace) * 2) ease-in-out infinite; }
.runner .arm { transform-origin: 34px 32px; animation: pump var(--pace) ease-in-out infinite alternate; }
.runner .sweat path { fill: var(--sweat); opacity: 0; animation: drip calc(var(--pace) * 2.2) linear infinite; }
.runner .sweat .d2 { animation-delay: calc(var(--pace) * -0.7); }
.runner .sweat .d3 { animation-delay: calc(var(--pace) * -1.4); }
.runner .dust circle { fill: #c9bfa8; animation: puff calc(var(--pace) * 2) ease-out infinite; }
.runner .dust circle:nth-child(2) { animation-delay: calc(var(--pace) * -0.6); }
.runner .dust circle:nth-child(3) { animation-delay: calc(var(--pace) * -1.2); }
.runner.panic .sweat path { animation-duration: calc(var(--pace) * 1.1); }
.runner.panic .head > * { animation: wobble 0.3s ease-in-out infinite alternate; transform-origin: 32px 19px; }
.runner.still .bob, .runner.still .legs, .runner.still .horse, .runner.still .arm, .runner.still .dust circle, .runner.still .sweat path { animation-play-state: paused; }
.runner.lead::after { content: '1ST'; position: absolute; right: -4px; top: -8px; font-family: var(--mono); font-size: 9px; font-weight: 700; color: #fff; background: var(--red); padding: 0 3px; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes legA { from { transform: rotate(-30deg); } to { transform: rotate(32deg); } }
@keyframes gallop { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(5deg); } }
@keyframes pump { from { transform: rotate(-10deg); } to { transform: rotate(12deg); } }
@keyframes drip { 0% { opacity: 0; transform: translate(0, 0); } 10% { opacity: 1; } 100% { opacity: 0; transform: translate(-16px, 10px); } }
@keyframes puff { 0% { opacity: 0.9; transform: translate(0, 0) scale(0.6); } 100% { opacity: 0; transform: translate(-12px, -4px) scale(1.4); } }
@keyframes wobble { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }

/* ---------- track caller: one big line right under the chart ---------- */
.deck { margin: 12px -16px 0; background: var(--ink); color: #fff; }
.caller { display: flex; align-items: center; gap: 16px; min-height: 64px; padding: 12px 18px; }
.caller b { flex: none; font-family: var(--cond); font-weight: 800; letter-spacing: 1.6px; text-transform: uppercase; color: #ff5a6e; font-size: 15px; width: 112px; }
.caller span { font-size: 18px; line-height: 1.3; }
.caller.pop span { animation: pop 0.35s ease; }
@keyframes pop { from { opacity: 0.35; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.deck-card { border-top: 1px solid #3a3a3a; padding: 10px 18px 14px; font-size: 14px; }
.deck-card:empty { display: none; }
.dk-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dk-row .silk { width: 24px; height: 24px; flex: none; }
.dk-name { font-family: var(--cond); font-weight: 800; font-size: 22px; text-transform: uppercase; line-height: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dk-meta { font-family: var(--mono); font-size: 13px; color: #cfcfcf; white-space: nowrap; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dk-meta b { color: #fff; }
.dk-meta .pos, #deckReward { color: #7ee2a0; font-weight: 700; }
.dk-face { width: 30px; height: 30px; flex: none; border-radius: 50%; background: #fff; display: grid; place-items: center; }
.dk-face .face { width: 26px; height: 26px; }
.dk-small { margin: 8px 0 0; color: #cfcfcf; line-height: 1.4; }
.dk-small b { color: #fff; font-family: var(--mono); }
.dk-x { flex: none; margin-left: auto; width: 30px; height: 30px; border: 1.5px solid #777; background: none; color: #fff; font-size: 14px; cursor: pointer; }
.dk-hints { list-style: none; margin: 10px 0; padding: 0; }
.dk-hints li { display: flex; gap: 10px; padding: 5px 0; border-bottom: 1px solid #333; line-height: 1.35; }
.dk-hints li i { font-style: normal; font-family: var(--mono); font-weight: 700; font-size: 12px; color: #ff5a6e; width: 12px; flex: none; padding-top: 1px; }
.dk-hints li.locked { color: #8a8a8a; }
.dk-guess { display: flex; }
.dk-guess input { flex: 1; min-width: 0; padding: 10px 12px; border: 2px solid #fff; border-right: 0; font: inherit; font-size: 16px; border-radius: 0; background: #fff; color: var(--ink); }
.dk-guess input:focus { outline: none; box-shadow: inset 0 -3px 0 var(--red); }
.dk-guess input:disabled { background: #bdbdbd; }
.dk-guess button { padding: 0 16px; border: 2px solid var(--red); background: var(--red); color: #fff; font-family: var(--cond); font-weight: 800; font-size: 17px; text-transform: uppercase; cursor: pointer; }
.dk-guess button:disabled { opacity: 0.5; cursor: not-allowed; }
.dk-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; color: #bdbdbd; }
.dk-link { background: none; border: 0; padding: 0; color: #fff; text-decoration: underline; font: inherit; font-size: 12.5px; cursor: pointer; }
.dk-link:disabled { color: #777; text-decoration: none; cursor: not-allowed; }
.dk-btn { display: block; width: 100%; margin-top: 10px; padding: 10px; border: 2px solid #fff; background: none; color: #fff; font-family: var(--cond); font-weight: 800; font-size: 17px; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; }
.dk-btn:hover, .dk-x:hover { background: #fff; color: var(--ink); }
.dk-x:focus-visible, .dk-btn:focus-visible, .dk-link:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
body.replay .deck-card { display: none; }

.overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 5; }
.overlay > div {
  font-family: var(--cond); font-weight: 800; font-size: 96px; line-height: 1; text-transform: uppercase;
  background: color-mix(in srgb, var(--card) 90%, transparent); border: 3px solid var(--ink); padding: 10px 30px; text-align: center;
}
.overlay > div.small-ov { font-size: 34px; }
.overlay small { display: block; font-family: var(--sans); font-weight: 500; font-size: 14px; text-transform: none; margin-top: 6px; color: var(--muted); }

/* ---------- side panels ---------- */
.race-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sheet-tabs { display: none; }
.pick-main { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.pick-main > div { min-width: 0; display: flex; flex-direction: column; }
.pick-name { font-family: var(--cond); font-weight: 800; font-size: 26px; text-transform: uppercase; line-height: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-face { width: 44px; height: 44px; border: 2px solid var(--ink); border-radius: 50%; display: grid; place-items: center; background: var(--soft2); }
.pick-face .face { width: 36px; height: 36px; }
.pick-empty { margin: 0; padding: 18px 12px; border: 2px dashed var(--ink); text-align: center; font-weight: 600; }
.worth { font-size: 13px; margin: 10px 0; padding: 8px 10px; background: var(--soft2); }
.worth b { font-family: var(--mono); }
#pickBox .btn { margin-top: 4px; }
#pickNote { margin: 10px 0 0; }
.pick-history { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.pick-history li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--soft); }
.pick-history .silk { width: 18px; height: 18px; }

.file-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.file-tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; background: var(--card); border: 2px solid var(--soft); cursor: pointer; position: relative; }
.file-tabs button .silk { width: 20px; height: 20px; }
.file-tabs button b { font-family: var(--mono); font-size: 12px; }
.file-tabs button .ok { display: none; position: absolute; top: -8px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--pos); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.file-tabs button.solved .ok { display: block; }
.file-tabs button.on { border-color: var(--ink); background: var(--soft2); }
.file-tabs button.fresh::after { content: ''; position: absolute; top: 4px; left: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.file-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.file-head h4 { font-size: 26px; flex: 1; min-width: 0; }
.reward { font-family: var(--mono); font-weight: 700; font-size: 14px; white-space: nowrap; }
.hints { list-style: none; margin: 0 0 12px; padding: 0; }
.hints li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--soft); font-size: 15px; }
.hints li .n { font-family: var(--mono); font-weight: 700; width: 14px; flex: none; }
.hints li.locked { color: var(--muted); }
.guess { display: flex; }
.guess input { flex: 1; min-width: 0; padding: 10px 12px; border: 2px solid var(--ink); border-right: 0; font: inherit; font-size: 16px; border-radius: 0; background: var(--card); }
.guess input:focus, .rowguess input:focus, .topic-tools input:focus, .topic-tools select:focus { outline: none; box-shadow: inset 0 -3px 0 var(--red); }
.guess input:disabled { background: var(--soft2); }
.file-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; font-size: 13px; color: var(--muted); }

.rival-list { list-style: none; margin: 0; padding: 0; }
.rival-list li { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.ai-face { width: 34px; height: 34px; border: 1.5px solid var(--ink); border-radius: 50%; display: inline-grid; place-items: center; background: var(--soft2); flex: none; vertical-align: middle; }
.ai-face .face { width: 28px; height: 28px; }
.rival-list .nm { min-width: 0; display: flex; flex-direction: column; }
.rival-list .nm b { font-family: var(--cond); font-size: 17px; text-transform: uppercase; }
.rival-list .nm small { font-size: 12.5px; color: var(--muted); line-height: 1.3; }
.ai-pick { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 12px; }
.ai-pick b { font-family: var(--cond); font-size: 15px; text-transform: uppercase; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-pick .silk { width: 18px; height: 18px; }
.ai-pick small { color: var(--muted); }
.notices { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; }
.notices li { padding: 5px 0; border-bottom: 1px dashed var(--soft); }
.notices li.sys { color: var(--red); }
.notices li.ai { color: var(--muted); }

/* ---------- replay with names ---------- */
body.replay .race-side, body.replay .sheet-tabs, body.replay .c-hint, body.replay .c-guess { display: none !important; }
body.replay .race-layout { grid-template-columns: minmax(0, 1fr); }
body.replay .row, body.replay .track-cols { grid-template-columns: 40px 34px 210px minmax(0, 1fr); }
body.replay .caller { min-height: 80px; }
body.replay .caller span { font-size: 21px; }
body.replay .row { cursor: default; }

/* ---------- reveal ---------- */
.reveal-head { margin-bottom: 18px; }
.reveal-head h1 { font-size: clamp(34px, 5vw, 56px); }
.years { margin: 10px 0 2px; font-size: 16px; }
.years b { font-family: var(--mono); font-size: clamp(32px, 5vw, 46px); margin-right: 6px; }
.reveal-head .muted { margin: 0; }
.reveal-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.reveal-grid > div { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.finish { list-style: none; margin: 0; padding: 0; border: 2px solid var(--ink); background: var(--card); }
.finish li { display: grid; grid-template-columns: 40px 30px 16px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--soft); }
.finish li.first { background: var(--ink); color: #fff; }
.finish li.first .silk { border-color: #fff; }
.finish li.mine:not(.first) { background: var(--tint); }
.finish .pl { font-family: var(--mono); font-weight: 700; }
.finish .lt { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.finish li.first .lt { color: #bbb; }
.finish .nm { font-family: var(--cond); font-size: 21px; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finish .nm em { font-style: normal; font-size: 12px; background: var(--red); color: #fff; padding: 1px 5px; vertical-align: middle; }
.finish .v { font-family: var(--mono); font-weight: 700; font-size: 14px; }
.finish li.unit-note { display: block; font-size: 12px; color: var(--muted); text-align: right; border-bottom: 0; padding: 4px 14px; }
.your-race { border: 2px dashed var(--ink); padding: 14px 16px; background: var(--card); }
.your-race h3 { font-size: 20px; margin-bottom: 8px; }
.your-race p { margin: 6px 0 0; }
.yr-line { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; align-items: baseline; }
.yr-line b { font-family: var(--mono); font-size: 17px; white-space: nowrap; }
.yr-line small { color: var(--muted); }
.yr-line.total { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-weight: 600; }
.yr-line.total b { font-size: 22px; }
.reveal-actions { display: grid; grid-template-columns: 1fr 1fr; }
.reveal-actions .btn + .btn { border-left: 0; }
.reveal-actions.bottom { margin-top: 22px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
#shareMsg { margin: 0; min-height: 1em; }
.share-text { width: 100%; font-family: var(--mono); font-size: 12px; padding: 8px; border: 2px solid var(--ink); }
.rivals-result h3, .reveal-grid .card h3 { font-size: 22px; margin-bottom: 10px; }
.score-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.score-table th { text-align: right; font-family: var(--cond); text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-size: 13px; padding: 4px 6px; border-bottom: 2px solid var(--ink); }
.score-table th:first-child, .score-table td:first-child { text-align: left; }
.score-table td { padding: 6px; border-bottom: 1px solid var(--soft); text-align: right; font-family: var(--mono); font-weight: 700; white-space: nowrap; }
.score-table td:first-child { font-family: var(--sans); font-weight: 600; }
.score-table td .ai-face { width: 26px; height: 26px; margin-right: 8px; }
.score-table td .ai-face .face { width: 22px; height: 22px; }
.score-table tr.me td { background: var(--tint); }
.stories { list-style: none; margin: 12px 0 0; padding: 0; font-size: 14px; }
.stories li { padding: 6px 0; border-top: 1px dashed var(--soft); }
.results { list-style: none; margin: 0; padding: 0; }
.results li { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.results .nm { min-width: 0; display: flex; flex-direction: column; }
.results .nm b { font-family: var(--cond); font-size: 18px; text-transform: uppercase; }
.results .nm small { color: var(--muted); font-size: 13px; }
.results .st { font-family: var(--mono); font-size: 13px; font-weight: 700; }
.results .st.found { color: var(--pos); }
.share-card { border: 3px solid var(--ink); background: var(--card); padding: 18px; }
.share-card h4 { font-size: 30px; margin-bottom: 12px; }
.strip { display: flex; flex-wrap: wrap; gap: 4px; }
.strip i, .legend i { display: inline-block; width: 22px; height: 22px; border: 2px solid var(--ink); background: var(--card); }
.strip i.led, .legend i.led { background: #0b5d35; }
.strip i.top, .legend i.top { background: #f2c200; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 12px; }
.legend i { width: 12px; height: 12px; margin-left: 6px; }
.share-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink); }
.share-stats div { padding: 10px 8px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; }
.share-stats div + div { border-left: 2px solid var(--ink); }
.share-stats b { font-family: var(--mono); font-size: 24px; color: var(--ink); }
.share-card .small { margin: 12px 0 6px; font-family: var(--cond); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.silk-row { display: flex; gap: 6px; align-items: center; }
.site { margin: 14px 0 0; font-family: var(--cond); font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; }

/* ---------- jockey picker ---------- */
.picker { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: color-mix(in srgb, var(--ink) 45%, transparent); padding: 16px; }
.picker-card { width: min(420px, 100%); background: var(--card); border: 3px solid var(--ink); padding: 18px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- sister services (DearCommon) ---------- */
.sisters-wrap { margin-top: 26px; }
.dc-sisters {
  --dc-text: var(--ink);
  --dc-muted: var(--muted);
  --dc-line: var(--soft);
  --dc-bg: var(--card);
  --dc-nav-bg: color-mix(in srgb, var(--card) 92%, transparent);
}
.dc-sisters-title { font-family: var(--cond); font-weight: 800; text-transform: uppercase; font-size: 20px; }

/* ---------- series gate ---------- */
.dw-gate {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
  background: var(--paper);
}
.gate-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; background: var(--card); border: 3px solid var(--ink); padding: 28px 22px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 14px; }
.gate-card input { padding: 11px 12px; border: 2px solid var(--ink); font: inherit; font-size: 15px; border-radius: 0; }
.gate-card input:focus { outline: none; box-shadow: inset 0 -3px 0 var(--red); }
.gate-card .err { color: var(--red); }

/* ---------- mid-size desktops: sidebar stays, hint and guess columns move to the sidebar ---------- */
/* ---------- narrower screens ---------- */
@media (max-width: 1099px) {
  .track-cols { display: none; }
  .row { grid-template-columns: 40px 30px 130px minmax(0, 1fr); }
  body.replay .row { grid-template-columns: 40px 30px 170px minmax(0, 1fr); }
}
@keyframes blink { from { opacity: 0.3; } to { opacity: 1; } }

@media (max-width: 860px) {
  .lobby-grid { grid-template-columns: minmax(0, 1fr); }
  .how-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reveal-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 680px) {
  :root { --row-h: 40px; --bar-max: 0.5; --top-h: 50px; --gutter: 16px; }
  main { padding-top: 14px; }
  .brand-word { font-size: 24px; }
  .bank-label { display: none; }
  .bank b { font-size: 17px; }
  .hero h1 { font-size: 40px; }
  .lede { font-size: 15px; }
  .stats-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .how-steps { grid-template-columns: minmax(0, 1fr); }
  .race-head { margin-bottom: 10px; gap: 8px; }
  .race-head .muted { font-size: 13px; }
  .race-title { font-size: 28px; }
  .race-head .eyebrow { font-size: 12px; margin-bottom: 3px; }
  .controls .btn { min-height: 38px; padding: 6px 12px; font-size: 16px; }
  .track-card { padding: 10px 10px 0; }
  .progress-row { gap: 10px; margin-bottom: 10px; }
  .y-end { font-size: 12px; }
  .ybar { margin: 26px 20px 4px; }
  .ynow { font-size: 18px; }
  .row { grid-template-columns: 30px 22px 74px minmax(0, 1fr); gap: 6px; padding: 0 2px; }
  .silk { width: 22px; height: 22px; }
  .rank { font-size: 12px; }
  .name b { font-size: 16px; }
  .name .sub { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bar { height: 20px; }
  .val { font-size: 12px; margin-left: 4px; }
  .runner { width: 42px; height: 38px; margin: -14px 0 0 -6px; }
  .fans { margin-left: 6px; }
  .fan { width: 18px; height: 18px; }
  .fan .face { width: 14px; height: 14px; }
  .deck { margin: 8px -10px 0; }
  .caller { padding: 8px 12px; gap: 10px; min-height: 58px; }
  .deck-card { padding: 8px 12px 12px; }
  .dk-name { font-size: 19px; }
  .dk-meta { font-size: 12px; }
  .caller b { font-size: 12px; width: 62px; letter-spacing: 1px; }
  .caller span { font-size: 15px; }
  .overlay > div { font-size: 64px; padding: 6px 20px; }
  .overlay > div.small-ov { font-size: 26px; }
  .card { padding: 14px; }
  body.replay .row { grid-template-columns: 30px 22px 100px minmax(0, 1fr); }
  body.prerace { --row-h: 100px; }
  body.prerace .row { grid-template-columns: 30px 22px minmax(0, 1fr); grid-template-rows: auto auto; row-gap: 4px; align-content: center; }
  body.prerace .card-hints { grid-column: 2 / -1; font-size: 12.5px; }
  body.replay .caller span { font-size: 16px; }
  .finish li { grid-template-columns: 34px 26px 12px minmax(0, 1fr) auto; gap: 8px; padding: 8px 10px; }
  .finish .nm { font-size: 18px; }
  .reveal-actions.bottom { grid-template-columns: minmax(0, 1fr); }
  .reveal-actions.bottom .btn + .btn { border-left: 2px solid var(--ink); border-top: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .runner *, .row, .bar, .caller span, .jockey-stage { animation: none !important; transition: none !important; }
}
