:root {
    color-scheme: dark;
    --bg: #060a14;
    --bg-soft: #0b1224;
    --panel: rgba(15, 23, 42, 0.74);
    --panel-strong: rgba(17, 27, 50, 0.92);
    --line: rgba(148, 163, 184, 0.16);
    --line-strong: rgba(148, 163, 184, 0.3);
    --text: #e9f0fb;
    --muted: #93a4bd;
    --accent: #38bdf8;
    --accent-2: #818cf8;
    --gold: #fbbf24;
    --danger: #f87171;
    --radius-lg: 24px;
    --radius-md: 18px;
    --shadow: 0 24px 60px -30px rgba(2, 8, 23, 0.9);
    --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(900px 520px at 12% -8%, rgba(56, 189, 248, 0.16), transparent 62%),
        radial-gradient(760px 480px at 88% 4%, rgba(129, 140, 248, 0.16), transparent 60%),
        radial-gradient(700px 520px at 50% 110%, rgba(217, 70, 239, 0.1), transparent 62%);
    pointer-events: none;
    z-index: -2;
}

.ambient {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(148, 163, 184, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 163, 184, 0.05) 1px, transparent 1px);
    background-size: 56px 56px;
    mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 78%);
    pointer-events: none;
    z-index: -1;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px clamp(18px, 4vw, 48px);
    border-bottom: 1px solid var(--line);
    background: rgba(6, 10, 20, 0.72);
    backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    font-size: 1.02rem;
}

.brand em {
    font-style: normal;
    color: var(--muted);
    font-weight: 500;
}

