/* Import Google Fonts (Outfit) */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* --- Core Design System Tokens --- */
:root {
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    /* Sleek Harmonious Dark Theme Colors (HSL) */
    --bg-gradient-start: hsl(222, 47%, 12%);
    --bg-gradient-end: hsl(224, 64%, 5%);
    --card-bg: hsla(223, 47%, 16%, 0.6);
    --card-border: hsla(223, 47%, 25%, 0.4);
    
    --text-primary: hsl(210, 40%, 98%);
    --text-secondary: hsl(215, 20%, 78%);
    --text-muted: hsl(215, 16%, 55%);
    
    --accent-primary: hsl(250, 75%, 65%);
    --accent-primary-hover: hsl(250, 75%, 72%);
    --accent-primary-glow: hsla(250, 75%, 65%, 0.25);
    
    --success: hsl(142, 69%, 58%);
    --success-bg: hsla(142, 72%, 29%, 0.2);
    --success-border: hsla(142, 69%, 58%, 0.4);
    
    --error: hsl(350, 89%, 60%);
    --error-bg: hsla(350, 72%, 35%, 0.2);
    --error-border: hsla(350, 89%, 60%, 0.4);
    
    --button-option-bg: hsla(223, 47%, 20%, 0.5);
    --button-option-border: hsla(223, 47%, 30%, 0.5);
    --button-option-hover: hsla(223, 47%, 26%, 0.8);
    
    /* Layout & Transitions */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-premium: 0 10px 30px -10px rgba(0, 0, 0, 0.7);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-quick: all 0.15s ease;
}

/* --- Base Reset & Setup --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent; /* Remove mobile tap highlight */
}

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-x: hidden;
}

/* Scrollbar styles for modern look */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: hsla(223, 47%, 30%, 0.5);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: hsla(223, 47%, 40%, 0.8);
}

/* --- Layout Container (Glassmorphism card) --- */
.app-container {
    width: 100%;
    max-width: 500px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-premium);
    padding: 24px;
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

/* Screen Switcher Lógica */
.screen {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.screen.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateY(0);
}

/* --- Typography Utilities --- */
h1 {
    font-size: 2.2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    background: linear-gradient(to right, #fff, var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* --- Start Screen specific styles --- */
.start-decor {
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, var(--accent-primary) 0%, transparent 70%);
    opacity: 0.15;
    position: absolute;
    top: -20px;
    right: -20px;
    border-radius: 50%;
    pointer-events: none;
}

.config-panel {
    background: hsla(223, 47%, 12%, 0.4);
    border: 1px solid hsla(223, 47%, 25%, 0.3);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
}

.config-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.config-group {
    margin-bottom: 16px;
}

.config-group:last-child {
    margin-bottom: 0;
}

.config-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

/* Custom select styling */
.custom-select {
    width: 100%;
    padding: 12px;
    background: var(--button-option-bg);
    border: 1px solid var(--button-option-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    transition: var(--transition-quick);
}

.custom-select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

/* Switch toggle styling */
.switch-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.switch-label-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--button-option-border);
    transition: .3s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-primary);
}

input:checked + .slider:before {
    transform: translateX(24px);
}

/* General Buttons */
.btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    outline: none;
}

.btn-primary {
    background: var(--accent-primary);
    color: #fff;
    box-shadow: 0 4px 15px var(--accent-primary-glow);
}

.btn-primary:hover {
    background: var(--accent-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--accent-primary-glow);
}

.btn-primary:active {
    transform: translateY(0);
}

/* --- Quiz Screen Header (Stats) --- */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.stats-row {
    display: flex;
    gap: 16px;
}

