:root {
  --bg: #0a0e1a;
  --bg2: #111627;
  --card: rgba(22, 28, 52, 0.85);
  --card2: rgba(30, 38, 72, 0.75);
  --line: rgba(100, 116, 180, 0.2);
  --line-hover: rgba(124, 108, 255, 0.4);
  --text: #eef0ff;
  --muted: #8b95c0;
  --primary: #7c6cff;
  --primary2: #a89bff;
  --primary-glow: rgba(124, 108, 255, 0.3);
  --accent: #ff6b9d;
  --accent2: #ff8fb8;
  --ok: #3dd68c;
  --ok-glow: rgba(61, 214, 140, 0.25);
  --warn: #ffc857;
  --danger: #ff6b6b;
  --cyan: #5eead4;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-glow: 0 0 30px rgba(124, 108, 255, 0.15);
  --radius: 20px;
  --radius-sm: 12px;
  --font: "Segoe UI", "Noto Sans Thai", "Microsoft YaHei", "PingFang SC", sans-serif;
  --zh: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", "Segoe UI", sans-serif;
  --glass-blur: blur(16px);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(ellipse 1400px 700px at 8% -8%, rgba(124, 108, 255, 0.2), transparent 60%),
    radial-gradient(ellipse 1000px 550px at 95% 5%, rgba(255, 107, 157, 0.14), transparent 55%),
    radial-gradient(ellipse 800px 450px at 50% 105%, rgba(94, 234, 212, 0.1), transparent 50%),
    linear-gradient(180deg, #0a0e1a 0%, #0d1225 50%, #0a0e1a 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: none;
  cursor: pointer;
  background: none;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

::selection {
  background: rgba(124, 108, 255, 0.35);
  color: #fff;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(124, 108, 255, 0.3);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(124, 108, 255, 0.5); }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 100px;
}

/* ─── Header ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
  animation: slideDown 0.5s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: none; }
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  font-size: 24px;
  box-shadow: 0 8px 24px rgba(124, 108, 255, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  overflow: hidden;
}
.logo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent 60%);
  border-radius: inherit;
}
.brand h1 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  background: linear-gradient(135deg, #fff, #c4bfff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.3px;
}
.song-select {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.song-select select,
.field input,
.field textarea {
  background: rgba(22, 28, 52, 0.7);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-width: 220px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.song-select select:focus,
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.field textarea {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  line-height: 1.6;
}

/* ─── Stat Row ─── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
  animation: fadeUp 0.5s ease 0.1s both;
}
.stat {
  background: var(--card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), border-color var(--transition);
}
.stat:hover {
  transform: translateY(-2px);
  border-color: var(--line-hover);
}
.stat::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
}
.stat:nth-child(1)::before { background: linear-gradient(90deg, var(--primary), var(--cyan)); }
.stat:nth-child(2)::before { background: linear-gradient(90deg, var(--ok), #6ee7b7); }
.stat:nth-child(3)::before { background: linear-gradient(90deg, var(--accent), var(--warn)); }
.stat .n {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff, #c4bfff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat .l {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 16px;
  scrollbar-width: none;
  animation: fadeUp 0.5s ease 0.15s both;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  white-space: nowrap;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
  color: var(--muted);
  transition: all var(--transition);
  font-weight: 500;
  font-size: 0.9rem;
  position: relative;
}
.tab:hover {
  color: var(--text);
  background: rgba(124, 108, 255, 0.08);
  border-color: rgba(124, 108, 255, 0.15);
}
.tab.active {
  color: white;
  background: linear-gradient(135deg, var(--primary), #5b4fe0);
  border-color: transparent;
  box-shadow: 0 6px 20px rgba(124, 108, 255, 0.4), inset 0 1px 0 rgba(255,255,255,0.15);
  font-weight: 600;
}

/* ─── Panels ─── */
.panel { display: none; animation: fadeUp 0.3s ease; }
.panel.active { display: block; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.card {
  background: var(--card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}
.card + .card { margin-top: 14px; }
.card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 14px;
  line-height: 1.5;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.space-between { justify-content: space-between; }
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .song-select select { min-width: 100%; }
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  transition: all var(--transition);
  font-weight: 500;
  font-size: 0.9rem;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.05), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.btn:hover {
  transform: translateY(-2px);
  border-color: var(--line-hover);
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #5b4fe0);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 16px rgba(124, 108, 255, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 8px 28px rgba(124, 108, 255, 0.45);
  border-color: transparent;
}

.btn-green {
  background: linear-gradient(135deg, #2fbf78, #3dd68c);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 16px rgba(61, 214, 140, 0.25);
}
.btn-green:hover {
  box-shadow: 0 8px 28px rgba(61, 214, 140, 0.4);
  border-color: transparent;
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #ff8fb3);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 16px rgba(255, 107, 157, 0.25);
}
.btn-accent:hover {
  box-shadow: 0 8px 28px rgba(255, 107, 157, 0.4);
  border-color: transparent;
}

.btn-ok {
  background: linear-gradient(135deg, #2fbf78, #3dd68c);
  border-color: transparent;
  color: #042316;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(61, 214, 140, 0.25);
}
.btn-ok:hover {
  box-shadow: 0 8px 28px rgba(61, 214, 140, 0.4);
  border-color: transparent;
}

.btn-ghost { background: transparent; }
.btn-sm {
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--card2);
  border: 1px solid var(--line);
  transition: all var(--transition);
}
.icon-btn:hover {
  border-color: var(--line-hover);
  transform: scale(1.05);
}

/* ─── Lyrics ─── */
.lyric-line {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 16px;
  border-radius: 16px;
  border: 1px solid transparent;
  transition: all var(--transition);
  margin-bottom: 4px;
}
.lyric-line:hover,
.lyric-line.active {
  background: rgba(124, 108, 255, 0.06);
  border-color: rgba(124, 108, 255, 0.25);
}
.lyric-line.active {
  box-shadow: inset 0 0 0 1px rgba(124, 108, 255, 0.15), 0 4px 16px rgba(124, 108, 255, 0.08);
}
.line-num {
  color: var(--muted);
  font-size: 0.82rem;
  padding-top: 10px;
  font-variant-numeric: tabular-nums;
}
.zh-line {
  font-family: var(--zh);
  font-size: 1.5rem;
  line-height: 1.7;
  letter-spacing: 1.5px;
}
.pinyin-line {
  color: var(--cyan);
  font-size: 0.95rem;
  margin-top: 3px;
  letter-spacing: 0.3px;
}
.th-line {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 5px;
  line-height: 1.5;
}
.word-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 7px;
  margin: 2px 3px;
  border-radius: 10px;
  cursor: pointer;
  transition: all var(--transition);
  vertical-align: top;
}
.word-chip:hover,
.word-chip.on {
  background: rgba(255, 107, 157, 0.15);
  color: #ffd0e0;
  transform: translateY(-1px);
}
.word-chip .zh {
  font-family: var(--zh);
  font-size: 1.45rem;
  line-height: 1.3;
}
.word-chip .py {
  font-size: 0.72rem;
  color: var(--cyan);
  line-height: 1.2;
  margin-top: 2px;
}
.chip-th {
  font-size: 0.66rem;
  color: var(--primary2);
  line-height: 1.2;
  margin-top: 1px;
  max-width: 80px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.word-chip .th {
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.2;
  margin-top: 1px;
}
.line-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ─── Vocab ─── */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.vocab-card {
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.vocab-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity var(--transition);
}
.vocab-card:hover {
  border-color: var(--line-hover);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
}
.vocab-card:hover::before { opacity: 1; }
.vocab-card.known {
  border-color: rgba(61, 214, 140, 0.4);
}
.vocab-card.known::before {
  background: linear-gradient(90deg, var(--ok), #6ee7b7);
  opacity: 1;
}
.vocab-card .zh {
  font-family: var(--zh);
  font-size: 1.65rem;
  margin-bottom: 4px;
}
.vocab-card .py { color: var(--cyan); font-size: 0.88rem; }
.vocab-card .th { color: var(--muted); font-size: 0.88rem; margin-top: 6px; }
.vocab-card .pos {
  position: absolute;
  top: 10px;
  right: 42px;
  font-size: 0.68rem;
  color: var(--muted);
  background: rgba(0,0,0,0.25);
  padding: 2px 8px;
  border-radius: 999px;
}
.vocab-speak {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(124, 108, 255, 0.15);
  border: 1px solid rgba(124, 108, 255, 0.2);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  display: grid;
  place-items: center;
}
.vocab-speak:hover {
  background: rgba(124, 108, 255, 0.35);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(124, 108, 255, 0.3);
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(124,108,255,0.12);
  color: var(--primary2);
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid rgba(124,108,255,0.15);
}

/* ─── Flashcards ─── */
.flash-stage {
  min-height: 280px;
  display: grid;
  place-items: center;
  perspective: 1200px;
}
.flash-card {
  width: min(420px, 100%);
  min-height: 240px;
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(42, 49, 88, 0.9), rgba(26, 31, 56, 0.95));
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
  cursor: pointer;
  box-shadow: var(--shadow), var(--shadow-glow);
  transition: all var(--transition-slow);
  position: relative;
  overflow: hidden;
}
.flash-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 30%, rgba(124, 108, 255, 0.08), transparent 60%);
  pointer-events: none;
}
.flash-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow), 0 0 40px rgba(124, 108, 255, 0.2);
}
.flash-card.flipped {
  background: linear-gradient(160deg, rgba(58, 36, 88, 0.9), rgba(31, 22, 51, 0.95));
}
.flash-zh {
  font-family: var(--zh);
  font-size: 3.2rem;
  line-height: 1.2;
  position: relative;
}
.flash-py { color: var(--cyan); margin-top: 12px; font-size: 1.15rem; position: relative; }
.flash-th { color: #ffd0e0; font-size: 1.1rem; margin-top: 8px; position: relative; }
.flash-hint {
  position: absolute;
  bottom: 16px;
  color: var(--muted);
  font-size: 0.78rem;
}
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 18px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
  border-radius: 999px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(124, 108, 255, 0.4);
}

