/* ============================================
   Gran Premio Saber 11 — Estilos Base
   Estética retro 16 bits + colores institucionales
   ============================================ */

/* --- Variables CSS --- */
:root {
    /* Colores institucionales */
    --rojo-inst: #AD3333;
    --rojo-inst-light: #D04040;
    --rojo-inst-dark: #8A2828;
    --azul-inst: #003366;
    --azul-inst-light: #004080;
    --azul-inst-dark: #002244;
    --gris-inst: #DADADA;
    --gris-inst-dark: #B0B0B0;

    /* Paleta retro complementaria */
    --bg-dark: #1a1a2e;
    --bg-darker: #0f0f1a;
    --bg-surface: #16213e;
    --bg-card: #1e2a4a;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b8;
    --text-muted: #6c6c80;
    --accent-gold: #FFD700;
    --accent-green: #4ADE80;
    
    /* Variables de estados globales */
    --gp-success: #2ecc71;
    --gp-warning: #f39c12;
    --gp-danger: #e74c3c;
    --gp-primary: #3498db;
    --accent-red: #EF4444;
    --accent-blue: #38BDF8;
    --accent-purple: #A78BFA;

    /* Tamaños */
    --font-pixel: 'Press Start 2P', monospace;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --border-pixel: 3px solid;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --tap-target: 44px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Z-index layers */
    --z-minimap: 100;
    --z-hud: 200;
    --z-modal: 300;
    --z-toast: 400;
}

/* --- Reset y base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Tipografía pixel (solo HUD, títulos, marcadores) --- */
.font-pixel {
    font-family: var(--font-pixel);
    letter-spacing: 1px;
}

h1, h2, h3 {
    font-family: var(--font-pixel);
    line-height: 1.3;
    letter-spacing: 0.5px;
}

h1 { font-size: 1.25rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.875rem; }

/* Textos largos (preguntas, contextos) siempre legibles */
.text-readable {
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 1.7;
}

/* --- Pixel art rendering --- */
.pixel-art,
[data-pixel] {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* --- Contenedores --- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

.container-sm {
    max-width: 640px;
}

.container-md {
    max-width: 768px;
}

/* --- Cards retro con borde pixel --- */
.card-retro {
    background: var(--bg-card);
    border: var(--border-pixel) var(--azul-inst);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    position: relative;
}

.card-retro::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    pointer-events: none;
}

/* Efecto de marco de ventana retro */
.window-retro {
    background: var(--bg-surface);
    border: 3px solid var(--azul-inst-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.window-retro__header {
    background: linear-gradient(90deg, var(--azul-inst), var(--azul-inst-light));
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-pixel);
    font-size: 0.625rem;
    color: white;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.window-retro__body {
    padding: var(--space-md);
}

/* --- Botones --- */
.btn, .pixel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--tap-target);
    padding: var(--space-sm) var(--space-lg);
    font-family: var(--font-pixel);
    font-size: 0.75rem;
    border: 3px solid;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    text-transform: uppercase;
    transition: transform 0.1s, box-shadow 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
    background: var(--rojo-inst);
    border-color: var(--rojo-inst-dark);
    color: white;
    box-shadow: 0 4px 0 var(--rojo-inst-dark);
}

.btn-primary:hover {
    background: var(--rojo-inst-light);
}

.btn-primary:active {
    box-shadow: 0 1px 0 var(--rojo-inst-dark);
    transform: translateY(3px);
}

.btn-secondary {
    background: var(--azul-inst);
    border-color: var(--azul-inst-dark);
    color: white;
    box-shadow: 0 4px 0 var(--azul-inst-dark);
}

.btn-secondary:hover {
    background: var(--azul-inst-light);
}

.btn-success {
    background: #2E7D32;
    border-color: #1B5E20;
    color: white;
    box-shadow: 0 4px 0 #1B5E20;
}

/* Botones de opción de respuesta (ancho completo, mobile-first) */
.btn-option {
    width: 100%;
    min-height: 52px;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: left;
    background: var(--bg-card);
    border: 3px solid var(--azul-inst);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    text-transform: none;
    line-height: 1.4;
}

