:root {
  --bg: #fff8ef;
  --card: #ffffff;
  --card-alt: #fffdf7;
  --ink: #2d2417;
  --muted: #8a7d6b;
  --brand: #f4900c;
  --brand-dark: #d97a00;
  --teal: #0e9488;
  --teal-soft: #e0f5f3;
  --rose: #e85d75;
  --rose-soft: #fdeaea;
  --gold-soft: #fdeed3;
  --line: #f0e4d2;
  --shadow: 0 4px 16px rgba(120, 85, 20, 0.10);
  --radius: 18px;
  /* data-mark colors (charts, progress bars) – validated per mode */
  --data-orange: #f4900c;
  --data-teal: #0e9488;
}

html[data-theme="dark"] {
  --bg: #181310;
  --card: #251e17;
  --card-alt: #2b241c;
  --ink: #f3ead9;
  --muted: #a5977f;
  --brand: #f4900c;
  --brand-dark: #ffb14d;
  --teal: #19b8a6;
  --teal-soft: #12352f;
  --rose: #ff8296;
  --rose-soft: #43222a;
  --gold-soft: #3a2c14;
  --line: #3a3126;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  --data-orange: #cf7400;
  --data-teal: #10a091;
}

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

body {
  font-family: 'Nunito', 'Noto Sans Thai', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  transition: background 0.25s, color 0.25s;
}

