/* ============================================
   Thai Lessons V2 — DVC Dark Theme
   ============================================ */

:root {
  --bg-primary: #1a1a1a;
  --bg-card: #2a2a2a;
  --bg-card-hover: #333333;
  --bg-input: #222222;
  --accent: #c9a96e;
  --accent-dim: #a08450;
  --accent-glow: rgba(201, 169, 110, 0.15);
  --text-primary: #e0e0e0;
  --text-secondary: #999999;
  --text-muted: #666666;
  --text-thai: #ffffff;
  --green: #5cb85c;
  --green-dim: rgba(92, 184, 92, 0.15);
  --red: #d9534f;
  --red-dim: rgba(217, 83, 79, 0.15);
  --border: #3a3a3a;
  --nav-height: 64px;
  --header-height: 52px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.hidden { display: none !important; pointer-events: none !important; }
.screen { height: 100%; width: 100%; }

/* ============ LOADING SCREEN ============ */

#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============ AUTH SCREEN ============ */

#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
}

.auth-container {
  text-align: center;
  padding: 40px 24px;
  max-width: 340px;
  width: 100%;
}

.auth-logo { font-size: 64px; margin-bottom: 16px; }

.auth-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-family: 'Noto Sans Thai', sans-serif;
}

.auth-input-wrap { display: flex; gap: 8px; }

.auth-input-wrap input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-input-wrap input:focus { border-color: var(--accent); }

