/* ===== เว็บเรียนรู้สังคมศึกษา - สีถนอมสายตา + โหมดกลางวัน/กลางคืน ===== */
:root {
    /* Light mode - soft green / cream eye-friendly */
    --bg: #f5f9f5;
    --bg-card: #ffffff;
    --bg-soft: #e8f5e9;
    --text: #2e3a2e;
    --text-muted: #5a6b5a;
    --primary: #4caf50;
    --primary-dark: #388e3c;
    --primary-light: #c8e6c9;
    --accent: #81c784;
    --border: #d0e0d0;
    --shadow: 0 2px 12px rgba(46, 90, 46, 0.08);
    --header-bg: #e8f5e9;
    --sidebar-bg: #ffffff;
    --success: #43a047;
    --error: #e57373;
    --warning: #ffb74d;
    --radius: 14px;
    --font: 'Sarabun', 'Segoe UI', Tahoma, sans-serif;
}

body.dark-mode {
    --bg: #1a211a;
    --bg-card: #243024;
    --bg-soft: #2a352a;
    --text: #e0ebe0;
    --text-muted: #a0b0a0;
    --primary: #66bb6a;
    --primary-dark: #81c784;
    --primary-light: #2e4a2e;
    --accent: #a5d6a7;
    --border: #3a4a3a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
    --header-bg: #1e281e;
    --sidebar-bg: #1e281e;
    --success: #81c784;
    --error: #ef9a9a;
    --warning: #ffcc80;
}

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

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
    padding-bottom: 80px;
}

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

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

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

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

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
}

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

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

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

.theme-toggle:hover, .btn-user:hover {
    background: var(--primary-light);
}

body.light-mode .icon-moon { display: none; }
body.dark-mode .icon-sun { display: none; }

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

.sidebar.open { left: 0; }

.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
}

.nav-overlay.show { display: block; }

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

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

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

.nav-list > li > a,
.nav-group-title {
    display: block;
    padding: 12px 20px;
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    transition: 0.2s;
}

.nav-list > li > a:hover,
.nav-list > li > a.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.nav-group-title {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-group ul {
    list-style: none;
    padding-left: 12px;
}

.nav-group ul a {
    display: block;
    padding: 8px 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-group ul a:hover,
.nav-group ul a.active {
    background: var(--primary-light);
    border-radius: 8px;
    margin-right: 8px;
}

/* Main */
.main-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-dark);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

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

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

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

.btn-block {
    width: 100%;
    margin-top: 8px;
}

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

.grade-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: 0.25s;
    box-shadow: var(--shadow);
}

.grade-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.2);
}

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

/* Strand list */
.strand-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.strand-item {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    transition: 0.2s;
}

.strand-item:hover {
    border-color: var(--primary);
    background: var(--bg-soft);
}

.strand-icon {
    font-size: 1.8rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    border-radius: 12px;
    flex-shrink: 0;
}

/* Lesson content */
.lesson-header {
    margin-bottom: 24px;
}

.lesson-header h1 {
    font-size: 1.5rem;
    color: var(--primary-dark);
    margin-bottom: 8px;
}

.breadcrumb {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
}

.lesson-body h2 {
    font-size: 1.2rem;
    margin: 24px 0 12px;
    color: var(--primary-dark);
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 6px;
}

.lesson-body h3 {
    font-size: 1.05rem;
    margin: 18px 0 8px;
    color: var(--text);
}

.lesson-body p {
    margin-bottom: 12px;
}

.lesson-body ul, .lesson-body ol {
    margin: 0 0 16px 20px;
}

.example-box {
    background: var(--bg-soft);
    border-left: 4px solid var(--primary);
    border-radius: 0 10px 10px 0;
    padding: 14px 16px;
    margin: 14px 0;
}

.example-box .ex-title {
    font-weight: 600;
    color: var(--primary-dark);
    margin-bottom: 6px;
}

.lesson-img {
    width: 100%;
    max-width: 480px;
    border-radius: 12px;
    margin: 16px auto;
    display: block;
    box-shadow: var(--shadow);
}

.img-caption {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: -8px;
    margin-bottom: 16px;
}

/* Quiz */
.quiz-container {
    max-width: 640px;
    margin: 0 auto;
}

.quiz-progress {
    height: 8px;
    background: var(--bg-soft);
    border-radius: 4px;
    margin-bottom: 20px;
    overflow: hidden;
}

.quiz-progress-bar {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}

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

.question-num {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.question-text {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 16px;
}

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

.option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: 0.2s;
    background: var(--bg);
}

.option:hover {
    border-color: var(--primary);
}

.option.selected {
    border-color: var(--primary);
    background: var(--primary-light);
}

.option.correct {
    border-color: var(--success);
    background: rgba(67, 160, 71, 0.15);
}

.option.wrong {
    border-color: var(--error);
    background: rgba(229, 115, 115, 0.15);
}

.option input {
    display: none;
}

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

.explanation.show {
    display: block;
}

.quiz-result {
    text-align: center;
    padding: 32px 20px;
}

.quiz-result .score {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary);
}

/* Progress */
.progress-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

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

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

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

/* Game */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 400px;
    margin: 20px auto;
}

.game-card {
    aspect-ratio: 1;
    background: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    color: #fff;
    transition: 0.3s;
    user-select: none;
}

.game-card.flipped,
.game-card.matched {
    background: var(--bg-card);
    color: var(--text);
    border: 2px solid var(--primary);
}

.game-card.matched {
    opacity: 0.7;
    pointer-events: none;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-content h3 {
    margin-bottom: 16px;
}

.modal-content label {
    display: block;
    margin: 12px 0 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.modal-content input,
.modal-content select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
}

/* Certificate */
.certificate {
    background: #fff;
    color: #222;
    border: 8px double #4caf50;
    border-radius: 8px;
    padding: 40px 30px;
    text-align: center;
    max-width: 700px;
    margin: 0 auto;
}

.certificate h1 {
    font-size: 1.8rem;
    color: #2e7d32;
    margin-bottom: 8px;
}

.certificate .name {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 20px 0;
    color: #1b5e20;
}

@media print {
    body * { visibility: hidden; }
    .certificate, .certificate * { visibility: visible; }
    .certificate {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        border: 8px double #4caf50;
    }
    .no-print { display: none !important; }
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer-note {
    margin-top: 8px;
    font-size: 0.75rem;
}

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

/* Responsive */
@media (min-width: 768px) {
    .menu-toggle { display: none; }
    .sidebar {
        left: 0;
        position: fixed;
        width: 240px;
    }
    .main-content {
        margin-left: 240px;
        max-width: calc(100% - 240px);
        padding: 28px 32px 60px;
    }
    .header-inner {
        margin-left: 240px;
        max-width: calc(100% - 240px);
    }
    .nav-overlay { display: none !important; }
    .close-menu { display: none; }
}

@media (max-width: 480px) {
    .game-board {
        grid-template-columns: repeat(3, 1fr);
    }
    .grade-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
