/* GAME CONTAINER - Black Background */
.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: #000000;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
    padding: 10px;
    /* Safety padding for small screens */
    box-sizing: border-box;
}

.game-container.hidden {
    display: none;
}

/* ===== ANIMATED AI BACKGROUND ===== */
.trivia-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

/* Floating light blobs */
.trivia-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0;
    animation: blob-float 12s ease-in-out infinite;
}

.trivia-blob--1 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(0, 100, 255, 0.4) 0%, rgba(0, 50, 200, 0.1) 50%, transparent 70%);
    bottom: -150px;
    left: -100px;
    animation-delay: 0s;
    animation-duration: 15s;
}

.trivia-blob--2 {
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(0, 200, 255, 0.35) 0%, rgba(0, 100, 200, 0.1) 50%, transparent 70%);
    top: -100px;
    right: -80px;
    animation-delay: 3s;
    animation-duration: 18s;
}

.trivia-blob--3 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(80, 0, 255, 0.3) 0%, rgba(50, 0, 150, 0.1) 50%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 6s;
    animation-duration: 20s;
}

@keyframes blob-float {

    0%,
    100% {
        opacity: 0;
        transform: translate(0, 0) scale(1);
    }

    15% {
        opacity: 0.6;
    }

    50% {
        opacity: 0.8;
        transform: translate(30px, -20px) scale(1.1);
    }

    85% {
        opacity: 0.5;
    }
}

/* Aurora Borealis Effect - Unified Wave */
.trivia-aurora {
    position: absolute;
    pointer-events: none;
    will-change: transform, opacity;
}

/* Aurora Principal - Onda base que fluye */
.trivia-aurora--1 {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    opacity: 0;
    background: linear-gradient(0deg,
            transparent 0%,
            rgba(0, 60, 180, 0.4) 20%,
            rgba(0, 150, 255, 0.5) 40%,
            rgba(0, 200, 255, 0.3) 60%,
            transparent 100%);
    filter: blur(40px);
    animation: aurora-wave-main 15s ease-in-out infinite;
}

/* Aurora Secundaria - Capa de color que ondula */
.trivia-aurora--2 {
    bottom: 5%;
    left: -20%;
    width: 60%;
    height: 45%;
    opacity: 0;
    background: linear-gradient(30deg,
            transparent 0%,
            rgba(80, 0, 180, 0.35) 30%,
            rgba(0, 100, 255, 0.45) 50%,
            rgba(0, 180, 220, 0.35) 70%,
            transparent 100%);
    filter: blur(50px);
    animation: aurora-wave-secondary 15s ease-in-out infinite;
}

/* Aurora Terciaria - Brillo superior que complementa */
.trivia-aurora--3 {
    bottom: 10%;
    right: -20%;
    width: 60%;
    height: 40%;
    opacity: 0;
    background: linear-gradient(-30deg,
            transparent 0%,
            rgba(0, 120, 255, 0.3) 30%,
            rgba(100, 0, 200, 0.4) 50%,
            rgba(0, 150, 255, 0.35) 70%,
            transparent 100%);
    filter: blur(50px);
    animation: aurora-wave-tertiary 15s ease-in-out infinite;
}

/* Animación principal - La base pulsa y ondula */
@keyframes aurora-wave-main {

    0%,
    100% {
        opacity: 0;
        transform: translateY(20%) scaleY(0.8);
    }

    20% {
        opacity: 0.7;
        transform: translateY(0%) scaleY(1);
    }

    50% {
        opacity: 0.85;
        transform: translateY(-5%) scaleY(1.1);
    }

    80% {
        opacity: 0.6;
        transform: translateY(5%) scaleY(0.95);
    }
}

/* Animación secundaria - Se mueve de izq a der */
@keyframes aurora-wave-secondary {

    0%,
    100% {
        opacity: 0;
        transform: translateX(-10%) skewX(-3deg);
    }

    15% {
        opacity: 0.65;
    }

    40% {
        opacity: 0.8;
        transform: translateX(60%) skewX(3deg);
    }

    70% {
        opacity: 0.7;
        transform: translateX(100%) skewX(-2deg);
    }
}

