* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:root { --ink: #eef3ff; --accent: #4fd6ff; --hot: #ff9d4f; --muted: #8ea0c4; }

html, body {
    height: 100%;
    overflow: hidden;
    background: #101a2c;
    color: var(--ink);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}
.wrap { position: relative; width: 100%; height: 100dvh; }
#scene { display: block; width: 100%; height: 100%; touch-action: none; }

.hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud > * { pointer-events: auto; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 40px; height: 36px; padding: 0 8px;
    border: 1px solid rgba(79, 214, 255, 0.28);
    border-radius: 10px;
    background: rgba(8, 14, 28, 0.45);
    color: var(--ink); font-size: 15px; font-weight: 700;
    text-decoration: none; cursor: pointer; flex: 0 0 auto;
    backdrop-filter: blur(6px);
}
.icon-btn-text { font-size: 13px; }
.hud-mid { flex: 1; text-align: center; pointer-events: none; }
.score {
    font-size: 26px; font-weight: 800; color: var(--accent);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
    font-variant-numeric: tabular-nums; line-height: 1.05;
}
.sub { font-size: 11px; color: var(--muted); }
.sub b { color: var(--ink); }

.dial {
    position: absolute;
    right: calc(14px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
    text-align: right;
    pointer-events: none;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}
.speed {
    font-size: 46px; font-weight: 900; line-height: 0.95;
    color: var(--ink); font-variant-numeric: tabular-nums;
}
.speed.fast { color: var(--hot); }
.speed-unit { font-size: 11px; color: var(--muted); letter-spacing: 2px; }
.dist { margin-top: 6px; font-size: 13px; font-weight: 700; color: var(--accent); }

.banner {
    position: absolute; top: 26%; left: 50%;
    transform: translate(-50%, -50%) scale(0.7);
    font-size: 25px; font-weight: 900; color: var(--hot);
    text-shadow: 0 3px 12px rgba(0, 0, 0, 0.75);
    letter-spacing: 2px; opacity: 0; pointer-events: none; white-space: nowrap;
}
.banner.show { animation: pop 0.85s ease forwards; }
@keyframes pop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    22% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -85%) scale(1); }
}

.warn {
    position: absolute; top: 16%; left: 50%; transform: translateX(-50%);
    padding: 6px 16px; border-radius: 9px;
    background: rgba(190, 50, 40, 0.85);
    font-size: 14px; font-weight: 800; letter-spacing: 2px;
    pointer-events: none;
    animation: blink 0.55s steps(2, end) infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

.steer-hint {
    position: absolute;
    left: 50%; bottom: calc(14px + env(safe-area-inset-bottom));
    width: 46%; height: 5px; margin-left: -23%;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.14);
    pointer-events: none;
    overflow: hidden;
}
.steer-fill {
    position: absolute; top: 0; bottom: 0; left: 50%;
    width: 0; background: var(--accent);
    border-radius: 3px;
}
.brake-btn {
    position: absolute;
    left: calc(20px + env(safe-area-inset-left));
    bottom: calc(26px + env(safe-area-inset-bottom));
    width: 82px; height: 82px;
    border-radius: 50%;
    border: 2px solid rgba(255, 120, 90, 0.5);
    background: rgba(255, 90, 60, 0.16);
    color: #ff9d8a; font-size: 15px; font-weight: 800; font-family: inherit;
    backdrop-filter: blur(4px);
}
.brake-btn:active { background: rgba(255, 90, 60, 0.4); }

.overlay {
    position: fixed; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 20px;
    background: rgba(6, 11, 22, 0.9); z-index: 20;
}
.overlay.is-open { display: flex; }
.overlay-card {
    width: 100%; max-width: 330px; padding: 26px 20px;
    border-radius: 20px;
    background: linear-gradient(180deg, #1b2c4b, #121b30);
    border: 1px solid rgba(79, 214, 255, 0.24);
    text-align: center;
}
.title { font-size: 31px; letter-spacing: 5px; color: var(--accent); }
.subtitle { margin: 8px 0 18px; font-size: 13px; color: var(--muted); }
.over-title { font-size: 26px; color: var(--hot); letter-spacing: 3px; }
.over-sub { margin: 6px 0 14px; font-size: 13px; color: var(--muted); min-height: 18px; }
.btn {
    min-height: 48px; padding: 0 18px;
    border: 1px solid rgba(79, 214, 255, 0.3);
    border-radius: 13px; background: rgba(0, 0, 0, 0.26);
    color: var(--ink); font-size: 16px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.btn-primary {
    background: linear-gradient(180deg, #6fe3ff, #2aa8d6);
    border-color: #9aeeff; color: #062131;
}
.btn-wide { width: 100%; margin-top: 9px; }
.how { margin-top: 18px; text-align: left; }
.how-row {
    display: flex; justify-content: space-between; gap: 10px;
    padding: 5px 0; font-size: 12px; color: var(--muted);
}
.how-key { color: var(--ink); font-weight: 600; flex: 0 0 auto; }
.result-row {
    display: flex; justify-content: space-between;
    padding: 7px 4px; font-size: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
