/* PAPER 86 — paper-craft palette */
:root {
    --kraft: #e2d1aa;
    --paper: #f6eedb;
    --cream: #f3e6c9;
    --graphite: #5c5348;
    --ink: #2a241c;
    --cone: #d4773d;
    --red: #8b1e1e;
    --rule: #c4b089;
    --mono: "Courier New", Courier, monospace;
    --serif: Georgia, "Palatino Linotype", Palatino, serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: var(--serif);
    background: var(--kraft);
    color: var(--graphite);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- HUD ---------- */
#hud {
    position: absolute; left: 0; right: 0; top: 0;
    padding: calc(12px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
    display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
    pointer-events: none;
}
.hud-box {
    background: var(--paper); border: 2px solid var(--ink); box-shadow: 3px 4px 0 rgba(42, 36, 28, 0.18);
    padding: 6px 12px 7px; min-width: 104px; display: flex; flex-direction: column; transform: rotate(-0.6deg);
}
.hud-box.right { align-items: flex-end; transform: rotate(0.6deg); }
.hud-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.22em; color: var(--red); font-weight: bold; }
.hud-value { font-family: var(--mono); font-weight: bold; font-size: 28px; line-height: 1.05; color: var(--ink); font-variant-numeric: tabular-nums; }
.hud-value.low { color: var(--red); }
.hud-sub { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; color: var(--graphite); min-height: 12px; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 2px; }
.hud-track { font-size: 13px; letter-spacing: 0.28em; text-transform: uppercase; color: var(--ink); opacity: 0.75; text-align: center; }
.hud-buttons { display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--ink); background: var(--paper);
    font-family: var(--mono); font-weight: bold; font-size: 14px; color: var(--ink); line-height: 1;
}
.icon-btn.off { color: var(--rule); text-decoration: line-through; }

#chain {
    position: absolute; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom)); transform: translateX(-50%) rotate(-1deg);
    background: var(--paper); border: 2px solid var(--red); box-shadow: 3px 4px 0 rgba(42, 36, 28, 0.18);
    padding: 6px 14px 6px; min-width: 190px; text-align: center; pointer-events: none;
}
#chain.hot { animation: thump 0.18s ease-out; }
@keyframes thump { 0% { transform: translateX(-50%) rotate(-1deg) scale(1.14); } 100% { transform: translateX(-50%) rotate(-1deg) scale(1); } }
.chain-row { display: flex; justify-content: center; align-items: baseline; gap: 10px; font-family: var(--mono); font-weight: bold; color: var(--ink); }
#chain-pts { font-size: 24px; font-variant-numeric: tabular-nums; }
#chain-mult { font-size: 18px; color: var(--red); }
.chain-bar { height: 6px; background: rgba(42, 36, 28, 0.15); margin-top: 3px; }
.chain-bar i { display: block; height: 100%; width: 100%; background: var(--red); transform-origin: left; }
.chain-bar i.warn { background: var(--cone); }
.chain-label { font-family: var(--mono); font-size: 9px; letter-spacing: 0.22em; color: var(--graphite); margin-top: 3px; }
#chain.lost { border-color: var(--ink); background: #ecd9c4; }
#chain.lost #chain-pts, #chain.lost .chain-label { color: var(--red); text-decoration: line-through; }
#chain.lost .chain-label { text-decoration: none; }
#chain.won { border-color: var(--ink); }
.hud-gain { position: absolute; right: 8px; top: 100%; margin-top: 4px; font-family: var(--mono); font-weight: bold; font-size: 15px; color: var(--red); white-space: nowrap; opacity: 0; }
.hud-gain.go { animation: gain 1.1s ease-out; }
@keyframes gain { 0% { opacity: 0; transform: translateY(14px) scale(1.3); } 20% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-8px); } }
.hud-box.right { position: relative; }
.hud-box.bump .hud-value { animation: bump 0.3s ease-out; }
@keyframes bump { 0% { transform: scale(1.25); color: var(--red); } 100% { transform: scale(1); } }

