:root {
    /* GitHub Primer Light */
    --primary-main: #0969da;
    --primary-light: #54aeff;
    --primary-dark: #0550ae;

    --secondary-main: #24292f;
    --secondary-light: #57606a;

    /* Backgrounds */
    --primary-bg: #f6f8fa;
    --sidebar-bg: #ffffff;

    /* Text */
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-light: #8c959f;

    /* Neutrals */
    --white: #ffffff;
    --gray-100: #f6f8fa;
    --gray-200: #eaeef2;
    --gray-300: #d0d7de;

    /* Functional */
    --success: #1a7f37;
    --warning: #bf8700;
    --error: #cf222e;

    /* Cards */
    --glass-bg: #ffffff;
    --glass-border: 1px solid #d0d7de;
    --glass-shadow: 0 1px 3px rgba(31, 35, 40, 0.1);

    /* Spacing */
    --radius-sm: 6px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --header-height: 60px;

    /* Transitions */
    --transition-fast: 0.1s ease;
    --transition-smooth: 0.2s ease;
}

/* GitHub Dark Mode */
[data-theme="dark"] {
    --primary-main: #58a6ff;
    --primary-light: #388bfd;
    --primary-dark: #1f6feb;

    --secondary-main: #c9d1d9;
    --secondary-light: #8b949e;

    --primary-bg: #0d1117;
    --sidebar-bg: #161b22;

    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-light: #484f58;

    --white: #161b22;
    --gray-100: #21262d;
    --gray-200: #30363d;
    --gray-300: #484f58;

    --success: #3fb950;
    --warning: #d29922;
    --error: #f85149;

    --glass-bg: #161b22;
    --glass-border: 1px solid #30363d;
    --glass-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .btn-primary {
    background: #238636;
    color: #ffffff;
    border-color: rgba(240, 246, 252, 0.1);
}

[data-theme="dark"] .btn-primary:hover {
    background: #2ea043;
}

[data-theme="dark"] .btn-secondary {
    background: #21262d;
    color: #c9d1d9;
    border-color: rgba(240, 246, 252, 0.1);
}

[data-theme="dark"] .btn-secondary:hover {
    background: #30363d;
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: #0d1117;
    color: var(--text-primary);
    border-color: #30363d;
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--text-light);
}

[data-theme="dark"] .glass-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .sidebar {
    background: var(--glass-bg) !important;
    border: var(--glass-border) !important;
    box-shadow: var(--glass-shadow);
}

[data-theme="dark"] .tab-btn.active {
    background: var(--gray-200);
    color: var(--primary-main);
}

[data-theme="dark"] tr:hover td {
    background: #21262d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, 'Prompt', sans-serif;
    -webkit-font-smoothing: antialiased;
}

html {
    overflow-x: hidden; /* iOS Safari: must also set on html to prevent horizontal scroll */
}

body {
    background-color: var(--primary-bg);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Subtle watermark */
body::before {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vw;
    height: 60vh;
    background-image: url('assets/logo.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.02;
    z-index: 0;
    pointer-events: none;
}

[data-theme="dark"] body::before {
    opacity: 0.01;
    filter: invert(1) brightness(0.6);
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.5rem;
}

h3 {
    font-size: 1.25rem;
}

/* Layout */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
}

.main-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
}

/* Card */
.glass-card {
    background: var(--white);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-300);
    box-shadow: var(--glass-shadow);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 16px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-300);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition-fast);
    gap: 6px;
    line-height: 20px;
    white-space: nowrap;
    background: var(--gray-100);
    color: var(--text-primary);
    text-decoration: none;
}

.btn:hover {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.btn-primary {
    background: var(--primary-main);
    color: #ffffff;
    border-color: rgba(27, 31, 36, 0.15);
    padding: 5px 16px;
    height: 32px;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--text-primary);
    border-color: var(--gray-300);
}

.btn-secondary:hover {
    background: var(--gray-200);
}

.btn-block {
    width: 100%;
    height: auto;
    padding: 10px 16px;
    font-size: 0.95rem;
}

/* Tabs - GitHub style (underline tabs) */
.tab-container {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--gray-300);
    padding: 0;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--text-primary);
    border-bottom-color: #fd8c73;
    font-weight: 600;
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    background: var(--gray-100);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 5px 12px;
    height: 32px;
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition-fast);
    line-height: 20px;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-main);
    box-shadow: 0 0 0 3px rgba(9, 105, 218, 0.3);
}

/* Logo */
.logo-icon {
    height: 28px;
    width: auto;
    object-fit: contain;
}

.logo-large {
    height: 80px;
    width: auto;
    object-fit: contain;
    margin-bottom: 16px;
}

/* Exercise/header banner */
.header-bg {
    background: var(--primary-main);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
    color: white;
    margin-bottom: 20px;
    border: 1px solid rgba(27, 31, 36, 0.15);
}

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

/* Quiz Options */
.quiz-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    background: var(--white);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