.btn-option:hover {
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.05);
}

.btn-option.correct {
    border-color: var(--accent-green);
    background: rgba(74, 222, 128, 0.15);
    animation: flashCorrect 0.3s ease;
}

.btn-option.incorrect {
    border-color: var(--accent-red);
    background: rgba(239, 68, 68, 0.15);
    animation: flashIncorrect 0.3s ease;
}

.btn-option .option-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-right: var(--space-sm);
    background: var(--azul-inst);
    color: white;
    font-family: var(--font-pixel);
    font-size: 0.625rem;
    border-radius: 50%;
    flex-shrink: 0;
}

/* --- Formularios --- */
.form-group {
    margin-bottom: var(--space-md);
}

.form-label {
    display: block;
    margin-bottom: var(--space-xs);
    font-family: var(--font-pixel);
    font-size: 0.625rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.form-input {
    width: 100%;
    min-height: var(--tap-target);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-darker);
    border: 2px solid var(--azul-inst);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus {
    border-color: var(--accent-gold);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-error {
    color: var(--accent-red);
    font-size: 0.8125rem;
    margin-top: var(--space-xs);
}

/* --- HUD Retro --- */
.hud {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background: rgba(0, 0, 0, 0.7);
    border-bottom: 3px solid var(--azul-inst);
    font-family: var(--font-pixel);
    font-size: 0.625rem;
    color: var(--accent-gold);
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-label {
    font-size: 0.5rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.hud-value {
    font-size: 0.75rem;
    color: var(--accent-gold);
}

/* --- Mini-mapa (siempre visible) --- */
.minimap-container {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-minimap);
    background: var(--bg-darker);
    border-top: 3px solid var(--azul-inst);
    max-height: 72px;
    overflow: hidden;
}

.minimap-leader-strip {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    background: linear-gradient(90deg, rgba(173, 51, 51, 0.3), rgba(0, 51, 102, 0.3));
    font-family: var(--font-pixel);
    font-size: 0.5rem;
    color: var(--accent-gold);
    min-height: 32px;
}

.minimap-leader-strip .leader-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--accent-gold);
    object-fit: cover;
}

.minimap-leader-strip .leader-crown {
    font-size: 0.75rem;
}

.minimap-leader-strip .leader-name {
    font-size: 0.5625rem;
    color: white;
}

.minimap-leader-strip .leader-progress {
    margin-left: auto;
    color: var(--text-secondary);
}

/* --- Ranking / Clasificación --- */
.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.ranking-table th {
    font-family: var(--font-pixel);
    font-size: 0.5625rem;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-sm);
    border-bottom: 2px solid var(--azul-inst);
    text-align: left;
}

