/* ── Reset & Base ────────────────────────────────────────────────── 
*/
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Keep HTML's hidden attribute authoritative over component display rules. */
[hidden] { display: none !important; }

:root {
    --bg: #fafafa;
    --bg-card: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-light: #eef2ff;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --success: #22c55e;
    --success-light: #f0fdf4;
    --border: #e5e7eb;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    --transition: 0.2s ease;
}

html { font-size: 16px; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── Navbar ─────────────────────────────────────────────────────── 
*/
.navbar {
    display: flex;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 1.125rem;
}

.navbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
}

.nav-link:hover { color: var(--accent); }
.nav-button { padding: 0; border: 0; background: none; cursor: pointer; }

.profile-nav {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--text);
    text-decoration: none;
}

.profile-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--accent);
    font-weight: 700;
}

.profile-nav-meta { display: flex; flex-direction: column; line-height: 1.15; }
.profile-nav-label { font-size: 0.875rem; font-weight: 600; }
.profile-nav-meta small { margin-top: 0.15rem; color: var(--text-muted); font-size: 0.6875rem; }

.brand-logo {
    display: block;
    width: auto;
    height: 52px;
    object-fit: contain;
}

.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.messages { max-width: 640px; margin: 0 auto 1rem; }
.message { padding: 0.75rem 1rem; border-radius: var(--radius-sm); }
.message-success { color: #166534; background: var(--success-light); }

/* ── Account / Profile ─────────────────────────────────────────── */
.account-card {
    max-width: 560px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.account-card h1 { margin-bottom: 0.5rem; }
.account-intro { margin-bottom: 1.5rem; color: var(--text-muted); }
.social-login-list { display: grid; gap: 0.75rem; }

.social-login-btn {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.social-login-btn:hover { border-color: var(--accent); }
.facebook-login { color: #1877f2; }
.account-warning { padding: 1rem; color: #92400e; background: #fffbeb; border-radius: var(--radius-sm); }

.profile-form { display: grid; gap: 1.25rem; }
.form-field { display: grid; gap: 0.375rem; }
.form-field label { font-weight: 600; }
.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
}
.form-field textarea { resize: vertical; }
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.field-help, .word-counter { color: var(--text-muted); font-size: 0.8125rem; }
.field-error, .word-counter.over-limit { color: var(--danger); font-size: 0.8125rem; }

.subscription-summary {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--accent-light);
    border-radius: var(--radius-sm);
}
.subscription-summary span { color: var(--text-muted); }
.billing-portal-form { margin: 1rem 0 0; text-align: center; }

.profile-save-btn { width: 100%; }
.profile-logout-form { margin: 0.75rem 0 0; text-align: center; }
.profile-logout-btn {
    padding: 0.5rem 1rem;
    color: var(--danger);
    background: transparent;
    border: 0;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.profile-logout-btn:hover { text-decoration: underline; }

.subscription-section {
    margin: 1.75rem 0;
    padding: 1.25rem;
    background: var(--accent-light);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
}
.subscription-section h2 { font-size: 1.125rem; }
.subscription-section > .field-help { margin-bottom: 1rem; }
.profile-plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.profile-plan-option {
    display: grid;
    gap: 0.35rem;
    padding: 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.profile-plan-option.current { border: 2px solid var(--accent); box-shadow: var(--shadow); }
.profile-plan-option span { color: var(--text-muted); font-size: 0.8125rem; }
.profile-plan-option button {
    margin-top: 0.5rem;
    padding: 0.55rem;
    color: var(--accent);
    background: var(--accent-light);
    border: 0;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}
.profile-plan-option button:disabled { color: var(--text-muted); cursor: default; }

/* ── Plans ─────────────────────────────────────────────────────── */
.plans-page, .dashboard-page { max-width: 1000px; margin: 2rem auto; }
.plans-page:has(.plan-grid-three) { max-width: 1180px; }
.plan-grid.plan-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.plans-header { max-width: 700px; margin: 0 auto 2rem; text-align: center; }
.plans-header p { color: var(--text-muted); }
.bypass-notice { max-width: 700px; margin: 0 auto 1.5rem; }
.plan-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}
.plan-featured { border: 2px solid var(--accent); }
.plan-badge { position: absolute; top: 1rem; right: 1rem; color: var(--accent); font-weight: 700; }
.plan-price { margin: 1rem 0; font-size: 2rem; font-weight: 800; }
.plan-price span { color: var(--text-muted); font-size: 0.875rem; font-weight: 500; }
.plan-card ul { margin: 0 0 1.5rem 1.25rem; color: var(--text-muted); }
.plan-card form { margin-top: auto; }
.plan-card form .btn-primary { width: 100%; }

/* ── Staff dashboard ───────────────────────────────────────────── */
.dashboard-page h1, .dashboard-page h2 { margin-bottom: 1rem; }
.dashboard-page h2 { margin-top: 2rem; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.metric-card { padding: 1.25rem; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.metric-card span { display: block; color: var(--text-muted); font-size: 0.8125rem; }
.metric-card strong { font-size: 1.5rem; }
.table-wrap { overflow-x: auto; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.admin-table th, .admin-table td { padding: 0.75rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.admin-table th { color: var(--text-muted); }

/* ── Home / Hero ────────────────────────────────────────────────── 
*/
.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 70px);
    text-align: center;
    padding: 2rem 1rem;
}

.hero-inner {
    max-width: 640px;
    width: 100%;
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 0.75rem;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
}

.hero-form {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.hero-input {
    flex: 1;
    padding: 1rem 1.25rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: var(--bg-card);
}

.hero-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* ── Buttons ────────────────────────────────────────────────────── 
*/
.btn-primary {
    padding: 1rem 1.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    white-space: nowrap;
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-large {
    padding: 1.125rem 2.5rem;
    font-size: 1.0625rem;
}

/* ── Example chips ──────────────────────────────────────────────── 
*/
.examples {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.examples-label {
    color: var(--text-light);
    font-size: 0.875rem;
    margin-right: 0.25rem;
}

#example-chips {
    display: contents;
}

.example-chip {
    padding: 0.4rem 0.875rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 100px;
    cursor: pointer;
    transition: all var(--transition);
}

.example-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-light);
}

/* ── Error message ──────────────────────────────────────────────── 
*/
.error-message {
    margin-top: 1.5rem;
    padding: 0.875rem 1.25rem;
    background: var(--danger-light);
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
}

/* ── Loading overlay ────────────────────────────────────────────── 
*/
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(250, 250, 250, 0.92);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-card {
    text-align: center;
    padding: 3rem;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--accent-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1.5rem;
}

.loading-spinner.small {
    width: 28px;
    height: 28px;
    border-width: 3px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.loading-step {
    color: var(--text-muted);
    font-size: 0.9375rem;
}

/* ── Course clarification modal ────────────────────────────────── */
.clarification-modal {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(5px);
}

.clarification-card {
    position: relative;
    width: min(560px, 100%);
    padding: 2rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    text-align: left;
}

.clarification-card h2 { margin-bottom: 0.5rem; }
.clarification-card > p { margin-bottom: 1.25rem; color: var(--text-muted); }
.clarification-close {
    position: absolute;
    top: 0.75rem;
    right: 0.9rem;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}
.clarification-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.clarification-option {
    padding: 0.75rem 0.9rem;
    color: var(--text);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.clarification-option:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-light); }

.clarification-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.clarification-divider::before,
.clarification-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.clarification-custom label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.clarification-custom-row {
    display: flex;
    gap: 0.65rem;
}

.clarification-custom-row input {
    min-width: 0;
    flex: 1;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    font: inherit;
}

.clarification-custom-row input:focus {
    border-color: var(--accent);
    outline: 3px solid var(--accent-light);
}

.clarification-custom-row .btn-primary {
    white-space: nowrap;
}

/* ── Course page ────────────────────────────────────────────────── 
*/
.back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9375rem;
    transition: color var(--transition);
}

.back-link:hover { color: var(--accent); }

.course-header { margin-bottom: 2rem; }

.course-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 100px;
    margin-bottom: 0.75rem;
}

.course-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.75rem;
}

.course-description {
    font-size: 1.0625rem;
    color: var(--text-muted);
    max-width: 600px;
    margin-bottom: 0.75rem;
}

.course-meta {
    display: flex;
    gap: 1rem;
    color: var(--text-light);
    font-size: 0.875rem;
}

.course-actions { margin-bottom: 3rem; }

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
}

.lessons-grid { margin-bottom: 2rem; }

.lesson-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.lesson-card {
    display: flex;
    gap: 1rem;
    padding: 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow var(--transition), transform var(--transition);
}

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

.lesson-number {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 50%;
}

.lesson-card-title {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.lesson-card-summary {
    font-size: 0.9375rem;
    color: var(--text-muted);
}

/* ── Lesson / Professor page ────────────────────────────────────── */
.lesson-page {
    max-width: 800px;
    min-height: calc(100dvh - 110px);
    margin: 0 auto;
    padding: clamp(0.5rem, 2vh, 1rem) clamp(0.5rem, 2vw, 1rem);
    transition: padding 320ms ease;
}

.lesson-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    transition: margin 320ms ease;
}

.selector-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.lesson-selector-row {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 560px;
    gap: 0.75rem;
}

.lesson-combobox {
    width: 100%;
    min-width: 0;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition);
}

.lesson-combobox:focus { border-color: var(--accent); }

.lesson-play-btn {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    display: inline-grid;
    place-items: center;
    padding: 0 0 0 3px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: var(--accent);
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: transform var(--transition), opacity var(--transition), box-shadow var(--transition);
}

.lesson-play-btn:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 10px 24px rgba(79, 70, 229, 0.35);
}

