/* ============================================
   Obby Language School — Bright Theme
   Single source of truth for tokens + components.
   Per-locale accent overridden at runtime by I18N.boot via --accent.
   ============================================ */

:root {
  /* Palette */
  --bg-primary: #fff8eb;
  --bg-card: #ffffff;
  --bg-card-hover: #fffaf0;
  --bg-input: #ffffff;
  --bg-soft: #fff3d6;
  --accent: #0e7c7b;
  --accent-dim: #0a5957;
  --accent-glow: rgba(14, 124, 123, 0.15);
  --accent-soft: rgba(14, 124, 123, 0.08);
  --sun: #ffc857;
  --sun-dim: #e8b340;
  --sun-soft: rgba(255, 200, 87, 0.18);
  --text-primary: #1a2a3a;
  --text-secondary: #54657a;
  --text-muted: #8a99ad;
  --text-thai: #1a2a3a;
  --green: #7cd6a8;
  --green-strong: #4cb87f;
  --green-dim: rgba(124, 214, 168, 0.20);
  --red: #ef6f6c;
  --red-strong: #d94f4c;
  --red-dim: rgba(239, 111, 108, 0.18);
  --border: #ecdfc4;
  --border-strong: #d8c7a3;
  --shadow-sm: 0 1px 3px rgba(26, 42, 58, 0.06), 0 1px 2px rgba(26, 42, 58, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 42, 58, 0.08), 0 2px 4px rgba(26, 42, 58, 0.04);
  --shadow-lg: 0 10px 24px rgba(26, 42, 58, 0.10), 0 4px 8px rgba(26, 42, 58, 0.04);
  --shadow-glow: 0 0 0 4px var(--accent-glow);

  /* Layout */
  --nav-height: 72px;
  --header-height: 60px;
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 24px;
  --radius-pill: 999px;

  /* Type */
  --font-display: 'Fredoka', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --lang-font: var(--font-body);
}

/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
*:focus { outline: none; }
*:focus-visible { outline: 3px solid var(--accent-glow); outline-offset: 2px; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }

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

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

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

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

.loading-text {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 16px;
}

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

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

.auth-container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 24px;
  background: var(--bg-primary);
}

.auth-logo {
  font-size: 64px;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 12px rgba(26, 42, 58, 0.10));
  animation: bounce-in 600ms cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes bounce-in {
  0%   { transform: scale(.5); opacity: 0; }
  60%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); }
}

.auth-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 15px;
  text-align: center;
  max-width: 320px;
  margin-bottom: 12px;
}

.auth-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.auth-input-wrap input {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 150ms, box-shadow 150ms;
}

.auth-input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.auth-error {
  color: var(--red-strong);
  font-size: 13px;
  text-align: center;
  min-height: 16px;
  margin-top: 6px;
}

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

.btn-gold,
.btn-primary {
  background: var(--accent);
  color: #ffffff;
  padding: 12px 22px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-display);
  letter-spacing: 0.2px;
  box-shadow: var(--shadow-md);
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms;
}

.btn-gold:hover,
.btn-primary:hover { background: var(--accent-dim); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-gold:active,
.btn-primary:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn-gold:disabled,
.btn-primary:disabled { background: var(--border-strong); color: #fff; cursor: not-allowed; transform: none; box-shadow: none; opacity: 0.7; }

.btn-large { font-size: 17px; padding: 14px 26px; }

.btn-text {
  background: transparent;
  color: var(--accent);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  transition: background 120ms;
}
.btn-text:hover { background: var(--accent-soft); }

.btn-back {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: background 120ms, color 120ms;
}
.btn-back:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.btn-skip,
.btn-sound {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  border: 1px solid var(--border);
}
.btn-skip:hover, .btn-sound:hover { background: var(--bg-card-hover); }

.btn-action {
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-display);
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: transform 100ms, background 120ms, border-color 120ms;
}
.btn-action:hover { transform: translateY(-1px); }
.btn-know { border-color: var(--green-strong); color: var(--green-strong); }
.btn-know:hover { background: var(--green-dim); }
.btn-miss { border-color: var(--red-strong); color: var(--red-strong); }
.btn-miss:hover { background: var(--red-dim); }

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

#app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

#header-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.1px;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-user,
.header-lang,
.header-base {
  background: var(--bg-soft);
  color: var(--text-primary);
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  transition: background 120ms;
}
.header-user:hover, .header-lang:hover, .header-base:hover { background: var(--sun-soft); border-color: var(--sun-dim); }

.header-base-select {
  background: var(--bg-soft);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  border: 1px solid var(--border);
  font-family: var(--font-body);
  cursor: pointer;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary);
}

