/* Local Teko Font (100% Offline Support) */
@font-face {
    font-family: 'Teko';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('./fonts/teko-v23-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #0c0d0e;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Teko', 'Arial Narrow', sans-serif;
    user-select: none;
    touch-action: none;
}

button, input, select, textarea {
    font-family: 'Teko', 'Arial Narrow', sans-serif;
}

#game-container {
    position: relative;
    height: 100vh;
    aspect-ratio: 9 / 16;
    max-width: 100vw;
    background-color: #1a1c1e;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

/* Gameplay HUD Layer (Soft, Faded, Cinematic Overlay) */
#hud-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.12) 20%, rgba(0, 0, 0, 0) 45%);
}

.hud-score-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: radial-gradient(ellipse at top left, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 80%);
    padding: 4px 10px 8px 4px;
    border-radius: 8px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    background: transparent;
    border: none;
    padding: 2px 0;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
}

.hud-item.top-right {
    align-items: flex-end;
    text-align: right;
}

.hud-label {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 1.5px;
    color: #e6c846; /* Soft warm gold label */
    margin-bottom: -2px;
    text-transform: uppercase;
    opacity: 0.95;
}

.hud-val-large {
    font-size: 34px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 1px;
    line-height: 1.0;
}

.hud-right-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: auto;
    background: radial-gradient(ellipse at top right, rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0) 80%);
    padding: 2px 4px 10px 12px;
    border-radius: 8px;
}

.hud-btn-row {
    display: flex;
    gap: 8px;
}

/* Minimal Faded Buttons */
.hud-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #e6c846;
    height: 32px;
    padding: 0 12px;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1.5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: background 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
    margin-bottom: 2px;
}

.hud-btn.icon-only {
    width: 32px;
    padding: 0;
    border-radius: 50%;
    font-size: 12px;
}

.hud-btn:hover {
    background: rgba(230, 200, 70, 0.25);
    border-color: rgba(230, 200, 70, 0.5);
    color: #ffffff;
    transform: scale(1.08);
}

.hud-btn:active {
    transform: scale(0.95);
}

.hud-val-unit {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.hud-val {
    font-size: 24px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.0;
}

.hud-val.text-yellow {
    color: #ffd700;
}

.hud-val.text-green {
    color: #4cd964;
}

.unit {
    font-size: 13px;
    font-weight: 600;
    color: #ffd700;
    opacity: 0.95;
}

.text-green {
    color: #4cd964 !important;
}

.text-gold {
    color: #ffcc00 !important;
}

.text-red {
    color: #ff3333 !important;
}

/* Mobile Touch Controls Layer */
#mobile-controls-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 40;
    padding: max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-right));
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    touch-action: none;
}

#mobile-controls-layer.hidden {
    display: none;
}

.touch-btn-group {
    display: flex;
    gap: 14px;
    pointer-events: auto;
    touch-action: none;
}

.touch-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #e6c846;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 18px;
    font-weight: 900;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    user-select: none;
    touch-action: none;
    transition: background 0.1s ease, transform 0.1s ease, border-color 0.1s ease;
}

.touch-btn.accel-btn {
    color: #4cd964;
}

.touch-btn.brake-btn {
    color: #ff3333;
}

.touch-btn:active, .touch-btn.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(0.92);
}

/* Gameplay Unlock Toast Notification */
.toast-notification {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.95) 0%, rgba(255, 153, 0, 0.95) 100%);
    color: #000000;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 1.5px;
    padding: 6px 20px;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(255, 204, 0, 0.5);
    z-index: 90;
    pointer-events: none;
    animation: toastPop 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast-notification.hidden {
    display: none;
}