/* ─── Quiz / Listen / Speak ─── */
.q-box {
  text-align: center;
  padding: 12px 0 6px;
}
.q-prompt {
  font-family: var(--zh);
  font-size: 2.5rem;
  margin: 10px 0;
  letter-spacing: 2px;
}
.q-sub { color: var(--muted); margin-bottom: 16px; }
.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) {
  .choices { grid-template-columns: 1fr; }
}
.choice {
  text-align: left;
  padding: 16px 18px;
  border-radius: 16px;
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  transition: all var(--transition);
  font-weight: 500;
}
.choice:hover {
  border-color: var(--line-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.choice.correct {
  border-color: var(--ok);
  background: rgba(61, 214, 140, 0.1);
  box-shadow: 0 0 0 3px var(--ok-glow);
}
.choice.wrong {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.1);
  box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2);
}
.score-pill {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 0.88rem;
  border: 1px solid var(--line);
}
.score-pill strong { color: var(--text); }

/* ─── Game Modes Hub ─── */
.game-modes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.game-mode {
  text-align: left;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 2px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: all var(--transition);
  color: var(--text);
  position: relative;
  overflow: hidden;
}
.game-mode::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(124,108,255,0.05), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.game-mode:hover {
  border-color: var(--line-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.game-mode:hover::before { opacity: 1; }
.game-mode.active {
  border-color: var(--primary);
  background: linear-gradient(160deg, rgba(124,108,255,0.15), rgba(30,36,64,0.9));
  box-shadow: 0 0 0 3px var(--primary-glow), 0 8px 24px rgba(0,0,0,0.25);
}
.game-mode.active::before { opacity: 1; }
.game-mode .gm-icon {
  font-size: 0.85rem;
  color: var(--cyan);
  font-weight: 700;
  letter-spacing: 0.3px;
}
.game-mode strong {
  font-size: 0.95rem;
}
.game-mode small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

/* ─── Matching Game ─── */
.match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.match-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.match-item {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 2px solid var(--line);
  text-align: left;
  transition: all var(--transition);
}
.match-item.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: rgba(124, 108, 255, 0.08);
}
.match-item.matched {
  opacity: 0.35;
  border-color: var(--ok);
  pointer-events: none;
}
.match-item.zh-side {
  font-family: var(--zh);
  font-size: 1.25rem;
}
.match-item.py-side {
  font-family: inherit;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--cyan);
}
.match-item.audio-side {
  text-align: center;
  font-size: 1.05rem;
  min-height: 52px;
}
.match-item.wrong-flash {
  border-color: var(--danger);
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ─── Memory Cards ─── */
.memory-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 640px) {
  .memory-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 420px) {
  .memory-grid { grid-template-columns: repeat(2, 1fr); }
}
.mem-card {
  aspect-ratio: 1 / 1.05;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: linear-gradient(145deg, rgba(42, 49, 88, 0.9), rgba(26, 31, 56, 0.95));
  backdrop-filter: blur(8px);
  cursor: pointer;
  position: relative;
  perspective: 800px;
  transition: all var(--transition);
  padding: 0;
  overflow: hidden;
}
.mem-card:hover:not(.matched):not(.flipped) {
  border-color: var(--line-hover);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
}
.mem-card .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 10px;
  text-align: center;
  backface-visibility: hidden;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.mem-card .back {
  font-size: 1.6rem;
  background: linear-gradient(145deg, rgba(58, 42, 104, 0.9), rgba(30, 36, 64, 0.95));
}
.mem-card .front {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, rgba(36, 48, 79, 0.9), rgba(26, 32, 56, 0.95));
  font-family: var(--zh);
  font-size: 1.35rem;
  line-height: 1.25;
  word-break: break-word;
}
.mem-card.flipped .back { transform: rotateY(180deg); }
.mem-card.flipped .front { transform: rotateY(0); }
.mem-card.matched {
  border-color: var(--ok);
  opacity: 0.5;
  pointer-events: none;
}
.mem-card.matched .front {
  background: rgba(61, 214, 140, 0.1);
}
.mem-card .front.th-face {
  font-family: var(--font);
  font-size: 0.95rem;
  color: #ffd0e0;
}
.mem-card .front.py-face {
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--cyan);
}
.mem-card .front.audio-face {
  font-family: var(--font);
  font-size: 1.4rem;
}

