/* Racing 3D V1; shared tokens follow the existing body.dark-mode. */
.r3d-body { overflow: hidden; }
.r3d-app {
    --r3d-accent: #6c4fe0;
    position: relative; width: 100%; height: 100vh; height: 100dvh;
    min-height: 0; padding: 0; overflow: hidden; color: var(--game-text);
    background: #91cbea; isolation: isolate;
}
body.dark-mode .r3d-app { --r3d-accent: #b3a2ff; }
.r3d-app [hidden] { display: none; }
#r3dCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.r3d-overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: rgba(24, 30, 57, .36); overflow-y: auto; }
.r3d-panel { width: min(100%, 480px); max-height: 100%; overflow-y: auto; background: var(--game-surface); border: 1px solid var(--game-border); border-radius: 24px; padding: 28px; box-shadow: 0 24px 80px #11182740; }
.r3d-menu-panel { width: min(100%, 520px); }
.r3d-menu-top { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 26px; font-size: 13px; }
.r3d-menu-top a { min-height: 44px; display: flex; align-items: center; font-weight: 700; }
.r3d-eyebrow { color: var(--r3d-accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; margin-bottom: 10px; }
.r3d-panel h1 { font-size: clamp(38px, 7vw, 60px); line-height: 1; letter-spacing: -.055em; color: var(--game-text); }
.r3d-panel h1 em { color: var(--r3d-accent); font-style: normal; }
.r3d-panel h2 { font-size: 30px; letter-spacing: -.035em; margin-bottom: 12px; }
.r3d-intro { color: var(--game-text-muted); font-size: 15px; line-height: 1.65; margin-top: 14px; }
.r3d-circuit { border-left: 3px solid var(--r3d-accent); padding: 10px 14px; background: var(--game-surface-soft); border-radius: 0 10px 10px 0; margin: 22px 0; }
.r3d-circuit span { display: block; font-size: 11px; color: var(--r3d-accent); font-weight: 800; margin-bottom: 5px; }
.r3d-circuit strong { font-size: 14px; }
.r3d-menu-stats { display: flex; gap: 24px; margin-bottom: 24px; }
.r3d-menu-stats div { display: grid; gap: 5px; }
.r3d-menu-stats strong { font-size: 22px; }
.r3d-menu-stats span { color: var(--game-text-muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.r3d-button { width: 100%; min-height: 48px; padding: 12px 16px; border: 1px solid transparent; border-radius: 12px; background: #6c4fe0; color: #fff; font-size: 15px; font-weight: 800; transition: filter .15s, transform .15s; }
.r3d-button.secondary { background: var(--game-surface-soft); color: var(--game-text); border-color: var(--game-border); }
.r3d-online-link { display: flex; align-items: center; justify-content: center; text-align: center; margin-top: 12px; text-decoration: none; }
.r3d-button:hover:not(:disabled) { filter: brightness(1.1); }
.r3d-button:active:not(:disabled) { transform: translateY(1px); }
.r3d-button:disabled { opacity: .65; cursor: wait; }
.r3d-app button:focus-visible, .r3d-app a:focus-visible, .r3d-app select:focus-visible, .r3d-app input:focus-visible, .r3d-help summary:focus-visible { outline: 3px solid var(--r3d-accent); outline-offset: 3px; }
.r3d-secondary { color: var(--game-text-muted); line-height: 1.5; font-size: 13px; margin: 10px 0; }
.r3d-footnote { color: var(--game-text-muted); line-height: 1.5; font-size: 11px; margin-top: 18px; }
.r3d-help { margin-top: 14px; font-size: 13px; color: var(--game-text-muted); }
.r3d-help summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--game-text); font-weight: 700; }
.r3d-help p { line-height: 1.9; }
.r3d-help kbd { font: inherit; font-weight: 800; color: var(--game-text); }
.r3d-actions { display: grid; gap: 10px; margin-top: 20px; }
.r3d-hud { position: absolute; z-index: 2; inset: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left)); display: flex; flex-wrap: wrap; align-items: start; gap: 8px; pointer-events: none; }
.r3d-stats { display: flex; gap: clamp(12px, 3vw, 34px); padding: 12px 18px; border: 1px solid var(--game-border); background: var(--game-surface); border-radius: 14px; box-shadow: 0 4px 20px #0002; font-variant-numeric: tabular-nums; }
.r3d-stats div { display: grid; gap: 4px; }
.r3d-stats span { color: var(--game-text-muted); font-size: 9px; letter-spacing: .08em; font-weight: 800; }
.r3d-stats strong { font-size: clamp(16px, 2.5vw, 24px); white-space: nowrap; }
.r3d-stats small { font-size: 10px; font-weight: 600; color: var(--game-text-muted); }
.r3d-icon-button { margin-left: auto; flex-shrink: 0; width: 46px; height: 46px; pointer-events: auto; border: 1px solid var(--game-border); background: var(--game-surface); color: var(--game-text); border-radius: 12px; font-size: 24px; font-weight: 800; }
.r3d-lap-times { display: flex; gap: 14px; flex-basis: 100%; width: fit-content; font-size: 10px; }
.r3d-lap-times span { background: var(--game-surface); color: var(--game-text-muted); padding: 7px 10px; border-radius: 8px; }
.r3d-lap-times b { color: var(--game-text); margin-left: 5px; font-variant-numeric: tabular-nums; }
.r3d-countdown { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; color: #fff; text-shadow: 0 4px 18px #161827; font-size: clamp(64px, 16vw, 120px); font-weight: 900; z-index: 3; }
.r3d-message, .r3d-orientation { position: absolute; left: 50%; transform: translateX(-50%); z-index: 3; max-width: calc(100% - 32px); width: max-content; padding: 9px 14px; border-radius: 10px; background: var(--game-surface); color: var(--game-text); font-size: 12px; text-align: center; pointer-events: none; }
.r3d-message { bottom: max(24px, env(safe-area-inset-bottom)); }
.r3d-orientation { inset: 0; transform: none; width: 100%; max-width: none; z-index: 8; border-radius: 0; display: flex; gap: 16px; flex-direction: column; justify-content: center; align-items: center; padding: 28px; background: var(--game-surface); }
.r3d-orientation strong { font-size: 28px; }
.r3d-orientation span { color: var(--game-text-muted); }
.r3d-orientation button { width: min(100%,240px); pointer-events: auto; }
.r3d-touch { position: absolute; z-index: 2; inset: auto max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); display: none; justify-content: space-between; pointer-events: none; user-select: none; }
.r3d-touch-steering, .r3d-touch-pedals { display: flex; gap: 10px; }
.r3d-touch button { pointer-events: auto; touch-action: none; width: clamp(60px, 9vw, 84px); height: clamp(60px, 9vw, 84px); border: 2px solid #ffffffa0; border-radius: 18px; background: #27334bea; color: #fff; font-size: 15px; font-weight: 900; -webkit-user-select: none; }
.r3d-touch [data-drive="throttle"] { background: #246544ed; }
.r3d-touch button.is-held { background: #6c4fe0e0; border-color: #fff; }
.r3d-touch button { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; box-shadow: 0 3px 8px #0004; -webkit-touch-callout: none; }
.r3d-touch svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.r3d-touch span { font-size: 9px; letter-spacing: .05em; pointer-events: none; }
.r3d-touch button.is-held { box-shadow: inset 0 2px 4px #0005; transform: translateY(1px); }
.r3d-app:is([data-state="racing"],[data-state="countdown"]) { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: contain; }
.r3d-app :is(input,textarea,[contenteditable="true"]) { user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }
.r3d-standings { list-style: none; display: grid; gap: 8px; margin-top: 20px; counter-reset: place; }
.r3d-standings li { counter-increment: place; display: flex; gap: 10px; padding: 12px; border-radius: 10px; border: 1px solid var(--game-border); background: var(--game-surface-soft); font-size: 13px; }
.r3d-standings li::before { content: counter(place) "."; color: var(--game-text-muted); }
.r3d-standings .is-player { border-color: var(--r3d-accent); font-weight: 800; }
.r3d-standings time { margin-left: auto; color: var(--game-text-muted); font-variant-numeric: tabular-nums; }
.r3d-debug { position: absolute; right: 12px; top: 120px; z-index: 4; background: #0c1521db; color: #e1ffe7; padding: 10px; font-size: 11px; pointer-events: none; }
@media (pointer: coarse), (max-width: 900px) {
    .r3d-touch { display: flex; }
    .r3d-message { bottom: 112px; }
}
@media (max-width: 600px) {
    .r3d-panel { padding: 20px; border-radius: 18px; }
    .r3d-menu-top { margin-bottom: 14px; }
    .r3d-stats { flex: 1; gap: 10px; padding: 10px; justify-content: space-between; }
    .r3d-stats span { font-size: 8px; }
    .r3d-stats strong { font-size: 15px; }
    .r3d-stats small { font-size: 8px; }
    .r3d-hud { gap: 6px; }
    .r3d-icon-button { width: 44px; height: 44px; }
    .r3d-touch { left: 10px; right: 10px; }
    .r3d-touch-steering, .r3d-touch-pedals { gap: 6px; }
}
@media (max-height: 500px) { .r3d-menu-panel { width: min(100%, 580px); } .r3d-menu-top { margin-bottom: 8px; } .r3d-panel { padding: 20px; } }
.r3d-back { display: inline-flex; align-items: center; min-height: 44px; color: var(--game-text); background: none; border: 0; padding: 0 8px 0 0; font-size: 13px; font-weight: 700; margin-bottom: 12px; }
.r3d-wide-panel { width: min(100%, 900px); }
.r3d-track-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin: 18px 0; }
.r3d-choice { display: flex; flex-direction: column; gap: 8px; text-align: left; background: var(--game-surface-soft); color: var(--game-text); border: 2px solid var(--game-border); border-radius: 10px; min-height: 48px; padding: 12px; cursor: pointer; }
.r3d-choice[aria-pressed="true"] { border-color: var(--r3d-accent); }
.r3d-choice:hover { border-color: var(--r3d-accent); }
.r3d-choice small { color: var(--game-text-muted); line-height: 1.5; }
.r3d-choice svg { width: 100%; height: 82px; color: var(--r3d-accent); }
.r3d-garage-panel { margin-left: auto; margin-right: max(0px,calc((100vw - 1300px)/2)); width: min(45%,460px); }
.r3d-app[data-menu-screen="cars"] #r3dMenu { background: transparent; }
.r3d-car-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin: 18px 0; }
.r3d-car-grid .r3d-choice { align-items: center; font-size: 12px; padding: 12px 6px; }
.r3d-car-stats { display: grid; gap: 10px; }
.r3d-car-stats label { display: grid; grid-template-columns: 100px 1fr; gap: 8px; align-items: center; color: var(--game-text-muted); font-size: 12px; }
.r3d-car-stats meter { width: 100%; height: 12px; accent-color: var(--r3d-accent); }
.r3d-setting { display: grid; gap: 10px; margin: 20px 0; color: var(--game-text); font-weight: 700; }
.r3d-setting select { background: var(--game-surface-soft); border: 1px solid var(--game-border); border-radius: 8px; color: var(--game-text); padding: 10px; min-height: 48px; width: 100%; font: inherit; color-scheme: light; }
body.dark-mode .r3d-setting select { color-scheme: dark; }
.r3d-check { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.r3d-check input { width: 24px; height: 24px; accent-color: var(--r3d-accent); }
.r3d-minimap { position: absolute; right: 0; top: 58px; width: 128px; height: 128px; background: var(--game-surface); border: 1px solid var(--game-border); border-radius: 12px; color: var(--game-text-muted); }
.r3d-minimap path { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.r3d-minimap circle { stroke: var(--game-surface); stroke-width: 1.5; }
.r3d-app.is-impact .r3d-stats { border-color: #ee6155; }
@media (max-width: 800px) {
    .r3d-track-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .r3d-garage-panel { width: min(100%,540px); margin: auto auto 0; max-height: 55%; }
    .r3d-car-stats { grid-template-columns: repeat(3,minmax(0,1fr)); }
    .r3d-car-stats label { grid-template-columns: 1fr; }
    .r3d-minimap { width: 90px; height: 90px; top: 96px; }
}
@media (max-height: 500px) and (min-width: 601px) {
    .r3d-garage-panel { margin: 0 0 0 auto; width: 45%; max-height: 100%; }
    .r3d-car-stats { grid-template-columns: 1fr; gap: 6px; }
    .r3d-car-stats label { grid-template-columns: 80px 1fr; }
    .r3d-minimap { top: 0; right: 60px; width: 90px; height: 90px; }
    .r3d-stats { gap: 18px; }
    .r3d-hud { right: 12px; }
    .r3d-lap-times { width: auto; }
    .r3d-help { margin-top: 4px; }
}
