:root {
    --max-width: 1200px;

    --color-bg-main: #EAEAEA;
    --color-text-primary: #1A1A1A;
    --color-text-secondary: #666666;
    --color-border: #D1D1D1;
    --color-card-blue: #C8D5EB;
    --color-card-green: #CEEFCE;

    --color-blue: #007BFF;
    --color-link-blue: #4285f4;
    --color-red: #FF0000;
    --color-white: #FFFFFF;
    --color-gray-100: #F8F9FA;
    --color-gray-200: #F1F3F5;
    --color-gray-300: #E0E0E0;
    --color-gray-400: #CED4DA;
    --color-gray-500: #ADB5BD;
    --color-gray-600: #6C757D;
    --color-gray-800: #343A40;
    --color-gray-900: #212529;
    --color-black: #000000;

    --spacing-xs: 0.5rem;
    /* 8px */
    --spacing-sm: 1rem;
    /* 16px */
    --spacing-md: 2rem;
    /* 32px */
    --spacing-lg: 3rem;
    /* 48px */

    --border-radius-lg: 12px;
    --border-radius-sm: 6px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg-main);
    color: var(--color-text-primary);
    min-height: 100vh;
}

/* --- MAIN WRAPPER LAYOUT --- */
#main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

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

/* --- GLOBAL HEADER --- */
.global-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) 0;
    flex-shrink: 0;

    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
}

.brand-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    display: inline-block;
    margin-right: var(--spacing-xs);
    color: var(--color-text-secondary);
    /* Updated to match screenshot gray */
}

.logout-header a {
    text-decoration: none;
    color: var(--color-text-secondary);
    font-weight: 600;
    cursor: pointer;
}

.logout-header a:hover {
    text-decoration: underline;
}

.profile-avatar-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

/* --- USER SELECTION CONTENT --- */
.user-selection {
    flex-grow: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: max(2rem, 5vh);
    padding-bottom: var(--spacing-lg);
}

.user-selection h2 {
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: var(--spacing-md);
    width: 100%;
    text-align: left;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--spacing-md);
    width: 100%;
}

/* --- PROFILE CARDS --- */
.profile-card {
    display: flex;
    flex-direction: column;
    width: 100%;
    aspect-ratio: 3/4;
    min-height: 200px;
    border-radius: var(--border-radius-lg);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    border: none;
    padding: 0;
    outline: none;
}

.profile-card:focus-visible {
    box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.1);
}

.profile-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.profile-card--blue {
    background-color: var(--color-card-blue);
}

.profile-card--green {
    background-color: var(--color-card-green);
}

.profile-card__avatar {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.profile-card__icon {
    width: 80px;
    height: 80px;
    stroke: var(--color-text-primary);
    stroke-width: 1.5;
    fill: none;
}

.profile-card__avatar-icon {
    width: 40px;
    height: 40px;
    stroke: var(--color-text-primary);
    stroke-width: 1.5;
    fill: none;
}

.profile-card__label-container {
    background-color: var(--color-white);
    padding: var(--spacing-sm);
    text-align: center;
    width: 100%;
}

.profile-card__name {
    font-size: 1rem;
    font-weight: 500;
}

/* --- FORMS & AUTH (NEW SECTION) --- */
.general-form-container {
    flex-grow: 1;
    /* Fills vertical space */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Start from top, use margin to push down */
    padding-top: max(2rem, 10vh);
    /* Match user selection spacing */
    padding-left: var(--spacing-sm);
    padding-right: var(--spacing-sm);
    width: 100%;
}

.general-form {
    width: 90%;
    max-width: 600px;

    background-color: #ffffff;
    padding: 2.5rem;
    /* 40px */
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    margin: 0 auto;
    /* Center the form horizontally */
    /* Optional: Add white background for card look */
    /* background-color: var(--color-white); */
    /* padding: var(--spacing-lg); */
    /* border-radius: var(--border-radius-lg); */
}

.general-form h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    text-align: center;
}

.form-group {
    margin-bottom: var(--spacing-md);
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--color-text-secondary);
}

.form-group select {
    width: 100%;
    padding: 0.75rem;
    /* 12px */
    font-size: 1rem;
    /* 16px */
    line-height: 1.5;
    /* Added for consistent height */
    color: #495057;
    /* Default text color */
    background-color: #fff;
    border: 1px solid #ced4da;
    border-radius: 4px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;

    /* Remove default system appearance */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    /* Custom dropdown arrow */
    /* Using an inline SVG for a clean, modern arrow */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;

    /* Adjust right padding to make space for the arrow */
    padding-right: 2.5rem;
    /* 40px */
}