.lesson-play-btn:focus-visible {
    outline: 3px solid var(--accent-light);
    outline-offset: 3px;
}

.lesson-play-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* ── Professor area ─────────────────────────────────────────────── 
*/
.professor-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: clamp(1rem, 4vh, 2rem) 1rem;
    transition: padding 320ms ease;
}

.professor-avatar-wrap {
    width: 190px;
    height: 190px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
    transition: width 320ms ease, height 320ms ease, margin 320ms ease;
}

.lesson-page.has-lesson-detail {
    padding-top: 0.25rem;
}

.lesson-page.has-lesson-detail .lesson-selector {
    margin-bottom: 0.75rem;
}

.lesson-page.has-lesson-detail .professor-area {
    padding: 0.25rem 1rem 0.75rem;
}

.lesson-page.has-lesson-detail .professor-avatar-wrap {
    width: 112px;
    height: 112px;
    margin-bottom: 0.5rem;
}

.lesson-page.has-lesson-detail .professor-blob {
    width: 96px;
    height: 96px;
}

.professor-blob {
    position: relative;
    width: 150px;
    height: 150px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 42% 58% 61% 39% / 46% 42% 58% 54%;
    background:
        radial-gradient(circle at 32% 24%, rgba(255,255,255,.9) 0 7%, transparent 24%),
        linear-gradient(145deg, #a78bfa 4%, #6366f1 42%, #3b82f6 72%, #22d3ee 100%);
    box-shadow:
        0 22px 48px rgba(79, 70, 229, 0.28),
        inset 12px 14px 28px rgba(255,255,255,.28),
        inset -14px -18px 30px rgba(30, 64, 175, .24);
    will-change: transform, border-radius;
    transition: transform 70ms linear, box-shadow 180ms ease, width 320ms ease, height 320ms ease;
    animation: blob-morph 8s ease-in-out infinite alternate;
    cursor: pointer;
    user-select: none;
}

.professor-blob:focus-visible {
    outline: 4px solid rgba(99, 102, 241, .24);
    outline-offset: 8px;
}

.professor-blob.blurping {
    animation: blob-blurp 560ms cubic-bezier(.2, .9, .25, 1);
}

.professor-avatar-wrap.speaking .professor-blob {
    box-shadow:
        0 28px 64px rgba(79, 70, 229, 0.4),
        0 0 40px rgba(34, 211, 238, .18),
        inset 12px 14px 28px rgba(255,255,255,.32),
        inset -14px -18px 30px rgba(30, 64, 175, .24);
}

.professor-blob-shine {
    position: absolute;
    inset: 14% 48% 52% 18%;
    border-radius: 50%;
    background: rgba(255, 255, 255, .55);
    filter: blur(7px);
    transform: rotate(-22deg);
}

.professor-blob-core {
    position: absolute;
    inset: 35%;
    border-radius: 50%;
    background: rgba(255,255,255,.18);
    box-shadow: 0 0 30px rgba(255,255,255,.28);
}

@keyframes blob-morph {
    0% { border-radius: 42% 58% 61% 39% / 46% 42% 58% 54%; }
    35% { border-radius: 55% 45% 38% 62% / 58% 54% 46% 42%; }
    70% { border-radius: 38% 62% 56% 44% / 41% 61% 39% 59%; }
    100% { border-radius: 61% 39% 45% 55% / 52% 38% 62% 48%; }
}

@keyframes blob-blurp {
    0% { transform: scale(1); border-radius: 42% 58% 61% 39% / 46% 42% 58% 54%; }
    18% { transform: scaleX(1.28) scaleY(.72) rotate(-3deg); border-radius: 62% 38% 70% 30% / 35% 66% 34% 65%; }
    42% { transform: scaleX(.78) scaleY(1.3) rotate(4deg); border-radius: 31% 69% 36% 64% / 69% 32% 68% 31%; }
    68% { transform: scaleX(1.12) scaleY(.91) rotate(-2deg); }
    84% { transform: scaleX(.96) scaleY(1.06) rotate(1deg); }
    100% { transform: scale(1); border-radius: 42% 58% 61% 39% / 46% 42% 58% 54%; }
}

@media (prefers-reduced-motion: reduce) {
    .professor-blob { animation: none; transition-duration: 180ms; }
}

.professor-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.professor-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-light);
    transition: background var(--transition);
}

