/* StudyBuddy - Main Stylesheet */

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #22c55e;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 12px;
    --radius-lg: 16px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    touch-action: manipulation;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.app-header {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    border-radius: var(--radius-lg);
    color: white;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
}

.app-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.app-header .subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Subject Navigation */
.subject-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 30px;
}

.subject-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px 20px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.subject-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.subject-card:active {
    transform: translateY(-2px);
}

.subject-card .subject-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.subject-card .subject-name {
    font-size: 1.2rem;
    font-weight: 600;
}

/* Subject-specific colors */
.subject-card.english { border-color: #3b82f6; }
.subject-card.english:hover { background: #eff6ff; }

.subject-card.maths { border-color: #f59e0b; }
.subject-card.maths:hover { background: #fffbeb; }

.subject-card.science { border-color: #22c55e; }
.subject-card.science:hover { background: #f0fdf4; }

.subject-card.maltese { border-color: #ef4444; }
.subject-card.maltese:hover { background: #fef2f2; }

.subject-card.social-studies { border-color: #8b5cf6; }
.subject-card.social-studies:hover { background: #f5f3ff; }

/* Progress Section */
.progress-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
}

.progress-section h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.progress-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.progress-item {
    text-align: center;
    padding: 16px;
    background: var(--background);
    border-radius: var(--radius);
}

.progress-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.progress-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Quiz styles */
.quiz-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.quiz-question {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quiz-option {
    padding: 16px 20px;
    background: var(--background);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}

.quiz-option:hover {
    border-color: var(--primary-color);
    background: #f1f5f9;
}

.quiz-option.selected {
    border-color: var(--primary-color);
    background: #eef2ff;
}

.quiz-option.correct {
    border-color: var(--secondary-color);
    background: #dcfce7;
}

.quiz-option.incorrect {
    border-color: #ef4444;
    background: #fee2e2;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--background);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    border-color: var(--primary-color);
}

.btn-success {
    background: var(--secondary-color);
    color: white;
}

/* Chapter navigation */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chapter-card {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-primary);
    transition: all 0.2s;
}

.chapter-card:hover {
    border-color: var(--primary-color);
    background: #f8fafc;
}

.chapter-number {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    font-weight: 700;
    margin-right: 16px;
}

.chapter-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chapter-title {
    font-weight: 600;
}

.chapter-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.topic-tag {
    display: inline-block;
    padding: 3px 10px;
    background: #e0e7ff;
    color: #4338ca;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.chapter-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chapter-progress {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Admin Badge */
.admin-badge {
    display: inline-block;
    padding: 4px 12px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

/* Responsive */
@media (max-width: 600px) {
    .subject-nav {
        grid-template-columns: 1fr;
    }

    .progress-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .app-header h1 {
        font-size: 2rem;
    }
}

/* Mute Toggle */
.mute-toggle {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s;
    line-height: 1;
}
.mute-toggle:hover {
    background: rgba(255,255,255,0.2);
}

/* ============ XP DISPLAY ============ */
.xp-display {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.2);
    padding: 6px 12px;
    border-radius: 20px;
}
.level-badge {
    background: #fbbf24;
    color: #78350f;
    font-weight: 700;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}
.xp-bar-mini {
    width: 60px;
    height: 6px;
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
    overflow: hidden;
}
.xp-bar-fill {
    height: 100%;
    background: #fbbf24;
    border-radius: 3px;
    transition: width 0.5s ease;
}
.xp-text {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.9);
    font-weight: 600;
    white-space: nowrap;
}

/* ============ XP EARNED (results screen) ============ */
.xp-earned-display {
    text-align: center;
    margin: 16px 0 8px;
    animation: xpAppear 0.5s ease;
}
.xp-earned-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: #f59e0b;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.level-up-notice {
    margin-top: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    animation: levelUpPulse 0.8s ease;
}

@keyframes xpAppear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes levelUpPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ============ STREAK FIRE ============ */
.streak-section {
    text-align: center;
    margin-bottom: 20px;
}
.streak-display {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 32px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.streak-fire {
    display: flex;
    align-items: center;
    gap: 8px;
}
.streak-flame {
    font-size: 2.5rem;
    animation: flamePulse 2s ease-in-out infinite;
}
.streak-count {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
}
.streak-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 4px;
}
.streak-freezes {
    margin-top: 8px;
    font-size: 0.8rem;
    color: #3b82f6;
    font-weight: 600;
}

/* Hot streak (>= 7 days) */
.streak-fire.hot .streak-flame {
    animation: flameHot 0.6s ease-in-out infinite;
}
.streak-fire.hot .streak-count {
    color: #ea580c;
}

@keyframes flamePulse {
    0%, 100% { transform: scale(1) rotate(0); }
    50% { transform: scale(1.1) rotate(-3deg); }
}
@keyframes flameHot {
    0%, 100% { transform: scale(1) rotate(0); }
    25% { transform: scale(1.15) rotate(-5deg); }
    75% { transform: scale(1.15) rotate(5deg); }
}

/* ============ HEADER LAYOUT (index.php) ============ */
.header-content {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    text-align: left;
}
.header-left h1 { font-size: 1.8rem; }
.header-left .subtitle { font-size: 0.95rem; opacity: 0.9; }
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}
.user-info {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
}
.user-name { font-weight: 600; color: white; }
.user-link { color: rgba(255,255,255,0.8); font-size: 0.75rem; }
.login-btn {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}
.login-btn:hover { background: rgba(255,255,255,0.3); }

/* ============ ACHIEVEMENT TOAST ============ */
.achievement-toast {
    position: fixed;
    top: 20px;
    right: -400px;
    width: 340px;
    max-width: calc(100vw - 40px);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    z-index: 1000;
    transition: right 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
    border-left: 4px solid #fbbf24;
}
.achievement-toast.show {
    right: 20px;
}
.achievement-toast-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}
.achievement-toast-content {
    flex: 1;
    min-width: 0;
}
.achievement-toast-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fbbf24;
    font-weight: 700;
    margin-bottom: 2px;
}
.achievement-toast-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}
.achievement-toast-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}
.achievement-toast-xp {
    font-size: 0.8rem;
    color: #f59e0b;
    font-weight: 700;
    margin-top: 4px;
}

/* ============ BADGE GALLERY ============ */
.badges-section {
    margin-bottom: 20px;
}
.badges-section h2 {
    font-size: 1.3rem;
    margin-bottom: 16px;
}
.badge-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 12px;
}
.badge-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 8px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.2s;
}
.badge-item.earned {
    cursor: default;
}
.badge-item.earned:hover {
    transform: translateY(-2px);
}
.badge-item.locked {
    opacity: 0.4;
    filter: grayscale(1);
}
.badge-icon {
    font-size: 2rem;
    margin-bottom: 6px;
}
.badge-item.locked .badge-icon::after {
    content: '🔒';
    font-size: 0.8rem;
    position: relative;
    top: -8px;
    left: -4px;
}
.badge-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.badge-item.locked .badge-name {
    color: var(--text-secondary);
}

@media (max-width: 600px) {
    .header-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    .header-right {
        justify-content: center;
        flex-wrap: wrap;
    }
    .xp-display {
        order: 10;
        width: 100%;
        justify-content: center;
    }
    .streak-display {
        padding: 16px 24px;
    }
    .badge-gallery {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
        gap: 8px;
    }
    .achievement-toast {
        width: calc(100vw - 20px);
        right: -100%;
    }
    .achievement-toast.show {
        right: 10px;
    }
}
