/* ============================================================
   styles.css — ดีไซน์หลักของ EngMaster
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3fa;
  --text: #1c2433;
  --muted: #6b7488;
  --border: #e4e8f1;
  --primary: #5b6cff;
  --primary-d: #4453e6;
  --accent-1: #ff8a4c;
  --accent-2: #4cc38a;
  --accent-3: #ffb020;
  --accent-4: #5b6cff;
  --good: #2fa36b;
  --good-bg: #e7f7ee;
  --bad: #e0445b;
  --bad-bg: #fdeaed;
  --shadow: 0 4px 20px rgba(30, 40, 80, 0.06);
  --shadow-lg: 0 12px 40px rgba(30, 40, 80, 0.12);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0f1422;
  --surface: #1a2133;
  --surface-2: #232c42;
  --text: #e8ecf6;
  --muted: #9aa4bd;
  --border: #2c3650;
  --primary: #7b8aff;
  --primary-d: #6675ff;
  --good: #4cc38a;
  --good-bg: #173a2b;
  --bad: #ff6b80;
  --bad-bg: #3a1c23;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: "Sarabun", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s, color 0.25s;
}

h1, h2, h3 { font-family: "Poppins", "Sarabun", sans-serif; line-height: 1.25; }

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-logo {
  font-size: 28px;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #8a78ff);
  border-radius: 14px;
}
.brand-name { font-weight: 700; font-size: 18px; font-family: "Poppins", sans-serif; }
.brand-tag { font-size: 12px; color: var(--muted); letter-spacing: 0.5px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  border: none; background: transparent;
  color: var(--muted);
  font-family: inherit; font-size: 15px; font-weight: 500;
  padding: 12px 14px; border-radius: 12px;
  cursor: pointer; text-align: left; width: 100%;
  transition: all 0.18s;
}
.nav-item span { font-size: 18px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(91, 108, 255, 0.35); }

.sidebar-foot { display: flex; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.icon-btn {
  flex: 1; border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 17px; padding: 10px; border-radius: 10px; cursor: pointer;
  transition: all 0.18s;
}
.icon-btn:hover { background: var(--border); }

/* ---------- Content ---------- */
.content { flex: 1; min-width: 0; display: flex; justify-content: center; }
.view { width: 100%; max-width: 760px; padding: 36px 28px 80px; }

.page-head { margin-bottom: 22px; }
.page-head h1 { font-size: 27px; margin-bottom: 4px; }
.muted { color: var(--muted); }
.section-title { font-size: 18px; margin: 28px 0 14px; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 18px 16px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
}
.stat-card.accent-1::before { background: var(--accent-1); }
.stat-card.accent-2::before { background: var(--accent-2); }
.stat-card.accent-3::before { background: var(--accent-3); }
.stat-card.accent-4::before { background: var(--accent-4); }
.stat-num { font-size: 30px; font-weight: 700; font-family: "Poppins", sans-serif; }
.stat-num .of { font-size: 16px; color: var(--muted); font-weight: 500; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }

.menu-grid { display: grid; gap: 12px; }
.menu-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.menu-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.menu-icon {
  font-size: 26px; width: 54px; height: 54px; flex-shrink: 0;
  display: grid; place-items: center; background: var(--surface-2); border-radius: 14px;
}
.menu-body { flex: 1; }
.menu-title { font-weight: 600; font-size: 16px; }
.menu-sub { font-size: 13px; color: var(--muted); }
.menu-arrow { font-size: 26px; color: var(--muted); }

.tip {
  margin-top: 24px; background: var(--surface-2); border: 1px dashed var(--border);
  border-radius: 12px; padding: 14px 16px; font-size: 14px; color: var(--text);
}
.info-box {
  margin-top: 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; font-size: 14px;
}

/* ---------- Buttons / setup ---------- */
.setup-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.setup-card p { margin-bottom: 12px; font-weight: 500; }
.chip-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 9px 18px; border-radius: 999px; cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 500; transition: all 0.15s;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.btn-primary {
  background: var(--primary); color: #fff; border: none; border-radius: 12px;
  padding: 14px 22px; font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer; width: 100%; transition: background 0.15s, transform 0.1s;
  box-shadow: 0 6px 16px rgba(91, 108, 255, 0.3);
}
.btn-primary:hover { background: var(--primary-d); }
.btn-primary:active { transform: scale(0.99); }
.btn-ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 22px; font-family: inherit; font-size: 15px;
  font-weight: 600; cursor: pointer; width: 100%;
}
.btn-ghost:hover { background: var(--surface-2); }

/* ---------- Session top bar ---------- */
.session-top {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
}
.back-link {
  background: transparent; border: none; color: var(--muted); font-family: inherit;
  font-size: 15px; cursor: pointer; padding: 6px 4px;
}
.back-link:hover { color: var(--primary); }
.session-progress { font-size: 14px; color: var(--muted); font-weight: 600; }

