:root {
    --bg: #f7f5f0;
    --bg-card: #ffffff;
    --text: #2c2c2c;
    --text-muted: #5a5a5a;
    --primary: #3d6b4f;
    --primary-light: #5a8f6e;
    --secondary: #8b6b4a;
    --accent: #c4a35a;
    --border: #e0dcd3;
    --success: #2e7d4f;
    --danger: #b33a3a;
    --shadow: 0 4px 16px rgba(0,0,0,0.08);
    --radius: 12px;
    --header-h: 56px;
}

body.dark-mode {
    --bg: #1a1c1e;
    --bg-card: #25282c;
    --text: #e8e6e1;
    --text-muted: #a8a69f;
    --primary: #6bb88a;
    --primary-light: #8fd4a8;
    --secondary: #c9a66b;
    --accent: #e0c078;
    --border: #3a3e44;
    --success: #5cb87a;
    --danger: #e07070;
    --shadow: 0 4px 16px rgba(0,0,0,0.4);
}

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

body {
    font-family: 'Sarabun', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
    min-height: 100vh;
    padding-bottom: 40px;
}

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

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 12px;
    max-width: 900px;
    margin: 0 auto;
}

.menu-toggle {
    background: none;
    border: none;
    width: 36px;
    height: 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
}

.menu-toggle span {
    display: block;
    height: 2px;
    width: 22px;
    background: var(--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-btn, .user-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.side-menu.open { left: 0; }

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

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

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

.menu-list a, .group-title {
    display: block;
    padding: 12px 20px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.95rem;
}

.menu-list a:hover, .menu-list a.active {
    background: var(--primary);
    color: #fff;
}

.group-title {
    font-weight: 600;
    color: var(--primary);
    font-size: 0.85rem;
    margin-top: 8px;
}

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

.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}

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

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

.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

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

/* Hero */
.hero {
    text-align: center;
    padding: 24px 8px;
}

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

.subtitle {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.user-name-box {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    background: var(--bg-card);
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.user-name-box input {
    flex: 1;
    min-width: 160px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
}

.quick-stats {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 20px;
    text-align: center;
    min-width: 100px;
    box-shadow: var(--shadow);
}

.stat-num {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

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

/* Strand Grid */
.strand-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
    margin-top: 24px;
}

.strand-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.strand-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.strand-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.strand-card h3 {
    font-size: 1.05rem;
    margin-bottom: 6px;
    color: var(--primary);
}

.strand-card p {
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* Lesson List */
.lesson-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lesson-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.lesson-card h3 {
    font-size: 1.05rem;
    margin-bottom: 6px;
}

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

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: 0.2s;
}

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

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

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

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progress */
.progress-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
}

.progress-bar-wrap {
    height: 12px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin: 12px 0;
}

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

.lesson-progress-list {
    margin: 16px 0;
}

.progress-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

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

.game-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}

.game-area {
    margin-top: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    border: 1px solid var(--border);
}

.hidden { display: none !important; }

/* Lesson Modal */
.lesson-modal {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    overflow-y: auto;
    padding: 16px 12px 40px;
}

.lesson-modal-content {
    max-width: 800px;
    margin: 0 auto;
}

.close-lesson {
    position: sticky;
    top: 8px;
    float: right;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    z-index: 10;
    font-size: 0.95rem;
}

.lesson-body {
    clear: both;
    padding-top: 8px;
}

.lesson-body h2 {
    color: var(--primary);
    margin-bottom: 12px;
    font-size: 1.35rem;
}

.lesson-body h3 {
    margin: 20px 0 8px;
    font-size: 1.1rem;
}

.lesson-body p, .lesson-body li {
    margin-bottom: 10px;
    font-size: 1rem;
}

.lesson-body ul, .lesson-body ol {
    padding-left: 20px;
    margin-bottom: 12px;
}

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

.example-box h4 {
    color: var(--secondary);
    margin-bottom: 6px;
}

.img-wrap {
    text-align: center;
    margin: 16px 0;
}

.img-wrap img {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.img-caption {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Quiz */
.quiz-area {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
}

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

.quiz-question h4 {
    margin-bottom: 10px;
}

.quiz-options label {
    display: block;
    padding: 10px 12px;
    margin: 6px 0;
    background: var(--bg);
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
}

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

.quiz-options input {
    margin-right: 8px;
}

.quiz-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--bg-card);
}

.correct { color: var(--success); }
.incorrect { color: var(--danger); }

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

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 0.95rem;
    z-index: 500;
    box-shadow: var(--shadow);
}

.toast.show {
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Cert */
.cert-panel {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
}

.cert-status {
    margin: 16px 0;
    padding: 12px;
    border-radius: 8px;
    background: var(--bg);
}

/* Responsive */
@media (min-width: 600px) {
    .hero h1 { font-size: 2rem; }
    .main-content { padding: 24px 20px; }
}