.form-group input {
    width: 100%;
    padding: 0.75rem var(--spacing-sm);
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    outline: none;
    transition: border-color 0.2s;
    background-color: var(--color-white);
}

.form-group input:focus {
    border-color: var(--color-text-primary);
}

/* Password Toggle Wrapper */
.password-wrapper {
    position: relative;
    width: 100%;
}

.password-wrapper input {
    padding-right: 3rem;
    /* Space for the eye icon */
}

#togglePassword {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--color-text-secondary);
    display: flex;
    /* Ensures SVG aligns correctly */
    align-items: center;
}

/* Base class: Handles structure, size, and fonts */
.btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    /* border: none; */
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s, background-color 0.2s;
    text-decoration: none;
}

/* Modifier: Primary Color Scheme */
.btn-primary {
    background-color: var(--color-blue);
    color: var(--color-white);
    border-color: var(--color-blue);
}

.btn-primary:hover {
    opacity: 0.9;
}

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

.btn-secondary:hover {
    background-color: var(--color-gray-100);
    border-color: var(--color-blue);
}

/* Social Login Divider */
.social-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: var(--spacing-md) 0;
    color: var(--color-gray-500);
    font-size: 0.85rem;
}

.social-divider::before,
.social-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--color-border);
}

.social-divider span {
    padding: 0 10px;
}

/* Social Buttons */
.social-login {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.social-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    background-color: var(--color-white);
    color: var(--color-text-primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: background-color 0.2s;
}

.social-button:hover {
    background-color: #f5f5f5;
}

/* Icons in buttons */
.icon-google,
.icon-apple {
    margin-right: 0.5rem;
    font-size: 1.2rem;
}

/* Links */
.forgot-password {
    display: block;
    text-align: center;
    margin-top: var(--spacing-md);
    color: var(--color-link-blue);
    font-size: 0.9rem;
    text-decoration: none;
}

.register-link {
    text-align: center;
    margin-top: var(--spacing-sm);
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.register-link a,
.forgot-password:hover {
    color: var(--color-link-blue);
    text-decoration: underline;
}

/* --- User Dropdown --- */
.user-dropdown {
    position: relative;
}

.user-dropdown:focus-within .dropdown-menu {
    display: block;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--color-gray-400);
    border-radius: 6px;
    background-color: var(--color-white);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    min-width: max-content;
}

.dropdown-toggle>span {
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- 2. Hide the default triangle/marker on the <summary> tag --- */
.dropdown-toggle::-webkit-details-marker {
    display: none;
}

.dropdown-toggle:hover {
    background-color: var(--color-gray-100);
}

.dropdown-toggle svg:first-of-type {
    color: var(--color-gray-600);
    margin-right: 8px;
}

.dropdown-toggle svg.chevron {
    color: var(--color-gray-600);
    margin-left: 16px;
    width: 16px;
    height: 16px;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    width: max-content;
    max-width: 400px;
    background-color: var(--color-white);
    border: 1px solid var(--color-gray-300);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.05);
    padding: 8px;
    z-index: 100;
}

/* --- 3. Show the menu when the <details> tag is [open] --- */
.user-dropdown[open]>.dropdown-menu {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    color: var(--color-gray-800);
}

.dropdown-item svg {
    margin-right: 12px;
    width: 20px;
    height: 20px;
    color: var(--color-gray-600);
}

.dropdown-item>span {
    /* Prevents long account_ids from wrapping in the menu */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dropdown-item:hover {
    background-color: var(--color-gray-100);
}

/* --- 4. Style for the active (blue) item in the dropdown --- */
.dropdown-item.active {
    background-color: var(--color-gray-200);
    color: var(--color-blue);
    font-weight: 600;
}

.dropdown-item.active svg {
    color: var(--color-blue);
}

/* 1. Tab Navigation Buttons */
.tab-navigation {
    display: flex;
    flex-direction: row;
    /* Explicitly force row layout */
    justify-content: flex-start;
    gap: var(--spacing-sm);
    /* Space between the two buttons */

    /* Space below the buttons section */
    margin-bottom: var(--spacing-lg);
}

/* 2. Section Containers (Guardians / Students) */
.section-group {
    /* Space between "Guardians" section and "Students" section */
    margin-bottom: var(--spacing-lg);
    width: 100%;
}

/* 3. Section Headings */
.section-group h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-text-secondary);

    /* Space between Text and Profile Cards */
    margin-bottom: var(--spacing-md);
}

/* 4. Dashed "Add New" Card */
.profile-card--dashed {
    background-color: transparent;
    border: 2px dashed var(--color-gray-400);
    color: var(--color-text-secondary);
    justify-content: center;
    align-items: center;
}