.status-dot.status-connected { background: var(--success); }
.status-dot.status-listening { background: var(--accent); animation: pulse-dot 
1s infinite; }
.status-dot.status-speaking { background: var(--success); animation: pulse-dot 
0.8s infinite; }
.status-dot.status-thinking { background: #f59e0b; animation: pulse-dot 1.2s 
infinite; }
.status-dot.status-error { background: var(--danger); }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Waveform ───────────────────────────────────────────────────── 
*/
.waveform {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 32px;
    margin-top: 0.75rem;
}

.waveform span {
    width: 4px;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}

.waveform span:nth-child(1) { animation-delay: 0s; }
.waveform span:nth-child(2) { animation-delay: 0.1s; }
.waveform span:nth-child(3) { animation-delay: 0.2s; }
.waveform span:nth-child(4) { animation-delay: 0.3s; }
.waveform span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 28px; }
}

/* ── Illustration area ──────────────────────────────────────────── 
*/
.lesson-complete {
    max-width: 600px;
    margin: 0 auto 1.5rem;
    padding: 1rem 1.25rem;
    color: #166534;
    background: var(--success-light);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    text-align: center;
}

.lesson-complete:not([hidden]),
.illustration-area:not([hidden]),
.written-example-area:not([hidden]) {
    animation: lesson-detail-reveal 320ms ease both;
}

