/* ═══════════════════════════════════════════════════════════════════════════
   CANICAS RACE — CSS Principal
   Optimizado para formato vertical 1080x1920 (TikTok Live & OBS)
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;800;900&family=Orbitron:wght@700;900&display=swap');

/* ── Reset & Variables ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:    #7c3aed;
    --primary-l:  #a78bfa;
    --accent:     #06b6d4;
    --accent2:    #f59e0b;
    --danger:     #ef4444;
    --success:    #22c55e;
    --bg-deep:    #04001a;
    --bg-mid:     #08002e;
    --glass-bg:   rgba(8,0,46,0.85);
    --glass-border: rgba(124,58,237,0.35);
    --text-main:  #f1f5f9;
    --text-muted: #94a3b8;
    --radius-sm:  8px;
    --radius-md:  14px;
    --radius-lg:  20px;
    --shadow-glow: 0 0 30px rgba(124,58,237,0.4);
    --font-game:  'Orbitron', monospace;
    --font-ui:    'Outfit', sans-serif;
    --w: 1080px;
    --h: 1920px;
}

/* ── Base ─────────────────────────────────────────────────────────────── */
html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    font-family: var(--font-ui);
    color: var(--text-main);
    position: relative;
}

/* ── Game Wrapper ─────────────────────────────────────────────────────── */
#gameWrapper {
    position: relative;
    width: var(--w);
    height: 100vh;
    margin: 0 auto;
    overflow: hidden;
    background: var(--bg-deep);
}

/* ── Canvas ───────────────────────────────────────────────────────────── */
#raceCanvas {
    position: absolute;
    top: 0; left: 0;
    display: block;
    pointer-events: none;
}

/* ════════════════════════════════════════════════════════════════════════
   HEADER — Logo y título
   ════════════════════════════════════════════════════════════════════════ */
#gameHeader {
    position: absolute;
    top: 0; left: 0; right: 0;
    z-index: 100;
    padding: 18px 24px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(4,0,26,0.98) 0%, transparent 100%);
    pointer-events: none;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-marble {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff 0%, var(--primary) 40%, #000 100%);
    box-shadow: 0 0 20px var(--primary), 0 0 40px rgba(124,58,237,0.4);
    animation: logoFloat 3s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50%       { transform: translateY(-5px) rotate(15deg); }
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.logo-title {
    font-family: var(--font-game);
    font-size: 1.8rem;
    font-weight: 900;
    background: linear-gradient(135deg, #a78bfa 0%, #06b6d4 50%, #f59e0b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 2px;
}

.logo-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    letter-spacing: 3px;
    text-transform: uppercase;
}

.header-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.stat-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 0.82rem;
    font-weight: 700;
    backdrop-filter: blur(12px);
    pointer-events: all;
}

.stat-pill .val { color: var(--accent); font-size: 1rem; }

/* ════════════════════════════════════════════════════════════════════════
   PHASE LABEL — Estado de la carrera
   ════════════════════════════════════════════════════════════════════════ */
#phaseBar {
    position: absolute;
    top: 100px; left: 0; right: 0;
    z-index: 90;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

#phaseLabel {
    font-family: var(--font-game);
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 8px 28px;
    background: linear-gradient(135deg, rgba(124,58,237,0.9) 0%, rgba(6,182,212,0.9) 100%);
    border-radius: 30px;
    border: 1px solid rgba(167,139,250,0.4);
    box-shadow: 0 4px 20px rgba(124,58,237,0.35), inset 0 1px 0 rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    animation: phasePulse 2.5s ease-in-out infinite;
}

@keyframes phasePulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(124,58,237,0.35); }
    50%       { box-shadow: 0 4px 30px rgba(6,182,212,0.55), 0 0 60px rgba(124,58,237,0.2); }
}

/* ════════════════════════════════════════════════════════════════════════
   RANKING LATERAL — Top 8 en tiempo real
   ════════════════════════════════════════════════════════════════════════ */
#rankingPanel {
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 80;
    width: 220px;
    pointer-events: none;
}

.ranking-header {
    font-family: var(--font-game);
    font-size: 0.8rem;
    letter-spacing: 2px;
    color: var(--accent2);
    text-align: center;
    margin-bottom: 8px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(245,158,11,0.3);
}

#rankingList {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    background: rgba(8,0,46,0.88);
    border: 1px solid rgba(124,58,237,0.25);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease;
}

.rank-item.finished {
    border-color: rgba(250,204,21,0.5);
    background: rgba(250,204,21,0.08);
}

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

.rank-pos { font-size: 1rem; width: 26px; text-align: center; flex-shrink: 0; }
.rank-flag { font-size: 1.1rem; flex-shrink: 0; }
.rank-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.rank-empty {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-align: center;
    padding: 12px;
}

