:root {
    /* Mauritanian Flag Theme — Green background with Gold and Red accents */
    --bg: #E8F5EE;
    /* Light green background inspired by Mauritanian flag */
    --surface: #FFFFFF;
    /* cards */
    --surface-2: #F0F9F4;
    /* subtle green tint */
    --ink: #0D4F3A;
    /* dark green text - deeper contrast */
    --ink-2: #1A5C47;
    /* secondary green text */
    --muted: #2E7D5F;
    /* tertiary green text */
    --line: #C3E6D7;
    /* green-tinted lines */
    --line-2: #D4EDDA;
    --accent: #009750;
    /* Mauritanian Islamic Green */
    --accent-ink: #006837;
    /* Darker Green for hover/text */
    --gold: #FFCC00;
    /* Mauritanian Gold */
    --danger: #D40000;
    /* Mauritanian Red */

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 14px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, 0.12);
    --shadow-glow: 0 0 30px rgba(0, 151, 80, 0.15);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --sidebar-width: 280px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Content is always visible - no auth-based hiding */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Tajawal', sans-serif;
}

body {
    background: var(--bg);
    color: var(--ink);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-feature-settings: 'rlig' 1, 'calt' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* =========================
   Sidebar
   ========================= */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    height: 100%;
    border-left: 1px solid var(--line);
    position: fixed;
    right: 0;
    top: 0;
    z-index: 100;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px 22px 20px;
    border-bottom: 1px solid var(--line);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.brand-logo {
    font-size: 2.4rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 2px;
    letter-spacing: -0.5px;
}

.brand-logo .rim {
    color: #009750;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 151, 80, 0.2);
}

.brand-logo .prepa {
    color: #FFCC00;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(255, 204, 0, 0.2);
}

.brand-text span {
    font-size: 1.1rem;
    color: var(--muted);
    letter-spacing: 0.02em;
    font-weight: 600;
}

.sidebar-nav {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

.nav-section {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 14px 14px 6px;
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--ink-2);
    font-weight: 500;
    font-size: 0.92rem;
    border-radius: 8px;
    transition: var(--transition);
    position: relative;
}

.nav-item>span:not(.nav-dot):not(.nav-count) {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    color: var(--muted);
    flex-shrink: 0;
}

.nav-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--nav-color, var(--muted));
    flex-shrink: 0;
}

.nav-item[data-color] {
    --nav-color: attr(data-color);
}

.nav-count {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--muted);
    background: var(--line-2);
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--ink);
}

.nav-item:hover .nav-count {
    background: #fff;
    color: var(--ink-2);
}

.nav-item.active {
    background: var(--ink);
    color: #fff;
}

.nav-item.active svg,
.nav-item.active .nav-count {
    color: #fff;
}

.nav-item.active .nav-count {
    background: rgba(255, 255, 255, 0.15);
}

.nav-item.active .nav-dot {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
}

.sidebar-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--line);
    font-size: 0.72rem;
    color: var(--muted);
    text-align: center;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--ink);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 12px;
    transition: var(--transition);
}

.login-btn:hover {
    background: var(--ink-2);
}

.login-btn svg {
    width: 16px;
    height: 16px;
}

/* =========================
   Main content
   ========================= */
.main-content {
    margin-right: var(--sidebar-width);
    flex: 1;
    height: 100%;
    overflow-y: auto;
    padding: 0 40px 60px;
    transition: var(--transition);
    scroll-behavior: smooth;
}

.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 32px;
}



.menu-btn {
    display: none;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.menu-btn:hover {
    background: var(--line-2);
}

.menu-btn svg {
    width: 22px;
    height: 22px;
}

.header-search {
    flex: 1;
    max-width: 440px;
    position: relative;
    display: flex;
    align-items: center;
    perspective: 1000px;
}

.header-search svg {
    position: absolute;
    right: 16px;
    color: var(--accent);
    pointer-events: none;
    z-index: 1;
    transition: transform 0.3s ease;
}

.header-search input {
    width: 100%;
    padding: 12px 46px 12px 18px;
    background: var(--surface);
    border: 1.5px solid var(--line);
    border-radius: 14px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--ink);
    transition: all 0.2s ease;
}

.header-search input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 8px 30px rgba(0, 151, 80, 0.08);
    transform: translateY(-1px);
}

.header-search input:focus+svg {
    transform: scale(1.1);
}

#page-title {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--ink), var(--ink-2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    border-radius: 8px;
    transition: var(--transition);
    margin-right: auto;
    font-family: inherit;
}

.btn-back:hover {
    background: var(--ink);
    color: #fff;
    border-color: var(--ink);
}

.btn-back svg {
    width: 16px;
    height: 16px;
}

.content-grid {
    display: block;
    padding-bottom: 40px;
    transition: opacity 0.35s ease, transform 0.35s ease;
}

/* =========================
   Skeleton Loading
   ========================= */
@keyframes shimmer {
    0% {
        background-position: -400px 0;
    }

    100% {
        background-position: 400px 0;
    }
}

.skeleton {
    background: linear-gradient(90deg, var(--line-2) 25%, var(--surface) 37%, var(--line-2) 63%);
    background-size: 800px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius);
}

.skeleton-hero {
    height: 280px;
    border-radius: var(--radius-lg);
    margin-bottom: 36px;
}

.skeleton-section-head {
    height: 28px;
    width: 200px;
    margin-bottom: 20px;
}

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.skeleton-card {
    height: 200px;
}

.skeleton-lecture {
    height: 80px;
    margin-bottom: 12px;
}