/* Animación terciaria - Se mueve de der a izq (contrario) */
@keyframes aurora-wave-tertiary {

    0%,
    100% {
        opacity: 0;
        transform: translateX(10%) skewX(3deg);
    }

    20% {
        opacity: 0.6;
    }

    50% {
        opacity: 0.75;
        transform: translateX(-60%) skewX(-3deg);
    }

    80% {
        opacity: 0.5;
        transform: translateX(-100%) skewX(2deg);
    }
}

/* Particle canvas */
.trivia-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* ROTATION FOR BORDER */
@keyframes rotate-border {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* BOUNCE ANIMATION */
@keyframes soft-bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* BASE TRIVIA UI (Shared) */
.trivia-ui {
    width: 100%;
    /* Responsive width */
    max-width: 500px;
    height: auto;
    max-height: 90vh;
    /* Max height to avoid overflow */
    border-radius: 20px;
    padding: 3px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    background: #1e1f20;
    overflow: hidden;
    /* Clips the spinning light */
    position: relative;
    margin: 0 auto;
}

#triviaIntro {
    background: transparent;
    z-index: 1;
}

#triviaIntro::before {
    content: '';
    position: absolute;
    z-index: -2;
    left: -50%;
    top: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg,
            transparent 0%,
            transparent 280deg,
            #0004ff 320deg,
            #00d4ff 360deg);
    animation: rotate-border 4s linear infinite;
}

#triviaIntro::after {
    content: '';
    position: absolute;
    z-index: -1;
    left: 3px;
    top: 3px;
    right: 3px;
    bottom: 3px;
    background: #1e1f20;
    border-radius: 17px;
}

#triviaGame,
#triviaResult {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: #1e1f20;
}

/* CONTENT ALIGNMENT FIX */
.trivia-content {
    position: relative;
    z-index: 2;
    padding: 2rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    /* Enable internal scrolling for small screens */
}

/* Inner containers */
#triviaGame,
#triviaResult {
    padding: 1.5rem;
    /* Slightly reduced padding */
    flex-direction: column;
    align-items: center;
    text-align: center;
    overflow-y: auto;
    /* Enable internal scrolling */
}

/* Typography */
.trivia-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
    animation: soft-bounce 2s infinite ease-in-out;
}

#resultIcon {
    display: none;
}

.trivia-title {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    color: white;
    text-align: center;
}

.text-highlight {
    color: #0004ff;
    text-shadow: 0 0 15px rgba(0, 4, 255, 0.4);
}

.trivia-subtitle {
    font-size: 1rem;
    color: #94a3b8;
    margin-bottom: 2rem;
    text-align: center;
}

/* Buttons */
.trivia-actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: auto;
    width: 100%;
    padding-top: 1rem;
}

.btn {
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 0.9rem;
    width: 100%;
    min-height: 48px;
    /* Touch target size */
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.btn--primary {
    background: #0004ff;
    color: white;
    box-shadow: 0 4px 15px rgba(0, 4, 255, 0.3);
}

.btn--secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
}

.btn-link {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #cbd5e1;
    text-decoration: none;
    cursor: pointer;
    margin-top: 1rem;
    font-size: 0.9rem;
    padding: 12px;
    border-radius: 8px;
    transition: all 0.2s;
    display: inline-block;
    width: 100%;
    min-height: 44px;
}

.btn-link:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
    color: white;
}

/* Quiz Interface */
.trivia-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
    width: 100%;
}

.trivia-card {
    width: 100%;
}

#questionText {
    font-size: 1.3rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
}

.trivia-options {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    width: 100%;
}

.trivia-option {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 14px;
    /* Touch optimization */
    border-radius: 12px;
    color: #e2e8f0;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    /* Touch target size */
    display: flex;
    align-items: center;
}

.trivia-option:hover:not(.disabled) {
    background: rgba(255, 255, 255, 0.08);
    border-color: #0004ff;
}

.trivia-option.selected {
    background: rgba(0, 4, 255, 0.1);
    border-color: #0004ff;
    color: #fff;
    font-weight: 600;
}

