/* ===== ตัวแปรสีถนอมสายตา ===== */
:root {
    /* โหมดกลางวัน (Eye-friendly) */
    --bg-primary: #f5f7f0;
    --bg-secondary: #e8efe0;
    --bg-card: #ffffff;
    --text-primary: #2c3e2d;
    --text-secondary: #5a6b5c;
    --accent: #4a7c59;
    --accent-hover: #3d6a4a;
    --border: #c5d4c0;
    --shadow: rgba(74, 124, 89, 0.12);
    --success: #3d8b5a;
    --danger: #c45c5c;
    --warning: #d4a017;
    --sidebar-bg: #eef4e8;
    --input-bg: #fafcf7;
}

body.dark {
    /* โหมดกลางคืน (Dark - ถนอมสายตา) */
    --bg-primary: #1a1f1b;
    --bg-secondary: #242b25;
    --bg-card: #2c342e;
    --text-primary: #e0e8dc;
    --text-secondary: #a8b5a9;
    --accent: #6ab07a;
    --accent-hover: #7bc28b;
    --border: #3d4a3f;
    --shadow: rgba(0, 0, 0, 0.4);
    --success: #5cb87a;
    --danger: #e07a7a;
    --warning: #e0b840;
    --sidebar-bg: #222922;
    --input-bg: #2a322c;
}

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

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

body {
    font-family: "Sarabun", "Noto Sans Thai", "Segoe UI", Tahoma, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

a {
    color: var(--accent);
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* ===== Top Bar ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    box-shadow: 0 2px 8px var(--shadow);
}

.menu-btn, .icon-btn, .close-btn {
    background: none;
    border: none;
    font-size: 1.35rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.menu-btn:hover, .icon-btn:hover, .close-btn:hover {
    background: var(--bg-secondary);
}

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

.logo i {
    font-size: 1.3rem;
}

.top-actions {
    display: flex;
    gap: 4px;
}

/* ===== 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 16px 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);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    color: var(--accent);
}

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

.menu-list > li > a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: background 0.2s;
}

.menu-list > li > a:hover,
.menu-list > li > a.active {
    background: var(--bg-secondary);
    color: var(--accent);
}

.menu-list > li > a i {
    width: 22px;
    text-align: center;
}

.has-submenu > a::after {
    content: "\f107";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    margin-left: auto;
}

.submenu {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: var(--bg-primary);
}

.has-submenu.open .submenu {
    max-height: 300px;
}

.submenu a {
    display: block;
    padding: 10px 16px 10px 50px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.submenu a:hover {
    color: var(--accent);
    background: var(--bg-secondary);
}

.overlay {
    position: fixed;
    inset: 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 {
    margin-top: 56px;
    padding: 20px 16px 40px;
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

.hero {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 28px 20px;
    text-align: center;
    box-shadow: 0 4px 16px var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border);
}

.hero h1 {
    font-size: 1.45rem;
    margin-bottom: 12px;
    color: var(--accent);
    line-height: 1.4;
}

.hero p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 20px;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}

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

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

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

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

/* ===== Stats Card ===== */
.stats-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 24px;
    border: 1px solid var(--border);
    box-shadow: 0 2px 10px var(--shadow);
}

.stats-card h2 {
    font-size: 1.15rem;
    margin-bottom: 16px;
    color: var(--accent);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-item {
    background: var(--bg-secondary);
    padding: 12px;
    border-radius: 10px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

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

/* ===== Cards ===== */
.quick-access h2 {
    font-size: 1.2rem;
    margin-bottom: 14px;
    color: var(--text-primary);
}

.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 14px;
    text-align: center;
    transition: 0.25s;
    box-shadow: 0 2px 8px var(--shadow);
}

.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 18px var(--shadow);
    border-color: var(--accent);
}

.card i {
    font-size: 1.8rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.card h3 {
    font-size: 0.95rem;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.card p {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ===== Notice ===== */
.notice {
    background: var(--bg-card);
    border-left: 4px solid var(--accent);
    border-radius: 0 12px 12px 0;
    padding: 16px 18px;
    margin-bottom: 24px;
}

.notice h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--accent);
}

.notice ul {
    padding-left: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.notice li {
    margin-bottom: 6px;
}

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

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

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

.modal-content h3 {
    margin-bottom: 8px;
    color: var(--accent);
}

.modal-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
}

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

/* ===== Content Pages ===== */
.lesson-header {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

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

.lesson-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.lesson-content {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    line-height: 1.8;
}

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

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

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

.lesson-content ul, .lesson-content ol {
    margin: 10px 0 14px 22px;
}

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

.example-box .example-title {
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
}

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

/* ===== Quiz ===== */
.quiz-section {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.quiz-section h2 {
    color: var(--accent);
    margin-bottom: 16px;
}

.question {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

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

.options label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    margin: 6px 0;
    background: var(--bg-card);
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: 0.2s;
}

.options label:hover {
    border-color: var(--accent);
}

.options input {
    margin-top: 3px;
}

.quiz-result {
    margin-top: 16px;
    padding: 14px;
    border-radius: 10px;
    display: none;
}

.quiz-result.correct {
    background: rgba(61, 139, 90, 0.15);
    border: 1px solid var(--success);
    color: var(--success);
}

.quiz-result.wrong {
    background: rgba(196, 92, 92, 0.15);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.explanation {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .main-content {
        padding: 28px 24px 50px;
    }
    .hero h1 {
        font-size: 1.7rem;
    }
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .sidebar {
        left: 0;
        width: 260px;
    }
    .main-content {
        margin-left: 260px;
    }
    .menu-btn {
        display: none;
    }
    .overlay {
        display: none !important;
    }
    .top-bar {
        left: 260px;
    }
}

@media (min-width: 1024px) {
    .card-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}
