/* ===== CSS Variables for Themes ===== */
:root {
    /* Light Mode - Eye-friendly soft colors */
    --bg-primary: #f7f5f0;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0ebe3;
    --text-primary: #2c2c2c;
    --text-secondary: #5a5a5a;
    --text-muted: #8a8a8a;
    --accent: #4a7c59;
    --accent-light: #6b9b7a;
    --accent-dark: #3a6347;
    --border: #e0d8cc;
    --shadow: rgba(0, 0, 0, 0.08);
    --success: #4caf50;
    --error: #e57373;
    --warning: #ffb74d;
    --info: #64b5f6;
    --quiz-correct: #e8f5e9;
    --quiz-wrong: #ffebee;
    --header-bg: #4a7c59;
    --header-text: #ffffff;
    --sidebar-bg: #ffffff;
    --menu-active: #e8f0eb;
}

body.dark-mode {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1f2a44;
    --bg-hover: #2a3a5c;
    --text-primary: #e8e6e3;
    --text-secondary: #b8b6b3;
    --text-muted: #888680;
    --accent: #7cb992;
    --accent-light: #9dcea8;
    --accent-dark: #5a9a6e;
    --border: #2d3a55;
    --shadow: rgba(0, 0, 0, 0.3);
    --success: #66bb6a;
    --error: #ef9a9a;
    --warning: #ffcc80;
    --info: #90caf9;
    --quiz-correct: #1b3a1f;
    --quiz-wrong: #3a1f1f;
    --header-bg: #1f2a44;
    --header-text: #e8e6e3;
    --sidebar-bg: #16213e;
    --menu-active: #2a3a5c;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

/* ===== Header ===== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--header-bg);
    color: var(--header-text);
    z-index: 1000;
    box-shadow: 0 2px 8px var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 12px;
    max-width: 1200px;
    margin: 0 auto;
}

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

.menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--header-text);
    border-radius: 2px;
    transition: 0.3s;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1.1rem;
}

.logo-icon {
    font-size: 1.4rem;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.theme-toggle, .user-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.theme-toggle:hover, .user-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--sidebar-bg);
    z-index: 1100;
    transition: left 0.3s ease;
    overflow-y: auto;
    box-shadow: 4px 0 20px var(--shadow);
}

.sidebar.open {
    left: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    color: var(--header-text);
}

.sidebar-header h2 {
    font-size: 1.1rem;
}

.close-menu {
    background: none;
    border: none;
    color: var(--header-text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
}

.menu-list {
    list-style: none;
    padding: 12px 0;
}

.menu-item {
    display: block;
    padding: 12px 20px;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s;
    font-size: 0.95rem;
}

.menu-item:hover, .menu-item.active {
    background: var(--menu-active);
    color: var(--accent);
}

.menu-group-title {
    display: block;
    padding: 12px 20px 6px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.submenu {
    list-style: none;
    padding-left: 12px;
}

.submenu .menu-item {
    padding: 10px 20px;
    font-size: 0.9rem;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1050;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}

.overlay.show {
    opacity: 1;
    visibility: visible;
}

/* ===== Main Content ===== */
.main-content {
    padding: 72px 16px 32px;
    max-width: 900px;
    margin: 0 auto;
    min-height: 100vh;
}

/* ===== Cards & Sections ===== */
.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border);
}

.card-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.section-subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ===== Home Page ===== */
.hero {
    text-align: center;
    padding: 24px 16px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    border-radius: 16px;
    margin-bottom: 24px;
}

.hero h1 {
    font-size: 1.6rem;
    margin-bottom: 8px;
}

.hero p {
    opacity: 0.9;
    font-size: 0.95rem;
}

.grade-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.grade-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    color: var(--text-primary);
}