.stat-badge {
    background: hsla(223, 47%, 12%, 0.4);
    border: 1px solid hsla(223, 47%, 25%, 0.3);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.stat-badge.aciertos {
    color: var(--success);
    border-color: rgba(142, 69, 58, 0.2);
}

.stat-badge.errores {
    color: var(--error);
    border-color: rgba(350, 89, 60, 0.2);
}

.progress-container {
    width: 100%;
    height: 6px;
    background: hsla(223, 47%, 25%, 0.3);
    border-radius: 3px;
    margin-bottom: 24px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(to right, var(--accent-primary), var(--success));
    border-radius: 3px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Question & Options --- */
.question-container {
    margin-bottom: 24px;
    min-height: 80px;
}

.question-text {
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-line; /* Keeps manual line breaks from JSON */
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

/* Large mobile friendly option buttons */
.option-btn {
    width: 100%;
    background: var(--button-option-bg);
    border: 1px solid var(--button-option-border);
    border-radius: var(--radius-md);
    padding: 16px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: var(--transition-quick);
    display: flex;
    align-items: center;
    gap: 12px;
    outline: none;
    position: relative;
    overflow: hidden;
}

.option-btn:hover:not(:disabled) {
    background: var(--button-option-hover);
    border-color: var(--text-secondary);
}

.option-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.option-btn:disabled {
    cursor: default;
}

/* Letter indicator (A, B, C, D) */
.option-letter {
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    background: hsla(223, 47%, 30%, 0.5);
    border: 1px solid var(--button-option-border);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: var(--transition-quick);
}

.option-text {
    flex: 1;
    line-height: 1.4;
}

/* --- Correct / Incorrect States --- */

/* Highlight Correct Answer directly selected */
.option-btn.correct {
    background: var(--success-bg);
    border-color: var(--success);
    box-shadow: 0 0 15px rgba(142, 69, 58, 0.15);
}

.option-btn.correct .option-letter {
    background: var(--success);
    border-color: var(--success);
    color: var(--bg-gradient-end);
}

/* Highlight Incorrect selection */
.option-btn.incorrect {
    background: var(--error-bg);
    border-color: var(--error);
    animation: shake 0.4s ease;
    box-shadow: 0 0 15px rgba(350, 89, 60, 0.15);
}

.option-btn.incorrect .option-letter {
    background: var(--error);
    border-color: var(--error);
    color: #fff;
}

/* Reveal correct option when incorrect was chosen */
.option-btn.reveal-correct {
    background: var(--success-bg);
    border-color: var(--success);
    transition: all 0.5s ease;
}

.option-btn.reveal-correct .option-letter {
    background: var(--success);
    border-color: var(--success);
    color: var(--bg-gradient-end);
}

/* Dim unselected/disabled options */
.option-btn.dimmed {
    opacity: 0.4;
}

/* --- Feedback area --- */
.feedback-box {
    min-height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
    font-size: 1.15rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.feedback-box.active {
    opacity: 1;
    transform: translateY(0);
}

.feedback-box.correct {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    animation: pulseGlow 1.5s infinite alternate;
}

.feedback-box.incorrect {
    color: var(--error);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
}

/* Siguiente action layout */
.action-box {
    margin-top: 12px;
}

/* --- Results Screen --- */
.results-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
}

.score-circle {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: radial-gradient(circle, hsla(223, 47%, 20%, 0.8) 0%, hsla(223, 47%, 10%, 0.8) 100%);
    border: 4px solid var(--accent-primary);
    box-shadow: 0 0 30px var(--accent-primary-glow);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 24px;
}

.score-circle .grade {
    font-size: 2.5rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.score-circle .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-top: 4px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    width: 100%;
    margin-bottom: 32px;
}

.grid-item {
    background: hsla(223, 47%, 12%, 0.4);
    border: 1px solid hsla(223, 47%, 25%, 0.2);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.grid-item .value {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.grid-item .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.grid-item.accent-success .value {
    color: var(--success);
}

.grid-item.accent-error .value {
    color: var(--error);
}

/* Warnings */
.warning-message {
    background: hsla(38, 92%, 50%, 0.15);
    border: 1px solid hsla(38, 92%, 50%, 0.3);
    color: hsl(38, 92%, 65%);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    margin-top: 16px;
    text-align: left;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.warning-icon {
    font-size: 1.1rem;
    line-height: 1;
}

/* --- Animations --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 5px rgba(142, 69, 58, 0.1);
    }
    100% {
        box-shadow: 0 0 15px rgba(142, 69, 58, 0.3);
    }
}

/* --- Quiz Navigation Bar --- */
.quiz-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.btn-nav {
    background: var(--button-option-bg);
    border: 1px solid var(--button-option-border);
    color: var(--text-secondary);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition-quick);
    outline: none;
}

.btn-nav:hover:not(:disabled) {
    background: var(--button-option-hover);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn-nav:disabled {
    opacity: 0.25;
    cursor: default;
}

/* Custom Navigation Button Colors */
#btn-back {
    color: hsl(48, 95%, 60%);
    border-color: hsla(48, 95%, 60%, 0.25);
}

#btn-back:hover:not(:disabled) {
    border-color: hsl(48, 95%, 60%);
    background: hsla(48, 95%, 60%, 0.1);
}

#btn-home {
    color: hsl(210, 95%, 66%);
    border-color: hsla(210, 95%, 66%, 0.25);
}

#btn-home:hover:not(:disabled) {
    border-color: hsl(210, 95%, 66%);
    background: hsla(210, 95%, 66%, 0.1);
}
