/* Race Track Feature - Only visible on screens > 1200px */

/* ---- Race Viewport: fixed fullscreen container during race ---- */
.race-viewport {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    overflow: hidden;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* ---- Track Container ---- */
.race-track-container {
    display: none;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 1200px;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: visible;
}

/* When racing: fully opaque */
.race-track-container.racing {
    z-index: auto; /* inside fixed viewport, no need */
}

.race-track-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* --- SVG Track Layers (bottom to top) --- */

/* Red curb layer (solid, outermost visible layer) */
.race-track-curb {
    fill: none;
    stroke: transparent;
    stroke-width: 224;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.racing .race-track-curb {
    stroke: #FF0000;
}

/* White edge line between curbs and road */
.race-track-edge-outer {
    fill: none;
    stroke: transparent;
    stroke-width: 210;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.racing .race-track-edge-outer {
    stroke: #ffffff;
}

/* Road surface (200px) */
.race-track-road {
    fill: none;
    stroke: transparent;
    stroke-width: 200;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.racing .race-track-road {
    stroke: #222222;
}

/* Finish / Start lines - hidden until racing */
.race-start-line,
.race-finish-line {
    display: none;
}

.racing .race-start-line,
.racing .race-finish-line {
    display: block;
}

/* ---- Toggle Car Button ---- */
.race-toggle-btn {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    pointer-events: all;
    background: rgba(0, 0, 0, 0.75);
    color: #4ade80;
    border: 1.5px solid rgba(74, 222, 128, 0.4);
    border-radius: 8px;
    padding: 8px 16px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.race-toggle-btn:hover {
    background: rgba(74, 222, 128, 0.9);
    color: #000;
    border-color: #4ade80;
    transform: scale(1.04);
}

.race-toggle-btn.off {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.4);
}

.race-toggle-btn.off:hover {
    background: rgba(248, 113, 113, 0.9);
    color: #000;
    border-color: #f87171;
}

/* ---- Start Button ---- */
.race-start-btn {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    pointer-events: all;
    background: rgba(0, 0, 0, 0.75);
    color: #eab01c;
    border: 1.5px solid rgba(234, 176, 28, 0.4);
    border-radius: 8px;
    padding: 8px 16px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.race-start-btn:hover {
    background: rgba(234, 176, 28, 0.9);
    color: #000;
    border-color: #eab01c;
    transform: scale(1.04);
}

.race-start-btn .race-btn-icon {
    margin-right: 6px;
    font-size: 0.85rem;
}

.race-start-btn .race-best-time {
    display: block;
    font-size: 0.6rem;
    font-weight: 400;
    color: rgba(234, 176, 28, 0.7);
    margin-top: 2px;
    letter-spacing: 0.04em;
}

/* ---- Race HUD ---- */
.race-hud {
    display: none;
    position: fixed;
    top: 16px;
    right: 24px;
    z-index: 99999999;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.85);
    border: 1.5px solid rgba(234, 176, 28, 0.5);
    border-radius: 10px;
    padding: 12px 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-family: 'Montserrat', sans-serif;
    min-width: 160px;
    text-align: center;
}

.race-hud-current {
    font-size: 1.8rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.race-hud-label {
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(234, 176, 28, 0.7);
    margin-bottom: 2px;
}

.race-hud-best {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.race-hud-best span {
    color: rgba(234, 176, 28, 0.8);
}

/* ---- Race Car ---- */
.race-car {
    display: none;
    position: absolute;
    width: 32px;
    height: 56px;
    pointer-events: none;
    z-index: 100;
    transform-origin: center center;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
    transition: none;
}

/* Hide cursor car during race */
.race-active .car-cursor,
.race-active .drift-canvas {
    display: none !important;
}

/* ---- Countdown ---- */
.race-countdown {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999999999;
    font-family: 'Montserrat', sans-serif;
    font-size: 6rem;
    font-weight: 700;
    color: #eab01c;
    text-shadow: 0 0 40px rgba(234, 176, 28, 0.4), 0 4px 20px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    animation: race-countdown-pop 0.6s ease-out;
}

@keyframes race-countdown-pop {
    0% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
    50% { opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ---- Finish Overlay ---- */
.race-finish-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999999;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: all;
}

.race-finish-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    animation: race-finish-in 0.5s ease-out;
}

@keyframes race-finish-in {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.race-finish-flag {
    font-size: 3rem;
    margin-bottom: 12px;
}

.race-finish-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: #eab01c;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

.race-finish-time {
    font-family: 'Montserrat', sans-serif;
    font-size: 3.5rem;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
}

.race-finish-record {
    font-family: 'Montserrat', sans-serif;
    font-size: 1rem;
    color: rgba(234, 176, 28, 0.9);
    margin-bottom: 24px;
}

.race-finish-close {
    background: rgba(234, 176, 28, 0.9);
    color: #000;
    border: none;
    border-radius: 6px;
    padding: 10px 28px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: all;
}

.race-finish-close:hover {
    background: #eab01c;
    transform: scale(1.05);
}

/* ---- Name section in Finish Overlay ---- */
.race-finish-name-section {
    margin: 12px auto 4px;
}

.race-finish-name-input {
    display: block;
    width: 240px;
    margin: 0 auto 8px;
    padding: 9px 14px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border: 1.5px solid rgba(234, 176, 28, 0.45);
    border-radius: 6px;
    outline: none;
    text-align: center;
    letter-spacing: 0.04em;
}

.race-finish-name-input:focus {
    border-color: #eab01c;
    background: rgba(255, 255, 255, 0.15);
}

.race-finish-name-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.race-finish-name-error {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.65rem;
    color: #ff6b6b;
    min-height: 16px;
    margin-bottom: 6px;
}

.race-finish-name-btn {
    background: rgba(234, 176, 28, 0.9);
    color: #000;
    border: none;
    border-radius: 6px;
    padding: 9px 24px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.race-finish-name-btn:hover {
    background: #eab01c;
    transform: scale(1.05);
}

/* ---- Leaderboard in Finish Overlay ---- */
.race-leaderboard {
    margin: 16px auto 20px;
    max-width: 340px;
}

.race-lb-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: #eab01c;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 10px;
}

.race-lb-loading {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
}

.race-lb-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.race-lb-row {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
    transition: background 0.2s;
}

.race-lb-row.race-lb-me {
    background: rgba(234, 176, 28, 0.15);
    border: 1px solid rgba(234, 176, 28, 0.4);
    color: #fff;
}

.race-lb-rank {
    width: 32px;
    flex-shrink: 0;
    font-weight: 700;
    text-align: left;
}

.race-lb-name {
    flex: 1;
    text-align: left;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.race-lb-time {
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    color: rgba(234, 176, 28, 0.9);
    font-weight: 600;
    margin-left: 12px;
}

.race-lb-change-name {
    margin-top: 10px;
    font-family: 'Montserrat', sans-serif;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.4);
}

.race-lb-rename {
    background: none;
    border: none;
    color: rgba(234, 176, 28, 0.7);
    font-family: 'Montserrat', sans-serif;
    font-size: 0.65rem;
    cursor: pointer;
    text-decoration: underline;
    padding: 0 4px;
}

.race-lb-rename:hover {
    color: #eab01c;
}

/* ---- Responsive ---- */
@media (min-width: 1201px) {
    .race-track-container {
        display: block;
    }
    .race-start-btn,
    .race-toggle-btn {
        display: block;
    }
}

@media (max-width: 1200px) {
    .race-track-container,
    .race-viewport,
    .race-start-btn,
    .race-toggle-btn,
    .race-hud,
    .race-car,
    .race-countdown,
    .race-finish-overlay {
        display: none !important;
    }
}
