:root {
    --primary: #f5f5f5;
    --accent: #ff4d4d;
    --bg-dark: rgba(0, 0, 0, 0.7);
    --bg-light: rgba(255, 255, 255, 0.1);
    --yellow: #f1c40f;
    --blue: #002d62; /* Dominican Blue */
    --red: #ce1126;  /* Dominican Red */
    --green: #2ecc71;
    --font-main: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent; /* Quita el cuadro gris al tocar en móviles */
    -webkit-touch-callout: none; /* Bloquea el menú contextual en iOS */
    -webkit-user-select: none; /* Bloquea selección de texto en iOS */
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none; /* Bloquea selección de texto general */
}

body {
    font-family: var(--font-main);
    background-color: #111;
    color: var(--primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    touch-action: manipulation;
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#ui-container {
    position: relative;
    z-index: 10;
    pointer-events: none;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}

#start-screen,
#pause-screen,
#game-over,
.panel,
button,
.nav-btn,
#car-preview-box,
#mobile-controls {
    pointer-events: auto;
}

button,
.nav-btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

header {
    background: linear-gradient(0deg, rgba(0,0,0,0.8) 0%, transparent 100%);
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
}

header::after {
    display: none;
}

h1 {
    font-weight: 900;
    font-size: 2.5rem;
    letter-spacing: -2px;
    color: var(--primary);
    text-shadow: 2px 2px 20px rgba(255, 255, 255, 0.1);
}

#stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    background: var(--bg-light);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 0.5rem 1.5rem;
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.label {
    font-size: 0.8rem;
    text-transform: uppercase;
    opacity: 0.7;
    font-weight: 700;
}

.value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--yellow);
}

#patience-bar {
    width: 150px;
    height: 8px;
    background: rgba(0,0,0,0.5);
    border-radius: 4px;
    margin-top: 5px;
    overflow: hidden;
}

#patience-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #2ecc71, #f1c40f, #e74c3c);
    background-size: 200% 100%;
    transition: width 0.3s ease;
}

#start-screen {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: flex-end; /* En PC lo movemos a la derecha */
    align-items: center;
    padding-right: 8vw; /* Espacio elegante a la derecha */
    z-index: 1000;
    pointer-events: auto;
    background: radial-gradient(circle at right, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.8) 100%);
}

@media (max-width: 768px) {
    #start-screen {
        align-items: flex-start; 
        padding-top: 10vh; 
        padding-right: 0;
        justify-content: center; /* En móvil se queda centrado */
        background: radial-gradient(circle at center, transparent 0%, rgba(0,0,0,0.6) 100%);
    }
}

#game-over-overlay, #pause-screen, .overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(12px);
}