@keyframes lesson-detail-reveal {
    from { opacity: 0; transform: translateY(12px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.lesson-complete strong { display: block; margin-bottom: 0.25rem; }
.lesson-complete p { font-size: 0.9375rem; }

.illustration-area {
    margin: 1.5rem auto;
    max-width: 600px;
}

.illustration-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.illustration-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.illustration-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.illustration-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 0 0.25rem;
}

.illustration-close:hover { color: var(--text); }

.illustration-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3rem;
    color: var(--text-muted);
    gap: 1rem;
}

.illustration-img {
    display: block;
    width: 100%;
    max-height: min(52dvh, 520px);
    height: auto;
    object-fit: contain;
}

.written-example-area {
    width: min(100%, 820px);
    margin: 1.5rem auto;
}

.written-example-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg-card);
    box-shadow: var(--shadow-md);
}

.written-example-card .illustration-header {
    margin: 0;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.written-example-meta {
    display: block;
    margin-top: 0.2rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.written-example-content {
    overflow-x: auto;
    max-height: min(42dvh, 440px);
    overflow-y: auto;
    margin: 0;
    padding: 1.25rem;
    background: #111827;
    color: #e5e7eb;
    font: 0.9rem/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    white-space: pre;
    tab-size: 4;
}

.written-example-explanation {
    margin: 0;
    padding: 1rem 1.25rem;
    color: var(--text-muted);
    line-height: 1.55;
}

/* ── Controls ──────────────────────────────────────────────────── 
*/
.lesson-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem 0;
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    min-width: 110px;
}

.control-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.control-btn:disabled { opacity: 0.4; cursor: not-allowed; }

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

.control-btn-danger:hover:not(:disabled) {
    border-color: var(--danger);
    color: var(--danger);
}

.control-icon { font-size: 1.5rem; }
.control-label { font-size: 0.8125rem; font-weight: 500; }

/* ── Toast ──────────────────────────────────────────────────────── 
*/
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.875rem 1.5rem;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    max-width: 90%;
    text-align: center;
}

/* ── Quiz Modal ─────────────────────────────────────────────────── 
*/
.quiz-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1500;
    padding: 1rem;
}