/* =========================
   PWA Install Button on Hero
   ========================= */
.hero-install-row {
    margin-bottom: 16px;
}

.hero-install-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 22px;
    background: var(--gold);
    color: var(--ink);
    border: none;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 16px rgba(255, 204, 0, 0.3);
}

.hero-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(255, 204, 0, 0.4);
    background: #FFD633;
}

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

.hero-install-btn svg {
    width: 18px;
    height: 18px;
}

/* =========================
   Update Toast
   ========================= */
#update-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 14px 24px;
    border-radius: 14px;
    font-size: 0.92rem;
    font-weight: 600;
    z-index: 9999;
    box-shadow: 0 8px 32px rgba(0, 151, 80, 0.3);
    animation: toastSlideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* =========================
   Hero
   ========================= */
.home-hero {
    background: var(--ink);
    color: #fff;
    border-radius: var(--radius-xl);
    padding: 40px 44px;
    margin-bottom: 36px;
    position: relative;
    overflow: hidden;
    border: 1px solid var(--ink);
    box-shadow: 0 8px 30px rgba(13, 79, 58, 0.15);
}

.home-hero::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -10%;
    width: 60%;
    height: 200%;
    background: radial-gradient(ellipse at center, rgba(0, 151, 80, 0.15), transparent 60%);
    pointer-events: none;
}

.home-hero::after {
    content: '';
    position: absolute;
    inset: 8px;
    border: 1px solid rgba(0, 151, 80, 0.2);
    border-radius: calc(var(--radius-lg) - 4px);
    pointer-events: none;
}

.hero-inner {
    position: relative;
    z-index: 1;
    max-width: 640px;
}

.hero-kicker {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--gold);
    padding: 4px 10px;
    border: 1px solid rgba(0, 151, 80, 0.4);
    border-radius: 4px;
    margin-bottom: 18px;
}

.hero-title {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 12px;
    letter-spacing: -0.03em;
}

.hero-title span {
    color: var(--gold);
}

.hero-sub {
    font-size: 1.05rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.6;
    margin-bottom: 28px;
}

.hero-sub .rim {
    background: linear-gradient(135deg, #ffffff 0%, #f0f4ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    filter: brightness(1.15);
}

.hero-sub .prepa {
    background: linear-gradient(135deg, var(--gold) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    filter: brightness(1.2);
}

.hero-stats {
    display: flex;
    gap: 40px;
    padding-top: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.hero-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hero-stat strong {
    font-size: 1.6rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.hero-stat span {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 500;
}

/* =========================
   Section headers
   ========================= */
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 8px;
}

.section-head h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -0.01em;
}

.section-head h3::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 16px;
    background: var(--gold);
    vertical-align: -2px;
    margin-left: 10px;
    border-radius: 2px;
}

.section-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

/* =========================
   Subjects grid
   ========================= */
.subjects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 40px;
}

.subject-card {
    --subject-color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow: hidden;
}

.subject-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 3px;
    height: 100%;
    background: var(--subject-color);
    opacity: 0.9;
}

.subject-card:hover {
    border-color: var(--subject-color);
    box-shadow: var(--shadow), 0 0 0 1px var(--subject-color);
    transform: translateY(-3px);
}

.subject-card--soon {
    cursor: default;
    opacity: 0.78;
}

.subject-card--soon:hover {
    transform: none;
    border-color: var(--line);
}

.subject-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.subject-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--subject-color) 10%, transparent);
    color: var(--subject-color);
    flex-shrink: 0;
}

.subject-icon svg {
    width: 22px;
    height: 22px;
}

.subject-seats {
    text-align: left;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.subject-seats strong {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
    letter-spacing: -0.02em;
}

.subject-seats span {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 500;
    margin-top: 2px;
}

.subject-body {
    flex: 1;
}

.subject-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 4px;
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.subject-meta {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 500;
}

.subject-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid var(--line-2);
    font-size: 0.8rem;
}

.subject-ready {
    color: var(--accent-ink);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.subject-ready .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.subject-soon-tag {
    background: var(--line-2);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 4px;
    letter-spacing: 0.05em;
}

.subject-cta {
    color: var(--subject-color);
    font-weight: 700;
}

.subject-cta.muted {
    color: var(--muted);
    font-weight: 500;
}

/* =========================
   Subject page (filtered view)
   ========================= */
.subject-page-head {
    --subject-color: var(--ink);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-right: 4px solid var(--subject-color);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 24px;
}

.subject-page-icon {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--subject-color) 10%, transparent);
    color: var(--subject-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.subject-page-icon svg {
    width: 26px;
    height: 26px;
}

.subject-page-head h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.subject-page-head p {
    font-size: 0.85rem;
    color: var(--muted);
}

/* Subject Introduction */
.subject-intro {
    display: flex;
    gap: 14px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 24px;
    align-items: flex-start;
}

.subject-intro .intro-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.subject-intro p {
    font-size: 0.92rem;
    line-height: 1.75;
    color: var(--ink-2);
    margin: 0;
    text-align: right;
}

/* =========================
   Lectures grid
   ========================= */
.lectures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 12px;
}

.lecture-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    transition: var(--transition);
}

.lecture-card:hover {
    border-color: var(--ink-2);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.lecture-header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.lecture-num {
    width: 42px;
    height: 42px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--ink-2);
    flex-shrink: 0;
}

.lecture-body {
    flex: 1;
    min-width: 0;
}

.lecture-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 4px;
    line-height: 1.5;
}