/* ---------- Progress bar ---------- */
.progress-row { margin-bottom: 20px; }
.progress-bar {
  height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar.slim { height: 6px; margin-bottom: 18px; }
.progress-bar span {
  display: block; height: 100%; background: linear-gradient(90deg, var(--primary), #8a78ff);
  border-radius: 999px; transition: width 0.4s;
}
.progress-text { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- Flashcard ---------- */
.flashcard { perspective: 1200px; margin: 10px 0 22px; cursor: pointer; }
.fc-inner {
  position: relative; transform-style: preserve-3d; transition: transform 0.5s;
  min-height: 300px;
}
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.fc-front, .fc-back {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 28px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 10px;
}
.fc-back { transform: rotateY(180deg); }
.fc-tag {
  font-size: 12px; color: var(--primary); background: var(--surface-2);
  padding: 4px 12px; border-radius: 999px; font-weight: 600;
}
.fc-word { font-size: 40px; font-weight: 700; font-family: "Poppins", sans-serif; }
.fc-phon { color: var(--muted); font-size: 17px; }
.fc-hint { font-size: 13px; color: var(--muted); margin-top: 14px; }
.fc-th { font-size: 24px; font-weight: 600; }
.fc-ex { font-size: 16px; font-style: italic; color: var(--text); margin-top: 6px; }
.fc-ex-th { font-size: 14px; color: var(--muted); }

.speak {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--primary);
  border-radius: 999px; padding: 6px 14px; font-family: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.speak:hover { background: var(--primary); color: #fff; }

.flip-hint { text-align: center; color: var(--muted); font-size: 13px; }
.rate-row { display: flex; gap: 12px; margin-bottom: 12px; }
.btn-good, .btn-bad {
  flex: 1; border: none; border-radius: 12px; padding: 15px; font-family: inherit;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: transform 0.1s;
}
.btn-good { background: var(--good-bg); color: var(--good); }
.btn-bad { background: var(--bad-bg); color: var(--bad); }
.btn-good:active, .btn-bad:active { transform: scale(0.97); }

/* ---------- Quiz / choices ---------- */
.q-cat {
  display: inline-block; font-size: 12px; font-weight: 600; color: var(--primary);
  background: var(--surface-2); padding: 4px 12px; border-radius: 999px; margin-bottom: 12px;
}
.q-text { font-size: 20px; font-weight: 500; margin-bottom: 20px; line-height: 1.5; }
.choices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.choice {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 12px;
  padding: 14px 16px; font-family: inherit; font-size: 15px; color: var(--text);
  cursor: pointer; transition: all 0.15s; width: 100%;
}
.choice:hover:not(.disabled) { border-color: var(--primary); background: var(--surface-2); }
.choice-key {
  width: 26px; height: 26px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--surface-2); border-radius: 8px; font-weight: 700; font-size: 13px;
}
.choice.disabled { cursor: default; }
.choice.correct { border-color: var(--good); background: var(--good-bg); }
.choice.correct .choice-key { background: var(--good); color: #fff; }
.choice.wrong { border-color: var(--bad); background: var(--bad-bg); }
.choice.wrong .choice-key { background: var(--bad); color: #fff; }

.explain {
  background: var(--surface-2); border-left: 4px solid var(--primary);
  border-radius: 10px; padding: 14px 16px; font-size: 14px; margin-bottom: 16px;
}

/* ---------- Result ---------- */
.result-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 34px 26px; text-align: center; box-shadow: var(--shadow-lg); margin-bottom: 20px;
}
.result-emoji { font-size: 56px; }
.result-card h2 { font-size: 23px; margin: 8px 0; }
.result-score { font-size: 26px; font-weight: 700; color: var(--primary); font-family: "Poppins", sans-serif; }
.result-actions { display: flex; gap: 12px; margin-top: 22px; }

.review-list { display: flex; flex-direction: column; gap: 12px; }
.review-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
}
.review-q { font-weight: 500; margin-bottom: 8px; }
.review-ans { font-size: 14px; color: var(--muted); }
.review-ans .bad { color: var(--bad); font-weight: 600; }
.review-ans .good { color: var(--good); font-weight: 600; }

/* ---------- Topic list (grammar / conversation) ---------- */
.topic-list { display: flex; flex-direction: column; gap: 12px; }
.topic-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s;
}
.topic-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.topic-main { flex: 1; }
.topic-title { font-weight: 600; font-size: 16px; margin-bottom: 3px; }
.topic-sum { font-size: 13px; color: var(--muted); }
.topic-badge {
  font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2);
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
}
.topic-badge.done { color: var(--good); background: var(--good-bg); }

/* ---------- Lesson ---------- */
.lesson-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.lesson-card h3 { font-size: 17px; margin-bottom: 14px; }
.point-list { list-style: none; display: flex; flex-direction: column; gap: 12px; }
.point-list li {
  position: relative; padding-left: 26px; font-size: 15px; line-height: 1.6;
}
.point-list li::before {
  content: "›"; position: absolute; left: 8px; top: -1px; color: var(--primary);
  font-weight: 700; font-size: 18px;
}

/* ---------- Dialogue ---------- */
.dialogue { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.bubble-row { display: flex; }
.bubble-row.right { justify-content: flex-end; }
.bubble {
  max-width: 82%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px 16px; box-shadow: var(--shadow);
}
.bubble-row.right .bubble { background: var(--surface-2); }
.bubble-speaker { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.bubble-en { font-size: 16px; font-weight: 500; }
.bubble-en .speak { padding: 3px 9px; font-size: 12px; margin-left: 4px; }
.bubble-th { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* ---------- Mobile nav ---------- */
.mobile-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .view { padding: 24px 18px 96px; }
  .page-head h1 { font-size: 24px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
  }
  .mobile-nav .nav-item {
    flex: 1; flex-direction: column; gap: 2px; padding: 6px 2px; justify-content: center;
    font-size: 11px; border-radius: 10px;
  }
  .mobile-nav .nav-item span { font-size: 20px; }
  .mobile-nav .nav-item small { font-size: 11px; }
  .mobile-nav .nav-item.active { background: transparent; color: var(--primary); box-shadow: none; }
}
@media (max-width: 420px) {
  .result-actions { flex-direction: column; }
  .fc-word { font-size: 33px; }
}