.panel {
    background: rgba(20, 20, 25, 0.95);
    backdrop-filter: blur(15px);
    padding: 3rem 2.5rem;
    border-radius: 3rem;
    border: 1px solid rgba(255,255,255,0.08); /* Borde sutil, no blanco sólido */
    text-align: center;
    max-width: 500px;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
    position: relative;
    overflow: hidden;
    animation: panelEnter 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes panelEnter {
    from { opacity: 0; transform: translateY(30px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.hero-title {
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 1rem;
    line-height: 1;
    background: linear-gradient(135deg, #fff, #aaa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.description {
    font-size: 1.1rem;
    opacity: 0.8;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.controls-hint {
    background: rgba(0,0,0,0.3);
    padding: 1rem;
    border-radius: 1rem;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.game-over-panel {
    border: 2px solid var(--red);
    box-shadow: 0 0 50px rgba(231, 76, 60, 0.3);
}

.emoji-header {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
}

.final-score-card {
    background: rgba(255,255,255,0.05);
    padding: 1.5rem;
    border-radius: 1.5rem;
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,0.1);
}

.score-label {
    font-size: 0.9rem;
    font-weight: 700;
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.score-number {
    font-size: 4rem;
    font-weight: 900;
    color: var(--yellow);
    text-shadow: 0 0 20px rgba(241, 196, 15, 0.5);
}

.btn-primary-glow, .btn-main {
    background: #fff;
    color: #000;
    border: none;
    padding: 1.2rem 2.5rem;
    border-radius: 1.2rem;
    font-weight: 900;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-home {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 1.2rem 2rem;
    border-radius: 1.2rem;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.btn-main:hover {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 20px 40px rgba(255, 255, 255, 0.3);
    background: #f1f1f1;
}

.btn-home:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.02);
}

.overlay-card {
    background: rgba(20, 20, 25, 0.95);
    padding: 40px;
    border-radius: 40px;
    width: 100%;
    max-width: 460px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 40px 100px rgba(0,0,0,0.8);
    animation: panelEnter 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

button:active {
    transform: translateY(0) scale(1);
}

.hidden {
    display: none !important;
}

#mobile-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 18px;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
    gap: 16px;
}

.mobile-cluster {
    display: flex;
    gap: 12px;
}

.touch-btn {
    min-width: 86px;
    min-height: 64px;
    border: 0;
    border-radius: 20px;
    background: rgba(10, 15, 25, 0.78);
    color: #fff;
    font-weight: 900;
    font-size: 1rem;
    letter-spacing: 0.04em;
    border: 1px solid rgba(255,255,255,0.14);
    box-shadow: 0 12px 24px rgba(0,0,0,0.24);
    backdrop-filter: blur(10px);
}

.touch-btn-arrow {
    font-size: 2rem;
    line-height: 1;
}

.touch-btn:active {
    transform: scale(0.97);
    background: rgba(206, 17, 38, 0.92);
}

.touch-btn-secondary:active {
    background: rgba(0, 45, 98, 0.92);
}

/* Glassmorphism details */
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
}

.showroom-panel {
    /* Eliminamos la línea blanca de la derecha */
    border-right: none;
}

.badge {
    background: var(--red);
    color: white;
    padding: 0.3rem 1rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 900;
    display: inline-block;
    margin-bottom: 1.5rem;
    animation: pulse 2s infinite;
    letter-spacing: 1px;
}

@keyframes pulse {
    0% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0.8; transform: scale(1); }
}

.highlight {
    color: var(--yellow);
    text-shadow: 0 0 20px rgba(241, 196, 15, 0.4);
}

.showroom-selector {
    margin: 2.5rem 0;
    background: rgba(255,255,255,0.05);
    padding: 1.5rem;
    border-radius: 1.5rem;
    border: 1px solid rgba(255,255,255,0.1);
}

.selector-label {
    display: block;
    font-size: 0.75rem;
    opacity: 0.5;
    margin-bottom: 1.2rem;
    font-weight: 900;
    letter-spacing: 2px;
}

.selector-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.nav-btn {
    background: var(--red);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.4);
}

.nav-btn:hover {
    transform: scale(1.1);
    background: #ff4d4d;
    box-shadow: 0 8px 20px rgba(231, 76, 60, 0.6);
}

#car-preview-box {
    flex: 1;
    min-width: 160px;
}

#car-name {
    font-weight: 900;
    font-size: 1.4rem;
    letter-spacing: 1px;
    color: var(--yellow);
    text-transform: uppercase;
}

.controls-card {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
    background: rgba(255,255,255,0.03);
    padding: 1.2rem;
    border-radius: 1.5rem;
}

.control-key {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.7;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    text-transform: uppercase;
}

.control-key span {
    background: rgba(255,255,255,0.15);
    padding: 0.3rem 0.6rem;
    border-radius: 0.5rem;
    margin-right: 0.5rem;
    font-weight: 900;
    color: #fff;
    border-bottom: 2px solid rgba(255,255,255,0.2);
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    header {
        position: fixed;
        top: 0;
        bottom: auto;
        padding: 15px;
        flex-direction: row; /* Título y botón en la misma línea */
        justify-content: center;
        align-items: center;
        width: 100%;
        background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, transparent 100%);
        pointer-events: none;
    }

    header h1 {
        font-size: 1.4rem;
        margin: 0;
        pointer-events: auto;
    }

    #stats {
        position: fixed;
        top: 65px; /* Debajo del título en la zona del cielo */
        bottom: auto;
        left: 0;
        right: 0;
        justify-content: center;
        gap: 8px;
        padding: 0 10px;
        pointer-events: none;
        z-index: 100;
        
        display: flex !important; /* Asegurar visibilidad */
    }
    
    #start-screen:not(.hidden) ~ #stats,
    #game-over-overlay:not(.hidden) ~ #stats {
        display: none !important;
    }

    header h1 {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }

    #stats {
        gap: 0.5rem;
        width: 100%;
        justify-content: space-between;
    }

    header::after {
        display: none;
    }

    .stat-item {
        padding: 0.3rem 0.8rem;
        border-radius: 0.5rem;
        background: rgba(0,0,0,0.4);
    }

    .label {
        font-size: 0.6rem;
    }

    .value {
        font-size: 0.9rem;
    }

    #patience-bar {
        width: 70px;
        height: 5px;
    }

    .hero-title {
        font-size: 1.8rem;
    }

    .panel {
        padding: 1.5rem;
        width: 90%;
    }

    .description {
        font-size: 0.9rem;
    }

    #mobile-controls {
        bottom: max(18px, env(safe-area-inset-bottom));
    }

    .mobile-cluster {
        width: calc(50% - 8px);
        justify-content: center;
    }

    .touch-btn {
        min-width: 72px;
        min-height: 58px;
        font-size: 0.95rem;
    }

    /* Menú de inicio compacto en móvil */
    #start-screen, #pause-screen, #game-over {
        justify-content: center;
        padding-top: 1rem;
    }

    .showroom-panel {
        padding: 1rem;
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .hero-title {
        font-size: 1.6rem;
        margin-bottom: 0.5rem;
    }

    .showroom-selector {
        margin: 1rem 0;
        padding: 0.8rem;
    }

    .showroom-selector .selector-controls {
        gap: 0.5rem;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
    }

    #car-name {
        font-size: 1rem;
    }

    .controls-card {
        display: none; /* No mostramos controles de teclado en móvil */
    }

    .btn-primary-glow {
        padding: 0.8rem 2rem;
        font-size: 1rem;
    }

}
/* Mobile Pause Button */
.touch-btn-pause {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    z-index: 100;
    background: rgba(10, 15, 25, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-weight: 900;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
}

.touch-btn-pause:active {
    transform: scale(0.9);
    background: var(--red);
    border-color: white;
}
@media (max-width: 768px) {
    .overlay {
        justify-content: flex-end;
        padding-bottom: 30px;
    }
    .overlay-card {
        padding: 24px;
        width: 95%;
        border-radius: 30px;
    }
}

@media (max-width: 768px) {
    .touch-btn-pause {
        top: 15px;
        right: 15px;
        width: 44px;
        height: 44px;
        font-size: 0.9rem;
    }
}

.mute-btn {
    background: rgba(255,255,255,0.05); /* Más sutil */
    color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 10px 24px;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: inline-block;
    backdrop-filter: blur(5px);
    margin: 0 auto;
    width: auto;
}

.mute-btn:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .mute-btn {
        padding: 7px 14px;
        font-size: 0.65rem;
    }
}
