/* POLOMANIA — cartoony UI. Sizes are in rem; the root font-size scales with the viewport. */
@font-face { font-family: "Lilita One"; src: url("../fonts/LilitaOne.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Fredoka"; src: url("../fonts/Fredoka.woff2") format("woff2"); font-weight: 300 700; font-display: swap; }

:root {
  --ink: #0b1030; --navy: #141d4d; --blue: #2a6fe8; --sky: #58b7ff; --yellow: #ffd23f; --red: #d93a31; --green: #37c871; --slate: #6170b0;
  --paper: #fffdf5; --muted: #a9b6e8;
  --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --text: "Fredoka", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
html { font-size: clamp(10px, min(1.5vw, 2.35vh), 18px); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #8fd0ff; color: #fff; font-family: var(--text); -webkit-tap-highlight-color: transparent; }
body { user-select: none; -webkit-user-select: none; touch-action: manipulation; overscroll-behavior: none; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
input { font: inherit; }

/* ── building blocks ─────────────────────────────────────────── */
.screen { position: fixed; inset: 0; pointer-events: none; padding: max(1rem, env(safe-area-inset-top)) max(1.2rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1.2rem, env(safe-area-inset-left)); }
.screen > *, .screen .panel, .screen .btn { pointer-events: auto; }
.panel {
  background: linear-gradient(180deg, rgba(27, 39, 98, 0.95), rgba(15, 22, 60, 0.95));
  border: 0.2rem solid var(--ink); border-radius: 1.2rem;
  box-shadow: 0 0.4rem 0 rgba(8, 12, 36, 0.5), inset 0 0.12rem 0 rgba(255, 255, 255, 0.1);
  padding: 1rem 1.1rem;
}
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 1.5rem; margin: 0 0 0.6rem; letter-spacing: 0.03em; color: var(--yellow); text-shadow: 0 0.14rem 0 var(--ink); }
.btn {
  --bg: #fff; --shade: #b9bfd6; --fg: var(--ink);
  font-family: var(--display); font-size: 1.15rem; letter-spacing: 0.02em; line-height: 1.1;
  background: var(--bg); color: var(--fg); border: 0.2rem solid var(--ink); border-radius: 0.95rem;
  padding: 0.55em 1em; cursor: pointer; box-shadow: 0 0.32rem 0 var(--shade), 0 0.5rem 0 rgba(8, 12, 36, 0.35);
  transition: transform 0.06s, box-shadow 0.06s, filter 0.1s; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); transform: translateY(-0.06rem); }
.btn:active { transform: translateY(0.28rem); box-shadow: 0 0.04rem 0 var(--shade), 0 0.12rem 0 rgba(8, 12, 36, 0.35); }
.btn:focus-visible, .arrow:focus-visible, .toggle:focus-visible, input:focus-visible { outline: 0.2rem solid var(--yellow); outline-offset: 0.15rem; }
.btn[disabled] { filter: grayscale(0.8) brightness(0.8); cursor: not-allowed; }
.btn.yellow { --bg: var(--yellow); --shade: #c4950c; }
.btn.blue { --bg: var(--blue); --shade: #1b4fb0; --fg: #fff; }
.btn.green { --bg: var(--green); --shade: #1c8a49; --fg: #06301a; }
.btn.red { --bg: var(--red); --shade: #9c221b; --fg: #fff; }
.btn.big { font-size: 1.5rem; padding: 0.5em 1em; }
.btn.small { font-size: 0.95rem; padding: 0.45em 0.8em; border-radius: 0.8rem; }
.btn small { display: block; font-family: var(--text); font-weight: 500; font-size: 0.8rem; opacity: 0.8; letter-spacing: 0; margin-top: 0.1em; }
.btn.blue small { opacity: 1; }
.hint { font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0 0; line-height: 1.35; }

/* ── title ───────────────────────────────────────────────────── */
.title-col { position: absolute; left: max(2.2rem, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%); width: 23rem; display: flex; flex-direction: column; gap: 0.8rem; }
.logo { font-family: var(--display); font-weight: 400; font-size: 5.2rem; line-height: 0.86; margin: 0 0 0.3rem; transform: rotate(-4deg); transform-origin: left center; letter-spacing: 0.01em; filter: drop-shadow(0 0.5rem 0 rgba(8, 12, 36, 0.45)); }
.logo span { display: block; -webkit-text-stroke: 0.7rem var(--ink); paint-order: stroke fill; }
.logo span:first-child { color: var(--yellow); }
.logo span:last-child { color: #fff; margin-left: 1.1rem; }
.tagline { font-family: var(--display); font-size: 1.25rem; margin: 0 0 0.3rem 0.3rem; color: #fff; -webkit-text-stroke: 0.3rem var(--ink); paint-order: stroke fill; transform: rotate(-4deg); transform-origin: left center; }
.title-panel { display: flex; flex-direction: column; gap: 0.7rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; font-size: 0.9rem; color: var(--muted); }
.field input, .join-row input, .invite input {
  background: var(--paper); color: var(--ink); border: 0.2rem solid var(--ink); border-radius: 0.8rem; padding: 0.5em 0.7em;
  font-family: var(--display); font-size: 1.25rem; width: 100%; user-select: text; -webkit-user-select: text; min-width: 0;
}
.join-row { display: flex; gap: 0.5rem; }
.join-row input { width: 7.2rem; text-align: center; letter-spacing: 0.18em; text-transform: uppercase; flex: none; }
.join-row .btn { flex: 1; }
.form-error { min-height: 1.1em; margin: 0; color: #ffb3ad; font-weight: 600; font-size: 0.9rem; }
.mini-row { display: flex; gap: 0.6rem; }
.car-card { position: absolute; right: max(2.2rem, env(safe-area-inset-right)); bottom: 3.2rem; width: 19rem; text-align: center; }
.cc-label { font-size: 0.85rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.cc-name { font-family: var(--display); font-size: 1.7rem; line-height: 1.05; margin-top: 0.15rem; }
.cc-sub { color: var(--muted); font-weight: 500; margin-bottom: 0.7rem; }
.disclaimer { position: absolute; left: 50%; bottom: 0.5rem; transform: translateX(-50%); margin: 0; font-size: 0.75rem; color: #fff; font-weight: 600; pointer-events: none; white-space: nowrap; background: rgba(11, 16, 48, 0.72); padding: 0.18rem 0.75rem; border-radius: 0.6rem; }

/* ── lobby ───────────────────────────────────────────────────── */
#scr-lobby { display: flex; flex-direction: column; gap: 0.8rem; }
.lobby-top { display: flex; gap: 0.8rem; align-items: stretch; }
.room-code, .invite { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 0.9rem; }
.room-code b { font-family: var(--display); font-size: 2.2rem; letter-spacing: 0.14em; color: var(--yellow); text-shadow: 0 0.16rem 0 var(--ink); user-select: text; -webkit-user-select: text; }
.rc-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.invite { flex: 1; min-width: 0; }
.invite input { font-family: var(--text); font-weight: 600; font-size: 0.95rem; flex: 1; padding: 0.4em 0.6em; }
.lobby-top > .btn { align-self: center; }
.lobby-main { flex: 1; min-height: 0; display: flex; justify-content: space-between; gap: 1rem; pointer-events: none; }
.lobby-players, .lobby-settings { width: 23rem; max-height: 100%; overflow: auto; align-self: flex-start; }
.plist { display: flex; flex-direction: column; gap: 0.4rem; }
.prow { display: flex; align-items: center; gap: 0.55rem; background: rgba(255, 255, 255, 0.07); border-radius: 0.8rem; padding: 0.4rem 0.55rem; border: 0.14rem solid transparent; }
.prow.me { border-color: var(--yellow); background: rgba(255, 210, 63, 0.12); }
.pdot { width: 1.5rem; height: 1.5rem; border-radius: 50%; border: 0.18rem solid var(--ink); flex: none; box-shadow: inset 0 0.15rem 0 rgba(255, 255, 255, 0.35); }
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcar { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ppts { font-family: var(--display); font-size: 1.1rem; color: var(--yellow); text-align: right; line-height: 1; }
.ppts small { display: block; font-family: var(--text); font-size: 0.65rem; color: var(--muted); font-weight: 600; }
.badge { font-family: var(--display); font-size: 0.72rem; padding: 0.12em 0.5em; border-radius: 0.5rem; background: var(--yellow); color: var(--ink); margin-left: 0.35rem; vertical-align: 0.1em; }
.badge.grey { background: var(--slate); color: #fff; }
.kick { background: none; border: none; color: #ff9d97; cursor: pointer; font-size: 1.1rem; padding: 0 0.2rem; }
.ls-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin-bottom: 0.5rem; }
.ls-head h2 { margin: 0; }
.seg { display: flex; gap: 0.4rem; flex: 1; max-width: 13.5rem; }
.seg-btn { flex: 1; font-family: var(--display); font-size: 1.05rem; line-height: 1.1; padding: 0.32em 0.6em; border-radius: 0.7rem; border: 0.18rem solid var(--ink); background: var(--slate); color: #fff; cursor: pointer; box-shadow: 0 0.22rem 0 #434f8f; }
.seg-btn.on { background: var(--yellow); color: var(--ink); box-shadow: 0 0.22rem 0 #c4950c; }
.seg-btn:active { transform: translateY(0.2rem); box-shadow: none; }
.seg-btn:focus-visible { outline: 0.2rem solid var(--yellow); outline-offset: 0.15rem; }
.guest .seg-btn { pointer-events: none; box-shadow: none; }
.guest .seg-btn:not(.on) { opacity: 0.4; }
.track-pick { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.6rem; }
.track-info { flex: 1; text-align: center; min-width: 0; }
/* the track picture with the circuit outline as an inset; a cup shows its four tracks as a 2×2 grid with the outlines on top */
.ti-pic { position: relative; width: 100%; max-width: 15.5rem; aspect-ratio: 16 / 9; margin: 0 auto 0.3rem; border-radius: 0.8rem; overflow: hidden; background: linear-gradient(#5fb4ff, #9fe0a0); border: 3px solid rgba(11, 16, 48, 0.85); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); }
.ti-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; }
.ti-pic img.flip { transform: scaleX(-1); }
.ti-pic canvas { position: absolute; right: 0.3rem; bottom: 0.3rem; width: 38%; aspect-ratio: 200 / 130; height: auto; border-radius: 0.55rem; background: rgba(11, 16, 48, 0.55); }
.ti-pic.nopic canvas { right: auto; bottom: auto; left: 50%; top: 50%; width: 62%; transform: translate(-50%, -50%); background: none; }
.ti-pic.cup { aspect-ratio: 200 / 130; }
.ti-pic.cup canvas { inset: 0; width: 100%; height: 100%; background: none; border-radius: 0; }
.ti-cup { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; background: rgba(11, 16, 48, 0.85); }
.ti-cup img { position: static; min-width: 0; min-height: 0; filter: brightness(0.82); }
.ti-cup.one { grid-template-columns: 1fr; grid-template-rows: 1fr; gap: 0; background: none; }
.ti-cup.one img { filter: none; }
.ti-name { font-family: var(--display); font-size: 1.3rem; line-height: 1.1; }
.ti-facts { font-size: 0.76rem; font-weight: 700; color: var(--yellow); line-height: 1.3; margin: 0.12rem 0; }
.ti-desc { font-size: 0.8rem; color: var(--muted); line-height: 1.3; min-height: 2.6em; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; }
.pcups { font-family: var(--text); font-size: 0.78rem; vertical-align: 0.12em; }
.arrow { font-family: var(--display); width: 2.5rem; height: 2.5rem; border-radius: 0.75rem; border: 0.18rem solid var(--ink); background: var(--yellow); color: var(--ink); cursor: pointer; font-size: 1.1rem; box-shadow: 0 0.22rem 0 #c4950c; flex: none; }
.arrow:active { transform: translateY(0.2rem); box-shadow: none; }
.arrow.sm { width: 2rem; height: 2rem; font-size: 1rem; border-radius: 0.6rem; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 0.32rem 0; border-top: 0.1rem solid rgba(255, 255, 255, 0.09); font-weight: 600; }
.set-row.two { gap: 1rem; }
.set-row .half { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; min-width: 0; }
.set-row .half .stepper { gap: 0.3rem; }
.set-row .half .stepper b { min-width: 1.5rem; }
.set-row .half .toggle { min-width: 3.6rem; }
.stepper { display: flex; align-items: center; gap: 0.5rem; }
.stepper b { font-family: var(--display); font-weight: 400; font-size: 1.2rem; min-width: 4.6rem; text-align: center; }
.toggle { font-family: var(--display); font-size: 1.05rem; min-width: 4.6rem; padding: 0.25em 0.7em; border-radius: 0.7rem; border: 0.18rem solid var(--ink); background: var(--green); color: #06301a; cursor: pointer; box-shadow: 0 0.22rem 0 #1c8a49; }
.toggle.off { background: var(--slate); color: #fff; box-shadow: 0 0.22rem 0 #434f8f; }
.toggle.wide { min-width: 8.6rem; }
.guest .arrow, .guest .toggle { visibility: hidden; }
.guest .toggle { visibility: visible; pointer-events: none; box-shadow: none; }
.lobby-bottom { display: flex; justify-content: center; align-items: center; gap: 1rem; flex-wrap: wrap; }
.wait-msg { font-family: var(--display); font-size: 1.2rem; -webkit-text-stroke: 0.28rem var(--ink); paint-order: stroke fill; }
.wait-msg:empty { display: none; }

/* ── garage ──────────────────────────────────────────────────── */
#scr-garage { display: flex; flex-direction: column; gap: 0.7rem; }
.gen-tabs { display: flex; justify-content: center; gap: 0.45rem; flex-wrap: wrap; }
.gen-tab { font-family: var(--display); background: rgba(15, 22, 60, 0.92); color: #fff; border: 0.18rem solid var(--ink); border-radius: 0.9rem; padding: 0.35rem 0.9rem; cursor: pointer; font-size: 1.25rem; line-height: 1; box-shadow: 0 0.25rem 0 rgba(8, 12, 36, 0.5); pointer-events: auto; }
.gen-tab small { display: block; font-family: var(--text); font-size: 0.68rem; font-weight: 600; color: var(--muted); margin-top: 0.15rem; }
.gen-tab.on { background: var(--yellow); color: var(--ink); }
.gen-tab.on small { color: #6b5200; }
.garage-main { flex: 1; min-height: 0; display: flex; justify-content: space-between; gap: 1rem; pointer-events: none; }
.garage-list { width: 19.5rem; overflow: auto; max-height: 100%; align-self: flex-start; display: flex; flex-direction: column; gap: 0.4rem; }
.gen-blurb { font-size: 0.85rem; color: var(--muted); line-height: 1.35; margin: 0 0 0.3rem; }
.vcard { text-align: left; background: rgba(255, 255, 255, 0.07); border: 0.16rem solid transparent; border-radius: 0.8rem; padding: 0.45rem 0.6rem; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; color: #fff; }
.vcard:hover { background: rgba(255, 255, 255, 0.13); }
.vcard.on { border-color: var(--yellow); background: rgba(255, 210, 63, 0.16); }
.vcard .vn { font-weight: 700; font-size: 1rem; line-height: 1.15; }
.vcard .vs { font-size: 0.78rem; color: var(--muted); }
.vcard .vp { margin-left: auto; font-family: var(--display); font-size: 1rem; white-space: nowrap; text-align: right; }
.cls { display: inline-block; font-family: var(--display); width: 1.5rem; height: 1.5rem; line-height: 1.38rem; text-align: center; border-radius: 0.45rem; border: 0.14rem solid var(--ink); color: var(--ink); font-size: 0.85rem; flex: none; }
.cls.D { background: #b9c2d8; } .cls.C { background: #7fe08c; } .cls.B { background: #6cc4ff; } .cls.A { background: #c79bff; } .cls.S { background: #ffd23f; }
.garage-mid { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.drag-hint { font-size: 0.8rem; font-weight: 600; color: #fff; background: rgba(11, 16, 48, 0.6); padding: 0.14rem 0.7rem; border-radius: 0.6rem; margin-bottom: 0.2rem; }
.garage-spec { width: 22.5rem; overflow: auto; max-height: 100%; align-self: flex-start; }
.spec-name { font-family: var(--display); font-size: 1.75rem; line-height: 1.02; }
.spec-sub { color: var(--muted); font-weight: 600; margin: 0.15rem 0 0.5rem; font-size: 0.92rem; }
.spec-grid { display: grid; grid-template-columns: auto 1fr; gap: 0.16rem 0.8rem; font-size: 0.9rem; margin-bottom: 0.6rem; }
.spec-grid dt { color: var(--muted); font-weight: 600; }
.spec-grid dd { margin: 0; font-weight: 600; }
.bars { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.6rem; align-items: center; font-size: 0.8rem; font-weight: 700; color: var(--muted); margin-bottom: 0.6rem; }
.bar { height: 0.75rem; background: rgba(255, 255, 255, 0.12); border-radius: 0.5rem; overflow: hidden; border: 0.12rem solid var(--ink); }
.bar i { display: block; height: 100%; border-radius: 0.4rem; background: linear-gradient(90deg, #36d6ff, #7dff8a 60%, #ffe14a); transition: width 0.25s; }
.fact { font-size: 0.86rem; line-height: 1.4; background: rgba(255, 255, 255, 0.08); border-radius: 0.7rem; padding: 0.5rem 0.65rem; margin: 0 0 0.6rem; }
.swatches { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.swatch { width: 2rem; height: 2rem; border-radius: 50%; border: 0.18rem solid var(--ink); cursor: pointer; box-shadow: inset 0 0.2rem 0 rgba(255, 255, 255, 0.35); padding: 0; }
.swatch.on { outline: 0.22rem solid var(--yellow); outline-offset: 0.12rem; }
.color-name { font-size: 0.82rem; color: var(--muted); font-weight: 600; margin: 0.35rem 0 0; min-height: 1.2em; }
.garage-bottom { display: flex; justify-content: center; gap: 1rem; }

/* ── results ─────────────────────────────────────────────────── */
#scr-results { display: flex; align-items: center; justify-content: center; background: rgba(8, 12, 36, 0.35); }
.results-panel { width: min(46rem, 96vw); max-height: 96%; overflow: auto; }
.rtable { display: flex; flex-direction: column; gap: 0.3rem; }
.rrow { display: grid; grid-template-columns: 2.4rem 1.6rem 1fr 7rem 6rem 3.2rem; align-items: center; gap: 0.5rem; background: rgba(255, 255, 255, 0.07); border-radius: 0.75rem; padding: 0.35rem 0.6rem; animation: rowin 0.35s both; }
.rrow.me { background: rgba(255, 210, 63, 0.18); outline: 0.14rem solid var(--yellow); }
.rrow.head { background: none; font-size: 0.72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; padding-top: 0; padding-bottom: 0; animation: none; }
.rrow.cup { grid-template-columns: 2.4rem 1.6rem 1fr 5.2rem 3.4rem; }
.results-sub { margin: -0.35rem 0 0.6rem; color: var(--muted); font-weight: 600; font-size: 0.95rem; }
.results-sub:empty { display: none; }
.results-sub b { color: #fff; }
#scr-results.podium { justify-content: flex-end; background: none; padding-right: max(2.2rem, env(safe-area-inset-right)); }
#scr-results.podium .results-panel { width: min(30rem, 96vw); }
.rpos { font-family: var(--display); font-size: 1.5rem; text-align: center; }
.rrow:nth-child(2) .rpos { color: #ffd23f; } .rrow:nth-child(3) .rpos { color: #d7dcea; } .rrow:nth-child(4) .rpos { color: #e2a069; }
.rname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rname small { display: block; font-weight: 500; font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.rtime, .rbest { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; font-size: 0.95rem; }
.rbest { color: var(--muted); }
.rpts { font-family: var(--display); color: var(--yellow); text-align: right; font-size: 1.15rem; }
@keyframes rowin { from { opacity: 0; transform: translateX(-1.2rem); } }
.champ { margin: 0.7rem 0; font-size: 0.9rem; font-weight: 600; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; }
.champ b { color: #fff; }
.results-btns { display: flex; align-items: center; justify-content: flex-end; gap: 0.7rem; flex-wrap: wrap; }
.results-btns .btn.red { margin-right: auto; }

/* ── modal / loading / toasts ────────────────────────────────── */
#modal { position: fixed; inset: 0; background: rgba(8, 12, 36, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal-box { width: min(34rem, 96vw); max-height: 94vh; overflow: auto; }
.modal-box p { line-height: 1.45; margin: 0.4rem 0; }
.modal-btns { display: flex; gap: 0.7rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
.modal-col { display: flex; flex-direction: column; gap: 0.7rem; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.35rem 0; font-weight: 600; }
.srow input[type="range"] { width: 12rem; accent-color: var(--yellow); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 0.35rem 0.9rem; font-size: 0.95rem; align-items: center; }
kbd { font-family: var(--display); background: var(--paper); color: var(--ink); border-radius: 0.45rem; padding: 0.1em 0.5em; border: 0.14rem solid var(--ink); box-shadow: 0 0.16rem 0 #b9bfd6; font-size: 0.9em; white-space: nowrap; }
.tips { margin: 0.6rem 0 0; padding-left: 1.1rem; font-size: 0.9rem; line-height: 1.38; }
.modal-box.wide { width: min(58rem, 96vw); }
.help-cols { display: grid; grid-template-columns: 1.15fr 1fr; gap: 0.4rem 1.6rem; align-items: start; }
.help-cols .keys { font-size: 0.9rem; gap: 0.3rem 0.8rem; }
.help-cols .tips { font-size: 0.85rem; line-height: 1.34; }
.item-help { display: grid; grid-template-columns: 2rem 1fr; gap: 0.3rem 0.6rem; align-items: center; font-size: 0.85rem; line-height: 1.22; }
.item-help svg { width: 2rem; height: 2rem; }
#loading { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: linear-gradient(180deg, #2f7df6, #58b7ff); }
.loading-box { text-align: center; font-family: var(--display); font-size: 1.8rem; -webkit-text-stroke: 0.35rem var(--ink); paint-order: stroke fill; }
.spinner { width: 4.4rem; height: 4.4rem; margin: 0 auto 1rem; border-radius: 50%; border: 0.7rem solid rgba(255, 255, 255, 0.35); border-top-color: var(--yellow); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#app-toasts { position: fixed; left: 50%; top: 1rem; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 0.4rem; align-items: center; pointer-events: none; }
.atoast { background: var(--ink); color: #fff; font-weight: 600; padding: 0.5rem 1rem; border-radius: 0.9rem; border: 0.16rem solid var(--yellow); animation: toastin 0.25s both; max-width: 90vw; text-align: center; }
.atoast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toastin { from { opacity: 0; transform: translateY(-0.8rem); } }
#rotate-tip { position: fixed; left: 50%; bottom: 0.4rem; transform: translateX(-50%); background: var(--ink); padding: 0.3rem 0.8rem; border-radius: 0.7rem; font-size: 0.85rem; font-weight: 600; z-index: 40; pointer-events: none; opacity: 0.85; }
.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--navy); font-size: 1.4rem; padding: 2rem; text-align: center; }

/* ── HUD ─────────────────────────────────────────────────────── */
#hud { position: fixed; inset: 0; pointer-events: none; font-family: var(--display); z-index: 10; }
#hud .stroke, .hud-pos, .hud-lap, #hud-time, #hud-center, #hud-banner, .hud-speed, #hud-ending, #hud-spectate { -webkit-text-stroke: 0.32rem var(--ink); paint-order: stroke fill; }
.hud-tl { position: absolute; left: max(1.2rem, env(safe-area-inset-left)); top: max(0.8rem, env(safe-area-inset-top)); }
.hud-pos { font-size: 5.2rem; line-height: 0.9; color: var(--yellow); display: inline-block; transform-origin: left bottom; }
.hud-pos sup { font-size: 0.42em; vertical-align: 0.95em; margin-left: 0.04em; }
.hud-pos .hud-of { font-size: 0.3em; color: #fff; margin-left: 0.35em; }
.hud-pos.bump { animation: bump 0.35s; }
@keyframes bump { 30% { transform: scale(1.28) rotate(-6deg); } }
.hud-lap { font-size: 1.7rem; margin-top: 0.2rem; }
.hud-lap b { font-weight: 400; color: var(--yellow); font-size: 1.25em; }
.hud-lap span { margin: 0 0.1em; }
.hud-tc { position: absolute; top: max(0.7rem, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); text-align: center; }
#hud-time { font-size: 2.3rem; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
#hud-lapinfo { font-family: var(--text); font-weight: 700; font-size: 0.85rem; background: rgba(11, 16, 48, 0.7); border-radius: 0.6rem; padding: 0.15rem 0.6rem; display: inline-block; }
#hud-lapinfo:empty { display: none; }
.hud-tr { position: absolute; right: max(0.9rem, env(safe-area-inset-right)); top: max(0.7rem, env(safe-area-inset-top)); }
#hud-map { width: 11.5rem; height: 11.5rem; filter: drop-shadow(0 0.25rem 0 rgba(8, 12, 36, 0.35)); }
.hud-board { position: absolute; left: max(1.2rem, env(safe-area-inset-left)); top: 10.6rem; display: flex; flex-direction: column; gap: 0.18rem; font-family: var(--text); }
.hb-row { display: flex; align-items: center; gap: 0.4rem; background: rgba(11, 16, 48, 0.62); border-radius: 0.55rem; padding: 0.1rem 0.6rem 0.1rem 0.3rem; font-weight: 700; font-size: 0.86rem; width: fit-content; max-width: 13rem; }
.hb-row.me { background: var(--yellow); color: var(--ink); }
.hb-row.fin { opacity: 0.75; }
.hb-n { font-family: var(--display); width: 1.1rem; text-align: center; }
.hb-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; border: 0.1rem solid var(--ink); flex: none; }
.hb-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-br { position: absolute; right: max(0.9rem, env(safe-area-inset-right)); bottom: max(0.6rem, env(safe-area-inset-bottom)); width: 12.5rem; height: 12.5rem; }
#hud-gauge { width: 100%; height: 100%; }
.hud-speed { position: absolute; left: 0; right: 0; top: 34%; text-align: center; line-height: 0.95; }
.hud-speed b { font-weight: 400; font-size: 3.4rem; display: block; font-variant-numeric: tabular-nums; }
.hud-speed span { font-size: 1rem; color: var(--yellow); }
.hud-bl { position: absolute; left: max(1.2rem, env(safe-area-inset-left)); bottom: max(1rem, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 0.8rem; }
.hud-item { width: 6rem; height: 6rem; border-radius: 1.3rem; background: rgba(11, 16, 48, 0.7); border: 0.25rem solid var(--ink); box-shadow: inset 0 0 0 0.2rem rgba(255, 255, 255, 0.16); position: relative; display: flex; align-items: center; justify-content: center; }
.hud-item.has { background: var(--paper); box-shadow: inset 0 0 0 0.2rem var(--yellow); animation: itempop 0.35s; }
.hud-item.rolling { background: #d9defa; }
.hud-item-icon { width: 78%; height: 78%; }
.hud-item-icon svg { width: 100%; height: 100%; display: block; }
.hud-item.rolling .hud-item-icon { animation: roll 0.17s linear infinite; }
@keyframes roll { 0% { transform: translateY(-14%); opacity: 0.4; } 50% { opacity: 1; } 100% { transform: translateY(14%); opacity: 0.4; } }
@keyframes itempop { 0% { transform: scale(1.4); } 60% { transform: scale(0.94); } }
.hud-item-key { position: absolute; bottom: -0.75rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--yellow); font-size: 0.72rem; padding: 0.08rem 0.5rem; border-radius: 0.5rem; display: none; white-space: nowrap; }
.hud-item.has .hud-item-key { display: block; }
.hud-item-count { position: absolute; top: -0.7rem; right: -0.8rem; background: var(--yellow); color: var(--ink); font-size: 1.25rem; line-height: 1; padding: 0.18rem 0.5rem 0.24rem; border-radius: 0.8rem; border: 0.18rem solid var(--ink); }
.hud-item-count:empty { display: none; }
.hud-drift { width: 11rem; height: 1.35rem; border-radius: 0.8rem; background: rgba(11, 16, 48, 0.7); border: 0.2rem solid var(--ink); position: relative; overflow: hidden; opacity: 0; transition: opacity 0.2s; margin-bottom: 0.4rem; }
.hud-drift.on { opacity: 1; }
#hud-drift-fill { height: 100%; width: 0; background: #9fb0ff; }
.hud-drift.l1 #hud-drift-fill { background: #4fd8ff; } .hud-drift.l2 #hud-drift-fill { background: #ffb13b; } .hud-drift.l3 #hud-drift-fill { background: #ff5fd2; }
.hud-drift i { position: absolute; top: 0; bottom: 0; width: 0.16rem; background: var(--ink); }
.hud-drift i:nth-of-type(1) { left: 25%; } .hud-drift i:nth-of-type(2) { left: 59%; }
#hud-center { position: absolute; left: 0; right: 0; top: 27%; text-align: center; font-size: 8rem; line-height: 1; opacity: 0; color: #fff; }
#hud-center.pop { animation: pop 1.25s both; }
#hud-center.count { color: var(--yellow); font-size: 11rem; }
#hud-center.go { color: #5dff8a; font-size: 12rem; }
#hud-center.intro { font-size: 4.2rem; animation: intro 3.6s both; color: #fff; }
#hud-center.final { color: #ff8a80; font-size: 6rem; }
#hud-center.lapmsg { font-size: 5rem; }
#hud-center.finish { color: var(--yellow); font-size: 12rem; top: 32%; animation: finishpop 0.7s both; opacity: 1; }
@keyframes pop { 0% { opacity: 0; transform: scale(2.3); } 14% { opacity: 1; transform: scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: scale(0.85); } }
@keyframes intro { 0% { opacity: 0; transform: translateY(1.5rem); } 12% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
@keyframes finishpop { 0% { opacity: 0; transform: scale(3) rotate(-12deg); } 60% { transform: scale(0.92); } 100% { opacity: 1; transform: scale(1) rotate(-4deg); } }
#hud-banner { position: absolute; left: 0; right: 0; top: 6.2rem; text-align: center; font-size: 2.6rem; display: none; }
#hud-banner.show { display: block; }
#hud-banner.warn { color: #ff5a52; animation: blink 0.5s steps(2) infinite; }
#hud-banner.fin { color: #fff; top: 57%; font-size: 3.2rem; }
@keyframes blink { 50% { opacity: 0.25; } }
#hud-toasts { position: absolute; left: 50%; top: 8.4rem; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.3rem; font-family: var(--text); }
.toast { background: rgba(11, 16, 48, 0.86); border: 0.16rem solid rgba(255, 255, 255, 0.25); border-radius: 0.9rem; padding: 0.25rem 0.9rem; font-weight: 600; font-size: 1.05rem; animation: toastin 0.2s both; display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; }
.toast svg { width: 1.7rem; height: 1.7rem; flex: none; }
.toast.good { border-color: #5dff8a; } .toast.bad { border-color: #ff5a52; } .toast.fin { border-color: var(--yellow); }
.toast.out { opacity: 0; transition: opacity 0.45s; }
#hud-ending { position: absolute; left: 50%; top: 4.3rem; transform: translateX(-50%); font-size: 1.5rem; color: #ff8a80; white-space: nowrap; }
#hud-hint { position: absolute; left: 50%; bottom: 1.4rem; transform: translateX(-50%); font-family: var(--text); font-weight: 600; font-size: 1rem; background: rgba(11, 16, 48, 0.82); border-radius: 0.9rem; padding: 0.4rem 1rem; opacity: 0; transition: opacity 0.4s; text-align: center; max-width: min(46rem, 62vw); line-height: 1.45; }
#hud-hint.show { opacity: 1; }
#hud-hint b { color: var(--yellow); }
#hud-spectate { position: absolute; left: 50%; bottom: 4.8rem; transform: translateX(-50%); font-size: 1.4rem; white-space: nowrap; }
#hud-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
#hud-flash.go { animation: flash 1.1s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
#hud.finished .hud-br, #hud.finished .hud-bl, #hud.spectating .hud-bl, #hud.finished #hud-hint { display: none; }

/* ── touch controls ──────────────────────────────────────────── */
#touch { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.tc-btn { pointer-events: auto; touch-action: none; font-family: var(--display); color: #fff; background: rgba(11, 16, 48, 0.42); border: 0.25rem solid rgba(255, 255, 255, 0.7); border-radius: 50%; backdrop-filter: blur(2px); -webkit-user-select: none; user-select: none; }
.tc-btn.down { background: rgba(255, 210, 63, 0.75); color: var(--ink); transform: scale(0.94); }
.tc-left { position: absolute; left: max(1.4rem, env(safe-area-inset-left)); bottom: max(1.6rem, env(safe-area-inset-bottom)); display: flex; gap: 1.4rem; }
.tc-steer { width: 9.5rem; height: 9.5rem; font-size: 3.4rem; }
.tc-right { position: absolute; right: max(1.4rem, env(safe-area-inset-right)); bottom: max(1.6rem, env(safe-area-inset-bottom)); display: grid; grid-template-columns: auto auto; grid-template-areas: "item item" "brake drift"; gap: 0.9rem; align-items: end; justify-items: end; }
.tc-drift { grid-area: drift; width: 10.5rem; height: 10.5rem; font-size: 1.9rem; }
.tc-small { width: 6.6rem; height: 6.6rem; font-size: 1.15rem; }
.tc-small[data-a="item"] { grid-area: item; }
.tc-small[data-a="brake"] { grid-area: brake; }
.tc-top { position: absolute; left: 50%; top: max(4.6rem, calc(env(safe-area-inset-top) + 4.6rem)); transform: translateX(-50%); display: flex; gap: 0.8rem; }
.tc-mini { width: 3.6rem; height: 3.6rem; font-size: 1.2rem; border-width: 0.18rem; }
body.touch .hud-br { right: 50%; transform: translateX(50%) scale(0.72); transform-origin: bottom center; bottom: 0.2rem; }
body.touch .hud-bl { left: 50%; bottom: auto; top: 8.6rem; transform: translateX(-50%) scale(0.8); }
body.touch .hud-board { display: none; }
body.touch #hud-hint { bottom: 11rem; }

/* ── small / portrait screens ────────────────────────────────── */
@media (max-aspect-ratio: 1/1) {
  .title-col { position: static; transform: none; width: auto; margin: 0 auto; max-width: 26rem; }
  #scr-title { overflow: auto; display: flex; flex-direction: column; gap: 1rem; pointer-events: auto; }
  .car-card { position: static; width: auto; max-width: 26rem; margin: 0 auto; }
  .disclaimer { position: static; transform: none; align-self: center; white-space: normal; text-align: center; }
  .logo { font-size: 4.4rem; }
  .lobby-top { flex-wrap: wrap; }
  .lobby-main, .garage-main { flex-direction: column; overflow: auto; pointer-events: auto; justify-content: flex-start; }
  .lobby-players, .lobby-settings, .garage-list, .garage-spec { width: 100%; max-height: none; align-self: stretch; overflow: visible; }
  .garage-mid { min-height: 34vh; flex: none; }
  .garage-list { flex-direction: row; overflow-x: auto; flex: none; }
  .garage-list .vcard { flex: none; width: 15rem; }
  .gen-blurb { display: none; }
  .hud-board { display: none; }
  .help-cols { grid-template-columns: 1fr; }
  #hud-map { width: 8.5rem; height: 8.5rem; }
  #scr-results.podium { justify-content: center; align-items: flex-end; padding-right: max(1.2rem, env(safe-area-inset-right)); }
  #scr-results.podium .results-panel { max-height: 56%; }
}
@media (max-height: 430px) and (min-aspect-ratio: 1/1) {
  .hud-board { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .hud-pos.bump, #hud-banner.warn { transition: none; animation: none; }
}

/* short screens (phones on their side): keep the track picture as small as the old outline map was, the panel scrolls enough already */
@media (max-height: 460px) { .ti-pic { max-width: 11rem; margin-bottom: 0.15rem; } }
