/* Thai Learn — Ling-inspired modern UI */
:root {
  --bg: #0f1419;
  --bg-elevated: #1a222d;
  --bg-card: #222c3a;
  --bg-hover: #2a3544;
  --text: #f0f4f8;
  --text-muted: #8b9cb3;
  --text-dim: #5a6a7e;
  --accent: #FF6B4A;
  --accent-soft: rgba(255, 107, 74, 0.15);
  --teal: #4ECDC4;
  --teal-soft: rgba(78, 205, 196, 0.15);
  --gold: #FFE66D;
  --purple: #A78BFA;
  --pink: #F472B6;
  --success: #34d399;
  --error: #f87171;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: "Inter", "Noto Sans TC", "Noto Sans Thai", system-ui, sans-serif;
  --font-thai: "Noto Sans Thai", "Inter", sans-serif;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(255, 107, 74, 0.18), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(78, 205, 196, 0.12), transparent),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(167, 139, 250, 0.08), transparent);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--teal); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; }

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-b));
}

/* ——— Top bar ——— */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #ff8f6b);
  display: grid;
  place-items: center;
  font-family: var(--font-thai);
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 74, 0.4);
}

.streak {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gold);
  border: 1px solid var(--border);
}

/* ——— Bottom nav ——— */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 0 12px calc(8px + var(--safe-b));
  pointer-events: none;
}

.bottom-nav-inner {
  pointer-events: auto;
  display: flex;
  width: 100%;
  max-width: 720px;
  background: rgba(26, 34, 45, 0.92);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px;
  box-shadow: var(--shadow);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border-radius: 14px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s;
}

.nav-btn .icon { font-size: 1.35rem; line-height: 1; }
.nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ——— Views ——— */
.view { display: none; padding: 20px 20px 32px; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

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

.view-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.view-sub {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

/* ——— Home / Units ——— */
.hero {
  background: linear-gradient(135deg, rgba(255, 107, 74, 0.2), rgba(78, 205, 196, 0.1));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 28px;
  position: relative;
  overflow: hidden;
}

.hero h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 6px;
}

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

.progress-ring-wrap {
  display: flex;
  align-items: center;
  gap: 16px;
}

.progress-stats {
  flex: 1;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.stat-row strong { color: var(--text); }

.bar {
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  border-radius: 999px;
  transition: width 0.5s ease;
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.unit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.unit-card:hover, .unit-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.15);
  background: var(--bg-hover);
  outline: none;
}

.unit-emoji {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  font-family: var(--font-thai);
  font-weight: 700;
  flex-shrink: 0;
}

.unit-body { flex: 1; min-width: 0; }
.unit-body h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 2px; }
.unit-body .en { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 8px; }

.lesson-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

.pill.done { background: var(--teal-soft); color: var(--teal); }

.unit-progress {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ——— Lesson list (unit detail) ——— */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding: 6px 0;
}

.back-btn:hover { color: var(--text); }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.lesson-item:hover {
  background: var(--bg-hover);
  transform: translateX(4px);
}

.lesson-num {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--accent-soft);
  color: var(--accent);
  flex-shrink: 0;
}

.lesson-item.done .lesson-num {
  background: var(--teal-soft);
  color: var(--teal);
}

.lesson-item h4 { font-size: 1rem; font-weight: 700; }
.lesson-item .meta { font-size: 0.8rem; color: var(--text-muted); }

.type-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-dim);
}

/* ——— Flashcards ——— */
.card-stage {
  perspective: 1200px;
  margin: 24px 0;
  min-height: 280px;
}

.flashcard {
  width: 100%;
  min-height: 280px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  cursor: pointer;
}

.flashcard.flipped { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.card-face.back { transform: rotateY(180deg); }

.card-th {
  font-family: var(--font-thai);
  font-size: 2.75rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 12px;
}

.card-rom {
  font-size: 1.1rem;
  color: var(--teal);
  font-weight: 500;
  margin-bottom: 8px;
}

.card-en {
  font-size: 1.25rem;
  font-weight: 700;
}

.card-yue {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.card-hint {
  position: absolute;
  bottom: 16px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.card-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 0.95rem;
  transition: all 0.15s;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ff8f6b);
  color: #fff;
  box-shadow: 0 4px 16px rgba(255, 107, 74, 0.35);
}

.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }

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

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

.btn-success {
  background: var(--teal-soft);
  color: var(--teal);
  border: 1px solid rgba(78, 205, 196, 0.3);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.12);
  color: var(--error);
  border: 1px solid rgba(248, 113, 113, 0.25);
}

.btn-ghost {
  color: var(--text-muted);
  padding: 8px 12px;
}

.card-counter {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.cat-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.cat-chip {
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: all 0.15s;
}

.cat-chip.active {
  background: var(--accent-soft);
  border-color: rgba(255, 107, 74, 0.4);
  color: var(--accent);
}

/* ——— Alphabet ——— */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--bg-elevated);
  padding: 4px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  transition: all 0.15s;
}

.tab.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.alpha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.alpha-cell {
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  padding: 6px;
}

.alpha-cell:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: scale(1.04);
}

.alpha-cell .th {
  font-family: var(--font-thai);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1;
}