.brand-mark {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: linear-gradient(150deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 24px rgba(56, 189, 248, 0.5);
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 8px 10px;
    border-radius: 4px;
    background: #071022;
    box-shadow: 0 0 0 2px rgba(7, 16, 34, 0.6);
}

.topbar-note {
    font-size: 0.82rem;
    color: var(--muted);
    padding: 6px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
}

.wrap {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: clamp(26px, 4vw, 46px) clamp(16px, 4vw, 48px) 40px;
    flex: 1;
}

.screen {
    display: none;
    animation: fade-in 0.4s ease;
}

.screen.is-active {
    display: block;
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.hero {
    max-width: 760px;
    margin-bottom: clamp(24px, 4vw, 38px);
}

.eyebrow {
    margin: 0 0 10px;
    font-size: 0.76rem;
    letter-spacing: 0.32em;
    color: var(--accent);
    font-weight: 600;
}

.hero h1 {
    margin: 0 0 14px;
    font-size: clamp(1.9rem, 4.4vw, 3.1rem);
    line-height: 1.16;
    letter-spacing: -0.02em;
}

.grad {
    background: linear-gradient(100deg, #7dd3fc, #a5b4fc 45%, #f0abfc);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lede {
    margin: 0;
    max-width: 620px;
    color: var(--muted);
    font-size: clamp(0.95rem, 1.4vw, 1.05rem);
}

.lobby-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr);
    gap: clamp(16px, 2.4vw, 26px);
    align-items: start;
}

.panel {
    background: linear-gradient(170deg, rgba(23, 34, 60, 0.9), rgba(10, 16, 31, 0.86));
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: clamp(18px, 2.4vw, 26px);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.panel-head h2 {
    margin: 0;
    font-size: 1.16rem;
    letter-spacing: 0.01em;
}

.panel-tip {
    font-size: 0.78rem;
    color: var(--muted);
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.character-card {
    --c: var(--accent);
    --a: #0284c7;
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        "avatar info"
        "avatar best";
    align-items: center;
    gap: 2px 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background:
        radial-gradient(120% 130% at 0% 0%, color-mix(in srgb, var(--c) 26%, transparent), transparent 62%),
        rgba(10, 17, 33, 0.72);
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.character-card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--c) 55%, transparent);
    box-shadow: 0 18px 36px -24px color-mix(in srgb, var(--c) 70%, transparent);
}

.character-card:focus-visible {
    outline: 2px solid var(--c);
    outline-offset: 3px;
}

.character-card.is-selected {
    border-color: var(--c);
    box-shadow:
        0 0 0 3px color-mix(in srgb, var(--c) 26%, transparent),
        0 22px 44px -26px color-mix(in srgb, var(--c) 80%, transparent);
}

.avatar {
    grid-area: avatar;
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border-radius: 16px;
    background: color-mix(in srgb, var(--c) 16%, rgba(7, 13, 27, 0.9));
    border: 1px solid color-mix(in srgb, var(--c) 34%, transparent);
    color: var(--c);
}

.car-icon {
    width: 38px;
    height: 30px;
    filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
}

.char-info {
    grid-area: info;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.char-name {
    font-size: 1.06rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.char-title {
    font-size: 0.78rem;
    color: var(--muted);
}

.char-best {
    grid-area: best;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--muted);
}

.char-best b {
    color: var(--c);
    font-size: 0.92rem;
}

.garage {
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px dashed var(--line);
}

.garage-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.garage-head h3 {
    margin: 0;
    font-size: 0.82rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
}

.garage-note {
    font-size: 0.74rem;
    color: var(--muted);
}

.garage-body {
    display: grid;
    grid-template-columns: 132px minmax(0, 1fr);
    gap: 18px;
    margin-top: 14px;
    align-items: center;
}

.garage-preview {
    position: relative;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background:
        radial-gradient(120% 90% at 50% 0%, rgba(56, 189, 248, 0.12), transparent 70%),
        rgba(7, 13, 27, 0.66);
    overflow: hidden;
    padding: 6px 6px 22px;
}

#garage-canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 12px;
}

.garage-label {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
}

.garage-controls {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.garage-title {
    display: block;
    margin-bottom: 6px;
    font-size: 0.7rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.model-btn {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(9, 15, 29, 0.72);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.model-btn b {
    font-size: 0.82rem;
    font-weight: 600;
}

.model-btn small {
    font-size: 0.66rem;
    color: var(--muted);
}

.model-btn:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
}

.model-btn.is-active {
    border-color: color-mix(in srgb, var(--accent) 62%, transparent);
    background: color-mix(in srgb, var(--accent) 15%, rgba(9, 15, 29, 0.86));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 18%, transparent);
}

.color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-chip {
    position: relative;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    background: var(--c, var(--accent));
    box-shadow: inset 0 0 0 1px rgba(3, 7, 18, 0.5);
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.color-chip:hover {
    transform: translateY(-1px) scale(1.06);
}

.color-chip.is-active {
    border-color: #fff;
    box-shadow:
        0 0 0 2px color-mix(in srgb, var(--c, var(--accent)) 55%, transparent),
        inset 0 0 0 1px rgba(3, 7, 18, 0.4);
}

.color-default {
    display: grid;
    place-items: center;
    background: conic-gradient(
        from 210deg,
        #38bdf8,
        #34d399,
        #fbbf24,
        #f472b6,
        #a78bfa,
        #38bdf8
    );
}

.color-default span {
    padding: 0 3px;
    border-radius: 6px;
    background: rgba(5, 9, 19, 0.72);
    color: #e9f0fb;
    font-size: 0.52rem;
    letter-spacing: 0.04em;
    line-height: 1.2;
    white-space: nowrap;
}

.start-row {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px dashed var(--line-strong);
}

.btn {
    font: inherit;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 14px;
    padding: 12px 26px;
    cursor: pointer;
    transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, opacity 0.16s ease;
    color: var(--text);
    background: rgba(30, 41, 59, 0.82);
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(120deg, #22d3ee, #6366f1);
    color: #041020;
    border: none;
    box-shadow: 0 16px 34px -18px rgba(56, 189, 248, 0.8);
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 20px 40px -16px rgba(56, 189, 248, 0.9);
}

.btn-ghost {
    background: transparent;
    border-color: var(--line-strong);
    color: var(--text);
    padding: 9px 18px;
    font-size: 0.86rem;
}

.hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    margin: 0 2px;
    border: 1px solid var(--line-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: rgba(8, 14, 28, 0.9);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.72rem;
    text-align: center;
    color: #cbd5e1;
}

.champion-slot {
    margin-bottom: 18px;
}

.champion {
    --c: var(--gold);
    display: grid;
    gap: 2px;
    padding: 18px;
    border-radius: var(--radius-md);
    border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
    background:
        radial-gradient(130% 100% at 0% 0%, color-mix(in srgb, var(--c) 24%, transparent), transparent 68%),
        rgba(9, 15, 30, 0.8);
}

.champion-crown {
    justify-self: start;
    font-size: 0.68rem;
    letter-spacing: 0.22em;
    font-weight: 700;
    color: var(--gold);
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid rgba(251, 191, 36, 0.4);
    background: rgba(251, 191, 36, 0.1);
}

.champion-name {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.champion-score {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
}

.champion-score small {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 500;
}

.champion-meta {
    font-size: 0.78rem;
    color: var(--muted);
}

.champion-empty .champion-name {
    color: #cbd5e1;
    font-size: 1.2rem;
}

.champion-empty .champion-score {
    color: #94a3b8;
}

.board-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.board-row {
    --c: var(--accent);
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: rgba(9, 16, 31, 0.6);
    transition: border-color 0.2s ease, background 0.2s ease;
}

.board-row:hover {
    border-color: var(--line-strong);
}

.board-row:first-child {
    border-color: color-mix(in srgb, var(--gold) 42%, transparent);
    background: linear-gradient(100deg, rgba(251, 191, 36, 0.12), rgba(9, 16, 31, 0.6));
}

.rank {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--c) 22%, transparent);
    color: var(--c);
    font-weight: 700;
    font-size: 0.86rem;
}

.board-row:first-child .rank {
    background: rgba(251, 191, 36, 0.18);
    color: var(--gold);
}

.board-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-weight: 600;
}

.board-name small {
    color: var(--muted);
    font-weight: 400;
    font-size: 0.72rem;
}

.board-score {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--c);
}

.board-score small {
    margin-left: 3px;
    font-size: 0.7rem;
    color: var(--muted);
    font-weight: 500;
}

.recent {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed var(--line-strong);
}

.recent h3 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.06em;
}