.profile-card--dashed:hover {
    border-color: var(--color-blue);
    color: var(--color-blue);
    background-color: var(--color-gray-100);
    transform: translateY(-2px);
}

.profile-card--dashed .profile-card__icon {
    width: 32px;
    height: 32px;
    stroke: currentColor;
    margin-bottom: var(--spacing-xs);
}

.profile-card--editable .profile-card__avatar {
    position: relative;
    /* Ensure the overlay doesn't spill out if the avatar has rounded corners */
    overflow: hidden;
}

.profile-card__edit-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    /* The "Darken" effect */
    background-color: rgba(0, 0, 0, 0.5);

    /* Center the Text and Icon */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    /* Text Styles */
    color: var(--color-white);
    font-weight: 600;
    font-size: 1.1rem;

    /* Animation state: Hidden */
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* 3. The Hover Trigger */
.profile-card--editable:hover .profile-card__edit-overlay {
    opacity: 1;
}

/* 4. The Pencil Icon Size */
.profile-card__edit-icon {
    width: 32px;
    height: 32px;
    margin-bottom: 4px;
    stroke: currentColor;
    stroke-width: 2;
}

/* The darkened background */
.modal-overlay {
    display: none;
    /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* Semi-transparent black */
    z-index: 1000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
    /* Optional: slight blur effect */
}

/* The modal box */
.modal-content {
    background-color: #fff;
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    animation: modalFadeIn 0.2s ease-out;
}

/* Centers labels and text within the modal form */
.modal-form-content-centered {
    text-align: center;
}

/* Vertical Button Stack (Create above Cancel) */
.modal-form-actions-centered {
    display: flex;
    flex-direction: column;
    /* Stacks items vertically */
    gap: 0.75rem;
    /* Space between buttons */
    margin-top: 1.5rem;
    width: 100%;
}

/* Ensure buttons are full width or centered properly */
.modal-form-actions-centered .btn-modal {
    width: 100%;
    justify-content: center;
}

.modal-form-actions-row {
    display: flex;
    flex-direction: row;
    /* Side-by-side */
    justify-content: center;
    gap: 1rem;
    /* Space between buttons */
    margin-top: 1.5rem;
    width: 100%;
}

.modal-form-actions-row .btn {
    flex: 1;
    /* Both buttons take equal width */
    max-width: 160px;
    /* Prevent them from getting too huge */
}

.btn-primary-modal {
    background-color: var(--color-blue);
    /* Adjust to your brand blue */
    color: var(--color-white);
}

.btn-secondary-modal {
    background-color: var(--color-gray-100);
    color: var(--color-gray-800);
}

.btn-danger-modal {
    background-color: var(--color-red);
    color: var(--color-white);
    border-color: var(--color-red);
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

/* Form styling matches your likely existing theme */
.modal-form-group {
    margin-bottom: 0.5rem;
}

.modal-form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.modal-form-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    box-sizing: border-box;
    /* Important for padding */
}

/* --- AVATAR MODAL SPECIFIC CLASSES --- */

#avatar-modal {
    max-width: 400px !important;
    width: 100%;
}

/* 1. The main container: Places Card (Left) and Buttons (Right) side-by-side */
.avatar-modal-form-layout {
    display: flex;
    flex-direction: row;
    /* Horizontal layout */
    align-items: center;
    /* Centers buttons vertically against the card */
    justify-content: center;
    /* Centers the whole group in the modal */
    gap: var(--spacing-md);
    /* 2rem gap between card and buttons */
    width: 100%;
}

/* 2. Sizing the profile card specifically for this modal view */
/* We fix the width to prevent it from growing too large in this layout */
.avatar-modal-card-preview {
    width: 160px;
    /* Fixed width for a balanced look */
    flex-shrink: 0;
    /* Prevents squishing if space is tight */
    /* Inherits aspect-ratio 3/4 from your base .profile-card class */
}

.avatar-modal-card-preview:hover {
    transform: none;
    /* Stops it from moving up */
    box-shadow: none;
    /* Stops the shadow from appearing */
    cursor: default;
    /* Changes the hand icon back to a normal arrow */
}