.lecture-tag {
    font-size: 0.72rem;
    color: var(--muted);
    font-weight: 500;
}

.lecture-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.bookmark-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.bookmark-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.bookmark-btn.active {
    background: var(--gold);
    color: var(--ink);
    border-color: var(--gold);
}

.bookmark-btn {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.bookmark-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--surface-2);
}

.bookmark-btn.active {
    background: var(--gold);
    color: var(--ink);
    border-color: var(--gold);
}

.lecture-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
}

.lecture-btn svg {
    width: 14px;
    height: 14px;
}

.lecture-btn--read:hover {
    border-color: var(--ink);
    color: var(--ink);
    background: var(--surface-2);
}

.lecture-btn--quiz {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.lecture-btn--quiz:hover {
    background: var(--accent-ink);
    border-color: var(--accent-ink);
}

/* =========================
   Empty state
   ========================= */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: var(--radius);
}

.empty-icon {
    color: var(--muted);
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-state h3 {
    font-size: 1.1rem;
    color: var(--ink);
    font-weight: 700;
    margin-bottom: 6px;
}

.empty-state p {
    color: var(--muted);
    font-size: 0.9rem;
}

/* =========================
   Legacy button styles (kept for modal)
   ========================= */
.btn {
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--ink);
    font-family: inherit;
}

.btn-read {
    color: var(--ink-2);
}

.btn-read:hover {
    background: var(--surface-2);
    border-color: var(--ink);
}

.btn-quiz {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-quiz:hover {
    background: var(--accent-ink);
    border-color: var(--accent-ink);
}

.btn svg {
    width: 16px;
    height: 16px;
}

/* =========================
   Modal
   ========================= */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.overlay.active .modal {
    transform: scale(1);
    opacity: 1;
}

.modal {
    background: var(--surface);
    padding: 28px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    text-align: right;
    box-shadow: var(--shadow-lg);
    transform: scale(0.96);
    opacity: 0;
    transition: all 0.2s ease;
    border: 1px solid var(--line);
}

.modal h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--ink);
}

.btn-close {
    margin-top: 18px;
    width: 100%;
    background: var(--surface-2);
    color: var(--ink);
    border: 1px solid var(--line);
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: -20px 0 40px rgba(15, 23, 42, 0.1);
    }

    .main-content {
        margin-right: 0;
        padding: 0 12px 80px;
    }

    .top-header {
        margin: 0;
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 12px;
        border-radius: 0;
        background: var(--surface);
        margin-bottom: 20px;
    }



    .menu-btn {
        display: inline-flex;
        order: 1;
        background: #fff;
        border-color: rgba(0, 0, 0, 0.05);
        box-shadow: var(--shadow-sm);
    }

    #page-title {
        order: 2;
        font-size: 1.15rem;
        flex: 1;
        text-align: center;
        background: none;
        -webkit-text-fill-color: initial;
        color: var(--ink);
    }

    .btn-back {
        order: 3;
        margin-right: 0;
        background: #fff;
        border-color: rgba(0, 0, 0, 0.05);
        box-shadow: var(--shadow-sm);
        padding: 8px 12px;
    }

    .header-search {
        order: 4;
        width: 100%;
        max-width: none;
        margin: 4px 0 0;
    }

    .header-search input {
        background: #fff;
        border-color: rgba(0, 0, 0, 0.06);
        box-shadow: var(--shadow-xs);
    }

    .home-hero {
        padding: 24px 16px;
        border-radius: 20px;
    }

    .hero-stats {
        gap: 10px;
    }

    .hero-stat strong {
        font-size: 1.1rem;
    }

    .subjects-grid {
        gap: 12px;
    }

    .subject-card {
        border-radius: 18px;
    }

    .lectures-grid {
        gap: 12px;
    }

    .lecture-card {
        border-radius: 18px;
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .lecture-header {
        width: 100%;
        gap: 12px;
    }

    .lecture-num {
        width: 36px;
        height: 36px;
        font-size: 0.85rem;
    }

    .lecture-title {
        font-size: 0.95rem;
        line-height: 1.4;
        margin-bottom: 2px;
    }

    .lecture-tag {
        font-size: 0.75rem;
    }

    .lecture-actions {
        width: 100%;
        justify-content: space-between;
        margin-top: 4px;
    }

    .bookmark-btn {
        width: 40px;
        height: 40px;
    }

    .lecture-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 14px;
    }

    .subject-page-head {
        border-radius: 20px;
        margin-top: 10px;
    }
}

/* =================================
   Quiz Interface – Full Redesign
   ================================= */

.quiz-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: none;
    z-index: 2000;
}

.quiz-overlay.active {
    display: block;
    animation: quizFadeIn 0.3s ease forwards;
}

@keyframes quizFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ---- Container ---- */
.quiz-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    /* Modern mobile viewport height */
    background: var(--bg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ---- Top Bar ---- */
.quiz-topbar {
    background: var(--sidebar-bg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 1px 0 var(--border);
    border-bottom: 1px solid var(--border);
}

.quiz-exit-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.quiz-exit-btn:hover {
    background: rgba(212, 0, 0, 0.08);
    color: var(--danger);
    border-color: var(--danger);
}

.quiz-topbar-center {
    flex: 1;
    overflow: hidden;
}

.quiz-topbar-title {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.quiz-counter-badge {
    background: var(--accent);
    color: #fff;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ---- Progress Track ---- */
.quiz-progress-track {
    height: 3px;
    background: var(--border);
}

.quiz-progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Body (scrollable) ---- */
.quiz-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.quiz-screen {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
}

.quiz-screen-question {
    align-items: flex-start;
}

/* ---- Start Screen ---- */
.quiz-start-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 44px 36px;
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--line);
}

.quiz-start-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
}

.quiz-start-title {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--ink);
    margin-bottom: 6px;
}