.recent-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 7px;
}

.recent-row {
    display: grid;
    grid-template-columns: 10px minmax(0, auto) minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    font-size: 0.8rem;
    color: var(--muted);
    animation: fade-in 0.3s ease;
}

.recent-name {
    color: var(--text);
    font-weight: 600;
}

.recent-detail {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.74rem;
}

.recent-score {
    color: var(--gold);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.recent-empty {
    color: var(--muted);
    font-size: 0.8rem;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c);
    box-shadow: 0 0 10px color-mix(in srgb, var(--c) 70%, transparent);
}

.race-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    max-width: 720px;
    margin: 0 auto 16px;
}

.race-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 1;
}

.race-character {
    font-weight: 800;
    font-size: 1.06rem;
    letter-spacing: 0.04em;
}

.race-sub {
    font-size: 0.75rem;
    color: var(--muted);
}

.race-best {
    font-size: 0.8rem;
    color: var(--muted);
}

.race-best b {
    color: var(--gold);
    font-size: 0.95rem;
}

.stage {
    position: relative;
    width: 100%;
    max-width: 520px;
    height: min(76vh, 800px);
    margin: 0 auto;
    border-radius: 26px;
    overflow: hidden;
    border: 1px solid var(--line-strong);
    background: #0a1322;
    box-shadow: 0 40px 80px -40px rgba(2, 8, 23, 0.95), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
    touch-action: none;
    user-select: none;
}

#game {
    display: block;
    width: 100%;
    height: 100%;
}

.hud {
    position: absolute;
    inset: 12px 12px auto;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    pointer-events: none;
}

.hud-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 64px;
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(5, 10, 22, 0.62);
    backdrop-filter: blur(10px);
}

.hud-label {
    font-size: 0.64rem;
    letter-spacing: 0.14em;
    color: var(--muted);
}

.hud-item b {
    font-size: 1.06rem;
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
}

.hud-item b small {
    font-size: 0.62rem;
    margin-left: 2px;
    color: var(--muted);
    font-weight: 500;
}