.ctrl-row { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.ctrl-btn {
  border: none; background: var(--card); box-shadow: var(--shadow);
  border-radius: 12px; height: 38px; min-width: 38px; padding: 0 12px;
  font-size: 1rem; font-weight: 800; font-family: inherit; color: var(--ink);
  cursor: pointer;
}

.thai { font-family: 'Noto Sans Thai', sans-serif; }

#app { max-width: 640px; margin: 0 auto; padding: 16px 16px 64px; }

/* ---------- header ---------- */
.hero { text-align: center; padding: 24px 8px 8px; }
.hero h1 {
  font-size: 2rem; font-weight: 800; letter-spacing: -0.5px;
}
.hero h1 .sun { color: var(--brand); }
.hero .tagline { color: var(--muted); margin-top: 4px; font-size: 1rem; }
.hero .tagline .thai { color: var(--teal); font-weight: 600; }

.progress-banner {
  display: flex; justify-content: center; gap: 20px;
  margin: 18px 0 6px; font-size: 0.9rem; color: var(--muted);
}
.progress-banner b { color: var(--ink); font-size: 1.05rem; }

/* ---------- top bar in sub-views ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0 18px;
}
.topbar h2 { font-size: 1.25rem; flex: 1; }
.back-btn {
  border: none; background: var(--card); box-shadow: var(--shadow);
  border-radius: 12px; width: 42px; height: 42px; font-size: 1.2rem;
  cursor: pointer; flex-shrink: 0;
}

/* ---------- lesson cards ---------- */
.section-label {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1.5px;
  color: var(--muted); margin: 22px 4px 10px; font-weight: 700;
}
.lesson-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
  cursor: pointer; border: 2px solid transparent;
  transition: transform 0.12s ease;
}
.lesson-card:active { transform: scale(0.98); }
.lesson-card.done { border-color: var(--teal); }
.lesson-card .emoji {
  font-size: 1.7rem; background: var(--gold-soft);
  border-radius: 14px; width: 54px; height: 54px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.lesson-card.done .emoji { background: var(--teal-soft); }
.lesson-card .info { flex: 1; min-width: 0; }
.lesson-card .info h3 { font-size: 1.05rem; }
.lesson-card .info .th-title { color: var(--muted); font-size: 0.85rem; }
.lesson-card .status { font-size: 0.8rem; color: var(--muted); text-align: right; flex-shrink: 0; }
.lesson-card .status .check { color: var(--teal); font-size: 1.1rem; font-weight: 800; }

.review-card {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(120deg, var(--teal) 0%, #12b3a4 100%);
  color: #fff; border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow); cursor: pointer;
}
.review-card .emoji { font-size: 1.7rem; }
.review-card h3 { font-size: 1.05rem; }
.review-card p { font-size: 0.85rem; opacity: 0.9; }

.review-card.stats {
  background: linear-gradient(120deg, var(--brand) 0%, #ffb347 100%);
}

/* ---------- stats view ---------- */
.stat-tiles {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.tile {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 14px; text-align: center;
}
.tile .num { font-size: 1.5rem; font-weight: 800; }
.tile .lbl { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.seg-bar {
  display: flex; gap: 2px; height: 18px; border-radius: 9px; overflow: hidden;
  background: var(--line);
}
.seg.known { background: var(--data-teal); }
.seg.learning { background: var(--data-orange); }
.seg.fresh { background: var(--line); }
.seg-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px;
  font-size: 0.85rem; color: var(--muted);
}
.seg-legend b { color: var(--ink); }
.seg-legend .dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 5px;
}
.dot.known { background: var(--data-teal); }
.dot.learning { background: var(--data-orange); }
.dot.fresh { background: var(--line); }

.chart-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 14px 12px;
}
.chart {
  display: flex; align-items: flex-end; gap: 8px; height: 130px;
}
.chart-col {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; height: 100%; gap: 4px;
}
.chart-col .bar {
  width: 70%; max-width: 34px; background: var(--data-orange);
  border-radius: 4px 4px 0 0; min-height: 2px;
}
.chart-col .val { font-size: 0.75rem; font-weight: 700; color: var(--ink); min-height: 1em; }
.chart-col .day { font-size: 0.75rem; color: var(--muted); }
.chart-col .day.today { color: var(--brand-dark); font-weight: 800; }
.chart-note { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 10px; }

.stat-lesson {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px;
}
.stat-lesson .emoji { font-size: 1.3rem; }
.stat-lesson .mid { flex: 1; min-width: 0; }
.stat-lesson .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 0.9rem; }
.stat-lesson .name { font-weight: 700; }
.stat-lesson .nums { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.stat-lesson .mini-bar {
  height: 6px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden;
}
.stat-lesson .mini-bar .fill { height: 100%; background: var(--data-teal); border-radius: 3px; }
.stat-lesson .check { color: var(--teal); font-weight: 800; width: 16px; text-align: center; }

/* ---------- lesson view ---------- */
.intro-box {
  background: var(--gold-soft); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 18px; font-size: 0.95rem; line-height: 1.5;
}
.vocab-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.vocab-row .txt { flex: 1; min-width: 0; }
.vocab-row .de { font-weight: 800; font-size: 1.05rem; }
.vocab-row .pron { color: var(--brand-dark); font-size: 0.8rem; font-weight: 600; }
.vocab-row .trans { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.vocab-row .trans .thai { color: var(--teal); }
.audio-btn {
  border: none; background: var(--teal-soft); color: var(--teal);
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.05rem;
  cursor: pointer; flex-shrink: 0; transition: transform 0.1s;
}
.audio-btn:active { transform: scale(0.9); }
.audio-btn.slow { background: var(--gold-soft); color: var(--brand-dark); font-size: 0.75rem; font-weight: 800; }

.tip-box {
  background: var(--teal-soft); border-radius: var(--radius);
  padding: 14px 16px; margin: 18px 0; font-size: 0.92rem; line-height: 1.55;
}
.tip-box b { color: var(--teal); }

.big-actions { display: flex; gap: 10px; margin-top: 22px; }
.btn {
  flex: 1; border: none; border-radius: 14px; padding: 15px;
  font-family: inherit; font-size: 1rem; font-weight: 800; cursor: pointer;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(244, 144, 12, 0.35); }
.btn-teal { background: var(--teal); color: #fff; box-shadow: 0 4px 14px rgba(14, 148, 136, 0.3); }
.btn-ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* ---------- flashcards ---------- */
.flash-wrap { perspective: 1200px; margin-top: 8px; }
.flash-card {
  position: relative; width: 100%; min-height: 300px;
  transform-style: preserve-3d; transition: transform 0.45s;
  cursor: pointer;
}
.flash-card.flipped { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center;
}
.flash-face.back { transform: rotateY(180deg); background: var(--card-alt); }
.flash-face .de-word { font-size: 1.9rem; font-weight: 800; }
.flash-face .hint { color: var(--muted); font-size: 0.85rem; }
.flash-face .en { font-size: 1.3rem; font-weight: 700; }
.flash-face .th { font-size: 1.25rem; color: var(--teal); font-weight: 600; }
.flash-face .pron { color: var(--brand-dark); font-weight: 700; font-size: 0.95rem; }
.flash-counter { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 14px 0 8px; }
.flash-grade { display: flex; gap: 10px; margin-top: 14px; }
.btn-again { background: var(--rose-soft); color: var(--rose); }
.btn-good { background: var(--teal-soft); color: var(--teal); }

/* ---------- quiz ---------- */
.quiz-progress {
  height: 8px; background: var(--line); border-radius: 4px; margin-bottom: 20px; overflow: hidden;
}
.quiz-progress .fill { height: 100%; background: var(--brand); border-radius: 4px; transition: width 0.3s; }
.quiz-q {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; text-align: center; margin-bottom: 16px;
}
.quiz-q .ask { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.quiz-q .word { font-size: 1.5rem; font-weight: 800; }
.quiz-opt {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin-bottom: 10px; font-family: inherit;
  font-size: 1rem; font-weight: 600; cursor: pointer; transition: border-color 0.15s;
}
.quiz-opt .thai { color: var(--teal); font-size: 0.9rem; }
.quiz-opt.correct { border-color: var(--teal); background: var(--teal-soft); }
.quiz-opt.wrong { border-color: var(--rose); background: var(--rose-soft); }
.quiz-opt:disabled { cursor: default; opacity: 1; color: inherit; }

.result-box {
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  text-align: center; padding: 36px 24px; margin-top: 24px;
}
.result-box .big { font-size: 3rem; }
.result-box h2 { margin: 10px 0 6px; }
.result-box p { color: var(--muted); margin-bottom: 20px; }

.empty-note { text-align: center; color: var(--muted); padding: 40px 20px; line-height: 1.6; }

footer.credit { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 36px; }