@keyframes toastPop {
    from {
        opacity: 0;
        transform: translate(-50%, -10px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }
}

/* Overlays (Home, Pause, Game Over, Garage) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, rgba(12, 14, 18, 0.78) 0%, rgba(0, 0, 0, 0.88) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 1;
    transition: opacity 0.35s ease;
    padding: 20px;
}

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

.overlay-box {
    text-align: center;
    background: rgba(22, 24, 28, 0.95);
    padding: 32px 45px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    min-width: 220px;
}

.overlay-title {
    font-size: 38px;
    font-weight: 700;
    letter-spacing: 3px;
    margin-bottom: 20px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.overlay-btn-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-button {
    color: #ffffff;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: 2px;
    padding: 10px 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s ease, background 0.15s ease;
}

.menu-button.btn-green {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
}

.menu-button.btn-green:hover {
    background: linear-gradient(135deg, #34d07b 0%, #2ecc71 100%);
    transform: translateY(-2px);
}

.menu-button.btn-gold {
    background: linear-gradient(135deg, #ffd700 0%, #ccac00 100%);
    color: #000000;
}

.menu-button.btn-gold:hover {
    background: linear-gradient(135deg, #ffe033 0%, #ffd700 100%);
    transform: translateY(-2px);
}

.menu-button.btn-dark {
    background: rgba(40, 44, 52, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.menu-button.btn-dark:hover {
    background: rgba(60, 66, 78, 0.9);
    transform: translateY(-2px);
}

.menu-button.btn-red {
    background: linear-gradient(135deg, #e62e2e 0%, #b31414 100%);
}

.menu-button.btn-red:hover {
    background: linear-gradient(135deg, #ff3d3d 0%, #cc1818 100%);
    transform: translateY(-2px);
}

.menu-button:active {
    transform: translateY(1px);
}

/* Home Screen Container & Layout */
.home-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 380px;
    padding: 12px 10px;
    animation: goSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.home-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 6px;
}

.home-header-stat {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.85);
}

.home-label {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 1.5px;
    color: #a0a6b2;
    text-transform: uppercase;
    margin-bottom: -2px;
}

.home-val-large {
    font-size: 34px;
    font-weight: 700;
    line-height: 1.0;
}

.home-val {
    font-size: 20px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.0;
}

.home-garage-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 215, 0, 0.3);
    color: #ffd700;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1.5px;
    padding: 6px 18px;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s ease, background 0.15s ease;
}

.home-garage-btn:hover {
    background: rgba(255, 215, 0, 0.25);
    transform: scale(1.05);
}

.garage-badge {
    color: #ff3333;
    font-size: 16px;
    line-height: 1;
}

/* Home Hero Section (LaneRush Logo, Selected Car, & Play Button) */
.home-hero-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: 0;
}

/* Prominent Extra Large LaneRush Logo Styling */
.home-logo-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 2px;
    margin-bottom: 6px;
}

.home-logo {
    width: clamp(280px, 86vw, 370px);
    height: auto;
    max-height: 165px;
    object-fit: contain;
    filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.9));
    transition: transform 0.2s ease;
}

.home-car-name {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 2.5px;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
    margin-bottom: 2px;
}

.home-stat-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 2px 14px;
    border-radius: 14px;
    margin-bottom: 8px;
}

.home-stat-pill .pill-label {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 1px;
    color: #e6c846;
}

.home-stat-pill .pill-val {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
}

.home-car-wrapper {
    width: 130px;
    height: clamp(120px, 18vh, 150px);
    display: flex;
    justify-content: center;
    align-items: center;
    filter: drop-shadow(0 12px 25px rgba(0, 0, 0, 0.85));
    animation: carFloat 3s infinite alternate ease-in-out;
    margin-bottom: 4px;
}

