/* --- SGenius CSS Overhaul: Apple x Duolingo Aesthetic --- */

/* --- 1. Root Variables & Global Setup --- */
:root {
    /* Color Palette */
    --c-bg: #f9f5ffff;              /* Magnolia - Main light background */
    --c-bg-alt: #ffffff;            /* White - For cards and elevated surfaces */
    --c-text: #28262cff;             /* Raisin Black - Main text color */
    --c-text-subtle: #998fc7ff;      /* Tropical Indigo - Meta text, subtitles */
    --c-primary: #14248aff;          /* Resolution Blue - Main call-to-action */
    --c-primary-light: #d4c2fcff;    /* Periwinkle - Hover states, light accents */
    --c-border: #e8e1f5;            /* A subtle border derived from the palette */

    /* UI States */
    --c-success: #28a745;
    --c-error: #dc3545;
    --c-warning: #ffc107;

    /* Typography */
    --font-family-sans: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --font-size-base: 16px;
    --line-height-base: 1.7;

    /* Sizing & Spacing */
    --spacing-unit: 1rem; /* 16px */
    --container-width: 1140px;
    --radius-sm: 0.5rem;  /* 8px */
    --radius-md: 0.75rem; /* 12px */
    --radius-lg: 1rem;    /* 16px */
    --radius-full: 9999px;/* Pill shape */

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -4px rgba(0, 0, 0, 0.07);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-family-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--c-text);
    background-color: var(--c-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- 2. Typography & Base Elements --- */
h1, h2, h3, h4 {
    margin: 0 0 0.75em 0;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}
h1 { font-size: 3.5rem; }
h2 { font-size: 2.5rem; }
h3 { font-size: 1.5rem; }
p { margin: 0 0 1em 0; }
a { color: var(--c-primary); text-decoration: none; transition: var(--transition); }
a:hover { opacity: 0.8; }
.logo { font-size: 1.75rem; font-weight: 700; color: var(--c-text); }
.logo .accent { color: var(--c-primary); }

/* --- 3. Layout & Container --- */
.container {
    width: 100%;
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 var(--spacing-unit);
}

/* --- 4. Core Components --- */
.btn, .cta-button, .nav-button {
    display: inline-block;
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    border: none;
    padding: 0.8em 1.75em;
    border-radius: var(--radius-full);
    transition: var(--transition);
    background: var(--c-primary);
    color: white;
}
.btn:hover, .cta-button:hover, .nav-button:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    background: #293ddc; /* Slightly brighter blue on hover */
}
.btn-secondary { background-color: var(--c-text-subtle); }
.btn-secondary:hover { background-color: #8a81b9; }

/* Form Inputs */
input, select, textarea {
    display: block;
    width: 100%;
    padding: 0.9rem 1rem;
    font-size: 1rem;
    font-family: var(--font-family-sans);
    color: var(--c-text);
    background-color: var(--c-bg-alt);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(20, 36, 138, 0.15);
}
.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--c-text);
}

/* --- 5. Landing Page --- */
#landing-page-container {
    background: linear-gradient(180deg, #ffffff 0%, var(--c-bg) 100%);
}
.landing-header {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: fixed;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    z-index: 100;
    border: 1px solid rgba(232, 225, 245, 0.7);
    border-radius: var(--radius-full);
}
.landing-header nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

#hero {
    padding: 180px 0 120px 0;
    text-align: center;
}
.hero-text h1 {
    margin-bottom: 0.5em;
    font-size: clamp(2.5rem, 5vw, 4rem); /* Responsive font size */
}
.hero-text p.sub-text {
    font-size: 1.25rem;
    color: var(--c-text-subtle);
    max-width: 600px;
    margin: 0 auto 2rem auto;
}

