/* OCR Buddy: the game. The look follows the app prototype: blue bar + orange line, slanted Barlow
   Condensed caps, glass cards on the dark, orange for the one next step. */
@font-face { font-family: Barlow; font-weight: 400; src: url(fonts/barlow-400.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Barlow; font-weight: 600; src: url(fonts/barlow-600.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: Barlow; font-weight: 700; src: url(fonts/barlow-700.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; src: url(fonts/barlow-condensed-700.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-style: italic; src: url(fonts/barlow-condensed-700-italic.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Barlow Condensed"; font-weight: 800; font-style: italic; src: url(fonts/barlow-condensed-800-italic.woff2) format("woff2"); font-display: swap; }

:root {
  color-scheme: dark;
  --bg: #0b131c; --text: #fff; --muted: rgba(255, 255, 255, .7); --line: rgba(255, 255, 255, .16);
  --brand: #2bb0ee; --accent: #ff9208; --glass: rgba(10, 20, 30, .72);
  --font: Barlow, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --head: "Barlow Condensed", "Arial Narrow", Barlow, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; touch-action: none; }
[hidden] { display: none !important; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
input { font: inherit; user-select: text; -webkit-user-select: text; }

/* --- menus --- */
#menu { position: fixed; inset: 0; display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); overflow-y: auto; touch-action: pan-y; pointer-events: none; }
.card { pointer-events: auto; width: min(100%, 25rem); padding: 22px 20px 18px; background: var(--glass); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 14px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; gap: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.logo { width: 150px; height: auto; justify-self: center; filter: drop-shadow(0 3px 10px rgba(21, 131, 198, .8)); }
h1, h2 { font-family: var(--head); font-style: italic; font-weight: 800; text-transform: uppercase; margin: 0; line-height: 1; }
h1 { font-size: 2.6rem; text-align: center; color: var(--accent); letter-spacing: .02em; margin-top: -6px; }
h2 { font-size: 1.7rem; }
.lead { margin: 0; color: var(--muted); text-align: center; font-size: .98rem; }
.field { display: grid; gap: 6px; }
.field > span { font-family: var(--head); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: .82rem; color: var(--brand); }
input { width: 100%; height: 48px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .08); color: #fff; font-size: 16px; font-weight: 600; outline: none; }
input:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches button { aspect-ratio: 1; min-height: 34px; border-radius: 50%; border: 3px solid transparent; background: var(--c); }
.swatches button[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--bg) inset; }
.swatches button:disabled { opacity: .25; cursor: default; }
.go, .alt { height: 54px; border-radius: 10px; font-family: var(--head); font-style: italic; font-weight: 800; text-transform: uppercase; font-size: 1.45rem; letter-spacing: .03em; transform: skewX(-6deg); }
.go { background: var(--accent); color: #0b131c; box-shadow: 0 6px 0 #b76400; }
.go:active { transform: skewX(-6deg) translateY(4px); box-shadow: 0 2px 0 #b76400; }
.alt { background: rgba(255, 255, 255, .1); border: 1px solid var(--line); }
.alt.small { height: 42px; font-size: 1.1rem; }
.go:disabled { opacity: .5; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: var(--head); font-size: 1.4rem; height: 54px; }
.join .alt { padding: 0 22px; }
.link { background: none; color: var(--muted); text-decoration: underline; padding: 8px; justify-self: center; min-height: 40px; }
.err { margin: 0; color: #ffb4ab; text-align: center; font-weight: 600; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.code { font-family: var(--head); font-weight: 800; font-style: italic; font-size: 1.9rem; letter-spacing: .14em; background: #fff; color: #0b131c; padding: 2px 12px; border-radius: 6px; border-top: 6px solid var(--accent); }
.racers, .results { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 38vh; overflow-y: auto; }
.racers li, .results li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: rgba(255, 255, 255, .07); border-radius: 8px; font-weight: 600; }
.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--c); flex: none; }
.tagc { margin-left: auto; font-family: var(--head); font-weight: 700; font-size: .85rem; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.results .pl { font-family: var(--head); font-style: italic; font-weight: 800; font-size: 1.3rem; width: 2.2rem; color: var(--accent); }
.results .tm { margin-left: auto; font-variant-numeric: tabular-nums; font-family: var(--head); font-weight: 700; font-size: 1.15rem; }
.results li.me { outline: 2px solid var(--accent); }
.pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pills button { height: 44px; border-radius: 8px; background: rgba(255, 255, 255, .08); border: 1px solid var(--line); font-family: var(--head); font-weight: 700; text-transform: uppercase; font-size: 1.05rem; transform: skewX(-6deg); }
.pills button small { display: block; font-size: .7rem; color: var(--muted); font-weight: 700; margin-top: -2px; }
.pills button[aria-pressed="true"] { background: var(--brand); color: #0b131c; border-color: transparent; }
.pills button[aria-pressed="true"] small { color: #0b131c; }
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 44px; height: 44px; border-radius: 8px; background: rgba(255, 255, 255, .1); border: 1px solid var(--line); font-size: 1.5rem; font-weight: 700; }
.stepper b { font-family: var(--head); font-size: 1.6rem; min-width: 1.5ch; text-align: center; }

/* --- in the race --- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top { position: absolute; top: calc(8px + var(--safe-t)); left: 10px; right: 10px; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.place, .clock { background: var(--glass); border-radius: 8px; padding: 4px 12px; font-family: var(--head); font-style: italic; font-weight: 800; transform: skewX(-6deg); border-bottom: 3px solid var(--accent); }
.place b { font-size: 1.9rem; }
.place span { font-size: 1rem; color: var(--muted); margin-left: 4px; }
.clock { font-size: 1.5rem; font-variant-numeric: tabular-nums; min-width: 5.2ch; text-align: right; }
.track { position: relative; height: 12px; border-radius: 6px; background: rgba(10, 20, 30, .6); border: 1px solid var(--line); }
.track .tick { position: absolute; top: 2px; bottom: 2px; width: 2px; background: rgba(255, 255, 255, .4); }
.track .fin { position: absolute; right: -2px; top: -4px; bottom: -4px; width: 5px; background: repeating-linear-gradient(#fff 0 4px, #111 4px 8px); }
.track .r { position: absolute; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--c); border: 2px solid #0b131c; transition: left .2s linear; }
.track .r.me { width: 18px; height: 18px; margin: -9px 0 0 -9px; border-color: #fff; z-index: 2; }
.prompt { position: absolute; top: calc(64px + var(--safe-t)); left: 50%; transform: translateX(-50%) skewX(-6deg); background: var(--glass); border-left: 4px solid var(--accent); padding: 6px 16px 7px; border-radius: 6px; text-align: center; max-width: calc(100% - 24px); }
.prompt b { display: block; font-family: var(--head); font-style: italic; font-weight: 800; font-size: 1.5rem; text-transform: uppercase; line-height: 1.05; }
.prompt span { font-size: .95rem; color: #cfeaf8; font-weight: 600; }
.meter { position: absolute; left: 50%; bottom: calc(31% + var(--safe-b)); transform: translateX(-50%); width: min(78vw, 22rem); text-align: center; }
.meter-label { font-family: var(--head); font-style: italic; font-weight: 800; font-size: 1.35rem; text-transform: uppercase; text-shadow: 0 2px 6px #000; margin-bottom: 4px; }
.meter-bar { position: relative; height: 22px; border-radius: 6px; background: rgba(10, 20, 30, .8); border: 2px solid #fff; overflow: hidden; }
.meter-bar .zone { position: absolute; top: 0; bottom: 0; left: 35%; width: 30%; background: var(--accent); }
.meter-bar .mark { position: absolute; top: -2px; bottom: -2px; width: 6px; margin-left: -3px; background: #fff; box-shadow: 0 0 6px #000; }
.meter-bar .fill { position: absolute; top: 0; bottom: 0; left: 0; background: var(--brand); }
.big { position: absolute; left: 0; right: 0; top: 24%; text-align: center; font-family: var(--head); font-style: italic; font-weight: 800; font-size: clamp(4.5rem, 22vw, 10rem); line-height: 1; color: #fff; text-shadow: 0 6px 0 var(--accent), 0 10px 30px rgba(0, 0, 0, .6); }
.big.pop { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(1.7); opacity: 0; } }
.toast { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font-family: var(--head); font-style: italic; font-weight: 800; font-size: clamp(1.8rem, 8vw, 3rem); text-transform: uppercase; color: var(--accent); text-shadow: 0 3px 0 #0b131c, 0 0 18px rgba(0, 0, 0, .7); opacity: 0; }
.toast.show { animation: toast 1.4s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: translateY(14px) scale(.8); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; transform: translateY(-16px); } }
.keys { position: absolute; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); background: var(--glass); border-radius: 8px; padding: 8px 14px; font-weight: 600; font-size: .95rem; text-align: center; max-width: calc(100% - 24px); }
.keys kbd { font: inherit; font-family: var(--head); font-weight: 700; background: #fff; color: #0b131c; border-radius: 4px; padding: 0 6px; margin: 0 2px; }
.done { position: absolute; left: 50%; top: 30%; transform: translateX(-50%) skewX(-6deg); background: var(--glass); border-left: 6px solid var(--accent); border-radius: 8px; padding: 12px 26px; text-align: center; }
.done b { display: block; font-family: var(--head); font-style: italic; font-weight: 800; font-size: 3rem; line-height: 1; text-transform: uppercase; }
.done span { font-family: var(--head); font-weight: 700; font-size: 1.5rem; color: var(--accent); font-variant-numeric: tabular-nums; }

/* --- touch controls --- */
#stick { position: fixed; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5); background: rgba(10, 20, 30, .3); pointer-events: none; }
#nub { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 255, 255, .85); }
.pad { position: fixed; right: calc(18px + env(safe-area-inset-right, 0px)); bottom: calc(26px + var(--safe-b)); width: 96px; height: 96px; border-radius: 50%; background: var(--accent); color: #0b131c; font-family: var(--head); font-style: italic; font-weight: 800; font-size: 1.5rem; box-shadow: 0 6px 0 #b76400; touch-action: none; }
#btnCrawl { right: calc(126px + env(safe-area-inset-right, 0px)); bottom: calc(16px + var(--safe-b)); width: 78px; height: 78px; font-size: 1.15rem; background: var(--brand); box-shadow: 0 6px 0 #1165a1; }
.pad.down { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .5) !important; filter: brightness(1.15); }
body:not(.touch) .pad, body:not(.racing) .pad { display: none; }
.chip-btn { position: fixed; top: calc(52px + var(--safe-t)); right: 10px; height: 30px; padding: 0 10px; border-radius: 6px; background: var(--glass); border: 1px solid var(--line); font-family: var(--head); font-weight: 700; font-size: .8rem; letter-spacing: .08em; color: var(--muted); }
#btnLeave { right: auto; left: 10px; }
body:not(.racing) #btnMute { top: calc(10px + var(--safe-t)); }

@media (max-height: 480px) and (orientation: landscape) {
  .card { padding: 12px 16px; gap: 8px; }
  .logo { width: 96px; } h1 { font-size: 1.8rem; }
  .prompt { top: calc(50px + var(--safe-t)); }
  .big { top: 14%; font-size: 5rem; }
}
@media (prefers-reduced-motion: reduce) { .big.pop, .toast.show { animation-duration: .01s; } .toast.show { opacity: 1; } }