/* ─── Speed Match ─── */
.speed-prompt {
  text-align: center;
  padding: 20px 14px;
  margin-bottom: 14px;
  border-radius: 18px;
  background: rgba(124,108,255,0.08);
  border: 1px solid rgba(124,108,255,0.2);
  backdrop-filter: blur(8px);
}
.speed-prompt .big {
  font-family: var(--zh);
  font-size: 2.8rem;
  margin: 10px 0;
  letter-spacing: 2px;
}
.speed-timer {
  font-variant-numeric: tabular-nums;
  color: var(--warn);
  font-weight: 700;
}
.game-win {
  text-align: center;
  padding: 28px 14px;
  border-radius: 18px;
  background: rgba(61,214,140,0.08);
  border: 1px solid rgba(61,214,140,0.25);
  margin-top: 10px;
  animation: fadeUp 0.4s ease;
}
.game-win h3 {
  margin: 0 0 10px;
  color: var(--ok);
  font-size: 1.3rem;
}

/* ─── Cloze / Order ─── */
.cloze-line {
  font-family: var(--zh);
  font-size: 1.55rem;
  line-height: 2;
  text-align: center;
  margin: 18px 0;
  letter-spacing: 1px;
}
.blank {
  display: inline-block;
  min-width: 64px;
  padding: 4px 14px;
  margin: 0 4px;
  border-bottom: 2px dashed var(--accent);
  color: var(--accent);
  font-weight: bold;
}
.tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.tile {
  font-family: var(--zh);
  font-size: 1.2rem;
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  transition: all var(--transition);
  cursor: pointer;
}
.tile:hover {
  border-color: var(--line-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}
.tile.used { opacity: 0.25; pointer-events: none; }
.answer-strip {
  min-height: 56px;
  border: 2px dashed rgba(124, 108, 255, 0.2);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  margin: 14px 0;
  background: rgba(124, 108, 255, 0.03);
  transition: border-color var(--transition);
}
.answer-strip:focus-within {
  border-color: var(--primary);
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.75);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-backdrop.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal {
  width: min(480px, 100%);
  background: linear-gradient(180deg, rgba(22, 28, 52, 0.98), rgba(17, 22, 39, 0.98));
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow), var(--shadow-glow);
  animation: modalIn 0.25s ease;
  position: relative;
  overflow: hidden;
}
.modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: none; }
}
.modal h3 { margin: 0 0 8px; font-family: var(--zh); font-size: 2.2rem; }
.modal .meta { color: var(--cyan); margin-bottom: 8px; font-size: 1rem; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(18, 22, 42, 0.95);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 14px 20px;
  border-radius: 16px;
  opacity: 0;
  pointer-events: none;
  transition: all var(--transition-slow);
  z-index: 60;
  max-width: min(90vw, 420px);
  text-align: center;
  box-shadow: var(--shadow);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ok { border-color: rgba(61,214,140,0.4); box-shadow: var(--shadow), 0 0 20px var(--ok-glow); }
.toast.bad { border-color: rgba(255,107,107,0.4); box-shadow: var(--shadow), 0 0 20px rgba(255,107,107,0.2); }

/* ─── Speak Status ─── */
.speak-status {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(124,108,255,0.06);
  border: 1px solid rgba(124,108,255,0.2);
  color: var(--muted);
  min-height: 48px;
  transition: all var(--transition);
}
.speak-status.listening {
  border-color: var(--accent);
  color: #ffd0e0;
  background: rgba(255, 107, 157, 0.06);
  box-shadow: 0 0 20px rgba(255, 107, 157, 0.1);
}
.speak-status.ok {
  border-color: var(--ok);
  color: #b8f5d4;
  background: rgba(61, 214, 140, 0.06);
  box-shadow: 0 0 20px var(--ok-glow);
}

/* ─── Empty State ─── */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 36px 14px;
  font-size: 0.95rem;
}