#features {
    padding: 80px 0;
    background: var(--c-bg);
}
#features h2 {
    text-align: center;
    margin-bottom: 4rem;
}
.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}
.feature-card {
    background: var(--c-bg-alt);
    padding: 2rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--c-border);
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}
.feature-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}
.feature-card h3 {
    font-size: 1.25rem;
    color: var(--c-primary);
}
.feature-card p {
    color: var(--c-text-subtle);
    font-size: 0.95rem;
}

/* --- 6. Auth & App Shell --- */
.page {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
#login-page, #personalization-modal {
    background-color: var(--c-bg);
    z-index: 200;
}
.auth-container {
    background: var(--c-bg-alt);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    text-align: center;
}
form.auth-form { margin-top: 2rem; }

/* --- 7. Main Application UI --- */
#main-app {
    background-color: var(--c-bg);
}
.dashboard-container {
    width: 100vw; height: 100vh;
    display: flex;
    flex-direction: column;
}
#main-app header {
    background: var(--c-bg-alt);
    border-bottom: 1px solid var(--c-border);
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-shrink: 0;
}
#main-app header nav { display: flex; align-items: center; gap: 1rem; }
#main-app header nav a {
    text-decoration: none;
    color: var(--c-text);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
}
#main-app header nav a:hover {
    background-color: var(--c-bg);
}
#main-app header nav a.active {
    background-color: var(--c-primary);
    color: white;
}
.user-info { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
#logout-btn {
    background: transparent;
    color: var(--c-text);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
}
#logout-btn:hover {
    background: var(--c-error);
    color: white;
    transform: none;
    box-shadow: none;
}

#main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem;
    display: grid;
    gap: 2rem;
}
.main-grid-one-col { grid-template-columns: 1fr; }
.main-grid-two-col { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }

.widget, .content-box {
    background: var(--c-bg-alt);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    border: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
}

/* --- 8. Dashboard & General Components --- */

/* AI Chat Widget */
.ai-assistant { display: flex; flex-direction: column; height: calc(100vh - 150px); }
.chat-window {
    flex-grow: 1;
    background-color: var(--c-bg);
    border-radius: var(--radius-md);
    padding: 1rem;
    overflow-y: auto;
    border: 1px solid var(--c-border);
}
.chat-message {
    padding: 0.75rem 1.25rem;
    border-radius: 1.25rem;
    margin-bottom: 1rem;
    max-width: 80%;
    line-height: 1.5;
}
.chat-message.user {
    background-color: var(--c-primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: var(--radius-sm);
}
.chat-message.ai {
    background-color: #e8e1f5;
    color: var(--c-text);
    margin-right: auto;
    border-bottom-left-radius: var(--radius-sm);
}
.chat-input-area {
    display: flex; gap: 0.75rem; margin-top: 1rem; flex-shrink: 0;
}
#ask-ai-btn { border-radius: var(--radius-md); }

/* Timer & Streak Widgets (Duolingo Style) */
.timer-display {
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 700;
    text-align: center;
    color: var(--c-text);
    font-family: monospace;
    margin: 1rem 0;
}
.timer-controls { display: flex; gap: 1rem; justify-content: center; }
.streak-widget {
    margin-top: 2rem;
    padding: 1.5rem;
    text-align: center;
    background: linear-gradient(135deg, var(--c-text-subtle), var(--c-primary-light));
    border-radius: var(--radius-lg);
    color: white;
}
.streak-widget .emoji { font-size: 2.5rem; }
.streak-widget h3 { color: white; }
.streak-widget p { font-size: 2.5rem; color: white; text-shadow: 1px 1px 2px rgba(0,0,0,0.1); margin: 0; }
.streak-widget .meta { opacity: 0.8; }


/* --- 9. AI Quiz & Review --- */
.quiz-form, .quiz-display-container { max-width: 700px; margin: auto; }
.question-block {
    background: transparent; border: none; padding: 0;
}
.question-text {
    font-size: 1.5rem; font-weight: 600; text-align: center; margin-bottom: 2rem;
}
.options-list {
    list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.75rem;
}
.options-list label {
    display: block;
    padding: 1rem;
    border: 2px solid var(--c-border);
    background: var(--c-bg-alt);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}
.options-list label:hover {
    transform: translateY(-2px);
    border-color: var(--c-primary-light);
}
.options-list input:checked + span { font-weight: 700; }
.options-list input { display: none; }
.quiz-results .options-list label.correct-answer {
    border-color: var(--c-success);
    background-color: #f0fff4;
}
.quiz-results .options-list label.incorrect-answer {
    border-color: var(--c-error);
    background-color: #fff5f5;
}
.explanation-box {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background-color: var(--c-bg);
    border-radius: var(--radius-md);
}

/* --- 10. Profile Page --- */
.profile-container {
    max-width: 700px;
    margin: auto;
}
.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 2rem;
}
.profile-avatar {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--c-primary-light), var(--c-text-subtle));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 1rem;
    box-shadow: 0 0 0 4px var(--c-bg-alt), 0 0 0 6px var(--c-primary-light);
}
.profile-header h2 {
    font-size: 2rem;
    margin: 0;
}
.profile-header p {
    color: var(--c-text-subtle);
    margin: 0;
}
.profile-details ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.profile-details li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--c-border);
}
.profile-details li:last-child {
    border-bottom: none;
}
.profile-details .detail-label {
    font-weight: 500;
    color: var(--c-text-subtle);
}
.profile-details .detail-value {
    font-weight: 600;
    color: var(--c-text);
}
.role-display {
    text-transform: capitalize;
    font-weight: 600;
    padding: 0.25em 0.75em;
    border-radius: var(--radius-full);
}
.role-display.student {
    background-color: #e6f7ff;
    color: #006dff;
}
.role-display.teacher {
    background-color: #e6fff0;
    color: #007b55;
}


