:root { 
            --bg-color: #0f172a; 
            --card-bg: #1e293b; 
            --accent: #10b981; 
            --wrong: #ef4444; 
            --text: #f8fafc; 
            --secondary: #94a3b8;
            --blue: #3b82f6;
        }

        body {
            font-family: 'Montserrat', sans-serif;
            background-color: var(--bg-color);
            color: var(--text);
            margin: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            padding: 20px;
        }

        header {
            text-align: center;
            margin-bottom: 30px;
        }

        h1 {
            color: var(--accent-color);
            margin-bottom: 5px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        /* Aviso de carga */
        .loading-notice { 
            background: rgba(59, 130, 246, 0.2); 
            border: 1px solid #3b82f6; 
            padding: 10px 15px; 
            border-radius: 8px; 
            font-size: 0.85rem; 
            margin-bottom: 20px; 
            max-width: 500px; 
            text-align: center;
            color: #93c5fd;
        }

        .external-link {
            color: var(--secondary);
            text-decoration: none;
            font-size: 0.85rem;
            transition: color 0.3s;
            display: block;
            margin-top: 10px;
        }

        .external-link:hover { color: var(--accent); }

        /* Filtro */
        select {
            background: var(--card-bg);
            color: white;
            border: 2px solid #334155;
            padding: 10px 20px;
            border-radius: 12px;
            cursor: pointer;
            font-family: inherit;
            margin-bottom: 25px;
            outline: none;
        }

        /* Contenedor Flashcard */
        .flashcard-container {
            perspective: 1200px;
            width: 100%;
            max-width: 500px;
            height: 380px;
            cursor: pointer;
            margin-bottom: 30px;
        }

        .flashcard {
            position: relative;
            width: 100%;
            height: 100%;
            transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
            transform-style: preserve-3d;
        }

        .flashcard.flipped { transform: rotateY(180deg); }

        .front, .back {
            position: absolute;
            width: 100%;
            height: 100%;
            backface-visibility: hidden;
            border-radius: 20px;
            border: 1px solid rgba(255,255,255,0.1);
            background: var(--card-bg);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            overflow: hidden;
            box-shadow: 0 15px 35px rgba(0,0,0,0.4);
        }

        .back { transform: rotateY(180deg); padding: 25px; text-align: center; box-sizing: border-box; }

        img { width: 100%; height: 100%; object-fit: cover; }

        /* Botones y Estadísticas */
        .nav-controls { 
            display: flex; 
            gap: 15px; 
            width: 100%; 
            max-width: 500px; 
            margin-bottom: 30px; 
        }

        .nav-btn { 
            flex: 1; 
            background: rgba(51, 65, 85, 0.4); 
            color: var(--text); 
            border: 1px solid rgba(255,255,255,0.1); 
            padding: 14px; 
            border-radius: 16px; 
            cursor: pointer; 
            font-size: 0.85rem; 
            font-weight: 600;
            transition: all 0.3s ease; 
            backdrop-filter: blur(5px);
        }

        .nav-btn:hover { 
            background: rgba(51, 65, 85, 0.8); 
            border-color: var(--blue); 
            transform: translateY(-2px); 
        }

        .btn-group { 
            display: flex; 
            gap: 15px; 
            margin-top: 25px; 
            }
        
        button {
            padding: 12px 24px;
            border-radius: 12px;
            border: none;
            cursor: pointer;
            font-weight: bold;
            font-family: inherit;
            transition: transform 0.2s, opacity 0.2s;
        }

        button:active { transform: scale(0.95); }
        .btn-correct { background: var(--accent); color: white; }
        .btn-wrong { background: var(--wrong); color: white; }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 12px;
            width: 100%;
            max-width: 500px;
        }

        .stat-card {
            background: rgba(30, 41, 59, 0.4);
            border: 1px solid #334155;
            padding: 12px;
            border-radius: 14px;
            text-align: center;
            transition: all 0.2s ease; /* Añadir transición */
        }

        .stat-card:hover {
            background: rgba(51, 65, 85, 0.8);
            transform: translateY(-3px);
            border-color: var(--blue);
        }

        .stat-val { display: block; font-size: 1.2rem; font-weight: bold; }
        .stat-label { font-size: 0.6rem; color: var(--secondary); text-transform: uppercase; letter-spacing: 1px; }

        .badge {
            background: #334155;
            padding: 5px 12px;
            border-radius: 8px;
            font-size: 0.75rem;
            margin-top: 10px;
            color: var(--accent);
        }

        /* Barra de progreso de precarga */
        #preload-bar-container { 
            width: 100%; 
            max-width: 500px; 
            background: #334155; 
            height: 5px; border-radius: 10px; 
            margin-bottom: 20px; 
            overflow: hidden; 
            display: none; }

        #preload-bar { 
            width: 0%; 
            height: 100%; 
            background: var(--accent); 
            transition: width 0.3s; }

        @keyframes pulse {
            0% { transform: scale(1); opacity: 1; }
            50% { transform: scale(1.05); opacity: 0.8; }
            100% { transform: scale(1); opacity: 1; }
        }
        
        .repaso-active .flashcard {
            border: 2px solid var(--wrong);
        }

        #medals-container {
            position: fixed;
            left: 40px; /* Margen lateral aumentado */
            top: 50%;
            transform: translateY(-50%);
            display: grid;
            grid-template-columns: repeat(3, 1fr); /* 3 columnas */
            gap: 15px;
            z-index: 100;
            max-width: 250px; /* Limita el ancho para que no choque con la carta */
        }

        .medal {
            width: 50px;
            height: 50px;
            font-size: 1.5rem;
            filter: grayscale(1) opacity(0.3);
            transition: all 0.5s ease;
            cursor: help;
            background: var(--card-bg);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 2px solid #334155;
        }

        .medal.unlocked {
            filter: grayscale(0) opacity(1);
            border-color: var(--accent);
            box-shadow: 0 0 15px var(--accent);
        }

        /* Tooltip de Medalla */
        .medal:hover::after {
            content: attr(data-info);
            position: absolute;
            left: 70px;
            background: #000;
            color: #fff;
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 0.7rem;
            white-space: nowrap;
        }

        /* Modo Examen y Timer */
        .exam-controls {
            margin-bottom: 20px;
            padding: 10px 20px;
            background: rgba(30, 41, 59, 0.6);
            border-radius: 12px;
            border: 1px solid #334155;
            transition: all 0.3s ease;
        }

        #timer-bar-container {
            width: 200px;
            height: 8px;
            background: #334155;
            border-radius: 4px;
            display: none; /* Solo se ve en modo examen */
        }

        #timer-bar {
            width: 100%;
            height: 100%;
            background: var(--blue);
            border-radius: 4px;
            transition: width 1s linear;
        }

        .exam-controls:hover {
            border-color: var(--blue);
            background: rgba(59, 130, 246, 0.1);
        }

        #examStatus {
            color: var(--secondary);
            transition: color 0.3s;
        }

        /* Estado ON cuando está activo */
        .exam-on #examStatus {
            color: var(--blue);
        }

        /* Responsivo: Si la pantalla es pequeña, movemos las medallas abajo */
        @media (max-width: 1100px) {
            #medals-container {
                position: static;
                transform: none;
                margin: 20px auto;
                max-width: none;
                grid-template-columns: repeat(6, 1fr); /* Más columnas si están abajo */
            }
        }