.alpha-cell .rom {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.alpha-cell.mid { border-bottom: 3px solid #94a3b8; }
.alpha-cell.high { border-bottom: 3px solid #fbbf24; }
.alpha-cell.low { border-bottom: 3px solid #60a5fa; }

.detail-panel {
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: none;
}

.detail-panel.show { display: block; animation: fadeIn 0.2s; }

.detail-panel .big-th {
  font-family: var(--font-thai);
  font-size: 4rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.detail-meta {
  text-align: center;
  margin-top: 8px;
}

.detail-meta .name { font-weight: 700; font-size: 1.1rem; }
.detail-meta .rom { color: var(--teal); }
.detail-meta .en { color: var(--text-muted); font-size: 0.9rem; }

.class-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.class-badge.mid { background: rgba(148, 163, 184, 0.2); color: #94a3b8; }
.class-badge.high { background: rgba(251, 191, 36, 0.2); color: #fbbf24; }
.class-badge.low { background: rgba(96, 165, 250, 0.2); color: #60a5fa; }

.vowel-list, .tone-list { display: flex; flex-direction: column; gap: 10px; }

.vowel-row, .tone-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.vowel-row .th, .tone-row .th {
  font-family: var(--font-thai);
  font-size: 1.4rem;
  font-weight: 600;
}

.vowel-row .rom, .tone-row .rom { color: var(--teal); font-weight: 500; }
.vowel-row .en, .tone-row .en { color: var(--text-muted); font-size: 0.85rem; }

.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.legend span { display: flex; align-items: center; gap: 6px; }
.legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

/* ——— Phrases ——— */
.phrase-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

.phrase-card:hover { border-color: rgba(255, 255, 255, 0.12); }

.phrase-th {
  font-family: var(--font-thai);
  font-size: 1.45rem;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.4;
}

.phrase-rom { color: var(--teal); font-size: 0.95rem; margin-bottom: 4px; }
.phrase-en { font-weight: 700; font-size: 1rem; }
.phrase-yue { color: var(--text-muted); font-size: 0.9rem; margin-top: 2px; }
.phrase-note {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--gold);
  background: rgba(255, 230, 109, 0.08);
  padding: 6px 10px;
  border-radius: 8px;
}

/* ——— Quiz ——— */
.quiz-progress {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
}

.quiz-dot {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-elevated);
}

.quiz-dot.done { background: var(--teal); }
.quiz-dot.current { background: var(--accent); }
.quiz-dot.wrong { background: var(--error); }

.quiz-q {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.4;
}

.quiz-prompt {
  font-family: var(--font-thai);
  font-size: 2rem;
  font-weight: 600;
  text-align: center;
  margin: 16px 0 24px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

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

.quiz-opt {
  text-align: left;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.15s;
  font-family: var(--font-thai), var(--font);
}

.quiz-opt:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.quiz-opt.correct {
  border-color: var(--success);
  background: rgba(52, 211, 153, 0.12);
  color: var(--success);
}

.quiz-opt.incorrect {
  border-color: var(--error);
  background: rgba(248, 113, 113, 0.12);
  color: var(--error);
}

.quiz-opt:disabled { cursor: default; opacity: 0.85; }

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

.quiz-result .score {
  font-size: 3.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.quiz-result .msg {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 12px 0 24px;
}

/* ——— Practice hub ——— */
.practice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.practice-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.practice-tile:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.15);
  background: var(--bg-hover);
}

.practice-tile .emoji { font-size: 2rem; margin-bottom: 8px; }
.practice-tile h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; }
.practice-tile p { font-size: 0.75rem; color: var(--text-muted); }

/* ——— Progress ——— */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

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

.stat-card .num {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}

.stat-card .label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 4px;
}

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

.ach-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.ach-item.locked { opacity: 0.45; }
.ach-icon { font-size: 1.5rem; }
.ach-item h4 { font-size: 0.9rem; font-weight: 700; }
.ach-item p { font-size: 0.75rem; color: var(--text-muted); }

.reset-link {
  display: block;
  text-align: center;
  margin-top: 32px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.reset-link:hover { color: var(--error); }

/* ——— Empty / misc ——— */
.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 600px) {
  .alpha-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .card-th { font-size: 3.25rem; }
  .practice-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 380px) {
  .view-title { font-size: 1.45rem; }
  .stats-grid { grid-template-columns: 1fr 1fr 1fr; }
  .stat-card .num { font-size: 1.4rem; }
}

/* ——— Trilingual gloss rows ——— */
.gloss-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.95rem;
  margin-top: 6px;
  text-align: left;
  width: 100%;
  max-width: 320px;
  justify-content: center;
}
.gloss-row .tag-yue,
.gloss-row .tag-cmn {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px 6px;
  border-radius: 4px;
}
.tag-yue {
  background: rgba(78, 205, 196, 0.18);
  color: var(--teal);
}
.tag-cmn {
  background: rgba(167, 139, 250, 0.18);
  color: var(--purple);
}

.lang-switch {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  gap: 2px;
}
.lang-btn {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--text-muted);
  transition: all 0.15s;
}
.lang-btn.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.nav-btn .icon {
  font-family: var(--font-thai);
  font-size: 1.05rem;
  font-weight: 700;
}
