/* MathLearn - Eye-friendly colors, Day/Night mode, Mobile-first */
:root {
    /* Day mode - soft greens & blues, low contrast strain */
    --bg-primary: #f0f7f4;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-soft: #e8f5e9;
    --text-primary: #1a2e1a;
    --text-secondary: #3d5a3d;
    --text-muted: #5a7a5a;
    --accent: #2e7d32;
    --accent-hover: #1b5e20;
    --accent-soft: #c8e6c9;
    --border: #c8e6c9;
    --shadow: 0 2px 12px rgba(46, 125, 50, 0.08);
    --shadow-hover: 0 6px 20px rgba(46, 125, 50, 0.15);
    --success: #388e3c;
    --warning: #f9a825;
    --error: #d32f2f;
    --header-bg: #e8f5e9;
    --nav-bg: #ffffff;
    --quiz-correct: #e8f5e9;
    --quiz-wrong: #ffebee;
    --radius: 12px;
    --radius-sm: 8px;
    --font: 'Sarabun', 'Prompt', sans-serif;
    --transition: 0.25s ease;
}

[data-theme="night"] {
    --bg-primary: #0d1a12;
    --bg-secondary: #132a1a;
    --bg-card: #1a3324;
    --bg-soft: #1e3a28;
    --text-primary: #e0f0e4;
    --text-secondary: #b8d4bc;
    --text-muted: #8aa890;
    --accent: #66bb6a;
    --accent-hover: #81c784;
    --accent-soft: #2e4a36;
    --border: #2e4a36;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.5);
    --success: #66bb6a;
    --warning: #ffb74d;
    --error: #ef5350;
    --header-bg: #132a1a;
    --nav-bg: #1a3324;
    --quiz-correct: #1b3a22;
    --quiz-wrong: #3a1b1b;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

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

/* Header */
.site-header {
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

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

.logo-icon { font-size: 1.5rem; }
.logo-text small { font-weight: 400; opacity: 0.8; font-size: 0.85em; }

.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.menu-toggle span {
    display: block;
    width: 24px;
    height: 2.5px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: var(--transition);
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.95rem;
    transition: var(--transition);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.nav-link:hover, .nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-dropdown { position: relative; }
.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--nav-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-hover);
    min-width: 120px;
    z-index: 100;
}
.nav-dropdown:hover .dropdown-menu,
.nav-dropdown:focus-within .dropdown-menu { display: block; }
.dropdown-menu a {
    display: block;
    padding: 0.6rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
}
.dropdown-menu a:hover { background: var(--accent-soft); color: var(--accent); }

.theme-toggle {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: var(--transition);
}
.theme-toggle:hover { transform: scale(1.1); }
[data-theme="day"] .theme-icon.night { display: none; }
[data-theme="night"] .theme-icon.day { display: none; }

/* Main */
.main-content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}

/* Hero */
.hero {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}
.hero h1 {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    color: var(--accent);
    margin-bottom: 0.75rem;
}
.hero p {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 1.5rem;
    font-size: 1.05rem;
}
.user-name-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    align-items: center;
    margin-top: 1rem;
}
.user-name-box input {
    padding: 0.6rem 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-width: 180px;
}
.user-name-box button {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.user-name-box button:hover { background: var(--accent-hover); }

/* Level sections */
.level-section {
    margin-bottom: 2.5rem;
}
.level-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid var(--accent);
}
.level-header h2 {
    font-size: 1.4rem;
    color: var(--text-primary);
}
.level-badge {
    background: var(--accent);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.topic-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: var(--shadow);
    position: relative;
}
.topic-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--accent);
}
.topic-card .icon { font-size: 2rem; }
.topic-card h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
}
.topic-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
    flex: 1;
}
.topic-card .status {
    font-size: 0.8rem;
    font-weight: 600;
}
.topic-card .status.ready { color: var(--success); }
.topic-card .status.soon { color: var(--warning); }
.topic-card .progress-bar {
    height: 6px;
    background: var(--bg-soft);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 0.5rem;
}
.topic-card .progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 0.4s ease;
}