/* Hand-drawn edges: uneven corner radii, and an SVG wobble on the small stuff. */
.hud-box, #chain, .track-card, .btn, .daily, .stamp, #coach, .unlock, .badge { border-radius: 255px 14px 225px 14px / 14px 225px 14px 255px; }
.sheet, .card { border-radius: 6px 30px 8px 26px / 28px 8px 24px 6px; }
.stamp, .track-card svg, .medal, .wordmark, .icon-btn, .pips, .pace { filter: url(#sketch); }

.card.wide { max-width: 720px; }
.help-lede { margin: 14px 0 4px; font-size: 15px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 26px; text-align: left; margin: 10px 0 18px; }
.help-cols h3 { font-family: var(--mono); font-size: 12px; letter-spacing: 0.24em; padding-bottom: 4px; border-bottom: 2px solid currentColor; margin-bottom: 6px; }
.help-cols h3.plus { color: var(--ink); } .help-cols h3.minus { color: var(--red); }
.help-cols dt { font-family: var(--mono); font-weight: bold; color: var(--ink); font-size: 13px; margin-top: 8px; }
.help-cols h3.plus + dl dt::before { content: "+ "; } .help-cols h3.minus + dl dt::before { content: "− "; color: var(--red); }
.help-cols dd { font-size: 13.5px; line-height: 1.4; }
.help-note { font-family: var(--mono); font-size: 12px; color: var(--ink); margin-top: 12px; border: 1px dashed var(--rule); padding: 6px 8px; }
.breakdown { text-align: left; }
.breakdown div { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.breakdown b { font-family: var(--mono); color: var(--ink); }
.breakdown .bd-title { font-family: var(--mono); font-size: 10px; letter-spacing: 0.24em; color: var(--red); border-bottom: none; padding-bottom: 0; }
.breakdown .bd-lost, .breakdown .bd-lost b { color: var(--red); border-bottom: none; }
.hs { margin-top: 14px; text-align: left; }
.hs-list { list-style: none; margin-top: 6px; font-family: var(--mono); font-size: 15px; color: var(--ink); min-height: 24px; }
.hs-list li { display: grid; grid-template-columns: 2.2em 1fr auto; padding: 3px 6px; border-bottom: 1px dotted var(--rule); letter-spacing: 0.12em; }
.hs-list li.me { background: var(--red); color: var(--paper); font-weight: bold; }
.hs-list li.empty { display: block; font-family: var(--serif); font-style: italic; letter-spacing: 0; color: var(--graphite); border: none; text-align: center; }
.hs-list .sc { letter-spacing: 0; font-variant-numeric: tabular-nums; }
.hs-note { font-family: var(--mono); font-size: 10px; letter-spacing: 0.16em; color: var(--graphite); margin-top: 6px; text-align: center; }
.hs-entry { text-align: center; border: 2px dashed var(--red); padding: 10px 8px 12px; margin: 8px 0; outline: none; }
.hs-prompt { font-family: var(--mono); font-weight: bold; font-size: 12px; letter-spacing: 0.14em; color: var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.hs-slots { display: flex; justify-content: center; gap: 14px; margin: 8px 0 10px; }
.hs-slot { display: flex; flex-direction: column; align-items: center; }
.hs-letter { font-family: var(--mono); font-weight: bold; font-size: 44px; line-height: 1.05; width: 1.2em; color: var(--ink); border-bottom: 4px solid var(--rule); }
.hs-slot.on .hs-letter { border-bottom-color: var(--red); color: var(--red); }
.hs-step { background: none; border: none; font-size: 20px; color: var(--ink); padding: 4px 16px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 14px 0 10px; }
.tabs button { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; background: transparent; border: 2px solid var(--ink); color: var(--ink); padding: 5px 9px; }
.tabs button.on { background: var(--ink); color: var(--paper); }
.res-tip { font-size: 13px; font-style: italic; margin-top: 8px; min-height: 18px; }

#coach {
    position: absolute; left: 50%; bottom: calc(118px + env(safe-area-inset-bottom)); transform: translateX(-50%);
    background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 14px; letter-spacing: 0.04em;
    padding: 8px 14px; max-width: min(92vw, 520px); text-align: center; pointer-events: none;
}
#banner {
    position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) rotate(-3deg);
    font-family: var(--serif); font-size: clamp(64px, 16vw, 150px); letter-spacing: 0.08em; color: var(--red);
    border: 6px double var(--red); padding: 0 0.3em; background: rgba(246, 238, 219, 0.82); pointer-events: none; white-space: nowrap;
}
#banner.small { font-size: clamp(26px, 6vw, 44px); padding: 0.15em 0.5em; }
#banner.pop { animation: stamp 0.22s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes stamp { 0% { transform: translate(-50%, -50%) rotate(-3deg) scale(1.9); opacity: 0; } 100% { transform: translate(-50%, -50%) rotate(-3deg) scale(1); opacity: 1; } }

#touch-hints {
    position: absolute; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom));
    display: flex; pointer-events: none; font-family: var(--mono); font-weight: bold; color: var(--ink); opacity: 0.4;
}
.touch-zone { flex: 1; display: flex; justify-content: space-around; align-items: center; height: 64px; font-size: 26px; }
.touch-zone.steer { border-right: 2px dashed rgba(42, 36, 28, 0.5); }
.touch-zone.steer, .touch-zone.pedal { font-size: 16px; letter-spacing: 0.3em; }
#stick {
    position: absolute; left: -68px; top: -26px; width: 136px; height: 52px; border-radius: 26px;
    border: 2px dashed rgba(42, 36, 28, 0.55); background: rgba(246, 238, 219, 0.35); pointer-events: none;
    display: flex; align-items: center; justify-content: center;
}
#stick i { width: 44px; height: 44px; border-radius: 50%; background: var(--red); opacity: 0.8; border: 2px solid var(--ink); }
@media (pointer: coarse) { #chain { bottom: calc(96px + env(safe-area-inset-bottom)); } #coach { bottom: calc(186px + env(safe-area-inset-bottom)); } }

/* ---------- Overlays ---------- */
.overlay {
    position: absolute; inset: 0; z-index: 20; overflow-y: auto; touch-action: pan-y;
    background: rgba(226, 209, 170, 0.8);
    display: flex; justify-content: center; align-items: flex-start;
    padding: calc(20px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
}
.overlay > * { margin: auto; }

.sheet, .card {
    background: var(--paper); border: 3px solid var(--red); outline: 2px solid var(--red); outline-offset: -11px;
    box-shadow: 6px 9px 0 rgba(42, 36, 28, 0.16); padding: 30px 30px 24px; width: 100%;
}
.sheet { max-width: 780px; }
.card { max-width: 480px; text-align: center; animation: drop 0.28s cubic-bezier(0.2, 1.3, 0.4, 1); }
.card.small { max-width: 340px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
@keyframes drop { 0% { transform: translateY(-18px) rotate(-1.5deg); opacity: 0; } 100% { transform: none; opacity: 1; } }

.masthead { text-align: center; margin-bottom: 18px; }
.wordmark { font-weight: normal; font-size: clamp(38px, 9vw, 64px); letter-spacing: 0.24em; color: var(--ink); margin-right: -0.24em; }
.tagline { font-style: italic; font-size: 15px; margin-top: 2px; }
.section-title { font-family: var(--mono); font-size: 11px; letter-spacing: 0.34em; color: var(--red); margin: 20px 0 8px; border-bottom: 1px solid var(--rule); padding-bottom: 5px; }

.daily {
    width: 100%; display: flex; align-items: center; gap: 16px; text-align: left;
    background: var(--red); color: var(--paper); border: none; padding: 14px 18px;
    box-shadow: 3px 4px 0 rgba(42, 36, 28, 0.25); transition: transform 0.08s;
}
.daily:hover, .daily:focus-visible { transform: translate(-1px, -2px) rotate(-0.3deg); outline: 3px solid var(--ink); }
.daily .d-main { flex: 1; min-width: 0; }
.daily .d-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: 0.3em; opacity: 0.85; }
.daily .d-title { font-size: 24px; letter-spacing: 0.06em; }
.daily .d-sub { font-family: var(--mono); font-size: 12px; opacity: 0.9; margin-top: 2px; }
.daily svg { width: 96px; height: 68px; flex: none; filter: url(#sketch); }
.daily svg path:first-child { stroke: var(--paper); }
.daily svg path:last-child { stroke: var(--red); }
.section-title { display: flex; justify-content: space-between; align-items: center; }
.dir-btn { font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em; background: transparent; border: 2px solid var(--red); color: var(--red); padding: 4px 9px; }
.dir-btn:hover, .dir-btn:focus-visible { background: var(--red); color: var(--paper); outline: none; }
.daily .d-go { font-family: var(--mono); font-weight: bold; letter-spacing: 0.2em; border: 2px solid var(--paper); padding: 8px 12px; white-space: nowrap; }

.track-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.track-card {
    display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
    background: var(--cream); border: 2px solid var(--ink); padding: 10px 12px; transition: transform 0.08s;
}
.track-card:hover:not(:disabled), .track-card:focus-visible { transform: translate(-1px, -2px); box-shadow: 3px 5px 0 rgba(42, 36, 28, 0.2); outline: 2px solid var(--red); }
.track-card:disabled { opacity: 0.5; cursor: not-allowed; border-style: dashed; }
.track-card svg { width: 92px; height: 66px; flex: none; }
.t-main { flex: 1; min-width: 0; }
.t-name { font-size: 19px; color: var(--ink); letter-spacing: 0.04em; }
.t-blurb { font-size: 12.5px; font-style: italic; }
.t-pace { font-family: var(--mono); font-size: 10px; letter-spacing: 0.2em; margin-top: 3px; }
.pace { display: inline-flex; gap: 2px; vertical-align: middle; margin-left: 4px; }
.pace i { width: 9px; height: 5px; background: rgba(42, 36, 28, 0.18); }
.pace i.on { background: var(--red); }
.t-best { font-family: var(--mono); font-size: 12px; margin-top: 4px; color: var(--ink); }
.pips { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.pip { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); background: transparent; }
.pip.m1 { background: #b0703c; } .pip.m2 { background: #b9b4a6; } .pip.m3 { background: #d9a520; } .pip.m4 { background: #dfe9ee; } .pip.m5 { background: #7fd3e6; }

.menu-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.controls { font-family: var(--mono); font-size: 12px; line-height: 1.6; flex: 1; min-width: 220px; }
.controls b { color: var(--ink); }

.btn {
    font-family: var(--mono); font-weight: bold; letter-spacing: 0.2em; font-size: 14px;
    background: var(--red); color: var(--paper); border: 2px solid var(--red); padding: 11px 18px; transition: transform 0.08s;
}
.btn:hover, .btn:focus-visible { transform: translate(-1px, -2px); box-shadow: 3px 4px 0 rgba(42, 36, 28, 0.25); outline: none; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.outline { background: transparent; color: var(--red); }
.btn.quiet { background: transparent; color: var(--graphite); border-color: var(--rule); font-size: 11px; padding: 8px 12px; }

.stamp { display: inline-block; border: 3px solid var(--red); padding: 4px 20px; transform: rotate(-1.5deg); }
.stamp h2 { font-weight: normal; font-size: clamp(26px, 7vw, 38px); letter-spacing: 0.22em; color: var(--red); margin-right: -0.22em; }
.hint { font-size: 12px; font-style: italic; opacity: 0.8; margin-top: 12px; }

.result-head { display: flex; justify-content: center; align-items: center; gap: 16px; flex-wrap: wrap; }
.medal {
    width: 74px; height: 74px; border-radius: 50%; border: 3px double var(--ink); display: flex; align-items: center; justify-content: center;
    font-family: var(--mono); font-weight: bold; font-size: 11px; letter-spacing: 0.12em; color: var(--ink); transform: rotate(9deg);
    animation: stampin 0.35s 0.5s cubic-bezier(0.2, 1.7, 0.4, 1) backwards;
}
.medal.m1 { background: #c98a55; } .medal.m2 { background: #cfcabb; } .medal.m3 { background: #e4b635; }
.medal.m4 { background: #e3ecf0; font-size: 9px; letter-spacing: 0.06em; box-shadow: 0 0 0 3px #b9c7cf; }
.medal.m5 { background: #8fdcee; font-size: 10px; letter-spacing: 0.08em; box-shadow: 0 0 0 3px #2a241c, 0 0 0 6px #8fdcee; }
@keyframes stampin { 0% { transform: rotate(9deg) scale(2.4); opacity: 0; } 100% { transform: rotate(9deg) scale(1); opacity: 1; } }
.res-track { font-family: var(--mono); font-size: 11px; letter-spacing: 0.26em; margin-top: 12px; text-transform: uppercase; }
.res-score-row { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 2px; }
.res-score { font-family: var(--mono); font-weight: bold; font-size: clamp(44px, 12vw, 62px); color: var(--ink); font-variant-numeric: tabular-nums; }
.badge { background: var(--red); color: var(--paper); font-family: var(--mono); font-weight: bold; font-size: 11px; letter-spacing: 0.18em; padding: 4px 8px; transform: rotate(-4deg); }
.res-next { font-family: var(--mono); font-size: 12.5px; min-height: 18px; color: var(--ink); }
.print { width: 100%; height: auto; margin: 12px 0 8px; background: var(--kraft); border: 1px solid var(--rule); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; text-align: left; }
.stats div { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.stats b { font-family: var(--mono); color: var(--ink); }
.unlock { margin-top: 12px; font-family: var(--mono); font-weight: bold; letter-spacing: 0.12em; color: var(--red); border: 2px dashed var(--red); padding: 7px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

@media (max-width: 560px) {
    .sheet, .card { padding: 24px 20px 20px; outline-offset: -8px; }
    .hud-box { min-width: 86px; padding: 4px 9px 5px; }
    .hud-value { font-size: 22px; }
    .hud-track { font-size: 10px; letter-spacing: 0.18em; }
    .daily { flex-wrap: wrap; }
    .daily .d-title { font-size: 20px; }
    .track-list { grid-template-columns: 1fr; }
    .help-cols { grid-template-columns: 1fr; }
    .print { max-height: 170px; object-fit: contain; }
    .btn { padding: 10px 13px; font-size: 13px; }
}
@media (max-height: 520px) {
    /* Short, wide screens (a phone on its side): the car sits in the middle
       band, so everything else hugs the top and bottom edges. */
    .print { display: none; }
    #banner { top: 30%; font-size: clamp(48px, 20vh, 110px); }
    #chain { bottom: calc(8px + env(safe-area-inset-bottom)); padding: 3px 12px 4px; }
    #chain-pts { font-size: 19px; }
    #coach { bottom: auto; top: calc(62px + env(safe-area-inset-top)); font-size: 12px; padding: 5px 10px; }
    #touch-hints { bottom: calc(4px + env(safe-area-inset-bottom)); }
    .touch-zone { height: 44px; }
    .hud-box { padding: 3px 9px 4px; min-width: 84px; }
    .hud-value { font-size: 21px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (pointer: coarse) { .hint { display: none; } }
.hs .bd-title { font-family: var(--mono); font-size: 10px; letter-spacing: 0.24em; color: var(--red); }