@keyframes carFloat {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

.home-car-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Primary Play Button */
.home-play-btn {
    pointer-events: auto;
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: #ffffff;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: 4px;
    padding: 12px 64px;
    border: none;
    border-radius: 35px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(46, 204, 113, 0.5);
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.home-play-btn:hover {
    background: linear-gradient(135deg, #34d07b 0%, #2ecc71 100%);
    box-shadow: 0 10px 30px rgba(52, 208, 123, 0.7);
    transform: translateY(-2px) scale(1.03);
}

.home-play-btn:active {
    transform: translateY(1px) scale(0.97);
}

/* Home Footer Statistics Bar */
.home-footer-stats {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px 8px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 12px 8px;
    border-radius: 12px;
    text-align: center;
}

.stat-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Game Over Container (Cinematic Translucent Summary) */
.game-over-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 320px;
    animation: goSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes goSlideUp {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.game-over-title {
    font-size: 40px;
    font-weight: 700;
    letter-spacing: 4px;
    color: #ff3333;
    text-transform: uppercase;
    margin-bottom: 4px;
    text-shadow: 0 4px 16px rgba(255, 51, 51, 0.4);
}

.new-best-badge {
    background: linear-gradient(135deg, #ffcc00 0%, #ff9900 100%);
    color: #000000;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    padding: 3px 14px;
    border-radius: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 10px rgba(255, 204, 0, 0.5);
    animation: badgePulse 1.2s infinite alternate ease-in-out;
}

.new-best-badge.hidden {
    display: none;
}

@keyframes badgePulse {
    from { transform: scale(1); }
    to { transform: scale(1.06); }
}

.summary-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 28px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
}

.summary-label {
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 2px;
    color: #a0a6b2;
    margin-bottom: -2px;
    text-transform: uppercase;
}

.summary-val-large {
    font-size: 44px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 1px;
    line-height: 1.0;
}

.summary-row {
    display: flex;
    justify-content: space-around;
    width: 100%;
    gap: 12px;
}

.summary-val {
    font-size: 24px;
    font-weight: 600;
    color: #ffffff;
}

.game-over-btn-row {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

/* Translucent Soft Restart Button */
.game-over-restart-btn {
    pointer-events: auto;
    background: rgba(230, 46, 46, 0.85);
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 2px;
    padding: 10px 32px;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(230, 46, 46, 0.4);
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.game-over-restart-btn:hover {
    background: rgba(255, 51, 51, 0.95);
    box-shadow: 0 8px 25px rgba(255, 51, 51, 0.6);
    transform: translateY(-2px);
}

.game-over-restart-btn:active {
    transform: translateY(1px);
}

/* Garage Overlay & Preview Styling */
.garage-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    max-width: 360px;
    animation: goSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.garage-title {
    font-size: 38px;
    font-weight: 700;
    letter-spacing: 4px;
    color: #ffd700;
    text-transform: uppercase;
    margin-bottom: 2px;
    text-shadow: 0 4px 16px rgba(255, 215, 0, 0.4);
}

.garage-car-name {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    color: #ffffff;
    margin-bottom: 4px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

.garage-stat-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 215, 0, 0.25);
    padding: 3px 14px;
    border-radius: 15px;
    margin-bottom: 6px;
}

.garage-stat-badge .stat-label {
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 1.5px;
    color: #e6c846;
}

.garage-stat-badge .stat-val {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
}

.garage-preview-area {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    padding: 6px 0;
    margin-bottom: 14px;
    touch-action: pan-y;
}

.garage-img-wrapper {
    width: 160px;
    height: 210px;
    display: flex;
    justify-content: center;
    align-items: center;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.7));
}

.garage-img-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
}

.garage-img-wrapper img.locked-img {
    filter: brightness(0.4) grayscale(0.5);
    opacity: 0.7;
}

.garage-lock-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin-top: -8px;
    margin-bottom: 18px;
}

.garage-lock-info.hidden {
    display: none;
}

.lock-badge {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #ff3333;
    text-transform: uppercase;
}

.lock-req-text {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    color: #ffd700;
    text-transform: uppercase;
}

.lock-prog-text {
    font-size: 13px;
    font-weight: 500;
    color: #a0a6b2;
}

.garage-nav-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffd700;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    font-weight: 800;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: background 0.15s ease, transform 0.15s ease;
}

.garage-nav-btn:hover {
    background: rgba(255, 215, 0, 0.25);
    transform: scale(1.1);
}

.garage-nav-btn:active {
    transform: scale(0.95);
}

.garage-btn-group {
    display: flex;
    gap: 10px;
    width: 100%;
    justify-content: center;
}

.garage-btn {
    pointer-events: auto;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 2px;
    padding: 10px 22px;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s ease, background 0.15s ease;
}

.garage-btn.btn-gold {
    background: linear-gradient(135deg, #ffd700 0%, #ccac00 100%);
    color: #000000;
}

.garage-btn.btn-gold.selected {
    background: rgba(255, 255, 255, 0.2);
    color: #4cd964;
    border: 1px solid rgba(76, 217, 100, 0.5);
    box-shadow: none;
}

.garage-btn.btn-gold.locked {
    background: rgba(40, 44, 52, 0.6);
    color: #6c727f;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
    cursor: not-allowed;
    pointer-events: none;
}

.garage-btn.btn-green {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: #ffffff;
}

.garage-btn.btn-dark {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #a0a6b2;
}

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

.garage-btn:active {
    transform: translateY(1px);
}