.grade-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.grade-card .grade-num {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.grade-card .grade-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.feature-list {
    list-style: none;
}

.feature-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.feature-list li:last-child {
    border-bottom: none;
}

.feature-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

/* ===== Lesson Content ===== */
.lesson-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.lesson-btn {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s;
}

.lesson-btn:hover, .lesson-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.lesson-content h3 {
    color: var(--accent);
    margin: 20px 0 10px;
    font-size: 1.15rem;
}

.lesson-content p {
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.example-box {
    background: var(--bg-hover);
    border-left: 4px solid var(--accent);
    padding: 14px 16px;
    margin: 12px 0;
    border-radius: 0 8px 8px 0;
}

.example-box .ex-label {
    font-weight: 600;
    color: var(--accent);
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.example-box .ex-text {
    color: var(--text-primary);
}

.image-placeholder {
    background: var(--bg-hover);
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    margin: 16px 0;
    color: var(--text-muted);
}

.image-placeholder .img-icon {
    font-size: 3rem;
    margin-bottom: 8px;
}

.tip-box {
    background: linear-gradient(135deg, rgba(74, 124, 89, 0.1), rgba(74, 124, 89, 0.05));
    border: 1px solid var(--accent-light);
    border-radius: 10px;
    padding: 14px 16px;
    margin: 16px 0;
}

.tip-box .tip-title {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
}

/* ===== Quiz ===== */
.quiz-container {
    margin-top: 24px;
}

.quiz-question {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}

.quiz-question.correct {
    background: var(--quiz-correct);
    border-color: var(--success);
}

.quiz-question.wrong {
    background: var(--quiz-wrong);
    border-color: var(--error);
}

.q-number {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}

.q-text {
    font-size: 1.05rem;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.q-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.q-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-secondary);
}

.q-option:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.q-option.selected {
    border-color: var(--accent);
    background: var(--menu-active);
}

.q-option input {
    accent-color: var(--accent);
}

.q-explanation {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-hover);
    border-radius: 8px;
    font-size: 0.9rem;
    display: none;
}

.q-explanation.show {
    display: block;
}

.quiz-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.quiz-result {
    text-align: center;
    padding: 24px;
    border-radius: 12px;
    margin-top: 20px;
}

.quiz-result.pass {
    background: var(--quiz-correct);
}

.quiz-result.fail {
    background: var(--quiz-wrong);
}

.score-display {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
}

/* ===== Buttons ===== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

.btn-success {
    background: var(--success);
    color: white;
}

.btn-block {
    width: 100%;
    justify-content: center;
}

/* ===== Games ===== */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.game-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.game-card:hover {
    border-color: var(--accent);
    transform: translateY(-3px);
}

.game-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.game-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.game-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Matching Game */
.matching-game {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.match-item {
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-card);
}

.match-item.selected {
    border-color: var(--accent);
    background: var(--menu-active);
}

.match-item.matched {
    border-color: var(--success);
    background: var(--quiz-correct);
    opacity: 0.7;
    pointer-events: none;
}

/* ===== Progress ===== */
.progress-bar-container {
    background: var(--bg-hover);
    border-radius: 10px;
    height: 12px;
    overflow: hidden;
    margin: 8px 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 10px;
    transition: width 0.5s;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    text-align: center;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== Certificate ===== */
.certificate-preview {
    background: white;
    color: #2c2c2c;
    border: 8px double #4a7c59;
    border-radius: 8px;
    padding: 40px 30px;
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

.cert-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: #4a7c59;
    margin-bottom: 8px;
}

.cert-subtitle {
    font-size: 1rem;
    color: #666;
    margin-bottom: 24px;
}

.cert-name {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 16px 0;
    border-bottom: 2px solid #4a7c59;
    display: inline-block;
    padding: 0 20px 4px;
}

.cert-text {
    font-size: 0.95rem;
    line-height: 1.8;
    margin: 16px 0;
}

.cert-score {
    font-size: 1.2rem;
    font-weight: 600;
    color: #4a7c59;
}

.cert-date {
    margin-top: 24px;
    font-size: 0.9rem;
    color: #666;
}

.cert-seal {
    font-size: 3rem;
    margin: 16px 0;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
    padding: 16px;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

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

.modal-header h3 {
    font-size: 1.15rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 3000;
    transition: transform 0.3s;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .main-content {
        padding: 80px 24px 40px;
    }
    
    .hero h1 {
        font-size: 2rem;
    }
    
    .grade-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .matching-game {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 1024px) {
    .sidebar {
        left: 0;
    }
    
    .main-content {
        margin-left: 280px;
        max-width: calc(100% - 280px);
    }
    
    .menu-toggle, .close-menu, .overlay {
        display: none;
    }
    
    .header-content {
        padding-left: 24px;
    }
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: var(--quiz-correct);
    color: var(--success);
}

.badge-warning {
    background: rgba(255, 183, 77, 0.2);
    color: var(--warning);
}