.quiz-modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.quiz-header h2 { font-size: 1.25rem; font-weight: 700; }

.quiz-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.quiz-close:hover { color: var(--text); }

.quiz-score-bar {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9375rem;
    font-weight: 600;
}

.quiz-score-correct { color: var(--success); }
.quiz-score-wrong { color: var(--danger); }
.quiz-score-total { color: var(--text-muted); }

.quiz-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.quiz-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 3rem;
    color: var(--text-muted);
}

.quiz-question { margin-bottom: 1.5rem; }

.quiz-question-num {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.quiz-question-text {
    font-size: 1.0625rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.quiz-options { display: flex; flex-direction: column; gap: 0.5rem; }

.quiz-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.9375rem;
}

.quiz-option:hover { border-color: var(--accent); }
.quiz-option.selected { border-color: var(--accent); background: 
var(--accent-light); }
.quiz-option.correct { border-color: var(--success); background: 
var(--success-light); }
.quiz-option.wrong { border-color: var(--danger); background: 
var(--danger-light); }
.quiz-option.disabled { cursor: not-allowed; }
.quiz-option.disabled:hover { border-color: var(--border); }

.quiz-option-radio {
    position: relative;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    flex-shrink: 0;
    transition: border-color var(--transition), background var(--transition);
}

.quiz-option-radio::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
    transform: scale(0.35);
    transition: opacity var(--transition), transform var(--transition);
}

.quiz-option.selected .quiz-option-radio { border-color: var(--accent); }
.quiz-option.selected .quiz-option-radio::after {
    opacity: 1;
    transform: scale(1);
}
.quiz-option.correct .quiz-option-radio { border-color: var(--success); 
background: var(--success); }
.quiz-option.wrong .quiz-option-radio { border-color: var(--danger); 
background: var(--danger); }
.quiz-option.correct .quiz-option-radio::after,
.quiz-option.wrong .quiz-option-radio::after { background: #fff; }

.quiz-feedback {
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
}

.quiz-feedback.correct { background: var(--success-light); color: #15803d; }
.quiz-feedback.wrong { background: var(--danger-light); color: #b91c1c; }

.quiz-feedback strong { display: block; margin-bottom: 0.25rem; }

.quiz-confirm-btn {
    margin-top: 1rem;
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.quiz-confirm-btn:hover { background: var(--accent-hover); }
.quiz-confirm-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.quiz-next-btn {
    margin-top: 1rem;
    width: 100%;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--text);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.quiz-next-btn:hover { opacity: 0.9; }

.quiz-result {
    text-align: center;
    padding: 2rem 1rem;
}

.quiz-result-score {
    font-size: 3rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.quiz-result-percent {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.quiz-result-feedback {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.quiz-result-review {
    text-align: left;
    margin-top: 1.5rem;
}

.quiz-result-review h4 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.quiz-result-review ul {
    list-style: none;
    padding-left: 0;
}

.quiz-result-review li {
    padding: 0.375rem 0;
    font-size: 0.9375rem;
    color: var(--text-muted);
}

/* ── Responsive ─────────────────────────────────────────────────── 
*/
@media (min-width: 768px) {
    .lesson-cards { grid-template-columns: 1fr; }
    .hero-form { flex-direction: row; }
}

@media (max-width: 640px) {
    .main-content { padding: 1rem; }
    .lesson-page { padding: 0.5rem; }
    .hero-form { flex-direction: column; }
    .hero-input { width: 100%; }
    .btn-primary { width: 100%; }
    .lesson-controls { flex-wrap: wrap; }
    .control-btn { min-width: 140px; }
    .professor-avatar-wrap { width: 120px; height: 120px; }
    .quiz-modal-content { max-height: 95vh; }
    .plan-grid, .plan-grid.plan-grid-three, .metric-grid { grid-template-columns: 1fr; }
    .navbar { padding: 0.75rem 1rem; }
    .brand-logo { height: 44px; }
    .navbar-actions { gap: 0.5rem; }
    .profile-nav-meta { display: none; }
    .profile-plan-grid { grid-template-columns: 1fr; }
    .clarification-options { grid-template-columns: 1fr; }
    .clarification-custom-row { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
    .lesson-page,
    .lesson-selector,
    .professor-area,
    .professor-avatar-wrap,
    .lesson-complete:not([hidden]),
    .illustration-area:not([hidden]),
    .written-example-area:not([hidden]) {
        transition: none;
        animation: none;
    }
}