.quiz-start-sub {
    font-size: 1rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 28px;
}

.quiz-rules {
    background: var(--surface-2);
    border-radius: 14px;
    padding: 20px;
    text-align: right;
    margin-bottom: 28px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quiz-rule-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--ink-2);
}

.quiz-rule-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.quiz-start-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    font-family: 'Tajawal', sans-serif;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
}

.quiz-start-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 151, 80, 0.3);
}

/* ---- Question Screen ---- */
.question-wrap {
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
}

.question-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.q-num-badge {
    background: var(--accent);
    color: #fff;
    padding: 7px 18px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 700;
}

.q-cat-badge {
    background: var(--hover);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border);
}

.q-text {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.9;
    background: var(--surface);
    padding: 28px;
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--line);
    position: relative;
}

.q-text::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.options-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 16px;
}

/* ---- Option Items ---- */
.option-item {
    background: var(--surface);
    border: 2px solid var(--line);
    border-radius: 14px;
    padding: 16px 18px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 14px;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
}

.option-item:hover:not(.disabled) {
    border-color: var(--accent);
    background: var(--surface-2);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 151, 80, 0.06);
}

.option-letter {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.option-text {
    flex: 1;
    font-size: 1rem;
    color: var(--text);
    line-height: 1.6;
}

/* Selected */
.option-item.selected {
    border-color: var(--accent);
    background: rgba(26, 115, 232, 0.08);
}

.option-item.selected .option-letter {
    background: var(--accent);
    color: #fff;
}

/* Correct */
.option-item.correct {
    border-color: var(--accent);
    background: rgba(0, 151, 80, 0.08);
}

.option-item.correct .option-letter {
    background: var(--accent);
    color: #fff;
}

.option-item.correct .option-letter::after {
    content: "✓";
}

/* Wrong */
.option-item.wrong {
    border-color: var(--danger);
    background: rgba(212, 0, 0, 0.08);
}

.option-item.wrong .option-letter {
    background: var(--danger);
    color: #fff;
}

.option-item.wrong .option-letter::after {
    content: "✗";
}

/* ---- Footer Navigation ---- */
.quiz-footer {
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.qnav-btn {
    padding: 11px 22px;
    border-radius: 12px;
    border: none;
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s;
}

.qnav-prev {
    background: var(--surface-2);
    color: var(--ink-2);
}

.qnav-prev:hover:not(:disabled) {
    background: var(--line);
}

.qnav-prev:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.qnav-next {
    background: var(--accent);
    color: #fff;
}

.qnav-next:hover {
    filter: brightness(1.1);
}

.qnav-next.finish-btn {
    background: var(--success);
}

/* Answer dots */
.qnav-dots {
    display: none;
}

/* ---- Results Screen ---- */
.results-wrap {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    text-align: center;
}

.results-hero {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 40px 28px 32px;
    margin-bottom: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--line);
}

.score-ring {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-ring svg {
    position: absolute;
    top: 0;
    left: 0;
}

#score-percentage {
    position: relative;
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--ink);
    z-index: 1;
}