.auth-error {
  color: var(--red);
  font-size: 14px;
  margin-top: 12px;
  min-height: 20px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-form input {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus { border-color: var(--accent); }

.auth-swap {
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-secondary);
}

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

.auth-swap a:hover { text-decoration: underline; }

.header-logout {
  margin-left: 8px;
}

/* ============ BUTTONS ============ */

.btn-gold {
  padding: 12px 24px;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-gold:active { transform: scale(0.97); background: var(--accent-dim); }
.btn-gold:disabled { opacity: 0.4; cursor: default; transform: none; }

.btn-large {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 18px;
  border-radius: var(--radius);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 16px;
  transition: color 0.2s;
}

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

/* ============ HEADER ============ */

#app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}

#header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

/* ============ APP LAYOUT ============ */

#app {
  display: grid;
  grid-template-rows: var(--header-height) 1fr var(--nav-height);
  height: 100vh;
  height: 100svh;
  height: var(--app-height, 100svh);
  overflow: hidden;
}

#main-content {
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.view {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.view.active {
  display: flex;
  flex-direction: column;
  animation: viewFadeIn 0.15s ease-out;
}

@keyframes viewFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============ BOTTOM NAV ============ */

#bottom-nav {
  display: flex;
  height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 50;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  z-index: 51;
  min-height: 48px;
  touch-action: manipulation;
}

.nav-btn.active { color: var(--accent); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 500; }

/* ============ LESSONS VIEW ============ */

#view-lessons { flex-direction: column; }

.sidebar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.section-dropdown {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.section-nav { display: none; }

.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}

.welcome-card {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.welcome-card h2 { font-size: 20px; margin-bottom: 8px; }

/* ============ SECTION INTRO CARD ============ */

.section-intro {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.intro-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.intro-thai {
  font-size: 32px;
  color: var(--text-thai);
  font-weight: 500;
  line-height: 1.3;
}

.intro-english {
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 600;
}

.intro-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 16px;
}

.intro-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.intro-stat {
  font-size: 13px;
  color: var(--text-muted);
}

.intro-stat-sep {
  color: var(--text-muted);
  font-size: 13px;
}

.intro-progress-bar {
  flex: 1;
  min-width: 80px;
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
}

.intro-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.intro-pct {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

/* ============ GRAMMAR BLOCKS ============ */

.grammar-section {
  margin-bottom: 20px;
}

.grammar-block {
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.grammar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.grammar-header:active { background: var(--bg-card-hover); }

.grammar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
}

.grammar-chevron {
  font-size: 20px;
  color: var(--text-muted);
  transition: transform 0.25s ease;
  font-weight: 300;
}

.grammar-block.expanded .grammar-chevron {
  transform: rotate(90deg);
}

.grammar-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.grammar-block.expanded .grammar-body {
  max-height: 2000px;
}

.grammar-body > *:first-child {
  padding-top: 0;
}

.grammar-content {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 0 16px 12px;
}

.grammar-points {
  list-style: none;
  padding: 0 16px 12px;
}

.grammar-points li {
  padding: 8px 0;
  border-bottom: 1px solid rgba(58, 58, 58, 0.5);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grammar-points li:last-child { border-bottom: none; }

.gp-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
}

.gp-thai {
  font-size: 16px;
  color: var(--text-thai);
  opacity: 0.7;
}

.grammar-examples {
  padding: 0 16px 12px;
}

.grammar-example {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.ge-thai {
  font-size: 20px;
  color: var(--text-thai);
  font-weight: 500;
}

.ge-english {
  font-size: 13px;
  color: var(--text-secondary);
  flex: 1;
  min-width: 120px;
}

.grammar-tip {
  margin: 0 16px 16px;
  padding: 12px 14px;
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--accent);
  line-height: 1.5;
}

/* ============ VOCAB CARDS — INTERACTIVE ============ */

.vocab-section-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 16px 0 8px;
}

.category-divider {
  margin: 20px 0 12px;
  padding: 6px 12px;
  background: var(--accent-glow);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.vocab-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  transition: background 0.15s, border-color 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
  animation: fadeIn 0.2s ease-out;
}

.vocab-card:active { background: var(--bg-card-hover); }

.vocab-card.mastered {
  border-color: rgba(92, 184, 92, 0.3);
}

.vocab-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.vocab-thai {
  font-size: 28px;
  font-weight: 500;
  color: var(--text-thai);
  line-height: 1.3;
}

.vocab-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.vocab-romanization {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  margin-top: 2px;
  font-style: italic;
}

/* English hidden by default, revealed on tap */
.vocab-english-wrap {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  transition: max-height 0.3s ease, opacity 0.25s ease 0.05s, transform 0.25s ease 0.05s;
}

.vocab-card.revealed .vocab-english-wrap {
  max-height: 200px;
  opacity: 1;
  transform: translateY(0);
}

.vocab-english {
  font-size: 16px;
  color: var(--text-primary);
  line-height: 1.4;
  padding-top: 8px;
}

.vocab-example {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.vocab-notes {
  font-size: 12px;
  color: var(--accent-dim);
  margin-top: 4px;
}

.vocab-tap-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.vocab-card.revealed .vocab-tap-hint {
  display: none;
}

.vocab-mastered-badge {
  position: absolute;
  top: -4px;
  left: 12px;
  font-size: 11px;
  color: var(--green);
  background: var(--green-dim);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  pointer-events: none;
}

/* Speaker button */
.btn-speak {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  line-height: 1;
}

.btn-speak:active {
  background: var(--accent-glow);
  border-color: var(--accent);
}

.btn-speak-large {
  width: 44px;
  height: 44px;
  min-width: 44px;
  font-size: 20px;
}

.btn-speak-sm {
  width: 34px;
  height: 34px;
  min-width: 34px;
  font-size: 15px;
}

/* Favorite/bookmark button */
.btn-fav {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.btn-fav.active {
  color: var(--accent);
}

/* Section footer */
.section-footer {
  margin-top: 24px;
  padding: 20px 0;
  text-align: center;
}

.footer-progress {
  margin-bottom: 16px;
}

.footer-label {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============ SIDEBAR PROGRESS ============ */

.nav-item-label {
  display: block;
}

.nav-progress-bar {
  height: 3px;
  background: var(--bg-primary);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.nav-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.section-nav-item.completed .nav-item-label::after {
  content: ' ✓';
  color: var(--accent);
  font-size: 12px;
}

/* ============ QUIZ VIEW ============ */

.quiz-config {
  padding: 24px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.quiz-config h2 {
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 20px;
}

.config-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

.config-label:first-of-type { margin-top: 0; }

.chip-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.picker-chip {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.picker-chip.selected {
  background: rgba(201, 169, 110, 0.2);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.picker-chip:active { transform: scale(0.96); }

#quiz-start { margin-top: 24px; }

/* Quiz Player */
.quiz-player {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 16px;
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

#quiz-counter {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.quiz-timer-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s linear;
  width: 100%;
}

.timer-fill.urgent {
  background: var(--red);
}

#quiz-score {
  font-size: 14px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

/* Quiz question card */
.quiz-question {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  margin-bottom: 20px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.quiz-question .q-text {
  font-size: 36px;
  color: var(--text-thai);
  font-weight: 500;
  line-height: 1.3;
}

.quiz-question .q-text-en {
  font-size: 24px;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.4;
}

.quiz-question .q-romanization {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
}

.quiz-question .q-speak {
  margin-top: 12px;
}

/* Quiz answer buttons */
.quiz-answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.quiz-answer-btn {
  width: 100%;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  min-height: 52px;
}

.quiz-answer-btn:active { background: var(--bg-card-hover); }

.quiz-answer-btn.correct {
  border-color: var(--green);
  background: var(--green-dim);
  color: var(--green);
}

.quiz-answer-btn.wrong {
  border-color: var(--red);
  background: var(--red-dim);
  color: var(--red);
}

.quiz-answer-btn.disabled,
.quiz-answer-btn:disabled {
  pointer-events: none;
  opacity: 0.5;
}

.quiz-answer-btn.quiz-answer-thai {
  font-size: 22px;
  color: var(--text-thai);
}

/* Quiz feedback */
.quiz-feedback {
  text-align: center;
  padding: 16px;
  border-radius: var(--radius);
  margin-top: 12px;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}

.quiz-feedback.correct-fb {
  background: var(--green-dim);
  color: var(--green);
}

.quiz-feedback.wrong-fb {
  background: var(--red-dim);
  color: var(--red);
}

.quiz-feedback .fb-correct-answer {
  font-size: 20px;
  color: var(--text-thai);
  display: block;
  margin-top: 4px;
}

/* Typing quiz */
.quiz-typing {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-shrink: 0;
}

.quiz-typing input {
  flex: 1;
  padding: 14px 16px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.quiz-typing input:focus { border-color: var(--accent); }

/* Flashcard mode in quiz */
.quiz-flashcard-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-shrink: 0;
}

.btn-action {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  min-height: 48px;
}

.btn-action:active { transform: scale(0.96); }

.btn-miss {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(217, 83, 79, 0.3);
}

.btn-know {
  background: var(--green-dim);
  color: var(--green);
  border: 1px solid rgba(92, 184, 92, 0.3);
}

/* Quiz results */
.quiz-results {
  padding: 48px 24px 24px;
  text-align: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.quiz-results h2 {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 24px;
}

.result-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 32px;
}

.result-pct {
  font-size: 64px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.result-frac {
  font-size: 18px;
  color: var(--text-secondary);
}

.result-missed {
  text-align: left;
  margin-bottom: 24px;
}

.result-missed h3 {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.missed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.missed-item .mi-thai {
  font-size: 18px;
  color: var(--text-thai);
}

.missed-item .mi-english {
  font-size: 14px;
  color: var(--text-secondary);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============ SEARCH VIEW ============ */

.search-bar {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.search-bar input:focus { border-color: var(--accent); }

.search-bar .section-dropdown {
  width: auto;
  min-width: 100px;
  flex-shrink: 0;
}

#search-results { padding: 16px; }

.search-placeholder {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.search-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Search results cards should be revealed by default */
#search-results .vocab-card { cursor: default; }
#search-results .vocab-english-wrap {
  max-height: 200px;
  opacity: 1;
}
#search-results .vocab-tap-hint { display: none; }

/* ============ STATS VIEW ============ */

.stats-container {
  padding: 24px 16px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}

.stats-title {
  font-size: 22px;
  color: var(--accent);
  margin-bottom: 20px;
}

.stats-summary {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 90px;
}

.stat-big {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
}

.stat-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.stats-overall-bar {
  height: 8px;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.stats-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0;
}

.stats-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.stats-sections { }

.stats-section-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(58, 58, 58, 0.5);
}

.stats-section-row:last-child { border-bottom: none; }

.stats-sec-name {
  font-size: 13px;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-sec-bar {
  width: 80px;
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}

.stats-sec-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.stats-sec-pct {
  font-size: 13px;
  color: var(--text-muted);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ============ MOBILE TOUCH FIXES ============ */

/* Eliminate 300ms tap delay and prevent double-tap zoom on interactive elements */
button, select, input, a,
.vocab-card, .grammar-header, .quiz-flashcard,
.picker-chip, .nav-btn, .quiz-answer-btn,
.btn-speak, .btn-fav, .btn-action {
  touch-action: manipulation;
}

/* Ensure minimum 44px touch targets on mobile */
@media (max-width: 767px) {
  .picker-chip {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .btn-speak {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .btn-fav {
    width: 44px;
    height: 44px;
    min-width: 44px;
  }

  .btn-speak-sm {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .nav-btn {
    min-height: 48px;
  }

  .quiz-answer-btn {
    min-height: 52px;
  }

  .btn-action {
    min-height: 52px;
  }

  .section-dropdown {
    min-height: 44px;
  }
}

/* ============ DESKTOP ============ */

@media (min-width: 768px) {
  #view-lessons { flex-direction: row; }

  .sidebar {
    width: 280px;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding: 12px;
    overflow-y: auto;
    flex-shrink: 0;
  }

  .section-dropdown { display: none; }

  .section-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .section-nav-item {
    display: block;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    border: none;
    background: none;
    text-align: left;
    width: 100%;
    line-height: 1.3;
  }

  .section-nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
  .section-nav-item.active { background: var(--accent-glow); color: var(--accent); }

  .section-nav-part {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 16px 12px 6px;
  }

  .section-nav-part:first-child { padding-top: 8px; }

  .quiz-config, .quiz-results {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
  }

  .quiz-player {
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
  }

  .search-bar {
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
    padding: 16px;
  }

  .stats-container {
    max-width: 600px;
    margin: 0 auto;
  }

  .quiz-question .q-text { font-size: 48px; }
  .vocab-thai { font-size: 32px; }
}

/* ============ ANIMATIONS ============ */

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


/* ============ QUIZ FLASHCARD ============ */

.quiz-flashcard {
  cursor: pointer;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-fc-inner {
  width: 100%;
  position: relative;
}

.quiz-fc-front,
.quiz-fc-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.quiz-fc-back {
  display: none;
}

.quiz-flashcard.flipped .quiz-fc-front {
  display: none;
}

.quiz-flashcard.flipped .quiz-fc-back {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}

/* ============ QUIZ LISTENING ============ */

.quiz-listening-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.quiz-listening-hint {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
}

/* ============ QUIZ TYPING RESULTS ============ */

.quiz-typing-result {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.quiz-typing-result.correct {
  background: var(--green-dim);
  color: var(--green);
}

.quiz-typing-result.wrong {
  background: var(--red-dim);
  color: var(--red);
}

.quiz-typing-correct {
  font-size: 15px;
  color: var(--text-secondary);
  padding: 8px 16px;
}

.quiz-typing-correct strong {
  color: var(--text-thai);
  font-size: 20px;
}

/* ============ QUIZ ANSWER NUMBER ============ */

.quiz-answer-num {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  margin-right: 8px;
  flex-shrink: 0;
}

/* ============ SECTION COMPLETION CELEBRATION ============ */

.section-intro.completed {
  animation: completionGlow 1s ease-out;
  border-color: var(--accent);
}

@keyframes completionGlow {
  0% { box-shadow: 0 0 0 0 rgba(201, 169, 110, 0.4); }
  50% { box-shadow: 0 0 20px 4px rgba(201, 169, 110, 0.3); }
  100% { box-shadow: 0 0 0 0 rgba(201, 169, 110, 0); }
}

/* ============ SEARCH MOBILE STACKING ============ */

@media (max-width: 767px) {
  .search-bar {
    flex-direction: column;
    gap: 8px;
  }
  .search-bar .section-dropdown {
    width: 100%;
  }
}

/* ============ ADDITIONAL ACTIVE STATES ============ */

.nav-btn:active { opacity: 0.7; }
.btn-text:active { opacity: 0.7; }
.btn-fav:active { transform: scale(0.9); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ QUIZ UPGRADES ============ */

/* B1: Slide transition */
.quiz-slide-in {
  animation: quizSlideIn 0.3s ease-out;
}

@keyframes quizSlideIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* B2: Progress bar */
.quiz-progress {
  height: 3px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.quiz-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0;
}

/* B3: Skip button */
.btn-skip {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}

.btn-skip:hover { color: var(--text-secondary); border-color: var(--text-muted); }
.btn-skip:active { transform: scale(0.96); }

/* B4: Sound toggle */
.btn-sound {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.btn-sound:hover { opacity: 1; }

/* B5: Section picker part headers */
.picker-part-header {
  width: 100%;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 4px;
  flex-basis: 100%;
}

.picker-part-header:first-of-type {
  padding-top: 4px;
}

/* B5: Disabled direction picker for listening */
.disabled-picker {
  opacity: 0.4;
  pointer-events: none;
}

/* B5: Config note */
.config-note {
  font-size: 12px;
  color: var(--accent-dim);
  font-style: italic;
  margin-top: 4px;
}

/* B6: Config summary on results */
.result-config {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* C2: Streak on results */
.result-streak {
  font-size: 15px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 24px;
}

/* C3: Mastery ratio on missed items */
.mi-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.mi-ratio {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================
   LEARN MODE — Structured Lessons V3
   ============================================ */

/* ============ LEARN VIEW CONTAINER ============ */

#view-learn {
  flex-direction: column;
}

/* ============ LESSON LIST ============ */

.learn-list {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.learn-list-header {
  text-align: center;
  margin-bottom: 20px;
}

.learn-list-title {
  font-size: 22px;
  color: var(--accent);
  font-weight: 700;
}

.learn-list-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.lesson-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 2px solid transparent;
}

.lesson-card:active {
  transform: scale(0.98);
}

.lesson-card.current {
  border-color: var(--accent);
}

.lesson-card.locked {
  opacity: 0.4;
  cursor: default;
}

.lesson-card.locked:active {
  transform: none;
}

.lesson-card.completed {
  border-left: 4px solid var(--green);
}

.lesson-icon {
  font-size: 32px;
  width: 48px;
  text-align: center;
  flex-shrink: 0;
}

.lesson-info {
  flex: 1;
  min-width: 0;
}

.lesson-number {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.lesson-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 2px 0;
}

.lesson-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Progress ring */
.lesson-progress-ring {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.progress-ring-circle {
  transition: stroke-dashoffset 0.3s;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

/* Completed check mark */
.lesson-check-mark {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--green);
  background: var(--green-dim);
  border-radius: 50%;
  font-weight: 700;
}

/* Toast message for locked lessons */
.learn-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.learn-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ LESSON CONTENT VIEW ============ */

.learn-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.learn-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.btn-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-back:active {
  opacity: 0.7;
}

.progress-dots {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #444;
  transition: all 0.3s;
}

.progress-dot.active {
  background: var(--accent);
  width: 16px;
  border-radius: 8px;
}

.progress-dot.done {
  background: var(--accent);
}

.section-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.learn-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

/* ============ CULTURE CARD ============ */

.learn-culture {
  background: linear-gradient(135deg, var(--bg-card), #1f1f1f);
  border: 1px solid rgba(201, 169, 110, 0.25);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
}

.learn-culture-title {
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 12px;
}

.learn-culture-content {
  color: var(--text-primary);
  line-height: 1.7;
  font-size: 15px;
}

.learn-tip {
  background: rgba(201, 169, 110, 0.08);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin-top: 16px;
  border-radius: 0 8px 8px 0;
  font-size: 14px;
  color: #ccc;
  line-height: 1.5;
}

/* ============ TEACH SECTION ============ */

.learn-teach {
  margin-bottom: 24px;
}

.learn-teach-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.teach-item {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.3s;
}

.teach-item:active {
  transform: scale(0.99);
}

.teach-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.teach-text-col {
  flex: 1;
  min-width: 0;
}

.teach-item .teach-thai {
  font-size: 28px;
  color: var(--text-primary);
}

.teach-item .teach-roman {
  font-size: 14px;
  color: var(--accent);
  margin-top: 4px;
}

.teach-item .teach-english {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 8px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.3s;
}

.teach-item.revealed .teach-english {
  opacity: 1;
  max-height: 120px;
}

.teach-item .teach-note {
  font-size: 13px;
  color: #888;
  font-style: italic;
  margin-top: 4px;
}

.teach-item .teach-tap-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  opacity: 0.6;
}

.teach-item.revealed .teach-tap-hint {
  display: none;
}

/* ============ DIALOGUE ============ */

.learn-dialogue {
  margin-bottom: 24px;
}

.dialogue-context {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 14px;
  margin-bottom: 16px;
}

.dialogue-line {
  display: flex;
  margin-bottom: 12px;
}

.dialogue-line.left {
  justify-content: flex-start;
}

.dialogue-line.right {
  justify-content: flex-end;
}

.dialogue-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  position: relative;
}

.dialogue-line.left .dialogue-bubble {
  background: #333;
  border-bottom-left-radius: 4px;
}

.dialogue-line.right .dialogue-bubble {
  background: rgba(201, 169, 110, 0.12);
  border: 1px solid rgba(201, 169, 110, 0.25);
  border-bottom-right-radius: 4px;
}

.dialogue-speaker {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dialogue-thai {
  font-size: 20px;
  color: var(--text-primary);
}

.dialogue-roman {
  font-size: 13px;
  color: var(--accent);
  margin-top: 2px;
}

.dialogue-english {
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.dialogue-speak {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* ============ PRACTICE EXERCISES ============ */

.learn-practice {
  margin-bottom: 24px;
}

.practice-counter {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.practice-question {
  font-size: 18px;
  color: var(--text-primary);
  margin-bottom: 16px;
  text-align: center;
}

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

.practice-option {
  background: var(--bg-card);
  border: 1px solid #444;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 18px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.practice-option:active {
  transform: scale(0.98);
}

.practice-option.correct {
  background: rgba(76, 175, 80, 0.2);
  border-color: #4caf50;
  color: #4caf50;
}

.practice-option.wrong {
  background: rgba(244, 67, 54, 0.2);
  border-color: #f44336;
  color: #f44336;
}

.practice-option[disabled] {
  pointer-events: none;
}

.practice-score-card {
  text-align: center;
  padding: 24px;
  margin-bottom: 16px;
}

.practice-score-pct {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.practice-score-frac {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ============ SUMMARY ============ */

.learn-summary {
  text-align: center;
  padding: 24px 0;
}

.summary-celebration {
  font-size: 48px;
  margin-bottom: 8px;
}

.summary-title {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}

.summary-learned {
  text-align: left;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  margin: 16px 0;
}

.summary-learned h4 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 15px;
}

.summary-learned li {
  color: #ccc;
  padding: 4px 0;
  font-size: 15px;
  list-style: none;
}

.summary-learned li::before {
  content: "\2713 ";
  color: var(--green);
}

.summary-cultural {
  color: var(--text-secondary);
  font-style: italic;
  margin: 12px 0;
  font-size: 15px;
}

.summary-score {
  font-size: 20px;
  color: var(--text-primary);
  margin: 16px 0;
}

/* ============ CONTINUE BUTTON ============ */

.btn-continue {
  display: block;
  width: 100%;
  max-width: 400px;
  margin: 24px auto 0;
  background: linear-gradient(135deg, #c9a96e, #b8944f);
  color: #1a1a1a;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn-continue:active {
  transform: scale(0.97);
}

/* ============ LEARN SECTION ANIMATION ============ */

.learn-section-enter {
  animation: learnSlideIn 0.3s ease-out;
}

@keyframes learnSlideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============ LEARN MODE MOBILE FIXES ============ */

.learn-speak-btn {
  touch-action: manipulation;
}

.practice-option,
.btn-continue,
.lesson-card,
.btn-back,
.btn-play-all,
.btn-next-lesson,
.btn-back-to-list {
  touch-action: manipulation;
}

/* ============ LEARN MODE DESKTOP ============ */

@media (min-width: 768px) {
  .learn-list {
    max-width: 600px;
    margin: 0 auto;
  }

  .learn-body {
    max-width: 600px;
  }
}

/* User picker overlay */
.user-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.user-row { display: flex; gap: 8px; align-items: center; }
.user-select-btn { flex: 1; }
.user-delete-btn { padding: 8px 12px; opacity: 0.5; }
.user-delete-btn:hover { opacity: 1; color: var(--red); }

/* Header locale switcher */
.header-lang, .header-user { background: transparent; border: 1px solid currentColor; padding: 4px 10px; border-radius: 999px; font-size: 13px; opacity: 0.85; margin-left: 6px; cursor: pointer; }
.header-lang:hover, .header-user:hover { opacity: 1; }
#header-right { display: flex; align-items: center; }

/* Target-language font (set at runtime by I18N from meta.font_family) */
.vocab-thai, .teach-thai, .dialogue-thai, .gp-thai, .ge-thai, .mi-thai, .q-text, .quiz-answer-thai {
  font-family: var(--lang-font, 'Noto Sans Thai', Inter, system-ui, sans-serif);
}

/* ============================================
   GAMIFICATION — XP, streak, achievements, calendar, goal ring
   ============================================ */

:root {
  --xp-gold: var(--accent);
  --xp-gold-dim: var(--accent-dim);
  --flame: #ff7a18;
}

/* Top-bar pills */
#gamify-bar { display: flex; align-items: center; gap: 6px; margin-right: 4px; }
.gm-pill {
  background: transparent; border: 1px solid var(--border); color: var(--text-primary);
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.gm-pill:hover { border-color: var(--accent); }
.gm-streak .gm-flame { filter: grayscale(1); opacity: .6; }
.gm-streak.gm-streak-active .gm-flame { filter: none; opacity: 1; }
.gm-xp { color: var(--xp-gold); border-color: var(--xp-gold-dim); }
.gm-xp .gm-level { background: var(--accent-glow); color: var(--xp-gold); padding: 1px 6px; border-radius: 999px; font-size: 11px; }
.gm-ring-btn { padding: 2px 4px 2px 6px; }
.gm-ring-mini { display: block; }

/* Home (Learn) ring hero */
.gm-home-ring {
  display: flex; align-items: center; gap: 20px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 12px 4px 12px;
}
.gm-ring-wrap { position: relative; width: 108px; height: 108px; flex-shrink: 0; }
.gm-ring-svg { display: block; }
.gm-ring-fill { transition: stroke-dashoffset .6s cubic-bezier(.2,.9,.2,1); }
#gm-ring-fill, #gm-ring-mini-fill { transition: stroke-dashoffset .6s cubic-bezier(.2,.9,.2,1); }
.gm-ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.gm-ring-today { font-size: 28px; font-weight: 700; color: var(--xp-gold); line-height: 1; }
.gm-ring-goal { font-size: 11px; color: var(--text-secondary); }
.gm-ring-side { display: flex; flex-direction: column; gap: 8px; }
.gm-ring-stat { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.gm-ring-stat b { font-size: 20px; color: var(--text-primary); }
.gm-flame { filter: drop-shadow(0 0 4px rgba(255,122,24,0.45)); }
.gm-btn-text {
  background: transparent; border: none; color: var(--text-secondary);
  font-size: 13px; padding: 4px 0; text-align: left; cursor: pointer;
}
.gm-btn-text:hover { color: var(--accent); }
.gm-muted { color: var(--text-secondary); font-size: 12px; }

/* Pages (achievements, settings) */
.gm-page { padding: 18px 16px 32px; max-width: 640px; margin: 0 auto; }
.gm-page-title { font-size: 20px; font-weight: 700; color: var(--accent); margin-bottom: 16px; }
.gm-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.gm-card h3 { font-size: 15px; margin-bottom: 6px; color: var(--text-primary); }

/* Level banner */
.gm-level-banner {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto;
  gap: 4px 10px; align-items: center;
  background: linear-gradient(135deg, var(--bg-card), var(--bg-card-hover));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px;
}
.gm-level-label { font-size: 11px; text-transform: uppercase; color: var(--text-secondary); letter-spacing: 1px; grid-row: 1; }
.gm-level-big {
  font-size: 34px; font-weight: 700; color: var(--xp-gold);
  grid-column: 1; grid-row: 2; line-height: 1;
}
.gm-level-bar {
  grid-column: 2; grid-row: 2; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
  align-self: center;
}
.gm-level-bar-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 4px; transition: width .5s;
}
.gm-level-xp { grid-column: 3; grid-row: 2; font-size: 12px; color: var(--text-secondary); }

/* Achievements grid */
.gm-ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.gm-ach {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; display: flex; gap: 12px; align-items: flex-start;
  transition: border-color .15s, transform .15s;
}
.gm-ach.unlocked { border-color: var(--xp-gold-dim); background: linear-gradient(135deg, var(--bg-card), rgba(201,169,110,0.08)); }
.gm-ach.locked { opacity: .65; }
.gm-ach.locked .gm-ach-emoji { filter: grayscale(1); }
.gm-ach-emoji { font-size: 28px; flex-shrink: 0; }
.gm-ach-body { flex: 1; min-width: 0; }
.gm-ach-name { font-weight: 600; color: var(--text-primary); font-size: 14px; }
.gm-ach-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.gm-ach-unlocked-tag { font-size: 11px; color: var(--xp-gold); margin-top: 4px; font-weight: 600; }
.gm-ach-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.gm-ach-bar-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .4s; }
.gm-ach-progress { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Goal picker */
.gm-goal-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.gm-goal-chip {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.gm-goal-chip:hover { border-color: var(--accent); }
.gm-goal-chip.selected { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }
.gm-saved { margin-top: 8px; min-height: 16px; }

/* Calendar modal */
.gm-modal {
  position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: gmFade .15s ease-out;
}
@keyframes gmFade { from { opacity: 0; } to { opacity: 1; } }
.gm-modal.hidden { display: none; }
.gm-modal-inner {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 18px 22px; width: 100%; max-width: 420px; position: relative;
}
.gm-modal-close {
  position: absolute; top: 8px; right: 10px; background: transparent; border: none;
  color: var(--text-secondary); font-size: 28px; cursor: pointer; line-height: 1;
}
.gm-modal-close:hover { color: var(--accent); }
.gm-cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.gm-cal-header h3 { font-size: 16px; color: var(--text-primary); }
.gm-cal-header .gm-btn-text { font-size: 20px; padding: 4px 10px; color: var(--accent); }
.gm-cal-streak {
  display: flex; align-items: center; gap: 6px; margin-bottom: 12px;
  padding: 8px 10px; background: var(--bg-input); border-radius: 8px;
}
.gm-cal-streak b { font-size: 18px; color: var(--text-primary); }
.gm-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.gm-cal-dow {
  text-align: center; font-size: 10px; color: var(--text-secondary);
  text-transform: uppercase; padding: 4px 0;
}
.gm-cal-blank { aspect-ratio: 1; }
.gm-cal-day {
  aspect-ratio: 1; border-radius: 6px; background: var(--bg-input);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-primary); position: relative; overflow: hidden;
  border: 1px solid var(--border);
}
.gm-cal-day.practiced { border-color: transparent; }
.gm-cal-day-num { font-weight: 600; }
.gm-cal-day-flame { font-size: 10px; line-height: 1; }

/* Toasts */
.gm-toast-container {
  position: fixed; top: 14px; right: 14px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.gm-toast {
  background: var(--bg-card); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  opacity: 0; transform: translateY(-6px);
  transition: opacity .25s, transform .25s;
  min-width: 240px; max-width: 320px;
  pointer-events: auto;
}
.gm-toast.show { opacity: 1; transform: translateY(0); }
.gm-toast-emoji { font-size: 24px; }
.gm-toast-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); font-weight: 700; }
.gm-toast-desc { font-size: 14px; color: var(--text-primary); font-weight: 600; margin-top: 2px; }

/* Confetti burst for daily goal hit */
.gm-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; }
.gm-confetti span {
  position: absolute; top: 40%; left: 50%;
  width: 8px; height: 14px; border-radius: 2px;
  animation: gmConfetti 1.6s cubic-bezier(.2,.6,.4,1) forwards;
  transform: rotate(var(--r));
}
@keyframes gmConfetti {
  0% { opacity: 1; transform: translate(0,0) rotate(var(--r)); }
  100% { opacity: 0; transform: translate(calc(var(--x) * 220px), calc(var(--y) * 340px + 200px)) rotate(720deg); }
}

/* XP earned on quiz results */
.xp-earned {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 0 6px; opacity: 0; transform: translateY(6px);
  transition: opacity .35s, transform .35s;
}
.xp-earned.show { opacity: 1; transform: translateY(0); }
.xp-earned .xp-amt {
  font-size: 26px; font-weight: 700; color: var(--xp-gold);
  text-shadow: 0 0 12px var(--accent-glow);
}
.xp-earned .xp-bonus { font-size: 12px; color: var(--text-secondary); }

/* ============ REVIEW (SRS) ============ */
.nav-btn { position: relative; }
.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  background: var(--accent, #d4af37);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
  line-height: 1.2;
}
.nav-badge.hidden { display: none; }

.review-container {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.review-header { text-align: center; }
.review-title { font-size: 22px; margin: 0 0 4px; }
.review-stats-line { font-size: 13px; color: var(--text-muted); margin: 0; }

.review-card-wrap { display: flex; flex-direction: column; gap: 16px; }
.review-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 24px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.review-front { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.review-back { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; border-top: 1px solid var(--border); padding-top: 16px; }
.review-back.hidden { display: none; }
.review-target { font-size: 32px; font-weight: 600; font-family: var(--lang-font, inherit); }
.review-roman { font-size: 15px; color: var(--text-muted); font-style: italic; }
.review-english { font-size: 22px; font-weight: 500; }
.review-example { font-size: 14px; color: var(--text-secondary); margin-top: 8px; }
.review-ex-target { font-family: var(--lang-font, inherit); }
.review-ex-english { color: var(--text-muted); font-style: italic; margin-top: 4px; }

.review-rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.review-rate.hidden { display: none; }
.review-rate-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.review-rate-btn:active { transform: translateY(1px); }
.review-rate-btn[data-quality="1"] { border-color: #c62828; color: #ef5350; }
.review-rate-btn[data-quality="3"] { border-color: #ef6c00; color: #ffb74d; }
.review-rate-btn[data-quality="4"] { border-color: #2e7d32; color: #81c784; }
.review-rate-btn[data-quality="5"] { border-color: #1565c0; color: #64b5f6; }
.review-rate-btn small { font-size: 10px; font-weight: 400; color: var(--text-muted); }

.review-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.review-empty.hidden { display: none; }
.review-empty-icon { font-size: 48px; margin-bottom: 12px; }
.review-empty h3 { margin: 0 0 8px; }
.review-empty-next { color: var(--text-muted); font-size: 14px; }

#view-review { flex-direction: column; overflow-y: auto; }