.content-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + 16px);
}

.view {
  padding: 18px 16px 24px;
  max-width: 720px;
  margin: 0 auto;
}

.view:not(.active) { display: none; }

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

#app-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 90;
  box-shadow: 0 -4px 16px rgba(26, 42, 58, 0.04);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  position: relative;
  transition: color 120ms, background 120ms;
}

.nav-btn .nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-btn .nav-label {
  font-size: 11px;
  font-family: var(--font-display);
  font-weight: 500;
}

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

.nav-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  background: var(--red-strong);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  min-width: 18px;
  text-align: center;
}

/* ============ WELCOME / LEARN ============ */

.welcome-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px 24px 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  text-align: center;
  background-image: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-soft) 100%);
  position: relative;
}

.welcome-card::before {
  content: '';
  display: block;
  width: 96px;
  height: 96px;
  margin: 0 auto 8px;
  background-image: url('/assets/mascot/obby.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 4px 10px rgba(26, 42, 58, 0.12));
}

.welcome-card h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

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

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

.section-dropdown {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 15px;
  color: var(--text-primary);
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath fill='%2354657a' d='M3 5l4 4 4-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
  box-shadow: var(--shadow-sm);
}

.section-count {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
  margin-left: 6px;
}

.learn-list,
.learn-content,
.learn-body,
.learn-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.learn-header {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.learn-list {
  gap: 10px;
}

.learn-list .lesson-item,
.learn-list > * {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 120ms, box-shadow 120ms;
  cursor: pointer;
}
.learn-list .lesson-item:hover,
.learn-list > *:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

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

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.search-bar input,
#search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 15px;
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.search-bar input:focus,
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-placeholder {
  color: var(--text-muted);
  text-align: center;
  padding: 32px 16px;
  font-size: 14px;
}

#search-filter {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

/* ============ QUIZ CONFIG ============ */

#view-quiz { padding-top: 6px; }

.quiz-config {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 16px;
}

.config-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 6px;
  display: block;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  opacity: 0.7;
}

.config-note {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.chip-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.picker-part-header {
  width: 100%;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
  margin-bottom: 2px;
  padding-left: 4px;
}

.picker-chip {
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  border: 2px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-display);
  cursor: pointer;
  transition: transform 100ms, background 120ms, border-color 120ms, color 120ms, box-shadow 120ms;
  box-shadow: var(--shadow-sm);
}

.picker-chip:hover { transform: translateY(-1px); border-color: var(--accent); }

.picker-chip.selected {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-glow);
}

.disabled-picker { opacity: 0.45; pointer-events: none; }

#quiz-start {
  margin-top: 14px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-display);
  box-shadow: var(--shadow-md);
  transition: transform 120ms, box-shadow 120ms, background 120ms;
}
#quiz-start:hover:not(:disabled) { background: var(--accent-dim); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
#quiz-start:disabled { background: var(--border-strong); color: #fff; cursor: not-allowed; opacity: 0.6; box-shadow: none; }

/* ============ QUIZ PLAYER ============ */

.quiz-player {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-display);
}

#quiz-counter {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 14px;
}

#quiz-score {
  font-weight: 700;
  color: var(--accent);
  font-size: 15px;
}

.quiz-topup-notice {
  background: var(--sun-soft);
  color: var(--text-primary);
  border: 1px solid var(--sun-dim);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.quiz-progress,
.quiz-timer-bar {
  height: 8px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
  position: relative;
}

.quiz-progress-fill,
.timer-fill,
#quiz-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dim));
  border-radius: var(--radius-pill);
  transition: width 250ms ease;
}

.timer-fill.urgent,
#quiz-timer-fill.urgent {
  background: linear-gradient(90deg, var(--red), var(--red-strong));
}

