/* CSS Variables for theming */
:root {
    /* Light theme (default) */
    --bg-primary: #f0f4ff;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #8888a8;
    --accent-primary: #58cc02;
    --accent-secondary: #89e219;
    --accent-hover: #4caf00;
    --danger: #ff4b4b;
    --danger-hover: #e03e3e;
    --warning: #ffc800;
    --info: #1cb0f6;
    --success: #58cc02;
    --border-color: #e5e5e5;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.15);
    --option-bg: #ffffff;
    --option-border: #e5e5e5;
    --option-hover-bg: #f7f7f7;
    --timer-bg: #e5e5e5;
    --mascot-bg: #ffeaa7;
    --mascot-face: #fdcb6e;
    --header-bg: rgba(255, 255, 255, 0.95);
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #131f24;
    --bg-secondary: #1a2c35;
    --bg-card: #1f3640;
    --text-primary: #ffffff;
    --text-secondary: #b8c5cc;
    --text-muted: #7a8f9a;
    --accent-primary: #58cc02;
    --accent-secondary: #89e219;
    --accent-hover: #6dd800;
    --danger: #ff6b6b;
    --danger-hover: #ff5252;
    --warning: #ffd93d;
    --info: #4fc3f7;
    --success: #69f0ae;
    --border-color: #2d4a56;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.4);
    --option-bg: #1f3640;
    --option-border: #2d4a56;
    --option-hover-bg: #264653;
    --timer-bg: #2d4a56;
    --mascot-bg: #f9ca24;
    --mascot-face: #f0932b;
    --header-bg: rgba(26, 44, 53, 0.95);
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* App container */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 2px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
}

.logo-img {
    width: 40px;
    height: auto;
    vertical-align: middle;
    margin-right: 8px;
}

.logo-text {
    font-size: 24px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-primary), var(--info));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-controls {
    display: flex;
    gap: 10px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 12px;
    background: var(--bg-card);
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.icon-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--shadow-strong);
}

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

/* Screens */
.screen {
    display: none;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

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

/* Menu Screen */
.menu-content {
    text-align: center;
    padding-top: 20px;
}

/* Mascot */
.mascot {
    width: 120px;
    height: 120px;
    margin: 0 auto 24px;
    position: relative;
}

.mascot-face {
    width: 100%;
    height: 100%;
    background: var(--mascot-bg);
    border-radius: 50%;
    position: relative;
    box-shadow: 0 8px 24px var(--shadow-color);
    animation: bounce 2s ease-in-out infinite;
}

.mascot-eyes {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding-top: 35px;
}

.eye {
    width: 16px;
    height: 16px;
    background: #1a1a2e;
    border-radius: 50%;
    position: relative;
    animation: blink 4s ease-in-out infinite;
}

.eye::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    top: 2px;
    right: 2px;
}

.mascot-mouth {
    width: 40px;
    height: 20px;
    background: var(--mascot-face);
    border-radius: 0 0 40px 40px;
    margin: 15px auto 0;
    position: relative;
}

.mascot-mouth::after {
    content: '';
    position: absolute;
    width: 30px;
    height: 10px;
    background: #ff6b6b;
    border-radius: 0 0 30px 30px;
    bottom: 2px;
    left: 5px;
}

.mascot-face.sad .mascot-mouth {
    transform: rotate(180deg);
    margin-top: 20px;
}