/* 3. The Right Side: Buttons stacked vertically */
.avatar-modal-actions-side {
    display: flex;
    flex-direction: column;
    /* Stack buttons one below another */
    gap: 0.75rem;
    /* Consistent gap with your other buttons */
    flex-grow: 1;
    /* Takes up remaining space */
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .profile-grid {
        justify-content: center;
        gap: var(--spacing-sm);
    }

    .user-selection__title {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .profile-card {
        width: 45%;
        aspect-ratio: 3/4;
        height: auto;
    }
}



/* --- DASHBOARD LAYOUT --- */
.dashboard-layout {
    display: flex;
    gap: var(--spacing-lg);
    padding-top: var(--spacing-md);
    padding-bottom: var(--spacing-lg);
    align-items: flex-start;
    /* Prevents sidebar from stretching */
}

/* Sidebar Styles */
.sidebar {
    width: 120px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Main Content Styles */
.student-dashboard-main-content {
    flex-grow: 1;
    width: 100%;
}

.unit-page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-top: 0.5rem;
    margin-bottom: var(--spacing-md);
    color: var(--color-text-primary);
}

.unit-page-title span {
    font-weight: 500;
    color: var(--color-text-secondary);
}

/* --- TOPIC CARD --- */
.topic-card {
    background-color: var(--color-gray-200);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.topic-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.topic-title-wrapper {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.topic-title-wrapper h3 {
    font-size: 1.25rem;
    color: var(--color-text-primary);
    font-weight: 700;
    padding-left: var(--spacing-xs);
}

.topic-title-icon-wrapper {
    background-color: var(--color-white);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-xs);
    width: 110px;
    height: 40px;
    font-size: 1.25rem;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--item-color, --color-text-secondary);
}

.topic-title-icon-wrapper svg {
    width: 1.5rem;
    height: 1.5rem;
    margin-right: 0.25rem;
    margin-top: 0.25rem;
    color: var(--item-color, --color-text-primary);
}

.topic-description {
    color: var(--color-text-secondary);
    line-height: 1.2;
    margin-bottom: var(--spacing-md);
    max-width: 60%;
}

.topic-progress-wrapper {
    margin-left: auto;
    width: 40px;
    height: 40px;
}

/* Radial Progress CSS */
.progress-radial {
    width: 100%;
    height: 100%;
}

.progress-radial .circle-bg {
    fill: none;
    stroke: var(--color-gray-400);
    stroke-width: 2.5;
}

.progress-radial .circle {
    fill: none;
    stroke: #10B981;
    /* Green progress */
    stroke-width: 4;
    stroke-linecap: round;
}

.progress-radial .percentage {
    fill: var(--color-text-secondary);
    font-weight: 400;
    font-size: 0.75rem;
    font-style: italic;
    text-anchor: middle;
    /* transform: rotate(90deg) translate(0, 100%); Counter rotate text */
    dominant-baseline: middle;
    /* Center vertically */
}

.progress-radial-completed {
    width: 100%;
    height: 100%;
    color: #02CB60;
}

/* --- LESSON GRID --- */
.lesson-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

/* Base Lesson Card */
.lesson-card {
    border-radius: var(--border-radius-lg);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
    background-color: var(--color-gray-400);
}

.lesson-card h4 {
    margin-top: auto;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--color-text-primary);
}

.lesson-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 300;
    color: var(--color-text-secondary);
}

.lesson-header-title {
    display: flex;
    margin-bottom: 1rem;
}

.lesson-header-final-icon {
    width: 1rem;
    height: 1rem;
    margin-right: 0.25rem;
    color: var(--color-text-secondary);
}

.lesson-header-status-icon-wrapper {
    margin-left: auto;
    width: 30px;
    height: 30px;
}

.lesson-header-status-icon {
    color: var(--item-color, #02CB60);
    margin-top: 0.1rem;
    width: 100%;
    height: 100%;
}

.lesson-footer {
    margin-top: auto;
}

/* 1. COMPLETED CARD VARIANT */
.lesson-card--completed {
    background-color: #E6F9F0;
    /* Light mint green */
    border: 1px solid #D1E7DD;
}

.lesson-card--completed .status-icon {
    color: #10B981;
}

.lesson-card--completed h4 {
    color: #0A5C36;
}

.lesson-card-btn-completed {
    background-color: #00FFBF;
    font-weight: 600;
    color: #00804D;
    border: none;
}

.lesson-card-btn-completed:hover {
    opacity: 0.9;
}

/* 2. ACTIVE CARD VARIANT */
.lesson-card--active {
    background-color: var(--color-white);
    /* border: 2px solid var(--color-blue); */
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.15);
}

.lesson-card-btn-active {
    background-color: var(--color-blue);
    font-weight: 600;
    color: var(--color-white);
    border: none;
}

.lesson-card-btn-active:hover {
    opacity: 0.9;
}

/* 3. LOCKED CARD VARIANT */
.lesson-card--locked {
    background-color: var(--color-gray-400);
    border: 1px solid transparent;
    opacity: 0.5;
    color: var(--color-text-secondary);
}

