/* ─── Header (frosted-glass top bar) ───────────────────────────── */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: rgba(15, 17, 23, 0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.header-logo {
    height: 32px;
    width: auto;
    flex-shrink: 0;
    object-fit: contain;
}

.header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.3px;
    background: linear-gradient(135deg, #e8e8ed 0%, #9a9aad 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.header-link {
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s;
    white-space: nowrap;
}
.header-link:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

/* ─── Daily Quiz Button ────────────────────────────────────────── */
.daily-quiz-btn {
    display: none;
    font-size: 13px;
    font-weight: 600;
    color: #fbbf24;
    text-decoration: none;
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid rgba(251, 191, 36, 0.3);
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.12) 0%, rgba(245, 158, 11, 0.08) 100%);
    transition: all 0.25s ease;
    white-space: nowrap;
    gap: 6px;
    align-items: center;
}
.daily-quiz-btn.visible {
    display: inline-flex;
}
.daily-quiz-btn:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.25) 0%, rgba(245, 158, 11, 0.18) 100%);
    border-color: rgba(251, 191, 36, 0.5);
    color: #fcd34d;
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.15);
}
.daily-quiz-btn .quiz-icon {
    font-size: 15px;
}

/* ─── Quiz Modal Overlay ───────────────────────────────────────── */
.quiz-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.quiz-modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.quiz-modal-dialog {
    background: var(--surface, #1e202c);
    width: 92vw;
    max-width: 820px;
    height: 88vh;
    border-radius: 18px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(251, 191, 36, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.92) translateY(20px);
    opacity: 0;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border, #2a2d3a);
}
.quiz-modal-overlay.open .quiz-modal-dialog {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.quiz-modal-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border, #2a2d3a);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.06) 0%, transparent 100%);
}
.quiz-modal-title {
    margin: 0;
    font-family: var(--font-main, 'Inter', sans-serif);
    font-size: 15px;
    font-weight: 600;
    color: #fbbf24;
    display: flex;
    align-items: center;
    gap: 8px;
}
.quiz-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary, #9ba1b0);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: all 0.2s;
    border-radius: 6px;
}
.quiz-modal-close:hover {
    color: var(--text-primary, #e8e8ed);
    background: rgba(255, 255, 255, 0.1);
}
.quiz-modal-close:active {
    transform: scale(0.92);
}

.quiz-modal-body {
    flex: 1;
    position: relative;
    overflow: hidden;
}
.quiz-modal-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    border-radius: 0 0 18px 18px;
}

@media (max-width: 600px) {
    .quiz-modal-overlay {
        /* Align modal to top so header is always visible */
        align-items: flex-start;
    }
    .quiz-modal-dialog {
        width: 100vw;
        height: 100vh;
        height: 100dvh;          /* dynamic viewport — excludes system bars */
        max-width: 100vw;
        border-radius: 0;
        border: none;
    }
    .quiz-modal-header {
        /* Push below status bar / notch */
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top, 10px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        gap: 8px;
    }
    .quiz-modal-title {
        font-size: 14px;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .quiz-modal-close {
        font-size: 22px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    .quiz-modal-iframe {
        border-radius: 0;
    }
}

/* ─── Grade Selector (pill buttons) ────────────────────────────── */
.grade-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
    overflow-x: auto;
    scrollbar-width: none;
}
.grade-selector::-webkit-scrollbar { display: none; }

.grade-selector .grade-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-right: 4px;
    white-space: nowrap;
}

.grade-pill {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.grade-pill:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: rgba(255,255,255,0.15);
}
.grade-pill.active {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent-border);
    font-weight: 600;
}

/* ─── Navigation Buttons ────────────────────────────────────────── */
.nav-buttons {
    position: fixed;
    bottom: 28px;
    left: 28px;
    display: flex;
    gap: 6px;
    z-index: 100;
}

.nav-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(25, 27, 35, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    user-select: none;
}

.nav-btn:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: rgba(255,255,255,0.15);
}

.nav-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* ─── Toggle Button (Expand All) ───────────────────────────────── */
.toggle-btn {
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
}

.toggle-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
    border-color: rgba(255,255,255,0.15);
}

.toggle-btn.active {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent-border);
    font-weight: 600;
}

.toggle-btn i {
    margin-right: 4px;
}

/* ─── App Status ────────────────────────────────────────────────── */
.app-status {
    position: fixed;
    top: 70px;
    left: 20px;
    z-index: 20;
    max-width: min(440px, calc(100vw - 40px));
    color: var(--text-primary);
    padding: 12px 18px;
    background: rgba(25, 27, 35, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}

/* ─── Theme Selector ──────────────────────────────────────────────── */
.theme-selector-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
    border-left: 1px solid var(--border);
    padding-left: 16px;
}

.theme-select {
    font-family: var(--font-main);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 28px 4px 14px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239a9aad' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.theme-select:hover {
    background-color: var(--surface-hover);
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.15);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23e8e8ed' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.theme-select:focus {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.15);
}

.theme-select option {
    background: var(--bg);
    color: var(--text-primary);
    font-size: 13px;
    padding: 8px 12px;
}

/* ─── Mobile / Treemap mode  (< 768px) ────────────────────────── */
@media (max-width: 767px) {
    .header {
        padding: 10px 12px;
        gap: 8px;
    }
    .theme-selector-container,
    .header-link {
        display: none;
    }
}
