[hidden] { display: none !important; }
.race-page { --stick-size: clamp(164px, 28svh, 210px); min-width: 280px; }
.race-masthead { min-height: 72px; }
.race-actions, .dialog-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.race-shell { padding-bottom: 28px; }
.race-page button, .race-page input { font: inherit; }
.race-page button { cursor: pointer; }
.race-page button:disabled { opacity: .45; cursor: default; }
.race-page button:focus-visible, .race-page input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.subtle, .race-secondary, .text-button {
    border: 1px solid #4a5044;
    border-radius: 5px;
    color: #f7f7ec;
    background: #232821;
    padding: 9px 13px;
    font-size: 13px !important;
}
.text-button { background: transparent; border: none; padding-left: 0; margin-top: 10px; color: var(--muted); }
.race-primary { background: var(--accent); color: #15190b; border: 1px solid var(--accent); border-radius: 5px; padding: 10px 14px; font-weight: 750 !important; font-size: 13px !important; }
.race-primary:hover:not(:disabled) { background: #eeffa5; }
.race-secondary:hover:not(:disabled), .subtle:hover:not(:disabled) { background: #343b30; }
.scoreboard {
    display: grid;
    grid-template-columns: 1fr 1fr 1.45fr 1.15fr;
    padding: 13px 18px;
    margin-bottom: 10px;
    border: 1px solid #3a4134;
    border-radius: 7px;
    background: #1b2019;
    gap: 12px;
}
.scoreboard > div { min-width: 0; display: grid; gap: 4px; }
.scoreboard > div > span { color: #b0b8a6; text-transform: uppercase; letter-spacing: .11em; font-size: 9px; }
.scoreboard strong { font: 700 clamp(14px, 2.3vw, 25px)/1.1 'IBM Plex Mono', Consolas, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scoreboard strong span { color: #abb5a2; font-size: .64em; margin-left: .2em; }
.arena { position: relative; height: clamp(430px, 68vh, 680px); overflow: hidden; border: 1px solid #404738; border-radius: 8px; background: #293b25; }
#track { display: block; width: 100%; height: 100%; }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: #11170f75; }
.dialog {
    width: min(100%, 455px);
    max-height: 100%;
    overflow: auto;
    padding: clamp(19px, 3vw, 31px);
    border: 1px solid #596345;
    border-radius: 8px;
    background: #192017f7;
    box-shadow: 0 22px 70px #06090499;
}
.dialog h1, .dialog h2 { margin: 0 0 13px; font-size: clamp(29px, 5vw, 55px); line-height: .98; letter-spacing: -.055em; }
.dialog h1 { color: var(--accent); font-style: italic; }
.dialog p { margin: 0 0 16px; color: #c9d1be; font-size: 14px; line-height: 1.5; }
.dialog .race-kicker { margin-bottom: 12px; font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; color: var(--accent); }
.dialog label { display: grid; gap: 4px; font-size: 12px; color: #c9d1be; margin-bottom: 10px; }
.dialog input { width: 100%; padding: 8px 9px; border: 1px solid #58624f; border-radius: 4px; background: #111710; color: #f7f7ec; font-size: 14px; }
.invite-url { margin-top: 10px; }
.best { margin-top: 15px; color: #c0c8b5; font: 12px Consolas, monospace; }
.race-stats { display: flex; gap: 22px; margin: 16px 0 0; padding-top: 12px; border-top: 1px solid #404837; }
.race-stats dt { color: #b0b8a6; font-size: 11px; }
.race-stats dd { margin: 3px 0 0; color: #f7f7ec; font: 700 17px/1.2 'IBM Plex Mono', Consolas, monospace; }
.race-list { display: grid; gap: 4px; margin: 0 0 13px; padding: 0; list-style: none; }
.race-list li { display: grid; grid-template-columns: 11px 1fr auto; align-items: center; gap: 8px; min-height: 30px; padding: 4px 7px; border-bottom: 1px solid #404837; font-size: 13px; }
.race-list .driver-dot { width: 8px; height: 8px; border-radius: 50%; }
.race-list .driver-note { color: #b8c2ab; font-size: 11px; white-space: nowrap; }
.race-message { margin: 10px 0 0; color: #f0edc5; font-size: 13px; }
.countdown { pointer-events: none; position: absolute; inset: 0; display: grid; place-items: center; color: var(--accent); font: italic 900 clamp(80px, 14vw, 160px)/1 Arial, sans-serif; text-shadow: 0 4px 23px #121711; }
.race-help { display: flex; gap: 15px; flex-wrap: wrap; color: #aeb6a8; padding-block: 11px; font-size: 12px; }
kbd { display: inline-block; min-width: 19px; text-align: center; margin-right: 3px; padding: 1px 3px; border: 1px solid #4b5146; border-radius: 3px; color: #e9eddf; }
.touch-controls { display: none; }
.drive-stick {
    --stick-x: 0px;
    --stick-y: 0px;
    position: relative;
    width: var(--stick-size);
    aspect-ratio: 1;
    border: 1px solid #59634e;
    border-radius: 50%;
    background: radial-gradient(circle, #303b28 0 39%, #4a573c 40%, #252e21 41%);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: grab;
}
.drive-stick.is-held { cursor: grabbing; }
.stick-marks { position: absolute; inset: 5px; color: #d3ddc6; font-size: 16px; line-height: 1; pointer-events: none; }
.stick-marks span { position: absolute; }
.stick-marks span:nth-child(1) { top: 0; left: 50%; transform: translateX(-50%); }
.stick-marks span:nth-child(2) { right: 0; top: 50%; transform: translateY(-50%); }
.stick-marks span:nth-child(3) { bottom: 0; left: 50%; transform: translateX(-50%); }
.stick-marks span:nth-child(4) { left: 0; top: 50%; transform: translateY(-50%); }
.stick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 34%;
    aspect-ratio: 1;
    transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
    border: 1px solid #edff91;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: inset 0 -4px #0002, 0 4px 12px #0008;
    pointer-events: none;
}
.stick-hint { color: #c9d1be; font-size: 12px; line-height: 1.3; text-align: center; }
.race-actions .fullscreen-toggle { display: none; place-items: center; width: 44px; height: 44px; padding: 0; }
.fullscreen-toggle span { font: 24px/1 Arial, sans-serif; }

@media (any-pointer: coarse), (max-width: 700px) {
    .race-page.is-driving { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100svh; }
    .is-driving .race-shell { display: grid; grid-template-rows: auto minmax(120px, 1fr) auto; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .is-driving .arena { height: auto; }
    .touch-controls { display: grid; justify-items: center; gap: 5px; padding-top: 7px; }
    .race-help { display: none; }
    .race-actions .fullscreen-toggle { display: grid; }
}
@media (max-width: 680px) {
    .race-masthead { min-height: 58px; gap: 9px; }
    .race-actions { gap: 4px; flex-wrap: nowrap; }
    .subtle { padding: 6px 8px; }
    .scoreboard { gap: 7px; padding: 9px 8px; }
    .scoreboard strong { font-size: clamp(11px, 3.7vw, 18px); }
    .scoreboard > div > span { font-size: 8px; letter-spacing: .05em; }
    .race-page:not(.is-driving, .is-expanded) .arena { height: clamp(330px, 62svh, 555px); }
}

@media (max-width: 340px) {
    .race-masthead .mark { display: none; }
}

@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    .race-page { --stick-size: clamp(138px, 44svh, 192px); }
    .race-page .wrap { width: calc(100% - 32px); }
    .race-masthead { min-height: 48px; }
    .is-driving .race-shell { grid-template-columns: minmax(0, 1fr) var(--stick-size); grid-template-rows: auto minmax(120px, 1fr); column-gap: 10px; }
    .is-driving .scoreboard, .is-driving .race-message { grid-column: 1 / -1; }
    .touch-controls { align-self: end; padding: 0 0 5px; }
}

.race-page.is-expanded {
    --full-top: max(6px, env(safe-area-inset-top));
    --full-left: max(6px, env(safe-area-inset-left));
    --full-right: max(6px, env(safe-area-inset-right));
    display: block;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.is-expanded .race-masthead {
    position: absolute;
    inset: var(--full-top) var(--full-right) auto auto;
    z-index: 2;
    width: auto;
    min-height: 0;
    margin: 0;
}
.is-expanded .race-masthead .brand,
.is-expanded .race-actions > :not(.fullscreen-toggle),
.is-expanded .race-help,
.is-expanded .stick-hint { display: none; }
.is-expanded .race-actions .fullscreen-toggle { display: grid; }
.race-page.is-expanded .race-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: 100%;
    height: 100%;
    padding: var(--full-top) 0 0;
}
.is-expanded .scoreboard {
    align-content: center;
    min-height: 44px;
    margin: 0 calc(var(--full-right) + 50px) 6px var(--full-left);
    padding: 4px 8px;
}
.is-expanded .arena { height: auto; border: 0; border-radius: 0; }
.is-expanded .touch-controls {
    position: absolute;
    z-index: 1;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    padding: 0;
}
.is-expanded .drive-stick { background: radial-gradient(circle, #303b28d9 0 39%, #667654e6 40%, #252e21de 41%); }
.is-expanded .race-message { margin: 0; padding: 6px var(--full-right) 6px var(--full-left); }