.lesson-card--locked h4 {
    color: var(--color-gray-600);
}

.lesson-card--locked .status-icon {
    color: var(--color-gray-500);
}

.lesson-card-btn-locked {
    background-color: var(--color-gray-500);
    font-weight: 600;
    color: var(--color-gray-600);
    opacity: 0.7;
    border: none;
    cursor: not-allowed;
}

/* --- SIDEBAR SELECT (Native Dropdown) --- */

.sidebar-select-wrapper {
    position: relative;
    /* Establishes context for absolute positioning */
    width: 100%;
}

/* The Icon (Graduation Cap) */
.sidebar-select-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--color-text-secondary);
    /* Matches your gray text */
    pointer-events: none;
    /* Lets clicks pass through to the select */
    z-index: 2;
}

/* The Native Select Styling */
.sidebar-select {
    width: 100%;
    appearance: none;
    /* Removes default browser styling */
    -webkit-appearance: none;
    -moz-appearance: none;

    background-color: var(--color-white);
    border: 1px solid var(--color-gray-300);
    /* Matches existing border color */
    border-radius: var(--border-radius-sm);
    /* 6px */

    /* Padding: Top/Bottom 10px, Right 20px (for arrow), Left 35px (for icon) */
    padding: 10px 20px 10px 35px;

    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-primary);
    cursor: pointer;
    line-height: 1.5;

    /* Reusing the SVG Arrow from your existing .form-group select */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 16px 12px;

    transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-select:hover {
    border-color: var(--color-gray-400);
    background-color: var(--color-gray-100);
}