/* --- 11. Logbook Page --- */
.logbook-list {
    list-style: none;
    padding: 0;
    margin: 0;
    position: relative;
}
/* Optional timeline-style line */
.logbook-list::before {
    content: '';
    position: absolute;
    top: 1.5rem;
    bottom: 1.5rem;
    left: 1.5rem;
    width: 2px;
    background-color: var(--c-border);
    border-radius: 2px;
}
.logbook-item {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    padding: 1rem 0;
}
.logbook-item:not(:last-child) {
    border-bottom: 1px solid var(--c-border);
}
.logbook-icon {
    flex-shrink: 0;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--c-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    border: 1px solid var(--c-border);
    /* For alignment with the timeline */
    position: relative;
    z-index: 1;
}
.logbook-details {
    flex-grow: 1;
}
.logbook-details strong {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--c-text);
}
.logbook-details .meta {
    font-size: 0.9rem;
    color: var(--c-text-subtle);
}
.logbook-duration {
    flex-shrink: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--c-primary);
    align-self: center;
}
.logbook-empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--c-text-subtle);
}

/* --- 12. Leaderboard Page --- */
.leaderboard-tabs {
    display: flex;
    justify-content: center;
    background-color: var(--c-bg);
    border-radius: var(--radius-full);
    padding: 0.5rem;
    margin-bottom: 2rem;
}
.leaderboard-tabs button {
    flex: 1;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    color: var(--c-text-subtle);
    cursor: pointer;
    transition: var(--transition);
}
.leaderboard-tabs button.active {
    background: var(--c-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.rank-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.rank-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background-color: var(--c-bg-alt);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}
.rank-item:hover {
    transform: scale(1.02);
    border-color: var(--c-primary-light);
}
.rank-item.current-user {
    border-color: var(--c-primary);
    background-color: #f7f5ff; /* A lighter version of Magnolia */
    box-shadow: 0 0 0 2px var(--c-primary);
}
.rank-position {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--c-text-subtle);
    width: 40px;
    text-align: center;
}
.rank-item[data-rank="1"] .rank-position,
.rank-item[data-rank="2"] .rank-position,
.rank-item[data-rank="3"] .rank-position {
    font-size: 2rem; /* Make emoji bigger */
}
.rank-user {
    flex-grow: 1;
    font-weight: 600;
}
.rank-score {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--c-primary);
}