.trivia-option.disabled {
    pointer-events: none;
    opacity: 0.7;
}

/* RESULTS REVIEW */
.results-review {
    text-align: left;
    height: 250px;
    /* Reduced fixed height for mobile safety */
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 10px;
    margin: 1rem 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
    width: 100%;
}

.results-review::-webkit-scrollbar {
    width: 6px;
}

.results-review::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.results-review::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 3px;
}

.review-item {
    background: #27272a;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.review-q {
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 8px;
    font-size: 0.95rem;
    text-align: left;
}

.review-answer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 12px;
    border-radius: 8px;
    margin-top: 5px;
}

.review-answer-row.correct {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid #10b981;
    color: #34d399;
}

.review-answer-row.wrong {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid #ef4444;
    color: #f87171;
}

.review-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.review-correct-label {
    display: block;
    margin-top: 8px;
    font-size: 0.85rem;
    color: #94a3b8;
    background: rgba(16, 185, 129, 0.05);
    padding: 5px 10px;
    border-radius: 6px;
    text-align: left;
}

.result-score {
    font-size: 3rem;
    font-weight: 800;
    color: #fff;
    margin: 0.5rem 0;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

/* Ensure visibility logic works */
.trivia-ui:not(.hidden) {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

.trivia-ui.hidden {
    display: none !important;
}

/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 600px) {
    .trivia-ui {
        width: 100%;
        max-width: 95%;
        padding: 2px;
        /* Thinner border for mobile */
    }

    .trivia-content {
        padding: 1.2rem;
    }

    #triviaGame,
    #triviaResult {
        padding: 1.2rem;
    }

    .trivia-icon {
        font-size: 3rem;
        /* Smaller icon */
        margin-bottom: 0.5rem;
    }

    .trivia-title {
        font-size: 1.5rem;
        /* Smaller title */
    }

    .trivia-subtitle {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
    }

    #questionText {
        font-size: 1.1rem;
        /* Readable but compact question */
        margin-bottom: 1.2rem;
    }

    .result-score {
        font-size: 2.5rem;
    }

    .trivia-option {
        padding: 12px;
        font-size: 0.9rem;
    }

    .results-review {
        height: 200px;
        /* Smaller list on phones */
    }

    /* Aurora optimizations for mobile */
    .trivia-blob {
        filter: blur(60px);
    }

    .trivia-blob--1 {
        width: 250px;
        height: 250px;
    }

    .trivia-blob--2 {
        width: 200px;
        height: 200px;
    }

    .trivia-blob--3 {
        width: 180px;
        height: 180px;
    }

    .trivia-aurora--1 {
        height: 40%;
        filter: blur(30px);
    }

    .trivia-aurora--2 {
        width: 50%;
        height: 35%;
        filter: blur(35px);
    }

    .trivia-aurora--3 {
        width: 50%;
        height: 30%;
        filter: blur(35px);
    }
}

/* Tablet optimizations */
@media (min-width: 601px) and (max-width: 1024px) {
    .trivia-blob--1 {
        width: 320px;
        height: 320px;
    }

    .trivia-blob--2 {
        width: 250px;
        height: 250px;
    }

    .trivia-blob--3 {
        width: 220px;
        height: 220px;
    }

    .trivia-aurora--1 {
        height: 45%;
        filter: blur(35px);
    }

    .trivia-aurora--2 {
        width: 55%;
        height: 40%;
    }

    .trivia-aurora--3 {
        width: 55%;
        height: 35%;
    }
}

/* Landscape Mode Tweak (Short Screens) */
@media (max-height: 500px) and (orientation: landscape) {
    .trivia-ui {
        flex-direction: row;
        /* Side by side layout for landscape? or just standard scroll */
        height: 95vh;
        max-height: 95vh;
        overflow-y: auto;
        /* Allow scrolling entire container if needed */
    }

    .trivia-content {
        padding: 1rem;
    }

    .trivia-icon {
        display: none;
        /* Hide icon to save space in landscape */
    }

    .trivia-title {
        font-size: 1.2rem;
    }

    .trivia-actions {
        flex-direction: row;
        /* Buttons side-by-side */
    }
}