[data-theme="dark"] .quiz-option {
    background: var(--glass-bg);
    border-color: var(--gray-200);
}

.quiz-option:hover {
    background: var(--gray-100);
    border-color: var(--primary-light);
}

.quiz-option input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary-main);
    flex-shrink: 0;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    background: var(--gray-100);
    color: var(--text-primary);
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid var(--gray-300);
    border-top: 1px solid var(--gray-300);
}

th:first-child {
    border-left: 1px solid var(--gray-300);
    border-radius: var(--radius-sm) 0 0 0;
}

th:last-child {
    border-right: 1px solid var(--gray-300);
    border-radius: 0 var(--radius-sm) 0 0;
}

td {
    padding: 10px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    color: var(--text-primary);
    vertical-align: middle;
}

td:first-child {
    border-left: 1px solid var(--gray-300);
}

td:last-child {
    border-right: 1px solid var(--gray-300);
}

tr:last-child td:first-child {
    border-radius: 0 0 0 var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
}

tr:last-child td:last-child {
    border-radius: 0 0 var(--radius-sm) 0;
}

tr:hover td {
    background: var(--gray-100);
}

/* Login card */
.login-card {
    max-width: 480px;
    width: 100%;
    margin: 0 auto;
    padding: 40px;
}

/* Specific Layouts */
.lesson-grid {
    display: grid;
    grid-template-columns: 3.5fr 1fr;
    gap: 24px;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

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

.animate-enter {
    animation: fadeInUp 0.3s ease forwards;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

.text-navy {
    color: var(--secondary-main);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--gray-300);
    transition: .3s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: var(--white);
    transition: .3s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--primary-main);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* Dashboard specific styling */
.navbar {
    background: var(--glass-bg);
    padding: 15px 30px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.nav-icon {
    width: 40px;
    height: 40px;
    background: var(--gray-200);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-main);
}

.nav-titles .nav-title {
    font-size: 1.2rem;
    margin: 0;
    color: var(--text-primary);
    font-weight: 700;
    font-family: inherit;
}

.nav-titles .nav-subtitle {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-user-info {
    text-align: right;
}

.nav-user-info .nav-user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.nav-user-info .nav-user-class {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.logout-btn {
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dashboard-container {
    margin-top: 30px;
    max-width: 1200px;
    padding: 0 20px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 30px;
}

.right-content {
    padding: 40px;
    background: var(--white);
    min-height: 600px;
    display: flex;
    flex-direction: column;
}

.exercise-header-bg {
    padding: 30px;
}

.exercise-header-title {
    font-size: 1.8rem;
    margin: 0 0 10px;
    font-weight: 700;
    color: white;
}

.score-summary-number {
    font-size: 3rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .container {
        max-width: 100%;
    }

    h1 {
        font-size: 1.6rem;
    }

    .lesson-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 20px 15px;
        align-items: flex-start;
    }

    .login-card {
        padding: 24px 20px;
        max-width: 100%;
    }

    h1 {
        font-size: 1.4rem;
    }

    div[style*="display: grid"],
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    div[style*="justify-content: space-between"] {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .navbar {
        padding: 12px 15px;
    }

    .nav-user-info {
        display: none;
    }

    .nav-left {
        gap: 10px;
    }

    .dashboard-container {
        margin-top: 15px !important;
        padding: 0 10px !important;
    }

    .right-content {
        padding: 15px;
        min-height: auto;
    }

    .exercise-header-bg {
        padding: 15px 20px;
    }

    .exercise-header-title {
        font-size: 1.3rem;
    }

    .score-summary-number {
        font-size: 2rem;
    }

    .exercise-grid {
        grid-template-columns: 1fr !important;
    }

    .sidebar-container {
        padding: 12px;
    }

    /* Compact sidebar profile on mobile */
    .sidebar-profile-image {
        width: 70px !important;
        height: 70px !important;
    }

    /* Exercise cards: reduce padding on mobile */
    #exerciseGridContainer > div {
        padding: 16px !important;
    }

    /* Score summary: reduce padding on mobile */
    #exerciseScoreSummary {
        padding: 16px !important;
    }

    .btn {
        padding: 8px 12px;
        height: auto;
    }

    .form-control {
        font-size: 16px;
        height: auto;
        padding: 8px 12px;
    }
}

@media (hover: none) {

    .btn,
    .form-control,
    button {
        min-height: 44px;
    }
}

/* Math Content Styling */
.math-content {
    font-size: 1.15rem;
    line-height: 1.6;
    color: var(--text-primary);
}

mjx-container {
    font-size: 1.15em !important;
}

.option-text {
    font-size: 1.05rem;
    color: var(--text-primary);
    line-height: 1.4;
}

.correct-answer {
    background: #dcfce7 !important;
    border-color: var(--success) !important;
}

.wrong-answer {
    background: #fef2f2 !important;
    border-color: var(--error) !important;
}