/* ════════════════════════════════════════════════════════════════════════
   CONTROLES — Panel izquierdo (solo modo PC, oculto en OBS)
   ════════════════════════════════════════════════════════════════════════ */
#controlPanel {
    position: absolute;
    left: 18px;
    bottom: 100px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: all;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.ctrl-btn:hover { transform: scale(1.05); }
.ctrl-btn:active { transform: scale(0.97); }

.btn-start {
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff;
    box-shadow: 0 4px 20px rgba(16,185,129,0.4);
}

.btn-reset {
    background: linear-gradient(135deg, #7c3aed, #5b21b6);
    color: #fff;
    box-shadow: 0 4px 20px rgba(124,58,237,0.4);
}

.btn-bot {
    background: linear-gradient(135deg, #0891b2, #0284c7);
    color: #fff;
    box-shadow: 0 4px 20px rgba(8,145,178,0.4);
}

/* ════════════════════════════════════════════════════════════════════════
   COUNTDOWN — Pantalla de conteo regresivo
   ════════════════════════════════════════════════════════════════════════ */
#countdownDisplay {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    font-family: var(--font-game);
    font-size: 12rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 60px var(--primary), 0 0 120px var(--accent);
    animation: countPulse 0.9s ease-in-out infinite;
    pointer-events: none;
    align-items: center;
    justify-content: center;
}

@keyframes countPulse {
    0%   { transform: translate(-50%, -50%) scale(0.7); opacity: 0.5; }
    50%  { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.7; }
}

/* ════════════════════════════════════════════════════════════════════════
   PODIO — Pantalla de resultados finales
   ════════════════════════════════════════════════════════════════════════ */
#podiumOverlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 300;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: rgba(4,0,26,0.95);
    backdrop-filter: blur(20px);
    pointer-events: all;
    animation: fadeIn 0.5s ease;
}

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

.podium-title {
    font-family: var(--font-game);
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #facc15 0%, #f97316 50%, #ef4444 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    margin-bottom: 40px;
    animation: titleGlow 2s ease-in-out infinite alternate;
    letter-spacing: 3px;
}

@keyframes titleGlow {
    from { filter: drop-shadow(0 0 10px rgba(250,204,21,0.5)); }
    to   { filter: drop-shadow(0 0 30px rgba(250,204,21,0.9)); }
}

.podium-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 20px;
    margin-bottom: 40px;
}

.podium-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    border-radius: 14px 14px 0 0;
    padding: 24px 20px;
    min-width: 200px;
    border: 2px solid rgba(255,255,255,0.15);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease;
}

.podium-slot::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, transparent 100%);
}

.podium-slot-1 {
    height: 280px;
    background: linear-gradient(180deg, rgba(250,204,21,0.25) 0%, rgba(250,204,21,0.08) 100%);
    border-color: rgba(250,204,21,0.5);
    transform: translateY(0);
    animation: podiumBounce 1s ease 0.5s both;
}

.podium-slot-2 {
    height: 230px;
    background: linear-gradient(180deg, rgba(148,163,184,0.2) 0%, rgba(148,163,184,0.05) 100%);
    border-color: rgba(148,163,184,0.4);
    animation: podiumBounce 1s ease 0.7s both;
}

.podium-slot-3 {
    height: 190px;
    background: linear-gradient(180deg, rgba(180,83,9,0.2) 0%, rgba(180,83,9,0.05) 100%);
    border-color: rgba(180,83,9,0.4);
    animation: podiumBounce 1s ease 0.9s both;
}

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

.podium-medal { font-size: 2.8rem; margin-bottom: 8px; }
.podium-flag  { font-size: 3.2rem; margin-bottom: 8px; }
.podium-name  {
    font-size: 1rem;
    font-weight: 800;
    text-align: center;
    color: #fff;
    word-break: break-word;
    max-width: 180px;
}

.podium-pos-badge {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-game);
    font-size: 1.4rem;
    font-weight: 900;
    color: rgba(255,255,255,0.6);
}

.podium-restart-bar {
    width: 300px;
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 20px;
}

.podium-restart-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 4px;
    animation: fillBar 8s linear forwards;
    transform-origin: left;
}

@keyframes fillBar {
    from { width: 0%; }
    to   { width: 100%; }
}

.podium-restart-text {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 10px;
    text-align: center;
}

/* ════════════════════════════════════════════════════════════════════════
   TOAST — Notificaciones de eventos
   ════════════════════════════════════════════════════════════════════════ */
#toastMsg {
    position: absolute;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 150;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(12px);
}