.hud-speed {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid rgba(56, 189, 248, 0.28);
    background: rgba(5, 10, 22, 0.62);
    backdrop-filter: blur(10px);
    color: var(--accent);
    line-height: 1.2;
}

.hud-speed b {
    font-size: 1.16rem;
    font-variant-numeric: tabular-nums;
}

.hud-speed small {
    font-size: 0.6rem;
    color: var(--muted);
    letter-spacing: 0.08em;
}

.hud-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.hud-buffs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hud-buffs:empty {
    display: none;
}

.buff-chip {
    --c: var(--accent);
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--c) 46%, transparent);
    background: color-mix(in srgb, var(--c) 14%, rgba(5, 10, 22, 0.72));
    color: var(--c);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    line-height: 1.45;
    backdrop-filter: blur(8px);
}

.attack-btn {
    position: absolute;
    right: 14px;
    bottom: 18px;
    width: 66px;
    height: 66px;
    padding: 0;
    border: 1px solid rgba(56, 189, 248, 0.55);
    border-radius: 50%;
    background: radial-gradient(circle at 50% 35%, rgba(56, 189, 248, 0.3), rgba(5, 10, 22, 0.9) 72%);
    color: #e0f2fe;
    font: inherit;
    cursor: pointer;
    z-index: 4;
    pointer-events: auto;
    touch-action: none;
    box-shadow:
        0 12px 28px -14px rgba(56, 189, 248, 0.9),
        inset 0 0 20px rgba(56, 189, 248, 0.16);
    transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.attack-btn:active {
    transform: scale(0.94);
    box-shadow:
        0 6px 16px -10px rgba(56, 189, 248, 0.9),
        inset 0 0 24px rgba(56, 189, 248, 0.28);
}

.attack-btn.is-cooling {
    opacity: 0.72;
}

.attack-core {
    position: relative;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

.attack-cool {
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: rgba(4, 8, 18, 0.68);
    transform-origin: bottom center;
    transform: scaleY(0);
    pointer-events: none;
    transition: transform 0.08s linear;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(4, 8, 18, 0.74);
    backdrop-filter: blur(8px);
    transition: opacity 0.25s ease, visibility 0.25s ease;
    z-index: 5;
}

.overlay.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.overlay-card {
    width: 100%;
    max-width: 340px;
    text-align: center;
    display: grid;
    gap: 10px;
    animation: pop-in 0.32s cubic-bezier(0.22, 1.2, 0.4, 1);
}

@keyframes pop-in {
    from {
        opacity: 0;
        transform: scale(0.94);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.overlay-eyebrow {
    margin: 0;
    font-size: 0.7rem;
    letter-spacing: 0.26em;
    color: var(--accent);
    font-weight: 600;
}

.overlay-card h2 {
    margin: 0;
    font-size: clamp(1.6rem, 4.6vw, 2.2rem);
    line-height: 1.2;
}

.overlay-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.overlay-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 6px;
}

.result-score {
    display: grid;
    gap: 2px;
    padding: 12px;
    border-radius: 16px;
    border: 1px solid rgba(56, 189, 248, 0.26);
    background: rgba(56, 189, 248, 0.08);
}

.result-score b {
    font-size: 2.4rem;
    line-height: 1.05;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.result-score span {
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    color: var(--muted);
}

.result-meta {
    display: flex;
    justify-content: center;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--muted);
}

.result-meta b {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.result-flag {
    justify-self: center;
    font-size: 0.76rem;
    padding: 3px 12px;
    border-radius: 999px;
    border: 1px solid rgba(251, 191, 36, 0.4);
    background: rgba(251, 191, 36, 0.12);
    color: var(--gold);
    font-weight: 600;
}

.countdown {
    font-size: clamp(3.4rem, 16vw, 6rem);
    font-weight: 800;
    line-height: 1;
    color: var(--accent);
    text-shadow: 0 0 42px rgba(56, 189, 248, 0.55);
    animation: count-pop 0.6s ease;
}

@keyframes count-pop {
    from {
        opacity: 0;
        transform: scale(1.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 18px clamp(18px, 4vw, 48px);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.76rem;
}

@media (max-width: 960px) {
    .lobby-grid {
        grid-template-columns: 1fr;
    }

    .stage {
        height: min(72vh, 720px);
    }
}

@media (max-width: 560px) {
    .topbar {
        padding: 14px 16px;
    }

    .topbar-note {
        display: none;
    }

    .wrap {
        padding: 22px 14px 30px;
    }

    .character-card {
        padding: 13px;
        gap: 2px 10px;
    }

    .avatar {
        width: 46px;
        height: 46px;
    }

    .car-icon {
        width: 30px;
        height: 24px;
    }

    .char-name {
        font-size: 0.98rem;
    }

    .start-row {
        gap: 12px;
    }

    .garage-body {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .garage-preview {
        width: min(180px, 100%);
    }

    .garage-controls {
        width: 100%;
    }

    .start-row .btn {
        flex: 1;
    }

    .hint {
        flex-basis: 100%;
    }

    .stage {
        height: min(70vh, 640px);
        border-radius: 20px;
    }

    .hud {
        inset: 8px 8px auto;
    }

    .hud-item {
        min-width: 56px;
        padding: 5px 9px;
    }

    .attack-btn {
        right: 10px;
        bottom: 12px;
        width: 58px;
        height: 58px;
    }

    .attack-core {
        font-size: 0.74rem;
    }
}

/* ---------------------------------------------------------------- */
/* Portrait race mode                                               */
/* ---------------------------------------------------------------- */

.live-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.9);
    animation: pulse-dot 1.8s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.35;
    }
}

body.race-mode {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

body.race-mode .ambient,
body.race-mode .topbar,
body.race-mode .footer {
    display: none;
}

body.race-mode .wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 620px;
    height: 100vh;
    height: 100dvh;
    padding: 8px 10px 10px;
    margin: 0 auto;
}

body.race-mode #race.is-active {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
}

body.race-mode .race-head {
    flex: none;
    margin-bottom: 8px;
    gap: 10px;
}

body.race-mode .stage {
    flex: 1;
    width: 100%;
    max-width: 560px;
    height: auto;
    min-height: 0;
    border-radius: 22px;
}

.race-rank {
    font-size: 0.8rem;
    color: var(--muted);
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(8, 15, 30, 0.7);
    white-space: nowrap;
}

.race-rank b {
    color: var(--accent);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.live-board {
    position: absolute;
    top: 66px;
    left: 8px;
    right: 8px;
    display: flex;
    gap: 5px;
    pointer-events: none;
    z-index: 3;
}

.live-chip {
    --c: var(--accent);
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
        "pos name"
        "pos score";
    align-items: center;
    column-gap: 5px;
    padding: 4px 6px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(5, 10, 22, 0.58);
    backdrop-filter: blur(8px);
    line-height: 1.2;
}

.live-chip.is-me {
    border-color: color-mix(in srgb, var(--c) 60%, transparent);
    background: rgba(9, 20, 40, 0.72);
    box-shadow: 0 0 12px -4px color-mix(in srgb, var(--c) 60%, transparent);
}

.live-chip.is-finished .live-pos {
    color: var(--gold);
}

.live-pos {
    grid-area: pos;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--c);
    font-variant-numeric: tabular-nums;
}

.live-name {
    grid-area: name;
    font-size: 0.66rem;
    font-weight: 600;
    color: #cbd5e1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-score {
    grid-area: score;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--c);
    font-variant-numeric: tabular-nums;
}

.overlay-card {
    max-height: 90%;
    overflow-y: auto;
    scrollbar-width: none;
}

.overlay-card::-webkit-scrollbar {
    display: none;
}

.result-list {
    list-style: none;
    margin: 2px 0;
    padding: 0;
    display: grid;
    gap: 6px;
    text-align: left;
}

.result-row {
    --c: var(--accent);
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(9, 16, 31, 0.66);
}

.result-row.is-me {
    border-color: color-mix(in srgb, var(--c) 55%, transparent);
    background: color-mix(in srgb, var(--c) 12%, rgba(9, 16, 31, 0.66));
}

.result-row.is-champion {
    border-color: rgba(251, 191, 36, 0.45);
    background: linear-gradient(100deg, rgba(251, 191, 36, 0.14), rgba(9, 16, 31, 0.66));
}

.result-row.is-done .result-name small {
    color: var(--gold);
}

.result-rank {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--c) 20%, transparent);
    color: var(--c);
    font-size: 0.76rem;
    font-weight: 700;
}