.mascot-face.sad .mascot-mouth::after {
    background: #ff9999;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes blink {
    0%, 45%, 55%, 100% { transform: scaleY(1); }
    50% { transform: scaleY(0.1); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.main-title {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* Settings Panel */
.settings-panel {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: 0 4px 16px var(--shadow-color);
}

.setting-group {
    margin-bottom: 24px;
}

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

.setting-group label {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    text-align: left;
}

.time-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.time-btn {
    padding: 10px 18px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.time-btn:hover {
    border-color: var(--accent-primary);
    background: var(--option-hover-bg);
}

.time-btn.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(88, 204, 2, 0.4);
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 10px;
    border: 2px solid var(--border-color);
    border-radius: 16px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.difficulty-btn:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.difficulty-btn.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-color: var(--accent-primary);
    box-shadow: 0 4px 16px rgba(88, 204, 2, 0.4);
}

.difficulty-btn.active .diff-name,
.difficulty-btn.active .diff-desc {
    color: white;
}

.diff-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.diff-name {
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.diff-desc {
    font-family: 'Nunito', sans-serif;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.difficulty-btn:last-child {
    grid-column: span 2;
}

/* Buttons */
.primary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 48px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    border-radius: 16px;
    font-family: 'Nunito', sans-serif;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(88, 204, 2, 0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(88, 204, 2, 0.5);
}

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

.primary-btn.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(88, 204, 2, 0.4); }
    50% { box-shadow: 0 4px 32px rgba(88, 204, 2, 0.6); }
}

.secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    border-color: var(--text-muted);
    background: var(--option-hover-bg);
}

/* Stats Preview */
.stats-preview {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 2px solid var(--border-color);
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent-primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

/* Game Screen */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.streak-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.streak-icon {
    font-size: 24px;
    animation: fireGlow 1s ease-in-out infinite alternate;
}

@keyframes fireGlow {
    from { filter: brightness(1); }
    to { filter: brightness(1.3); }
}

.streak-count {
    font-size: 24px;
    font-weight: 800;
    color: var(--warning);
}

.timer-container {
    position: relative;
}

.timer-ring {
    width: 80px;
    height: 80px;
    position: relative;
}

.timer-svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.timer-bg {
    fill: none;
    stroke: var(--timer-bg);
    stroke-width: 8;
}

.timer-progress {
    fill: none;
    stroke: var(--accent-primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 0.1s linear, stroke 0.3s ease;
}

.timer-progress.warning {
    stroke: var(--warning);
}

.timer-progress.danger {
    stroke: var(--danger);
    animation: timerPulse 0.5s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% { stroke-width: 8; }
    50% { stroke-width: 10; }
}

.timer-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
}

.difficulty-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow-color);
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
}

/* Question */
.question-container {
    margin-bottom: 32px;
}

.question-card {
    background: var(--bg-card);
    border-radius: 24px;
    padding: 40px 24px;
    box-shadow: 0 8px 32px var(--shadow-color);
    transition: transform 0.2s ease;
}

.question-card.correct {
    animation: correctPop 0.4s ease;
}

.question-card.wrong {
    animation: wrongShake 0.4s ease;
}

@keyframes correctPop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes wrongShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

.question-text {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
    text-align: center;
    line-height: 1.4;
}

/* Options */
.options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.option-btn {
    padding: 24px 16px;
    background: var(--option-bg);
    border: 3px solid var(--option-border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
}

.option-btn:focus {
    outline: none;
}

.option-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Only apply hover effects on devices that support hover (not touch) */
@media (hover: hover) and (pointer: fine) {
    .option-btn:hover {
        border-color: var(--accent-primary);
        transform: translateY(-2px);
        box-shadow: 0 4px 16px var(--shadow-color);
    }

    .option-btn:hover::before {
        opacity: 1;
    }
}

/* Active state for touch devices */
.option-btn:active {
    border-color: var(--accent-primary);
    transform: scale(0.98);
}

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

.option-btn.correct {
    background: var(--success);
    border-color: var(--success);
    animation: correctBounce 0.4s ease;
}

.option-btn.correct .option-text {
    color: white;
}

.option-btn.wrong {
    background: var(--danger);
    border-color: var(--danger);
    animation: wrongShake 0.4s ease;
}

.option-btn.wrong .option-text {
    color: white;
}

.option-btn.disabled {
    pointer-events: none;
    opacity: 0.7;
}

@keyframes correctBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.option-text {
    font-family: 'Nunito', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.game-footer {
    text-align: center;
}

/* Game Over Screen */
.gameover-content {
    text-align: center;
    padding-top: 20px;
}

.result-mascot {
    width: 100px;
    height: 100px;
    margin: 0 auto 20px;
}

.result-mascot .mascot-face {
    width: 100%;
    height: 100%;
}

.result-title {
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.result-subtitle {
    font-size: 16px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 24px;
}

.result-stat {
    background: var(--bg-card);
    padding: 16px 24px;
    border-radius: 16px;
    box-shadow: 0 4px 12px var(--shadow-color);
}

.result-stat.main {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

.result-stat.main .result-value,
.result-stat.main .result-label {
    color: white;
}

.result-value {
    display: block;
    font-size: 28px;
    font-weight: 800;
    color: var(--accent-primary);
}

.result-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.correct-answer-display {
    background: var(--bg-card);
    border: 2px solid var(--danger);
    border-radius: 16px;
    padding: 16px 24px;
    margin-bottom: 24px;
}

.correct-answer-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.correct-answer-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--danger);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.achievement-popup {
    position: fixed;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #ffd700, #ffb700);
    color: #1a1a2e;
    padding: 16px 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 8px 32px rgba(255, 215, 0, 0.4);
    animation: achievementSlide 0.5s ease;
    z-index: 1000;
}

@keyframes achievementSlide {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.achievement-icon {
    font-size: 28px;
}

/* Responsive */

/* iPad and tablet screens - add top gap to game screen */
@media (min-width: 768px) {
    /* Stretch header background to full width while keeping content centered */
    .header {
        position: sticky;
        background: transparent;
        border-bottom: none;
    }
    
    .header::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 100vw;
        height: 100%;
        background: var(--header-bg);
        backdrop-filter: blur(10px);
        border-bottom: 2px solid var(--border-color);
        z-index: -1;
    }
    
    /* Center game content vertically */
    #game-screen.active {
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-height: calc(100vh - 80px);
        padding-top: 0;
        padding-bottom: 20px;
    }
    
    #gameover-screen.active {
        display: flex;
        flex-direction: column;
        justify-content: center;
        min-height: calc(100vh - 80px);
        padding-top: 0;
        padding-bottom: 20px;
    }
    
    .game-header {
        margin-bottom: 32px;
    }
    
    .question-card {
        padding: 48px 32px;
    }
    
    .options-container {
        gap: 16px;
        margin-bottom: 32px;
    }
    
    .option-btn {
        padding: 28px 20px;
    }
}

@media (max-width: 480px) {
    .main-title {
        font-size: 24px;
    }
    
    .question-text {
        font-size: 24px;
    }
    
    .option-text {
        font-size: 18px;
    }
    
    .timer-ring {
        width: 64px;
        height: 64px;
    }
    
    .timer-text {
        font-size: 20px;
    }
    
    .result-stats {
        flex-wrap: wrap;
    }
    
    .stats-preview {
        gap: 16px;
    }
    
    .stat-value {
        font-size: 24px;
    }
}

/* Animations for screen transitions */
.screen-enter {
    animation: slideIn 0.3s ease forwards;
}

.screen-exit {
    animation: slideOut 0.3s ease forwards;
}

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

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

/* Confetti effect container */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent-primary);
    animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}