#toastMsg.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#toastMsg.info   { background: rgba(6,182,212,0.9);  color: #fff; border: 1px solid #06b6d4; }
#toastMsg.win    { background: rgba(250,204,21,0.95); color: #000; border: 1px solid #facc15; }
#toastMsg.join   { background: rgba(34,197,94,0.9);  color: #fff; border: 1px solid #22c55e; }
#toastMsg.boost  { background: rgba(245,158,11,0.9);  color: #fff; border: 1px solid #f59e0b; }
#toastMsg.bomb   { background: rgba(239,68,68,0.9);  color: #fff; border: 1px solid #ef4444; }
#toastMsg.warn   { background: rgba(124,58,237,0.9);  color: #fff; border: 1px solid #7c3aed; }

/* ════════════════════════════════════════════════════════════════════════
   EVENT FEED — Feed de eventos TikTok (derecha inferior)
   ════════════════════════════════════════════════════════════════════════ */
#eventFeed {
    position: absolute;
    right: 18px;
    bottom: 220px;
    z-index: 80;
    width: 240px;
    max-height: 160px;
    overflow: hidden;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.feed-item {
    padding: 7px 12px;
    background: rgba(8,0,46,0.88);
    border: 1px solid rgba(124,58,237,0.2);
    border-radius: 20px;
    font-size: 0.75rem;
    backdrop-filter: blur(8px);
    animation: feedIn 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* ════════════════════════════════════════════════════════════════════════
   BOTTOM BAR — Barra inferior con info
   ════════════════════════════════════════════════════════════════════════ */
#bottomBar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    padding: 16px 24px;
    background: linear-gradient(0deg, rgba(4,0,26,0.98) 0%, transparent 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
}

.brand-tag {
    font-family: var(--font-game);
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 2px;
}

.live-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.4);
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    color: #ef4444;
}

.live-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: livePulse 1s ease-in-out infinite;
}

@keyframes livePulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.8); }
}

/* ════════════════════════════════════════════════════════════════════════
   OVERLAY (lobby / fases)
   ════════════════════════════════════════════════════════════════════════ */
#overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 50;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#overlay.lobby {
    background: none;
}

/* ════════════════════════════════════════════════════════════════════════
   PARTICLES CANVAS (overlay)
   ════════════════════════════════════════════════════════════════════════ */
#confettiCanvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 250;
    pointer-events: none;
    display: none;
}

#confettiCanvas.active { display: block; }

/* ════════════════════════════════════════════════════════════════════════
   SCROLLBAR CUSTOM
   ════════════════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }

/* ════════════════════════════════════════════════════════════════════════
   MEDIA QUERIES (OBS Browser Source 1080x1920)
   ════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1080px) {
    :root { --w: 100vw; }
    #gameWrapper { width: 100vw; }
    .logo-title { font-size: 1.4rem; }
    #rankingPanel { width: 190px; right: 10px; }
}

/* ════════════════════════════════════════════════════════════════════════
   CRONÓMETRO — Contador de tiempo de carrera
   ════════════════════════════════════════════════════════════════════════ */
#timerWrapper {
    position: absolute;
    top: 105px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 95;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    pointer-events: none;
}

#timerLabel {
    font-family: var(--font-game);
    font-size: 0.6rem;
    letter-spacing: 3px;
    color: rgba(167,139,250,0.8);
    text-transform: uppercase;
}

.timer-text {
    font-family: var(--font-game);
    font-size: 2.8rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 0 20px rgba(124,58,237,0.8), 0 0 40px rgba(6,182,212,0.4);
    line-height: 1;
    letter-spacing: 3px;
    transition: color 0.5s ease;
}

.timer-text.timer-urgent {
    color: #ef4444;
    text-shadow: 0 0 20px rgba(239,68,68,0.9), 0 0 40px rgba(239,68,68,0.5);
    animation: urgentPulse 0.5s ease-in-out infinite alternate;
}

@keyframes urgentPulse {
    from { transform: scale(1); }
    to   { transform: scale(1.08); }
}

#timerBarOuter {
    width: 200px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

#timerBar {
    height: 100%;
    width: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #7c3aed, #06b6d4);
    transition: width 0.95s linear, background 0.5s ease;
}

/* ════════════════════════════════════════════════════════════════════════
   RANK POWER INDICATOR — Ícono de poder activo en el ranking
   ════════════════════════════════════════════════════════════════════════ */
.rank-power {
    font-size: 0.85rem;
    flex-shrink: 0;
    animation: powerFlash 0.4s ease-in-out infinite alternate;
}

@keyframes powerFlash {
    from { opacity: 0.7; }
    to   { opacity: 1; transform: scale(1.2); }
}