.result-row.is-champion .result-rank {
    background: rgba(251, 191, 36, 0.2);
    color: var(--gold);
}

.result-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: 0.86rem;
    font-weight: 600;
}

.result-name small {
    font-size: 0.66rem;
    font-weight: 400;
    color: var(--muted);
}

.result-score {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--c);
    font-variant-numeric: tabular-nums;
}

.result-score small {
    margin-left: 2px;
    font-size: 0.64rem;
    color: var(--muted);
    font-weight: 500;
}

/* ---------------------------------------------------------------- */
/* Matchmaking modal                                                */
/* ---------------------------------------------------------------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(3, 7, 16, 0.78);
    backdrop-filter: blur(10px);
    animation: fade-in 0.25s ease;
}

.modal.is-hidden {
    display: none;
}

.modal-card {
    width: 100%;
    max-width: 380px;
    padding: 26px 22px 22px;
    border-radius: 24px;
    border: 1px solid var(--line-strong);
    background: linear-gradient(170deg, rgba(23, 34, 60, 0.96), rgba(8, 13, 26, 0.96));
    box-shadow: 0 40px 90px -40px rgba(2, 8, 23, 0.95);
    text-align: center;
    display: grid;
    gap: 10px;
}

.modal-card h2 {
    margin: 0;
    font-size: 1.5rem;
}

.modal-hint {
    margin: 4px 0 6px;
    font-size: 0.74rem;
    color: var(--muted);
    line-height: 1.55;
}

.seat-list {
    list-style: none;
    margin: 6px 0;
    padding: 0;
    display: grid;
    gap: 7px;
    text-align: left;
}

.seat {
    --c: var(--accent);
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 13px;
    border: 1px solid rgba(148, 163, 184, 0.14);
    background: rgba(8, 14, 28, 0.68);
    opacity: 0.58;
    transition: opacity 0.2s ease, border-color 0.2s ease;
}

.seat.is-filled {
    opacity: 1;
    border-color: color-mix(in srgb, var(--c) 44%, transparent);
}

.seat.is-me {
    border-color: var(--c);
    background: color-mix(in srgb, var(--c) 12%, rgba(8, 14, 28, 0.8));
}

.seat-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--c) 50%, #334155);
}

.seat.is-filled .seat-dot {
    background: var(--c);
    box-shadow: 0 0 10px color-mix(in srgb, var(--c) 80%, transparent);
}

.seat-name {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    font-weight: 600;
}

.seat-name small {
    font-size: 0.66rem;
    font-weight: 400;
    color: var(--muted);
}

.seat-state {
    font-size: 0.72rem;
    color: var(--muted);
}

.seat.is-filled .seat-state {
    color: var(--c);
    font-weight: 600;
}

.modal .btn {
    justify-self: center;
    min-width: 140px;
}

@media (max-width: 560px) {
    body.race-mode .wrap {
        padding: 6px 8px 8px;
    }

    .race-head .btn-ghost {
        padding: 7px 12px;
        font-size: 0.78rem;
    }

    .race-character {
        font-size: 0.94rem;
    }

    .race-sub {
        font-size: 0.68rem;
    }

    .race-rank {
        padding: 6px 10px;
        font-size: 0.72rem;
    }

    .live-board {
        top: 62px;
        left: 6px;
        right: 6px;
        gap: 4px;
    }

    .live-chip {
        padding: 3px 5px;
    }

    .live-name {
        font-size: 0.6rem;
    }

    .live-score {
        font-size: 0.62rem;
    }

    .result-row {
        padding: 7px 9px;
    }

    .modal-card {
        padding: 22px 16px 18px;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    body.race-mode .wrap {
        max-width: 100%;
    }

    body.race-mode .stage {
        max-width: none;
    }
}