.quiz-question {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.q-text {
  font-family: var(--lang-font);
  font-size: 36px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.q-text-en {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
}

.q-romanization {
  color: var(--text-secondary);
  font-size: 16px;
  font-style: italic;
  font-weight: 400;
}

.q-speak { margin-top: 8px; }

.btn-speak {
  background: var(--accent-soft);
  color: var(--accent);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 120ms, transform 100ms;
}
.btn-speak:hover { background: var(--accent); color: #fff; }
.btn-speak:active { transform: scale(0.95); }

.btn-speak-large { width: 88px; height: 88px; font-size: 36px; box-shadow: var(--shadow-md); }

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

.quiz-answer-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 16px;
  font-family: var(--font-body);
  color: var(--text-primary);
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 100ms, border-color 120ms, background 120ms, box-shadow 120ms;
  box-shadow: var(--shadow-sm);
}
.quiz-answer-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}
.quiz-answer-btn:disabled { cursor: default; opacity: 0.85; }

.quiz-answer-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-display);
  flex-shrink: 0;
}

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

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

.quiz-answer-thai .quiz-answer-num,
.quiz-answer-thai {
  font-family: var(--lang-font);
  font-size: 18px;
}

.quiz-feedback {
  position: fixed;
  bottom: calc(var(--nav-height) + 24px);
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 24px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  z-index: 80;
  box-shadow: var(--shadow-lg);
  animation: feedback-pop 200ms cubic-bezier(.34, 1.56, .64, 1);
}
.quiz-feedback.correct-fb { background: var(--green-strong); color: #fff; }
.quiz-feedback.wrong-fb { background: var(--red-strong); color: #fff; display: flex; flex-direction: column; gap: 4px; align-items: center; }
.fb-correct-answer { font-weight: 500; font-size: 14px; opacity: 0.95; }

@keyframes feedback-pop {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to   { transform: translate(-50%, 0);    opacity: 1; }
}

.quiz-typing input,
#quiz-type-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 18px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--lang-font);
}
.quiz-typing input:focus,
#quiz-type-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#quiz-type-submit {
  margin-top: 10px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-family: var(--font-display);
  box-shadow: var(--shadow-md);
}
#quiz-type-submit:hover { background: var(--accent-dim); }

.quiz-typing-result {
  padding: 14px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 600;
  text-align: center;
}
.quiz-typing-result.correct { background: var(--green-dim); color: var(--green-strong); }
.quiz-typing-result.wrong { background: var(--red-dim); color: var(--red-strong); }
.quiz-typing-correct { padding: 10px 14px; color: var(--text-secondary); text-align: center; font-size: 14px; }
.quiz-typing-correct strong { color: var(--text-primary); font-weight: 600; }

.quiz-listening-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
}
.quiz-listening-hint { color: var(--text-secondary); font-size: 14px; }

/* Flashcard */
.quiz-flashcard {
  perspective: 1000px;
  height: 200px;
  cursor: pointer;
  margin-bottom: 12px;
}
.quiz-fc-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 500ms cubic-bezier(.34, 1.2, .64, 1);
  transform-style: preserve-3d;
}
.quiz-flashcard.flipped .quiz-fc-inner { transform: rotateY(180deg); }
.quiz-fc-front, .quiz-fc-back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  backface-visibility: hidden;
  padding: 20px;
}
.quiz-fc-back {
  transform: rotateY(180deg);
  background: var(--bg-soft);
}

.quiz-flashcard-actions {
  display: flex;
  gap: 12px;
  margin-top: 12px;
}
.quiz-flashcard-actions .btn-action { flex: 1; }

.quiz-slide-in {
  animation: slide-in 280ms cubic-bezier(.34, 1.2, .64, 1);
}
@keyframes slide-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

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

.quiz-results { text-align: center; padding: 16px; }

#quiz-result-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.result-score {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  background-image: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-soft) 100%);
}

.result-pct, #result-percentage {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  color: var(--accent);
  display: block;
  line-height: 1;
}

.result-frac, #result-fraction {
  color: var(--text-secondary);
  font-size: 16px;
  margin-top: 6px;
  font-weight: 500;
}

.result-config, #result-config {
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font-body);
  margin-top: 14px;
  font-style: italic;
}

.result-streak, #result-streak {
  display: inline-block;
  background: var(--sun-soft);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  font-weight: 600;
  font-family: var(--font-display);
  font-size: 14px;
  border: 1px solid var(--sun-dim);
  margin-top: 12px;
}

.xp-earned {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 12px 6px 0;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--sun) 0%, var(--sun-dim) 100%);
  color: var(--text-primary);
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 700;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 240ms, transform 240ms;
  box-shadow: var(--shadow-md);
}
.xp-earned.show { opacity: 1; transform: scale(1); }
.xp-amt { font-size: 18px; }
.xp-bonus { font-size: 11px; font-weight: 500; opacity: 0.85; }

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}
.result-actions button { flex: 1; max-width: 200px; }