.sidebar-select:focus {
    outline: none;
    border-color: var(--color-blue);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Style for the placeholder text to look lighter until selected */
.sidebar-select:invalid {
    color: var(--color-text-secondary);
}

.unit-nav {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.unit-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.5rem;
    border-radius: var(--border-radius-sm);
    text-decoration: none;
    color: var(--item-color, --color-text-secondary);
    font-weight: 500;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    background-color: var(--color-white);
}

/* Completed Unit Style */
.unit-item--completed {
    background-color: #E6F4EA;
    /* Very light green */
    color: var(--item-color, #1E8E3E);
    border-color: transparent;
}

/* Active Unit Style */
.unit-item--active {
    border-left: 4px solid var(--item-color, --color-blue);
    /* Left accent bar */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

.unit-item:hover:not(.unit-item--active) {
    background-color: var(--color-gray-100);
}

.unit-icon {
    width: 1rem;
    height: 1rem;
    margin-right: var(--spacing-xs);
    color: var(--item-color, --color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.unit-icon-check {
    margin-left: auto;
    width: 1rem;
    height: 1rem;
    color: var(--item-color, #1E8E3E);
}


:root {
    --bg-color: #EAEAEA;
    --text-primary: #1A1A1A;
    --text-secondary: #666666;
    --lines-color: #E6E8EB;
    /* Faint blue-gray line */
    --accent-blue: #4285f4;
    --accent-green: #2ECC71;
    --accent-red: #FF6B6B;
    --accent-light-blue: #E8F0FE;
    --page-width: 500px;
    --page-height: 590px;

    --rect-width: 488px;
    --rect-height: 510px;

    --content-width: 420px;
    --content-height: 510px;

    /* TYPOGRAPHY (Figma) */
    --line-height: 30px;
    --font-size: 16px;

    --total-lines: 18;


}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.success-theme {
    --item-color: #2fb344;
    /* Green */
}

.error-theme {
    --item-color: #d63939;
    /* Red */
}

.blue-theme {
    --item-color: var(--color-link-blue);
    /* Blue */
}

.success-button-theme {
    --background-color: #2fb344;
    /* Green */
}

.error-button-theme {
    --background-color: #d63939;
    /* Red */
}

.locked-button-theme {
    --opacity: 0.6;
}

.prevent-button-events-theme {
    pointer-events: none
}

/* --- Main Workspace --- */
.workspace {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding-bottom: 2rem;
}

/* --- Book Container --- */
.book-container {
    position: relative;
    display: flex;
    gap: 8px;
    /* Slight gap between pages */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

/* --- Page Styling --- */
.page {
    width: var(--page-width);
    height: var(--page-height);
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);

    /* 1. Center the content-layer perfectly with equal padding */
    display: flex;
    align-items: center;
    justify-content: center;

    overflow: hidden;
}

.lines-layer {
    width: var(--rect-width);
    height: var(--rect-height);
    position: relative;

    /* Centering Layer 3 inside Layer 2 */
    display: flex;
    align-items: center;
    justify-content: center;

    /* DRAWING THE LINES */
    background-image:
        /* 1. The "18th Line": A single line at the very top (0px - 1px) */
        linear-gradient(var(--lines-color),
            var(--lines-color) 1px,
            transparent 1px),
        /* 2. The Standard Grid: Lines at the bottom of every 30px row (Lines 1-17) */
        repeating-linear-gradient(transparent,
            transparent calc(var(--line-height) - 1px),
            var(--lines-color) calc(var(--line-height) - 1px),
            var(--lines-color) var(--line-height));

    /* CRITICAL ALIGNMENT FIX:
       Height Diff = 510px - 480px = 30px total.
       Top Gap = 15px.
       We shift the background lines down by 15px so they align 
       perfectly with the text block starting 15px down. 
    */
}

/* Content Layer 
   Ensures text snaps to the lines defined by the background gradient.
*/
.content-layer {
    width: var(--content-width);
    height: var(--content-height);

    /* Figma Typography */
    font-family: 'Inter', sans-serif;
    font-style: normal;
    font-weight: 400;
    font-size: var(--font-size);
    line-height: var(--line-height);
    letter-spacing: -0.03em;
    color: var(--text-color-figma);

    /* Text Flow Control */
    /* Ensure the first line of text doesn't sit on the very top edge */
    /* padding-top: var(--line-height);  */

    /* Debug helper: Uncomment to see the bounding box */
    /* border: 1px dashed red; */
}

/* --- Markdown Grid Alignment --- */
.content-layer h1,
.content-layer h2,
.content-layer h3,
.content-layer p,
.content-layer ul,
.content-layer ol,
.content-layer li,
.content-layer blockquote {
    /* 1. Reset everything to the Grid */
    margin: 0;
    padding: 0;
    font-size: var(--font-size);
    /* 16px */
    line-height: var(--line-height);
    /* 30px */
}

/* Paragraphs: Add a 1-line gap after paragraphs? 
   Or 0 to keep them tight? Let's use 0 for a notepad feel, 
   or margin-bottom: var(--line-height) for a gap. */
.content-layer p {
    margin-bottom: 0;
}

/* Headings: Make them bold but keep them on the grid */
.content-layer h1,
.content-layer h2 {
    font-weight: 700;
    font-size: calc(var(--font-size) * 1.2);
    /* Optional: If you want headers to be bigger, they MUST be multiples of 30px */
    /* line-height: 60px; */
    /* margin-bottom: 30px; */
}

.content-layer h3 {
    font-weight: 700;
    font-size: calc(var(--font-size) * 1.1);
}

/* Lists: Ensure bullets align */
.content-layer ul,
.content-layer ol {
    padding-left: 20px;
    /* Indentation */
}

.content-layer hr {
    vertical-align: middle;
    display: inline-block;
    width: 100%;
}

/* Target tables specifically inside your content/preview area */
.content-layer table {
    width: 100%;
    /* Forces the table to respect the width, not the content */
    table-layout: fixed;
    border-collapse: collapse; /* Merges double borders into single lines */
    line-height: calc(var(--line-height) - 1.25px);
    
}

/* Style both Headers (th) and Cells (td) */
.content-layer th,
.content-layer td {
    border: 1px solid #ddd;    /* Adds the light gray border */
    padding: 0px 6px;         /* Adds breathing room */
    text-align: left;          /* FIXES THE INDENTATION: Forces headers to align left */

    white-space: normal;
    word-wrap: break-word;
}

/* Optional: Make the header background slightly distinct */
.content-layer th {
    background-color: #f8f9fa; 
    font-weight: 600;
}

.content-layer td {
    background-color: white;
}

.measurement-box {
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    font-family: 'Inter', sans-serif !important;
}

/* Math Display Blocks ($$ ... $$) */
.katex-display {
    /* margin: var(--line-height) 0 !important; Force top/bottom margin to be 1 line */
    /* overflow-x: auto; */
    /* overflow-y: hidden; */
    height: calc(var(--line-height) * 2);
    
    line-height: var(--line-height);
    font-size: var(--font-size);
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    margin: 0 !important;

    background-color: #D7F3FC;
    border-radius: 6px;
    border: 1px solid #BBEEFD;
}

/* Hide the br tag after the katex-display */
p > span:has(.katex-display) + br {
    display: none;
}

/* Question Block Styles */
.question-block {
    width: 100%;
    box-sizing: border-box;
    /* Critical for measurement */
    display: flow-root;
    margin-bottom: var(--line-height);
}

.question-block h2 {
    font-size: calc(var(--font-size) * 1.1);
    font-weight: 700;
    text-decoration: underline;
}

/* Hide the br tag after the question-block */
.question-block + br {
    display: none;
}

.question-text {
    /* margin-bottom: 16px; */
    font-size: var(--font-size);
    line-height: var(--line-height);
}

.question-text p {
    display: inline;
}

/* Choice Buttons */
.question-choices {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    column-gap: calc(var(--line-height) / 3);
    /* flex-direction: column; */

}

.choice-btn {
    /* 1. FLEX GROW: 1 -> Always expand to fill empty space (e.g. if alone on a row) */
    /* 2. FLEX SHRINK: 0 -> Don't shrink below content size */
    /* 3. FLEX BASIS: calc(50% - 12px) -> Attempt to start at 50% width (minus gap) */
    flex: 1 0 calc(50% - 12px);

    /* The Magic: Check content width */
    /* If the text is short, the button stays at 50% (basis). */
    /* If the text is long, 'fit-content' overrides the 50% basis, forcing the button 
       to be wider. Since it exceeds 50%, Flexbox forces it to a new row. */
    min-width: fit-content;

    /* Safety: Never exceed the container width */
    max-width: 100%;

    text-align: center;
    opacity: var(--opacity, 1);
    background: var(--background-color, #468BBD);
    color: white;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 10px;
    margin-top: calc(var(--line-height) / 3);
    margin-bottom: calc(var(--line-height) / 3);
    height: calc(var(--line-height) / 3 * 4);
    font-size: var(--font-size);
    cursor: pointer;
    transition: background 0.2s;
}

.choice-btn:hover {
    opacity: 0.9;
}

/* OVERRIDE FOR ODD COUNTS (3, 5, 7...) */
/* We force the basis to 100%, effectively creating a single column */
.question-choices.question-choices-layout-stack .choice-btn {
    flex-basis: 100%;
}

/* Input Field */
.question-input-wrapper {
    margin-top: calc(var(--line-height) / 3);
    margin-bottom: calc(var(--line-height) / 3);
    width: 100%;
    column-gap: calc(var(--line-height) / 3);
    display: flex;
}

.question-input {
    flex: 1;
    /* width: 100%; */
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    box-sizing: border-box;
    font-size: var(--font-size);
}

.question-submit-btn {
    padding: 0 20px;
    /* Horizontal padding */
    background-color: var(--color-blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: var(--font-size);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    /* Prevents text from wrapping */
    transition: all 0.3s ease;
}

.question-submit-btn:hover {
    background-color: #1c7ed6;
}

.question-submit-btn:disabled {
    /* A flat, neutral gray background */
    background-color: var(--color-gray-200);
    color: var(--color-gray-500);
    border: 1px solid transparent; /* Keeps sizing consistent */
    
    /* Low opacity makes it recede into the background */
    opacity: 0.6;
    
    cursor: not-allowed;
    
    /* Optional: A grayscale filter ensures NO color leaks through */
    filter: grayscale(100%);
}

.question-feedback {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size);
    /* visibility: hidden; */
}

.question-feedback div {
    display: flex;
    align-items: center;
    column-gap: 5px;
    color: var(--item-color, --color-text-primary);
}

.steps-to-solve-tooltip-style {
    position: fixed;
    /* FIXED is key: it ignores parent overflow */
    z-index: 9999;
    /* Sits on top of everything */

    background-color: white;
    width: auto;
    padding: 20px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border: 1px solid #eaeaea;

    /* Animation settings */
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    /* Lets mouse pass through so it doesn't flicker */

    /* Text Styles */
    text-align: left;
    color: #1a1a1a;
    font-size: 14px;
    line-height: 1.5;

    /* pointer-events: none; - if users should be able to click through the tooltip */
}

/* List Styling inside the tooltip */
.steps-to-solve-tooltip-style ul {
    margin: 0;
    padding-left: 20px;
    list-style-type: disc;
}

/* Fix headers to match the new 30px grid */
h3,
.question-title {
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    font-size: 16px;
    margin: 0;
    line-height: var(--line-height);
    /* 30px */
}

.page-buttons-bar {
    left: -3%;
    right: -3%;
    bottom: 1%;
    padding-left: 0%;
    padding-right: 0%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: absolute;
    z-index: 100;
    user-select: none;
    -webkit-user-select: none;
}

.page-button {
    display: flex;
    column-gap: 5px;
    width: auto;
}

.page-button-finish-quiz {
    display: flex;
    align-items: center;
    column-gap: 10px;
}

.page-button-finish-quiz span {
    color: var(--color-gray-500)
}

math-field {
    /* 1. Layout & Sizing */
    flex: 1;
    min-width: 0;
    height: 40px;
    padding-left: 6px;
    line-height: 1.5em;
    border: 1px solid #ced4da;
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 16px;
    outline: none;

    /* 2. Colors (Your working colors) */
    --caret-color: #0066cc;
    /* Blue cursor */
    --selection-background-color: #e6f2ff;
    /* Very light blue highlight */
    --inactive-selection-background-color: #e6f2ff;
    --contains-highlight-background-color: #e6f2ff;
    --selection-color: black;
    /* Keep text readable */
    --text-highlight-background-color: transparent;
}

math-field:focus-within {
    border-color: #0066cc;
    box-shadow: 0 0 0 1px #0066cc;
    /* Optional: adds a slight thickness */
    outline: none;
}

/* 3. Hide The Menu (Hamburger) */
math-field::part(menu-toggle) {
    display: none;
}

/* 4. Hide The Virtual Keyboard Toggle */
math-field::part(virtual-keyboard-toggle) {
    display: none;
}

/* 5. Force Scrolling (Stop dynamic resizing) */
math-field::part(content) {
    overflow-x: auto;
}

/* Success State */
math-field.correct {
    border-color: #2fb344;
    color: #2fb344;
    background-color: #f0fdf4;
    /* Light green background */
    --caret-color: #2fb344;
}

/* Error State */
math-field.incorrect {
    border-color: #d63939;
    color: #d63939;
    background-color: #fff5f5;
    /* Light red background */
    --caret-color: #d63939;
}

.btn {
    padding: 0 16px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid transparent;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.review-quiz-modal-content {
    border-radius: 16px;
    padding: var(--spacing-lg);
    width: 90%;
    line-height: 1.75rem;
    max-width: 30%;
    background-color: #fff;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    animation: modalFadeIn 0.2s ease-out;
}

.review-quiz-modal-content ul,
.review-quiz-modal-content ol {
    padding-left: 20px;
}

.review-quiz-modal-content li {
    margin-bottom: 4px;
}

.review-quiz-modal-content li {
    margin-bottom: 4px;
}

.review-quiz-modal-content h1 {
    margin-bottom: var(--spacing-sm);
}

.review-quiz-modal-content .question-summary {
    max-height: var(--page-height);
    overflow-y: auto;
    scroll-behavior: smooth;
}

.review-quiz-modal-content .question-summary-item {
    line-height: 1.2;
    margin-bottom: 8px;
}

.review-quiz-modal-content span {
    padding: 5px;
    font-size: var(--font-size);
    font-weight: 600;
}

.review-quiz-modal-content .success-theme {
    background-color: #E6F9F0;
    color: #1E8E3E;
    margin-bottom: 5px;
}

.review-quiz-modal-content .error-theme {
    background-color: #FFE6E6;
    color: #D63939;
    margin-bottom: 5px;
}

.review-quiz-modal-content .feedback-message {
    line-height: 1;
    margin-bottom: 8px;
}

.lesson-title-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    column-gap: 10px;
    position: relative;
    margin-top: -35px;
}

.lesson-title-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    column-gap: 3px;
    padding: 6px;
    color: #d63939;
    border: none;
    border-radius: 8px;
    background-color: white;
}

.lesson-title-btn:hover {
    opacity: 0.8;
}

input, 
button, 
textarea, 
select {
    font-family: inherit;
}


/* The main scrollable container */
.preview-list-container {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Space between items */
    
    /* SCROLLING LOGIC */
    height: 100%;       /* Fill parent height */
    max-height: 80vh;   /* Or fixed px. Prevents infinite growth */
    overflow-y: auto;   /* Scroll if too tall */
    
    padding: 20px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
}

/* Individual Item Wrapper */
.preview-item {
    background: white;
    padding: 20px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);

    /* ISOLATION MAGIC: */
    /* flow-root creates a new Block Formatting Context */
    /* This stops floats/margins from leaking out or in */
    display: flow-root; 
    width: 100%;
}

/* AVATAR STYLES */

.avatar {
    width: 600px;
    height: 600px;
    background-size: contain; /* Ensures image fits nicely */
    background-repeat: no-repeat;
    background-position: center;
    margin-top: -200px;
    /* background-size: cover; */
    /* transition: background-image 0.1s ease-out; */
     /* Smooths the transition */
}

.mouth-closed { background-image: url('/static/avatar/mouth-closed.png'); }
.mouth-open   { background-image: url('/static/avatar/mouth-open.png'); }
.mouth-semi   { background-image: url('/static/avatar/mouth-semi.png'); }

.is-speaking {
    animation: talking-bounce 0.2s infinite;
}

.text-area {
    margin-top: -100px;
    width: 600px;
    height: 200px;
    padding: 8px;
    outline: none;
    resize: none;
}