/* Lesson page */
.lesson-header {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}
.lesson-header h1 {
    font-size: 1.6rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.breadcrumb {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.breadcrumb a { color: var(--accent); text-decoration: none; }

.lesson-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.lesson-content h2 {
    font-size: 1.3rem;
    color: var(--accent);
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.3rem;
    border-bottom: 2px solid var(--accent-soft);
}
.lesson-content h3 {
    font-size: 1.1rem;
    margin: 1.25rem 0 0.5rem;
    color: var(--text-secondary);
}
.lesson-content p, .lesson-content li {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}
.lesson-content ul, .lesson-content ol {
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}
.example-box {
    background: var(--bg-soft);
    border-left: 4px solid var(--accent);
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.example-box .ex-title {
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.formula {
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 1.15rem;
    margin: 1rem 0;
    font-weight: 500;
}
.img-wrap {
    text-align: center;
    margin: 1.25rem 0;
}
.img-wrap img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.img-wrap figcaption {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* Quiz */
.quiz-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.quiz-section h2 {
    color: var(--accent);
    margin-bottom: 1rem;
}
.question-card {
    background: var(--bg-soft);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border);
}
.question-card.correct { background: var(--quiz-correct); border-color: var(--success); }
.question-card.wrong { background: var(--quiz-wrong); border-color: var(--error); }
.q-num {
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.option-label {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition);
}
.option-label:hover { border-color: var(--accent); }
.option-label input { margin-top: 0.3rem; accent-color: var(--accent); }
.explanation {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    display: none;
}
.question-card.show-exp .explanation { display: block; }
.quiz-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.btn {
    padding: 0.7rem 1.4rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}
.btn-primary {
    background: var(--accent);
    color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
    background: var(--bg-soft);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--accent-soft); }
.score-box {
    text-align: center;
    padding: 1.5rem;
    background: var(--bg-soft);
    border-radius: var(--radius);
    margin-top: 1rem;
    display: none;
}
.score-box.show { display: block; }
.score-box .big-score {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
}

/* Progress page */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.stat-card .num {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-card .label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Games */
.game-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}
.game-area {
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.5rem;
}
.game-score { font-size: 1.2rem; font-weight: 600; color: var(--accent); }

/* Certificate */
.cert-form {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto 2rem;
}
.cert-preview {
    background: white;
    color: #1a2e1a;
    padding: 2.5rem;
    border: 8px double #2e7d32;
    border-radius: 4px;
    max-width: 700px;
    margin: 0 auto;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.cert-preview h1 {
    font-size: 1.8rem;
    color: #1b5e20;
    margin-bottom: 0.5rem;
}
.cert-preview .cert-name {
    font-size: 1.6rem;
    font-weight: 700;
    color: #2e7d32;
    margin: 1rem 0;
    border-bottom: 2px solid #c8e6c9;
    display: inline-block;
    padding: 0 1rem 0.3rem;
}
@media print {
    body * { visibility: hidden; }
    .cert-preview, .cert-preview * { visibility: visible; }
    .cert-preview {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        border: 8px double #2e7d32;
    }
    .no-print { display: none !important; }
}

/* Footer */
.site-footer {
    background: var(--header-bg);
    border-top: 1px solid var(--border);
    padding: 1.5rem 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.footer-note { font-size: 0.8rem; margin: 0.5rem 0; }
.footer-copy { margin-top: 0.75rem; opacity: 0.8; }

/* Mobile */
@media (max-width: 768px) {
    .menu-toggle { display: flex; }
    .main-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--nav-bg);
        flex-direction: column;
        padding: 1rem;
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-hover);
        gap: 0.25rem;
    }
    .main-nav.open { display: flex; }
    .nav-dropdown .dropdown-menu {
        position: static;
        display: none;
        box-shadow: none;
        border: none;
        padding-left: 1rem;
    }
    .nav-dropdown.open .dropdown-menu { display: block; }
    .topics-grid {
        grid-template-columns: 1fr;
    }
    .hero { padding: 1.5rem 1rem; }
    .lesson-content, .quiz-section { padding: 1rem; }
}