/* ─── Footer ─── */
.footer-note {
  margin-top: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  opacity: 0.7;
}

/* ─── Responsive ─── */
@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .song-select {
    width: 100%;
  }
  .song-select select {
    min-width: 0;
    flex: 1;
  }
  .stat-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .stat { padding: 12px 8px; }
  .stat .n { font-size: 1.25rem; }
  .stat .l { font-size: 0.7rem; }
  .card { padding: 16px; }
  .card h2 { font-size: 1.05rem; }
  .q-prompt { font-size: 2rem; }
  .flash-zh { font-size: 2.5rem; }
  .game-modes {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 420px) {
  .app { padding: 14px 10px 80px; }
  .tabs { gap: 4px; }
  .tab { padding: 8px 12px; font-size: 0.82rem; }
  .vocab-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .game-modes {
    grid-template-columns: 1fr;
  }
}

/* ─── Level System ─── */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.level-card {
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  text-align: center;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.level-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
  opacity: 0;
  transition: opacity var(--transition);
}
.level-card:hover:not(.locked) {
  border-color: var(--line-hover);
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
}
.level-card:hover:not(.locked)::before { opacity: 1; }
.level-card.completed {
  border-color: rgba(61, 214, 140, 0.4);
}
.level-card.completed::before {
  background: linear-gradient(90deg, var(--ok), #6ee7b7);
  opacity: 1;
}
.level-card.locked {
  opacity: 0.45;
  pointer-events: none;
}
.level-num {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.level-card.completed .level-num {
  background: linear-gradient(135deg, var(--ok), #6ee7b7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.level-words {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  margin: 10px 0;
}
.level-word-chip {
  font-family: var(--zh);
  font-size: 0.95rem;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(124, 108, 255, 0.1);
  color: var(--primary2);
}
.level-card.completed .level-word-chip {
  background: rgba(61, 214, 140, 0.1);
  color: var(--ok);
}
.level-status {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 8px;
}
.level-status.done {
  color: var(--ok);
  font-weight: 600;
}

/* Stage progress bar */
.stage-progress {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin: 16px 0;
}
.stage-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 2px solid var(--line);
  transition: all var(--transition);
}
.stage-dot.done {
  background: var(--ok);
  border-color: var(--ok);
  box-shadow: 0 0 8px var(--ok-glow);
}
.stage-dot.current {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
  transform: scale(1.3);
}
.stage-line {
  width: 20px;
  height: 2px;
  background: var(--line);
  border-radius: 2px;
}
.stage-line.done {
  background: var(--ok);
}

/* Study cards */
.study-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.study-card {
  background: var(--card2);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.study-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.study-card:hover {
  border-color: var(--line-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.study-card .zh {
  font-family: var(--zh);
  font-size: 1.8rem;
  margin-bottom: 4px;
}
.study-card .py {
  color: var(--cyan);
  font-size: 0.88rem;
}
.study-card .th {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
}
.study-card .speak-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(124, 108, 255, 0.15);
  border: 1px solid rgba(124, 108, 255, 0.2);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  display: grid;
  place-items: center;
}
.study-card .speak-btn:hover {
  background: rgba(124, 108, 255, 0.35);
  transform: scale(1.1);
}

/* Level complete celebration */
.level-complete {
  text-align: center;
  padding: 32px 20px;
  border-radius: 20px;
  background: rgba(61, 214, 140, 0.06);
  border: 1px solid rgba(61, 214, 140, 0.25);
  margin: 16px 0;
  animation: fadeUp 0.4s ease;
}
.level-complete h3 {
  margin: 0 0 10px;
  color: var(--ok);
  font-size: 1.4rem;
}
.level-complete .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* Stage header */
.stage-header {
  text-align: center;
  margin-bottom: 16px;
}
.stage-header h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
}
.stage-header .stage-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(124, 108, 255, 0.1);
  color: var(--primary2);
  font-size: 0.82rem;
  font-weight: 500;
}

/* Quiz result in level */
.quiz-result {
  text-align: center;
  padding: 20px;
  border-radius: 16px;
  margin: 16px 0;
  animation: fadeUp 0.3s ease;
}
.quiz-result.pass {
  background: rgba(61, 214, 140, 0.08);
  border: 1px solid rgba(61, 214, 140, 0.25);
}
.quiz-result.fail {
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.2);
}
.quiz-result h3 {
  margin: 0 0 8px;
}
.quiz-result .score {
  font-size: 1.3rem;
  font-weight: 700;
  margin: 8px 0;
}

@media (max-width: 560px) {
  .level-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .study-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