.result-missed {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
  border: 1px solid var(--border);
  text-align: left;
  box-shadow: var(--shadow-sm);
}

.result-missed h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.missed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  gap: 12px;
}
.missed-item:last-child { border-bottom: none; }
.mi-thai {
  font-family: var(--lang-font);
  font-size: 18px;
  color: var(--text-primary);
  font-weight: 500;
}
.mi-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mi-english { color: var(--text-secondary); font-size: 14px; }
.mi-ratio {
  background: var(--bg-soft);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-family: var(--font-display);
  font-weight: 600;
}

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

.stats-container { display: flex; flex-direction: column; gap: 16px; }

.stats-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

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

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

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

.stats-overall-bar {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.stats-bar-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.stats-bar-fill {
  height: 12px;
  background: var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.stats-bar-fill > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dim));
  border-radius: var(--radius-pill);
  transition: width 400ms ease;
}

.stats-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.stats-sections {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.progress-dots {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.progress-dots > div {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.progress-dots > div.done { background: var(--accent); }

/* ============ REVIEW ============ */

.review-container { display: flex; flex-direction: column; gap: 14px; }

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.review-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.review-stats-line {
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  margin-bottom: 8px;
}

.review-card-wrap { perspective: 1000px; }

.review-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  min-height: 180px;
  cursor: pointer;
  transition: transform 200ms;
}
.review-card:hover { transform: translateY(-2px); }

.review-front {
  font-family: var(--lang-font);
  font-size: 32px;
  color: var(--text-primary);
  font-weight: 600;
}

.review-rate {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.review-rate-btn {
  padding: 14px 8px;
  border-radius: var(--radius);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 100ms, border-color 120ms, background 120ms;
}
.review-rate-btn:hover { transform: translateY(-1px); }
.review-rate-btn[data-rate="again"]:hover { border-color: var(--red-strong); color: var(--red-strong); background: var(--red-dim); }
.review-rate-btn[data-rate="hard"]:hover  { border-color: var(--sun-dim); color: var(--text-primary); background: var(--sun-soft); }
.review-rate-btn[data-rate="good"]:hover  { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.review-rate-btn[data-rate="easy"]:hover  { border-color: var(--green-strong); color: var(--green-strong); background: var(--green-dim); }

.review-empty {
  text-align: center;
  padding: 48px 20px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.review-empty-icon {
  font-size: 64px;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 8px rgba(26, 42, 58, 0.10));
}

.review-empty-next { color: var(--text-secondary); font-size: 14px; margin-top: 8px; }

.review-back {
  position: absolute;
  inset: 0;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border-radius: var(--radius-lg);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.sidebar {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  border: 1px solid var(--border);
}

/* ============ USER PICKER LIST ============ */

.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 320px;
  margin-bottom: 8px;
}
.user-list button {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  font-weight: 500;
  font-family: var(--font-display);
  transition: border-color 120ms, background 120ms;
  box-shadow: var(--shadow-sm);
}
.user-list button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ============ MOBILE TWEAKS ============ */

@media (max-width: 480px) {
  .q-text { font-size: 30px; }
  .q-text-en { font-size: 24px; }
  #result-percentage { font-size: 48px; }
  .quiz-question { padding: 24px 18px; }
}

/* ============ THAI TONE MATRIX (A3) ============ */

.tone-matrix-wrap {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 22px;
  margin: 18px 0;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.tone-matrix-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.tone-matrix-sub {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 14px;
}

.tone-matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 6px;
  margin-bottom: 18px;
}

.tone-matrix-table th {
  padding: 10px 12px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  text-align: center;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tone-matrix-table th:first-child,
.tone-matrix-table tr > th:first-child {
  text-align: left;
  background: var(--bg-soft);
  color: var(--text-primary);
}

.tone-matrix-table td {
  padding: 0;
  vertical-align: top;
}

.tm-cell {
  display: block;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 100ms, border-color 120ms, background 120ms;
  text-align: center;
  min-height: 90px;
}

.tm-cell:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.tm-tone {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.tm-example {
  font-family: var(--lang-font);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}

.tm-rom {
  color: var(--text-secondary);
  font-size: 12px;
  font-style: italic;
}

.tm-gloss {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 2px;
}

.tone-matrix-table.tm-marks th,
.tone-matrix-table.tm-marks td {
  padding: 10px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 500;
  text-align: center;
}

.tone-matrix-table.tm-marks td {
  background: #fff;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

/* ============ END ============ */