.score-label {
    font-size: 1rem;
    color: var(--muted);
    margin: 0;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.stat-card {
    border-radius: 16px;
    padding: 18px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.stat-correct {
    background: rgba(0, 151, 80, 0.08);
}

.stat-wrong {
    background: rgba(212, 0, 0, 0.08);
}

.stat-skipped {
    background: rgba(255, 204, 0, 0.08);
}

.stat-num {
    font-size: 2rem;
    font-weight: 800;
    color: var(--ink);
}

.stat-correct .stat-num {
    color: var(--accent);
}

.stat-wrong .stat-num {
    color: var(--danger);
}

.stat-skipped .stat-num {
    color: var(--gold);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}

.results-btns {
    display: flex;
    gap: 12px;
}

.quiz-btn-outline,
.quiz-btn-fill {
    flex: 1;
    padding: 14px;
    border-radius: 13px;
    font-family: 'Tajawal', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.quiz-btn-outline {
    background: var(--surface);
    color: var(--accent);
    border: 2px solid var(--accent);
}

.quiz-btn-outline:hover {
    background: var(--hover);
}

.quiz-btn-fill {
    background: var(--accent);
    color: #fff;
}

.quiz-btn-fill:hover {
    filter: brightness(1.1);
}

/* ---- Explanation Box ---- */
.explanation-box {
    margin-top: 20px;
    padding: 20px;
    border-radius: 14px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.explanation-box.correct {
    background: linear-gradient(135deg, rgba(0, 151, 80, 0.08), rgba(0, 151, 80, 0.12));
    border: 2px solid var(--accent);
}

.explanation-box.wrong {
    background: linear-gradient(135deg, rgba(212, 0, 0, 0.08), rgba(212, 0, 0, 0.12));
    border: 2px solid var(--danger);
}

.explanation-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 1.05rem;
}

.explanation-icon {
    font-size: 1.4rem;
}

.explanation-box.correct .explanation-icon::before {
    content: "✓";
    color: var(--accent);
}

.explanation-box.wrong .explanation-icon::before {
    content: "✗";
    color: var(--danger);
}

.explanation-box.correct .explanation-title {
    color: var(--accent);
}

.explanation-box.wrong .explanation-title {
    color: var(--danger);
}

.explanation-content {
    color: var(--ink);
    line-height: 1.8;
    font-size: 0.95rem;
    text-align: right;
}

.explanation-content strong {
    color: var(--ink);
    display: block;
    margin-top: 12px;
    margin-bottom: 6px;
}

/* Disabled state for answered questions */
.option-item.disabled {
    pointer-events: none;
    opacity: 0.9;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
    .quiz-topbar {
        padding: 12px 16px;
    }

    .quiz-topbar-title {
        font-size: 0.85rem;
    }

    .quiz-counter-badge {
        padding: 5px 12px;
        font-size: 0.8rem;
    }

    .quiz-screen {
        padding: 16px 14px;
    }

    .quiz-start-card {
        padding: 24px 18px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    }

    .quiz-start-icon {
        font-size: 2.8rem;
    }

    .quiz-start-title {
        font-size: 1.3rem;
    }

    .quiz-start-sub {
        font-size: 0.95rem;
    }

    .quiz-rules {
        padding: 16px;
        gap: 10px;
    }

    .quiz-rule-item {
        font-size: 0.9rem;
    }

    .quiz-start-btn {
        padding: 14px;
        font-size: 1.05rem;
    }

    .q-num-badge {
        padding: 6px 14px;
        font-size: 0.8rem;
    }

    .q-cat-badge {
        padding: 5px 10px;
        font-size: 0.75rem;
    }

    .q-text {
        font-size: 1.05rem;
        padding: 18px;
    }

    .option-item {
        padding: 14px;
        gap: 12px;
    }

    .option-letter {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }

    .option-text {
        font-size: 0.95rem;
    }

    .explanation-box {
        padding: 16px;
        margin-top: 16px;
    }

    .explanation-header {
        font-size: 1rem;
    }

    .explanation-content {
        font-size: 0.9rem;
    }

    .results-stats {
        gap: 8px;
    }

    .stat-card {
        padding: 14px 10px;
    }

    .stat-num {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.8rem;
    }

    .results-btns {
        flex-direction: column;
        gap: 10px;
    }

    .quiz-btn-outline,
    .quiz-btn-fill {
        padding: 13px;
        font-size: 0.95rem;
    }

    .qnav-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }

    .qnav-dots {
        display: none;
    }

    .quiz-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
        z-index: 100;
    }

    .quiz-body {
        padding-bottom: 80px;
    }

    /* Space for fixed footer */
    .quiz-btn-outline,
    .quiz-btn-fill {
        border-radius: 10px;
    }
}

/* =========================
   Smooth scroll behavior
   ========================= */
.main-content {
    scroll-behavior: smooth;
}

/* =========================
   Card entrance animations
   ========================= */
@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.subject-card {
    animation: cardFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.subject-card:nth-child(1) {
    animation-delay: 0.05s;
}

.subject-card:nth-child(2) {
    animation-delay: 0.1s;
}

.subject-card:nth-child(3) {
    animation-delay: 0.15s;
}

.subject-card:nth-child(4) {
    animation-delay: 0.2s;
}

.subject-card:nth-child(5) {
    animation-delay: 0.25s;
}

.subject-card:nth-child(6) {
    animation-delay: 0.3s;
}

.subject-card:nth-child(7) {
    animation-delay: 0.35s;
}

.subject-card:nth-child(8) {
    animation-delay: 0.4s;
}

.subject-card:nth-child(9) {
    animation-delay: 0.45s;
}

.subject-card:nth-child(10) {
    animation-delay: 0.5s;
}

.subject-card:nth-child(11) {
    animation-delay: 0.55s;
}

.subject-card:nth-child(12) {
    animation-delay: 0.6s;
}

.subject-card:nth-child(13) {
    animation-delay: 0.65s;
}

.subject-card:nth-child(14) {
    animation-delay: 0.7s;
}

.lecture-card {
    animation: cardFadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.lecture-card:nth-child(1) {
    animation-delay: 0.03s;
}

.lecture-card:nth-child(2) {
    animation-delay: 0.06s;
}

.lecture-card:nth-child(3) {
    animation-delay: 0.09s;
}

.lecture-card:nth-child(4) {
    animation-delay: 0.12s;
}

.lecture-card:nth-child(5) {
    animation-delay: 0.15s;
}

.lecture-card:nth-child(6) {
    animation-delay: 0.18s;
}

.lecture-card:nth-child(7) {
    animation-delay: 0.21s;
}

.lecture-card:nth-child(8) {
    animation-delay: 0.24s;
}

.lecture-card:nth-child(9) {
    animation-delay: 0.27s;
}

.lecture-card:nth-child(10) {
    animation-delay: 0.30s;
}

/* =========================
   Professional active states
   ========================= */
.lecture-btn:active {
    transform: scale(0.96);
}

.subject-card:active:not(.subject-card--soon) {
    transform: translateY(-1px) scale(0.99);
}

.quiz-start-btn:active {
    transform: scale(0.97);
}

/* =========================
   Enhanced scrollbar
   ========================= */
.main-content::-webkit-scrollbar {
    width: 6px;
}

.main-content::-webkit-scrollbar-track {
    background: transparent;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

.main-content::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* =========================
   Quiz option pulse on correct/wrong
   ========================= */
@keyframes correctPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 151, 80, 0.3);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(0, 151, 80, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 151, 80, 0);
    }
}

@keyframes wrongPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(212, 0, 0, 0.3);
    }

    70% {
        box-shadow: 0 0 0 8px rgba(212, 0, 0, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(212, 0, 0, 0);
    }
}