.ranking-table td {
    padding: var(--space-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    vertical-align: middle;
}

.ranking-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.ranking-position {
    font-family: var(--font-pixel);
    font-size: 0.75rem;
    font-weight: bold;
    width: 40px;
    text-align: center;
}

.ranking-position.p1 { color: var(--accent-gold); }
.ranking-position.p2 { color: #C0C0C0; }
.ranking-position.p3 { color: #CD7F32; }

.ranking-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

/* --- Avatar circular con aro de escudería --- */
.pilot-avatar {
    position: relative;
    display: inline-block;
}

.pilot-avatar img {
    border-radius: 50%;
    object-fit: cover;
}

.pilot-avatar--sm img { width: 32px; height: 32px; }
.pilot-avatar--md img { width: 48px; height: 48px; }
.pilot-avatar--lg img { width: 64px; height: 64px; }
.pilot-avatar--xl img { width: 96px; height: 96px; }

.pilot-avatar::after {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border-radius: 50%;
    border: 3px solid var(--team-color, var(--azul-inst));
    pointer-events: none;
}

/* --- Insignias / badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    font-family: var(--font-pixel);
    font-size: 0.5rem;
    border-radius: 2px;
    text-transform: uppercase;
}

.badge-drs {
    background: var(--accent-green);
    color: #000;
    animation: pulseBadge 1s infinite;
}

.badge-bandera-amarilla {
    background: #FFC107;
    color: #000;
}

.badge-pit {
    background: var(--accent-blue);
    color: #000;
}

.badge-vuelta-rapida {
    background: var(--accent-purple);
    color: white;
}

/* --- Temporizador retro --- */
.timer-retro {
    font-family: var(--font-pixel);
    font-size: 1.25rem;
    color: var(--accent-gold);
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.timer-retro.warning {
    color: #FFC107;
    animation: pulseBadge 0.5s infinite;
}

.timer-retro.danger {
    color: var(--accent-red);
    animation: pulseBadge 0.3s infinite;
}

/* --- Ticker de eventos --- */
.ticker {
    display: flex;
    align-items: center;
    padding: var(--space-xs) var(--space-md);
    background: rgba(0, 0, 0, 0.8);
    font-family: var(--font-pixel);
    font-size: 0.5625rem;
    color: var(--accent-gold);
    overflow: hidden;
    white-space: nowrap;
}

.ticker-text {
    animation: tickerScroll 15s linear infinite;
}

/* --- Semáforo de largada --- */
.semaforo {
    display: flex;
    gap: var(--space-sm);
    justify-content: center;
}

.semaforo-luz {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid #333;
    background: #222;
    transition: background 0.2s;
}

.semaforo-luz.rojo { background: #FF0000; box-shadow: 0 0 12px #FF0000; }
.semaforo-luz.verde { background: #00FF00; box-shadow: 0 0 12px #00FF00; }

/* --- Animaciones --- */
@keyframes flashCorrect {
    0%, 100% { background: rgba(74, 222, 128, 0.15); }
    50% { background: rgba(74, 222, 128, 0.35); }
}

@keyframes flashIncorrect {
    0%, 100% { background: rgba(239, 68, 68, 0.15); }
    50% { background: rgba(239, 68, 68, 0.35); }
}

@keyframes pulseBadge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes tickerScroll {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

@keyframes slideInUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes retroBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.animate-slide-up {
    animation: slideInUp 0.3s ease-out;
}

.animate-fade-in {
    animation: fadeIn 0.3s ease-out;
}

.blink-retro {
    animation: retroBlink 0.8s step-end infinite;
}

/* --- Utilidades --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-gold { color: var(--accent-gold); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-muted { color: var(--text-muted); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.p-md { padding: var(--space-md); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* --- Niveles de desempeño --- */
.nivel-4 { color: var(--accent-green); }
.nivel-3 { color: var(--accent-blue); }
.nivel-2 { color: #FFC107; }
.nivel-1 { color: var(--accent-red); }

.nivel-bar {
    height: 8px;
    background: var(--bg-darker);
    border-radius: 4px;
    overflow: hidden;
}

.nivel-bar__fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

/* --- Responsive (mobile-first) --- */

/* Layout de la pantalla de pregunta */
.race-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.race-layout__hud {
    flex-shrink: 0;
}

.race-layout__content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.race-layout__minimap {
    flex-shrink: 0;
}

/* Tablet (>=768px) */
@media (min-width: 768px) {
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1rem; }

    .container {
        padding: 0 var(--space-lg);
    }

    .btn-option {
        font-size: 1rem;
        padding: var(--space-md);
    }
}

/* Desktop (>=1024px) */
@media (min-width: 1024px) {
    h1 { font-size: 1.75rem; }

    .race-layout {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .race-layout__hud {
        width: 100%;
    }

    .race-layout__content {
        flex: 1;
    }

    .race-layout__minimap {
        width: 320px;
        max-height: none;
        border-top: none;
        border-left: 3px solid var(--azul-inst);
        position: sticky;
        top: 0;
        height: 100vh;
    }
}

/* --- prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .ticker-text {
        animation: none;
    }
}
select option {
    background-color: var(--color-bg);
    color: var(--color-text);
}

/* --- Print (informes) --- */
@media print {
    body {
        background: white;
        color: #000;
    }

    .minimap-container,
    .hud,
    .ticker,
    .btn {
        display: none !important;
    }

    .card-retro {
        border-color: #ccc;
        background: white;
    }
}