/* --- 13. Classrooms & Assignments --- */
.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Classroom List Grid */
.classroom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}
.classroom-card {
    background-color: var(--c-bg-alt);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: var(--c-text);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.classroom-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}
.classroom-card-banner {
    height: 80px;
    background: linear-gradient(135deg, var(--c-primary-light), var(--c-text-subtle));
}
.classroom-card-content {
    padding: 1rem 1.5rem 1.5rem 1.5rem;
    flex-grow: 1;
}
.classroom-card-content h3 {
    margin: 0 0 0.25rem 0;
    font-size: 1.25rem;
}
.classroom-card-content .meta {
    color: var(--c-text-subtle);
    font-size: 0.9rem;
}

/* Classroom Detail & Assignment List */
.back-link {
    display: inline-block;
    color: var(--c-text-subtle);
    text-decoration: none;
    margin-bottom: 1.5rem;
    font-weight: 500;
}
.back-link:hover { color: var(--c-primary); }
.join-code {
    background: var(--c-bg);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
}
.join-code span {
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--c-primary);
}
.item-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.list-item {
    background-color: var(--c-bg-alt);
    padding: 1rem 1.25rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}
.list-item:hover {
    border-color: var(--c-primary-light);
    background-color: #fcfcff;
}
.assignment-item {
    padding: 1rem 1.25rem;
}
.assignment-item a { text-decoration: none; }

/* Assignment Detail & Submission */
.assignment-worksheet {
    width: 100%;
    border-radius: var(--radius-lg);
    border: 1px solid var(--c-border);
    margin: 1rem 0 2rem 0;
}
.submission-card {
    background: var(--c-bg);
    padding: 1.5rem;
    border-radius: var(--radius-lg);
}
.status-badge {
    display: inline-block;
    padding: 0.25em 0.75em;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.status-graded { background-color: #e6fff0; color: #007b55; }
.status-submitted { background-color: #fffbe6; color: #d46b08; }
.status-viewed { background-color: #f0f0f0; color: #595959; }

/* Grading Form for Teachers */
.submissions-list > .list-item {
    flex-direction: column;
    align-items: stretch;
}
.submission-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}
.submission-details {
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid var(--c-border);
}
.submission-image {
    max-width: 250px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}
.submission-image:hover { transform: scale(1.5); z-index: 10; }
.grading-form {
    margin-top: 1rem;
    display: flex;
    gap: 0.75rem;
}
.grading-form input { flex-grow: 1; }
.grading-form button { flex-shrink: 0; }

/* --- Missing Modal Styles --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000; /* Ensure it's on top of everything */
}

.modal-content {
    background: var(--c-bg-alt);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 500px; /* Or any width you prefer */
}

.modal-actions {
    margin-top: 1.5rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}


/* --- 14. Mobile Responsiveness --- */
@media (max-width: 992px) {
    .main-grid-two-col { grid-template-columns: 1fr; }
    #main-app header {
        padding: 0.75rem 1rem;
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    h1 { font-size: 2.5rem; }
    .landing-header { top: 0; left: 0; right: 0; border-radius: 0; }
    #hero { padding-top: 120px; padding-bottom: 60px; }
    .features-grid { grid-template-columns: 1fr; }
    #main-content { padding: 1rem; gap: 1rem; }
    /* Hide text on nav links, show only icons (would require icons in HTML) */
    #main-app header nav a {
        font-size: 0; /* Hides text */
        width: 44px; /* Example size */
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .user-info #user-display-name { display: none; }
}

@media (max-width: 576px) {
    body { font-size: 15px; }
    .hero-text h1 { font-size: 2rem; }
    .hero-text p.sub-text { font-size: 1rem; }
    .auth-container {
        height: 100%;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}