.option-item.correct {
    animation: correctPulse 0.6s ease-out;
}

.option-item.wrong {
    animation: wrongPulse 0.6s ease-out;
}

/* =========================
   Question number badge improved
   ========================= */
.q-num-badge {
    background: linear-gradient(135deg, var(--accent), var(--accent-ink));
    box-shadow: 0 2px 8px rgba(0, 151, 80, 0.2);
}

/* =========================
   Quiz counter badge pulse
   ========================= */
.quiz-counter-badge {
    background: linear-gradient(135deg, var(--accent), var(--accent-ink));
    box-shadow: 0 2px 8px rgba(0, 151, 80, 0.2);
}

/* =========================
   Hero stats counter animation
   ========================= */
.hero-stat strong {
    display: inline-block;
    animation: countFade 0.6s ease backwards;
}

@keyframes countFade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-stat:nth-child(1) strong {
    animation-delay: 0.2s;
}

.hero-stat:nth-child(2) strong {
    animation-delay: 0.35s;
}

.hero-stat:nth-child(3) strong {
    animation-delay: 0.5s;
}

/* =========================
   Results screen animation
   ========================= */
.results-wrap {
    animation: cardFadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.results-stats .stat-card {
    animation: cardFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.results-stats .stat-card:nth-child(1) {
    animation-delay: 0.15s;
}

.results-stats .stat-card:nth-child(2) {
    animation-delay: 0.25s;
}

.results-stats .stat-card:nth-child(3) {
    animation-delay: 0.35s;
}

/* =========================
   Professional focus states
   ========================= */
.lecture-btn:focus-visible,
.quiz-start-btn:focus-visible,
.qnav-btn:focus-visible,
.quiz-btn-outline:focus-visible,
.quiz-btn-fill:focus-visible,
.subject-card:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* =========================
   Stat card hover
   ========================= */
.stat-card {
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* =========================
   DARK MODE
   ========================= */
html.dark {
    color-scheme: dark;
}

html.dark body,
html.dark {
    --bg: #0A1F17;
    --surface: #102B20;
    --surface-2: #14382A;
    --ink: #E8F5EE;
    --ink-2: #C8E0D4;
    --muted: #8AB4A0;
    --line: #1F4634;
    --line-2: #1A3D2D;
    --accent: #1FB76A;
    --accent-ink: #34D17F;
    --gold: #FFD633;
    --danger: #FF5C5C;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 30px rgba(31, 183, 106, 0.18);
}

html.dark .home-hero {
    background: linear-gradient(135deg, #0A1F17, #14382A);
    border-color: var(--line);
}

html.dark .nav-item.active {
    background: var(--accent);
    color: #0A1F17;
}

html.dark .nav-item.active svg,
html.dark .nav-item.active .nav-count {
    color: #0A1F17;
}

html.dark .header-search input {
    background: var(--surface);
}

html.dark #page-title {
    -webkit-text-fill-color: var(--ink);
    background: none;
}

html.dark .skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 37%, var(--surface-2) 63%);
    background-size: 800px 100%;
}

html.dark .stat-correct { background: rgba(31, 183, 106, 0.12); }
html.dark .stat-wrong   { background: rgba(255, 92, 92, 0.12); }
html.dark .stat-skipped { background: rgba(255, 214, 51, 0.10); }

html.dark .results-hero circle[stroke="#e9ecef"] {
    stroke: var(--line);
}

html.dark .explanation-box.correct {
    background: linear-gradient(135deg, rgba(31, 183, 106, 0.10), rgba(31, 183, 106, 0.18));
}
html.dark .explanation-box.wrong {
    background: linear-gradient(135deg, rgba(255, 92, 92, 0.10), rgba(255, 92, 92, 0.18));
}

html.dark .modal,
html.dark .lecture-card,
html.dark .subject-card,
html.dark .quiz-start-card,
html.dark .q-text,
html.dark .option-item,
html.dark .results-hero {
    background: var(--surface);
    border-color: var(--line);
}

html.dark .quiz-overlay,
html.dark .quiz-container {
    background: var(--bg);
}

/* =========================
   THEME TOGGLE BUTTON
   ========================= */
.theme-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    z-index: 950;
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: translateY(-2px) scale(1.05);
    color: var(--accent);
    border-color: var(--accent);
}

.theme-toggle .theme-icon-moon { display: none; }
.theme-toggle .theme-icon-sun  { display: block; }
html.dark .theme-toggle .theme-icon-sun  { display: none; }
html.dark .theme-toggle .theme-icon-moon { display: block; }

@media (max-width: 600px) {
    .theme-toggle {
        bottom: 14px;
        left: 14px;
        width: 40px;
        height: 40px;
    }
}

/* =========================
   PWA INSTALL STATE
   ========================= */
html.pwa-installed .hero-install-btn,
html.pwa-installed [data-pwa-install] { display: none !important; }
html.pwa-standalone .pwa-hide-in-standalone { display: none !important; }

/* =========================
   AUTH GATE (prevent flash for unauthenticated users)
   ========================= */
