:root{font-family:system-ui,sans-serif;color:#233d2b;background:#f6f2e6;line-height:1.5;--forest:#244831;--muted:#546456;--line:#e0dfcd;--paper:#fffdf5}
*{box-sizing:border-box}
[hidden]{display:none!important}
body{margin:0;min-height:100vh;isolation:isolate}
body::before{content:"";position:fixed;inset:0;z-index:-1;pointer-events:none;background:linear-gradient(180deg,#f8f2dfd9 0%,#e5ead061 42%,#d9e4c86b 100%),url('/woodland.webp') center 58%/cover no-repeat}
button,a{-webkit-tap-highlight-color:transparent}
button{font:inherit;color:inherit;border:1px solid #bac6ad;border-radius:10px;background:#fffdf4;padding:.55rem .8rem;cursor:pointer;font-weight:650}
button:hover:not(:disabled){background:#e5ecd9}
button:disabled{opacity:.65;cursor:default}
button:focus-visible,a:focus-visible,summary:focus-visible{outline:3px solid #966319;outline-offset:3px}
a{color:inherit}
.mast{max-width:1120px;margin:auto;padding:16px 26px;display:flex;justify-content:space-between;align-items:center}
.wordmark{text-decoration:none;font:700 1.4rem Georgia,serif}
.wordmark span{color:#608049;margin-right:.3rem}
.plain{background:transparent}
main{max-width:1120px;margin:auto;padding:0 26px 20px}
.hero{position:relative;isolation:isolate;overflow:hidden;min-height:330px;border-radius:22px;background:#aec3a0 url('/woodland.webp') center 57%/cover;border:1px solid #a7b28b;display:grid;grid-template-rows:1fr auto}
.hero::before{content:"";position:absolute;inset:0;z-index:-1;background:linear-gradient(180deg,#faf2d940,transparent 65%)}
.hero-copy{text-align:center;padding:26px 12px 36px}
.hero-copy h1{font:700 clamp(3rem,8vw,5.8rem)/.98 Georgia,serif;margin:12px 0;color:#183824;text-shadow:0 1px 8px #f7e9bf}
.hero-copy p:not(.date){display:inline-block;margin:0;padding:3px 11px;border-radius:8px;background:#fff9e5e8;font-weight:650}
.date,.kicker{font-size:.83rem;letter-spacing:.085em;font-weight:800;text-transform:uppercase}
.date{display:inline-block;background:#fff9e5ed;border:1px solid #d3c89e;border-radius:999px;margin:0;padding:4px 13px}
.track{position:relative;margin:0 clamp(40px,9vw,110px) 42px;height:68px}
.rail{position:absolute;inset:auto 0 0;height:8px;background:#7e6137;border-radius:99px;box-shadow:0 0 0 3px #fff0be}
.markers{position:absolute;inset:auto 0 0;display:flex;justify-content:space-between;height:8px}
.markers span{background:#fff4cb;width:2px;height:100%}
.flag{position:absolute;bottom:-32px;color:#233d2b;background:#fff4d0;border-radius:4px;padding:0 4px;font-size:.75rem;font-weight:800;z-index:1}
.start{left:0;transform:translateX(-50%)}
.finish-gate{position:absolute;right:0;bottom:-9px;width:44px;height:65px;transform:translateX(50%);z-index:3;pointer-events:none}
.finish-gate::before,.finish-gate::after{content:"";position:absolute;width:4px;height:37px;border-radius:4px;background:#755332;box-shadow:inset 1px 0 #dcb77d}
.finish-gate::before{left:6px;bottom:0;z-index:4}
.finish-gate::after{right:6px;bottom:17px;z-index:1}
.finish-line,.finish-tape{position:absolute;left:8px;width:33px;transform:rotate(-30deg);transform-origin:left center}
.finish-line{bottom:1px;height:3px;background:#fff1c6;border-radius:2px;box-shadow:0 1px 1px #6b4a36}
.finish-tape{bottom:27px;height:8px;z-index:3}
.finish-tape::before,.finish-tape::after{content:"";position:absolute;inset:0 50% 0 0;background:#ae392a;border-top:2px solid #ed8c6a;transform-origin:left center;transition:transform .24s ease-out}
.finish-tape::after{inset:0 0 0 50%;transform-origin:right center}
.ribbon-broken .finish-tape::before{transform:rotate(75deg);transition-delay:.55s}
.ribbon-broken .finish-tape::after{transform:rotate(-32deg);transition-delay:.55s}
.finish{left:50%;bottom:-17px;transform:translateX(-50%)}
.racer{position:absolute;bottom:4px;left:0%;transform:translateX(-50%);width:clamp(57px,9vw,105px);height:clamp(43px,7vw,76px);object-fit:contain;object-position:center bottom;filter:drop-shadow(0 3px 1px #24483165);transition:left .74s cubic-bezier(.2,.7,.3,1);z-index:2}
.racer.friend{bottom:25px;z-index:1;width:clamp(45px,7vw,83px);height:clamp(34px,6vw,62px)}
.racer.hop{animation:hop .28s ease-in-out 3}
@keyframes hop{50%{transform:translate(-50%,-8px)}}
.stats{display:flex;justify-content:center;gap:clamp(20px,6vw,65px);padding:11px 16px;margin:0 10px;background:#f1f1dcef;border-radius:0 0 14px 14px;color:var(--muted);font-size:.95rem}
.stats strong{margin-left:5px;color:var(--forest)}
.notice{margin:10px auto;color:#354e36;font-weight:650;min-height:1.5em;text-align:center}
.notice:not(:empty),.practice-note:not([hidden]){width:fit-content;max-width:100%;margin-inline:auto;background:#fff9e6ed;padding:4px 10px;border-radius:10px}
.layout{display:grid;align-items:start;gap:18px}
.card{background:var(--paper);border:1px solid var(--line);border-radius:17px;padding:clamp(16px,3vw,26px);box-shadow:0 2px 5px #3d4a2710}
h2,h3{font-family:Georgia,serif;line-height:1.18;margin:0 0 10px}
h2{font-size:clamp(1.43rem,2.6vw,1.85rem)}
.runners h2{font-size:1.35rem}
.kicker{color:#586e47;margin:0 0 8px}
.direction{font-size:.86rem;color:var(--muted);font-weight:700;margin:12px 0 4px}
#items{list-style:none;margin:0;padding:0;display:grid;gap:6px}
.item{display:flex;align-items:center;gap:9px;border:1px solid #dce1ce;background:#f2f3e8;border-radius:9px;padding:5px 7px 5px 10px;min-height:45px}
.item[draggable=true]{cursor:grab}
.label{flex:1;font-weight:650}
.nudge{padding:2px 7px;min-height:32px;min-width:32px;font-size:1rem}
.primary{background:var(--forest);color:#fffdf4;border-color:var(--forest);padding:.65rem 1rem}
.primary:hover:not(:disabled){background:#375b43}
#submit{width:100%;margin-top:10px;min-height:44px;touch-action:manipulation}
.runner-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.runner-grid button{display:grid;justify-items:center;gap:2px;background:#f2f3e7;padding:6px 4px;font-size:.88rem}
.runner-grid img{width:min(100%,84px);height:58px;object-fit:contain}
.runner-grid button[aria-pressed=true]{outline:2px solid #59794d;outline-offset:-2px;background:#e1ebd3}
.muted,.foot{color:var(--muted);font-size:.88rem}
.muted:last-child{margin-bottom:0}
.foot{display:flex;justify-content:space-between;gap:15px}
.foot span{margin-left:auto}
.foot > *{padding:3px 8px;border-radius:8px;background:#fff9e6ed}
.result-actions{display:flex;flex-wrap:wrap;gap:8px;margin-bottom:16px}
summary{cursor:pointer;font-weight:700}
dialog{width:min(calc(100% - 32px),480px);border:1px solid var(--line);border-radius:18px;padding:24px;background:var(--paper);color:inherit}
dialog::backdrop{background:#162d22ac}
@media(max-width:690px){.runner-grid img{height:48px}main,.mast{padding-left:12px;padding-right:12px}.hero{min-height:273px}.hero-copy{padding-top:22px}}
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}}
#next{margin-top:14px}
.result-actions button{width:auto;white-space:nowrap}
#answer h4{margin:14px 0 4px}
#answer ol{margin:0 0 12px}
@media(max-width:410px){.stats{gap:10px;padding-inline:4px;font-size:.8rem}.stats strong{margin-left:2px}}

.guess-clock{position:sticky;top:8px;z-index:4;border:1px solid #d0dac4;border-radius:12px;background:#f0f3e5;padding:7px 12px 10px;box-shadow:0 3px 8px #24483120}
.guess-clock-label{display:flex;justify-content:space-between;align-items:center;gap:8px;font-weight:750}
.guess-clock strong{font-size:clamp(1.6rem,5vw,2.15rem);font-variant-numeric:tabular-nums;line-height:1.2}
.clock-track{height:7px;background:#d7dfcc;border-radius:6px;overflow:hidden;margin-top:4px}
#timer-fill{height:100%;width:100%;background:#4f7946;transition:width .2s linear}
.guess-clock.urgent strong{color:#9b321d}
.guess-clock.urgent #timer-fill{background:#ae482c}
.spectator{position:absolute;right:clamp(18px,7vw,92px);bottom:105px;z-index:3;display:grid;justify-items:center;pointer-events:none}
.spectator.off-track{position:fixed;right:18px;bottom:20px;z-index:8;padding:8px 12px;background:#f5f0db;border:1px solid #d4c79f;border-radius:16px;box-shadow:0 3px 12px #233d2b35}
.spectator span{border:1px solid #d4c79f;background:#fff8df;color:#344b2d;font-weight:800;padding:2px 9px;border-radius:999px;transform:rotate(7deg)}
.spectator img{width:clamp(55px,10vw,95px);height:60px;object-fit:contain;object-position:bottom;filter:drop-shadow(0 2px 2px #24341f65)}

.mast-actions{display:flex;align-items:center;gap:8px}
.button-link{display:inline-block;font-weight:650;text-decoration:none;border:1px solid #bac6ad;border-radius:10px;padding:.55rem .8rem;background:#fffdf4}
.button-link:hover{background:#e5ecd9}
.practice-note{margin:0 0 10px;text-align:center;color:var(--muted);font-size:.9rem}
@media(max-width:420px){.mast-actions{gap:4px}.mast-actions a,.mast-actions button{font-size:.82rem;padding:.42rem .5rem}}
#share-text{width:100%;margin:0 0 12px;padding:8px;font:inherit;color:inherit;border:1px solid #bac6ad;border-radius:8px;background:#fffdf4}
#race-percentile{font-weight:750;color:var(--forest)}

#reorder-help{margin:8px 0;color:var(--muted);font-size:.9rem}
.grip{display:grid;place-items:center;flex:0 0 auto;min-height:44px;min-width:55px;padding:0 4px;border:1px solid #a9b79a;border-radius:7px;background:#e5ecd9;color:#244831;font-size:.8rem;font-weight:750;white-space:nowrap;touch-action:none;user-select:none;cursor:grab}
.item.touch-dragging{position:relative;z-index:3;box-shadow:0 4px 12px #233d2b40;opacity:.92}
.item.touch-dragging .grip{cursor:grabbing}
.item.touch-drop-target{outline:2px dashed #59794d;outline-offset:-2px}
.item.correct-slot{background:#dfecd5;border-color:#699362}
.correct-slot-mark{color:#24572b;font-weight:800}
.answer-value{display:inline-block;margin-inline-start:4px;padding:0 6px;border-radius:5px;background:#e8eddc;font-weight:700}

#head-to-head{margin:12px 0;padding:12px;border:1px solid var(--line);border-radius:12px;background:#eef0e2}
#head-to-head h4,#duel-outcome{margin:0}
.duel-runners{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;margin:8px 0;text-align:center}
.duel-runners div{display:grid;justify-items:center;overflow-wrap:anywhere}
.duel-runners img{width:min(100%,105px);height:64px;object-fit:contain}
#duel-outcome{font-weight:700}
#share-name-field{display:grid;gap:4px;margin:0 0 10px;font-size:.9rem;font-weight:650}
#share-name{width:min(100%,300px);padding:7px 9px;font:inherit;border:1px solid #bac6ad;border-radius:8px;background:#fffdf4;color:inherit}
#friend-racer-name{position:absolute;left:0;bottom:calc(28px + clamp(34px,6vw,62px));z-index:3;transform:translateX(-50%);max-width:clamp(76px,16vw,110px);padding:1px 7px;border-radius:8px;background:#fff6d8;color:#233d2b;font-size:.8rem;font-weight:750;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;pointer-events:none;transition:left .74s cubic-bezier(.2,.7,.3,1)}

#rules{width:min(560px,calc(100% - 24px));max-height:calc(100vh - 24px);max-height:calc(100dvh - 24px);padding:14px;overflow:hidden}
#rules[open]{display:flex;flex-direction:column}
#tutorial-content{min-height:0;overflow-y:auto;overscroll-behavior:contain}
.tutorial-header{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-bottom:10px;flex-shrink:0}
.tutorial-header h2{margin:0}
.visually-hidden{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
#tutorial-image{display:block;width:100%;height:auto;border-radius:10px;background:#243b2c}
.tutorial-copy{margin:12px 0;min-height:7rem}
.tutorial-copy h3{margin:4px 0}
.tutorial-copy p{margin:0}
#tutorial-progress{font-size:.85rem}
.tutorial-navigation{display:flex;justify-content:space-between;gap:10px;flex-shrink:0}
.tutorial-navigation button{min-width:84px;min-height:44px}

@media (max-width:480px),(max-height:560px){
  #rules{width:min(380px,calc(100% - 32px));padding:12px}
  .tutorial-header h2{font-size:1.25rem}
  .tutorial-header button{min-height:44px}
  #tutorial-image{max-height:24vh;max-height:24dvh;object-fit:contain}
  .tutorial-copy{min-height:0;margin:8px 0 10px}
}