html.auth-checking body { visibility: hidden !important; }
html.auth-checking::before {
    content: "";
    position: fixed;
    inset: 0;
    background: var(--bg, #E8F5EE);
    z-index: 99999;
}
html.auth-checking::after {
    content: "";
    position: fixed;
    top: 50%; left: 50%;
    width: 44px; height: 44px;
    margin: -22px 0 0 -22px;
    border: 4px solid rgba(0, 151, 80, 0.18);
    border-top-color: #009750;
    border-radius: 50%;
    animation: pwa-spin 0.8s linear infinite;
    z-index: 100000;
}
@keyframes pwa-spin { to { transform: rotate(360deg); } }

/* =========================
   PWA UPDATE TOAST
   ========================= */
.pwa-update-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100001;
    animation: pwa-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pwa-update-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #009750;
    color: #fff;
    padding: 12px 18px;
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 151, 80, 0.35);
    font-family: 'Tajawal', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
}
.pwa-update-btn {
    background: #fff;
    color: #009750;
    border: none;
    padding: 7px 16px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
}
.pwa-update-btn:hover { background: #FFCC00; color: #006837; }

/* =========================
   PWA INSTALL MODAL
   ========================= */
.pwa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 79, 58, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: pwa-fade-in 0.2s ease;
    font-family: 'Tajawal', sans-serif;
}
.pwa-modal {
    background: #fff;
    color: #0D4F3A;
    border-radius: 16px;
    padding: 20px 18px 18px;
    max-width: 380px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: pwa-pop-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
    direction: rtl;
    text-align: right;
}
.pwa-modal-close {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 34px;
    height: 34px;
    border: none;
    background: #F0F9F4;
    color: #0D4F3A;
    border-radius: 50%;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.pwa-modal-close:hover { background: #009750; color: #fff; transform: rotate(90deg); }
.pwa-modal-header { text-align: center; margin-bottom: 14px; }
.pwa-modal-icon { font-size: 2.2rem; line-height: 1; margin-bottom: 8px; }
.pwa-modal-header h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0D4F3A;
    margin: 0 0 4px;
}
.pwa-modal-sub { font-size: 0.8rem; color: #2E7D5F; margin: 0; }
.pwa-steps { list-style: none; padding: 0; margin: 0 0 16px; }
.pwa-step {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px;
    background: #F0F9F4;
    border: 1px solid #D4EDDA;
    border-radius: 10px;
    margin-bottom: 6px;
}
.pwa-step-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background: #009750;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
}
.pwa-step-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.pwa-step-text { font-size: 0.86rem; color: #1A5C47; line-height: 1.5; flex: 1; }
.pwa-step-text strong { color: #006837; font-weight: 700; }
.pwa-step-icon {
    flex-shrink: 0;
    color: #009750;
    background: #fff;
    border: 1px solid #C3E6D7;
    border-radius: 8px;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pwa-modal-note {
    background: rgba(255, 204, 0, 0.12);
    border: 1px solid rgba(255, 204, 0, 0.4);
    color: #92400E;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.4;
    margin-bottom: 12px;
}
.pwa-modal-ok {
    width: 100%;
    background: #009750;
    color: #fff;
    border: none;
    padding: 11px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s;
}
.pwa-modal-ok:hover { background: #006837; }

/* PWA Toast */
.pwa-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translate(-50%, 20px);
    background: #0D4F3A;
    color: #fff;
    padding: 12px 22px;
    border-radius: 30px;
    font-family: 'Tajawal', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    z-index: 100002;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.pwa-toast.pwa-toast-show { opacity: 1; transform: translate(-50%, 0); }

/* PWA iOS banner */
.pwa-ios-banner {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    z-index: 99998;
    animation: pwa-slide-up 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Tajawal', sans-serif;
}
.pwa-ios-banner-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    border: 1px solid #C3E6D7;
    border-radius: 16px;
    padding: 12px 14px;
    box-shadow: 0 12px 35px rgba(13, 79, 58, 0.25);
    max-width: 480px;
    margin: 0 auto;
    direction: rtl;
}
.pwa-ios-banner-icon { font-size: 1.8rem; flex-shrink: 0; }
.pwa-ios-banner-text { flex: 1; display: flex; flex-direction: column; text-align: right; line-height: 1.3; }
.pwa-ios-banner-text strong { font-size: 0.92rem; color: #0D4F3A; }
.pwa-ios-banner-text span { font-size: 0.78rem; color: #2E7D5F; }
.pwa-ios-banner-btn {
    background: #009750;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
}
.pwa-ios-banner-btn:hover { background: #006837; }
.pwa-ios-banner-close {
    background: transparent;
    border: none;
    color: #2E7D5F;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    flex-shrink: 0;
}

@keyframes pwa-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pwa-pop-in { from { opacity: 0; transform: scale(0.9) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes pwa-slide-up { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }

html.dark .pwa-modal { background: #1f2937; color: #f3f4f6; }
html.dark .pwa-modal-header h3 { color: #f3f4f6; }
html.dark .pwa-modal-sub { color: #9ca3af; }
html.dark .pwa-step { background: #111827; border-color: #374151; }
html.dark .pwa-step-text { color: #e5e7eb; }
html.dark .pwa-step-text strong { color: #34d399; }
html.dark .pwa-step-icon { background: #1f2937; border-color: #374151; }
html.dark .pwa-modal-close { background: #111827; color: #e5e7eb; }
html.dark .pwa-ios-banner-inner { background: #1f2937; border-color: #374151; }
html.dark .pwa-ios-banner-text strong { color: #f3f4f6; }
html.dark .pwa-ios-banner-text span { color: #9ca3af; }

@media (max-width: 600px) {
    .pwa-modal-overlay { padding: 0; align-items: flex-end; }
    .pwa-modal {
        padding: 18px 16px 16px;
        border-radius: 16px 16px 0 0;
        max-width: 100%;
        max-height: 88vh;
        max-height: 88dvh;
        animation: pwa-slide-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    .pwa-modal-header h3 { font-size: 1.05rem; }
    .pwa-modal-icon { font-size: 2rem; }
    .pwa-step { padding: 8px; gap: 8px; }
    .pwa-step-text { font-size: 0.8rem; line-height: 1.4; }
    .pwa-step-num { width: 22px; height: 22px; font-size: 0.7rem; }
    .pwa-modal-note { font-size: 0.75rem; padding: 7px 9px; }
    .pwa-modal-ok { padding: 10px; font-size: 0.88rem; }
    .pwa-ios-banner { left: 10px; right: 10px; bottom: 10px; }
    .pwa-ios-banner-inner { padding: 10px 12px; gap: 10px; }
    .pwa-ios-banner-text strong { font-size: 0.85rem; }
    .pwa-ios-banner-text span { font-size: 0.72rem; }
    .pwa-toast { left: 16px; right: 16px; bottom: 16px; transform: translateY(20px); border-radius: 14px; text-align: center; max-width: calc(100% - 32px); }
    .pwa-toast.pwa-toast-show { transform: translateY(0); }
    .pwa-update-toast { left: 10px; right: 10px; transform: none; }
    .pwa-update-inner { width: 100%; justify-content: space-between; }
}

/* Make sure modal text never overflows */
.pwa-modal, .pwa-modal * {
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: normal;
    max-width: 100%;
}
.pwa-step-text { min-width: 0; }

/* =========================
   THEME PICKER MODAL
   ========================= */
#theme-picker-overlay {
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
}
#theme-picker-overlay.show { opacity: 1; }
#theme-picker-overlay .theme-picker-modal {
    transform: scale(0.92);
    transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#theme-picker-overlay.show .theme-picker-modal { transform: scale(1); }

.theme-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 8px;
}

.theme-card {
    background: var(--surface-2);
    border: 2px solid var(--line);
    border-radius: 14px;
    padding: 10px 8px 12px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.theme-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 151, 80, 0.18);
}

.theme-card-preview {
    width: 100%;
    height: 70px;
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.theme-card-light { background: #ffffff; }
.theme-card-light .theme-card-bar { background: #009750; }
.theme-card-light .theme-card-row { background: #e5e7eb; }

.theme-card-dark { background: #0f1d18; border-color: rgba(255, 255, 255, 0.08); }
.theme-card-dark .theme-card-bar { background: #1FB76A; }
.theme-card-dark .theme-card-row { background: #2a3a32; }

.theme-card-system {
    background: linear-gradient(135deg, #ffffff 0%, #ffffff 50%, #0f1d18 50%, #0f1d18 100%);
}
.theme-card-system .theme-card-bar {
    background: linear-gradient(135deg, #009750 0%, #009750 50%, #1FB76A 50%, #1FB76A 100%);
}
.theme-card-system .theme-card-row {
    background: linear-gradient(135deg, #e5e7eb 0%, #e5e7eb 50%, #2a3a32 50%, #2a3a32 100%);
}

.theme-card-bar {
    height: 8px;
    border-radius: 3px;
    width: 60%;
}
.theme-card-row {
    height: 6px;
    border-radius: 3px;
    width: 100%;
}
.theme-card-row.short { width: 75%; }

.theme-card-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ink);
}

@media (max-width: 480px) {
    .theme-picker-grid { gap: 8px; }
    .theme-card { padding: 8px 6px 10px; }
    .theme-card-preview { height: 58px; padding: 6px; }
    .theme-card-label { font-size: 0.78rem; }
    .theme-card-label svg { width: 14px; height: 14px; }
}

/* =========================
   QUIZ TIMER + OPTIONS TOGGLES
   ========================= */
.quiz-timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--ink-2);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    transition: all 0.25s ease;
}

.quiz-timer.warning {
    background: rgba(212, 0, 0, 0.12);
    color: var(--danger);
    border-color: var(--danger);
    animation: pulseWarn 1s ease-in-out infinite;
}

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

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 22px;
}

.quiz-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    text-align: right;
}

.quiz-toggle:hover {
    border-color: var(--accent);
}

.quiz-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.quiz-toggle-track {
    flex-shrink: 0;
    width: 40px;
    height: 22px;
    background: var(--line);
    border-radius: 999px;
    position: relative;
    transition: background 0.2s ease;
}

.quiz-toggle-thumb {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.quiz-toggle input:checked ~ .quiz-toggle-track {
    background: var(--accent);
}

.quiz-toggle input:checked ~ .quiz-toggle-track .quiz-toggle-thumb {
    transform: translateX(-18px);
}

.quiz-toggle-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.3;
}

.quiz-toggle-label strong {
    font-size: 0.92rem;
    color: var(--ink);
    font-weight: 700;
}

.quiz-toggle-label small {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 500;
}

/* =========================
   MISTAKE BANK CARD
   ========================= */
.mistake-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-right: 4px solid var(--danger);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 12px;
    transition: var(--transition);
}

.mistake-card:hover {
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.mistake-q {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.7;
    margin-bottom: 10px;
}

.mistake-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 8px;
}

.mistake-meta span {
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 6px;
}

.mistake-answer {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    line-height: 1.6;
}

.mistake-answer .wrong-line {
    color: var(--danger);
}
.mistake-answer .right-line {
    color: var(--accent);
}

/* =========================
   TOAST NOTIFICATION
   ========================= */
.app-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--surface);
    color: var(--ink);
    padding: 12px 22px;
    border-radius: 12px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

.app-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.app-toast.success { border-color: var(--accent); }
.app-toast.error   { border-color: var(--danger); }