:root {
  --bg: #f5f1e8;
  --bg-paper: #faf6ed;
  --ink: #1a1a1a;
  --ink-muted: #5a5a5a;
  --ink-light: #888;
  --accent: #b8473b;
  --accent-soft: #d4756c;
  --gold: #c9a961;
  --line: #d8d0bf;
  --highlight: #fff4d6;
  --shadow: rgba(40, 30, 20, 0.08);
  --success: #4caf50;
  --error: #c62828;
}

[data-theme="dark"] {
  --bg: #1a1612;
  --bg-paper: #221d18;
  --ink: #f0e8d8;
  --ink-muted: #b8ad95;
  --ink-light: #807463;
  --accent: #e07566;
  --accent-soft: #b8473b;
  --gold: #d4b86a;
  --line: #3a3228;
  --highlight: #3a2f1e;
  --shadow: rgba(0, 0, 0, 0.3);
  --success: #66bb6a;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Noto Serif TC', sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.4s, color 0.4s;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(184, 71, 59, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(201, 169, 97, 0.04) 0%, transparent 40%);
}

/* ===== Header ===== */
header {
  border-bottom: 1px solid var(--line);
  padding: 1.2rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 50%;
  position: relative;
  overflow: hidden;
}
.brand-icon::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  background: var(--bg);
  border-radius: 50%;
  top: -10px;
  left: 8px;
}

.brand-zh {
  font-family: 'Noto Serif TC', serif;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-left: 0.3rem;
}

nav {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}
.nav-btn:hover { color: var(--ink); background: var(--bg-paper); }
.nav-btn.active { color: var(--accent); background: var(--bg-paper); }

.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.5rem;
  transition: all 0.2s;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ===== Main Layout ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.view { display: none; animation: fadeIn 0.5s ease; }
.view.active { display: block; }

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

/* ===== Dashboard ===== */
.greeting {
  font-family: 'Fraunces', serif;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 400;
  line-height: 1.1;
  margin-bottom: 0.5rem;
  letter-spacing: -0.03em;
}
.greeting em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.greeting-zh {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 1.05rem;
  margin-bottom: 2.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 3rem;
}

.stat-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-light);
  margin-bottom: 0.5rem;
}

.stat-value {
  font-family: 'Fraunces', serif;
  font-size: 2.4rem;
  font-weight: 500;
  line-height: 1;
}

.stat-unit {
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-left: 0.3rem;
  font-weight: 400;
}

.stat-card.streak .stat-value { color: var(--accent); }
.stat-card.gold .stat-value { color: var(--gold); }

/* Section heading */
.section-title {
  font-family: 'Fraunces', serif;
  font-size: 1.6rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  letter-spacing: -0.02em;
}
.section-title em { font-style: italic; color: var(--accent); }

.section-sub {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

/* Article List */
.article-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.2rem;
}

.article-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}
.article-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
  border-color: var(--accent-soft);
}

.article-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s;
}
.article-card:hover::before { transform: scaleX(1); }

.article-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
  font-size: 0.78rem;
  color: var(--ink-light);
}

.level-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.level-A2 { background: #e8f5e9; color: #2e7d32; }
.level-B1 { background: #fff3e0; color: #ef6c00; }
.level-B2 { background: #fce4ec; color: #c2185b; }
[data-theme="dark"] .level-A2 { background: #1b3a1d; color: #a5d6a7; }
[data-theme="dark"] .level-B1 { background: #3d2817; color: #ffcc80; }
[data-theme="dark"] .level-B2 { background: #3d1f2a; color: #f48fb1; }

.article-title {
  font-family: 'Fraunces', serif;
  font-size: 1.25rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
  line-height: 1.3;
}

.article-title-zh {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-bottom: 0.8rem;
}

.article-preview {
  font-size: 0.9rem;
  color: var(--ink-muted);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.completion-mark {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  opacity: 0;
}
.article-card.completed .completion-mark { opacity: 1; }

/* ===== Reader View ===== */
.reader-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.back-btn {
  background: none;
  border: none;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
}
.back-btn:hover { color: var(--accent); }

.reader-tools {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.tool-btn {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}
.tool-btn:hover { border-color: var(--accent); color: var(--accent); }
.tool-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.reader-container {
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: clamp(1.5rem, 4vw, 3rem);
  box-shadow: 0 4px 20px var(--shadow);
}

.reader-level {
  display: inline-block;
  margin-bottom: 1rem;
}

.reader-title {
  font-family: 'Fraunces', serif;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 500;
  line-height: 1.2;
  margin-bottom: 0.4rem;
  letter-spacing: -0.02em;
}

.reader-title-zh {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 1.05rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--line);
}

.reader-text {
  font-family: 'Fraunces', serif;
  font-size: 1.15rem;
  line-height: 1.85;
  color: var(--ink);
}

.reader-text p {
  margin-bottom: 1.2rem;
}

.reader-text .word {
  cursor: pointer;
  border-bottom: 1px dotted transparent;
  transition: all 0.15s;
  padding: 0 1px;
  border-radius: 2px;
}
.reader-text .word:hover {
  background: var(--highlight);
  border-bottom-color: var(--accent);
}
.reader-text .word.saved {
  background: var(--highlight);
  border-bottom: 1px solid var(--gold);
}
.reader-text .word.speaking {
  background: var(--accent);
  color: white;
  border-radius: 3px;
}

.reader-zh {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  line-height: 1.9;
  font-size: 1rem;
  display: none;
}
.reader-zh.visible { display: block; animation: fadeIn 0.4s; }

.reader-zh p { margin-bottom: 1rem; }

/* Audio controls */
.audio-bar {
  position: sticky;
  bottom: 1rem;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 50px;
  padding: 0.5rem 1rem;
  display: none;
  align-items: center;
  gap: 0.8rem;
  box-shadow: 0 4px 20px var(--shadow);
  max-width: 500px;
  margin: 1.5rem auto 0;
}
.audio-bar.visible { display: flex; }

.audio-btn {
  background: var(--accent);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
}
.audio-btn:hover { transform: scale(1.05); }
.audio-btn:active { transform: scale(0.95); }

.audio-speed {
  display: flex;
  gap: 0.3rem;
  font-size: 0.8rem;
}
.speed-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-muted);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
}
.speed-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.record-btn {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.record-btn.recording {
  background: var(--accent);
  color: white;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(184, 71, 59, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(184, 71, 59, 0); }
}

/* Quiz section */
.quiz-section {
  max-width: 720px;
  margin: 2rem auto 0;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem;
  display: none;
}
.quiz-section.visible { display: block; animation: fadeIn 0.5s; }

.quiz-title {
  font-family: 'Fraunces', serif;
  font-size: 1.4rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}
.quiz-title em { color: var(--accent); font-style: italic; }

.quiz-q {
  margin-top: 1.5rem;
  padding: 1.2rem;
  background: var(--bg);
  border-radius: 10px;
  border-left: 3px solid var(--accent);
}

.quiz-q-text {
  font-family: 'Fraunces', serif;
  font-size: 1.05rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.8rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s;
}
.quiz-option:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateX(3px);
}
.quiz-option.correct {
  background: #e8f5e9;
  border-color: #4caf50;
  color: #2e7d32;
}
.quiz-option.wrong {
  background: #ffebee;
  border-color: #f44336;
  color: #c62828;
}
[data-theme="dark"] .quiz-option.correct { background: #1b3a1d; color: #a5d6a7; }
[data-theme="dark"] .quiz-option.wrong { background: #3d1f1f; color: #ef9a9a; }

/* ===== Word Popup ===== */
.word-popup {
  position: fixed;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.2rem;
  box-shadow: 0 8px 30px var(--shadow);
  max-width: 320px;
  z-index: 1000;
  display: none;
  animation: popIn 0.2s ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.popup-word {
  font-family: 'Fraunces', serif;
  font-size: 1.4rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.popup-phonetic {
  color: var(--ink-light);
  font-size: 0.9rem;
  font-style: italic;
  margin-bottom: 0.8rem;
}

.popup-pos {
  font-size: 0.75rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.6rem;
  margin-bottom: 0.2rem;
  font-weight: 600;
}

.popup-def {
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 0.4rem;
  color: var(--ink-muted);
}

.popup-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.popup-btn {
  flex: 1;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.popup-btn.secondary {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
}
.popup-btn:hover { opacity: 0.9; }

.popup-loading, .popup-error {
  color: var(--ink-light);
  font-size: 0.9rem;
  text-align: center;
  padding: 1rem 0;
}

.popup-speak {
  background: none;
  border: none;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
}
.popup-speak:hover { color: var(--accent); }

/* ===== Vocabulary Page ===== */
.vocab-controls {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }

.filter-btn {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  color: var(--ink-muted);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.vocab-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.8rem;
}

.vocab-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  position: relative;
  transition: all 0.2s;
}
.vocab-card:hover { border-color: var(--accent-soft); }

.vocab-word {
  font-family: 'Fraunces', serif;
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 0.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.vocab-phonetic {
  font-size: 0.8rem;
  color: var(--ink-light);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.vocab-def {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vocab-srs {
  display: flex;
  justify-content: space-between;
  margin-top: 0.8rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--ink-light);
}

.srs-due {
  color: var(--accent);
  font-weight: 600;
}

.vocab-actions {
  display: flex;
  gap: 0.3rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--ink-light);
  cursor: pointer;
  padding: 0.2rem;
  border-radius: 4px;
  font-size: 0.95rem;
}
.icon-btn:hover { color: var(--accent); }

.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--ink-muted);
}
.empty-state-icon { font-size: 3rem; opacity: 0.4; margin-bottom: 1rem; }
.empty-state h3 { font-family: 'Fraunces', serif; font-size: 1.4rem; font-weight: 500; margin-bottom: 0.5rem; color: var(--ink); }

/* ===== Review (SRS) ===== */
.review-card {
  max-width: 540px;
  margin: 2rem auto;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 3rem 2rem;
  text-align: center;
  box-shadow: 0 4px 20px var(--shadow);
  min-height: 380px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.review-progress {
  font-size: 0.8rem;
  color: var(--ink-light);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.review-word {
  font-family: 'Fraunces', serif;
  font-size: 3.2rem;
  font-weight: 500;
  margin: 1rem 0 0.5rem;
  letter-spacing: -0.02em;
}
.review-phonetic {
  font-style: italic;
  color: var(--ink-muted);
  font-size: 1rem;
  margin-bottom: 1rem;
}

.review-back {
  display: none;
  margin: 1rem 0;
}
.review-back.visible { display: block; animation: fadeIn 0.3s; }

.review-pos {
  font-size: 0.8rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.review-def {
  font-size: 1.1rem;
  color: var(--ink);
  line-height: 1.5;
  margin-bottom: 0.8rem;
}

.review-example {
  font-family: 'Fraunces', serif;
  font-style: italic;
  color: var(--ink-muted);
  font-size: 0.95rem;
  padding: 0.8rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
  margin-top: 1rem;
}

.review-actions {
  margin-top: 1.5rem;
}

.show-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s;
}
.show-btn:hover { transform: scale(1.02); }

.rating-buttons {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
.rating-buttons.visible { display: grid; }

.rating-btn {
  padding: 0.8rem 0.5rem;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: center;
}
.rating-btn:hover { transform: translateY(-2px); }
.rating-btn .rating-label {
  font-size: 0.75rem;
  font-weight: 600;
}
.rating-btn .rating-zh {
  font-size: 0.7rem;
  color: var(--ink-muted);
  font-family: 'Noto Serif TC', serif;
}
.rating-btn[data-rating="0"]:hover { background: #ffebee; border-color: #c62828; color: #c62828; }
.rating-btn[data-rating="1"]:hover { background: #fff3e0; border-color: #ef6c00; color: #ef6c00; }
.rating-btn[data-rating="2"]:hover { background: #f1f8e9; border-color: #689f38; color: #689f38; }
.rating-btn[data-rating="3"]:hover { background: #e0f7fa; border-color: #00838f; color: #00838f; }

.review-done {
  text-align: center;
  padding: 4rem 2rem;
}
.review-done-icon { font-size: 3rem; margin-bottom: 1rem; }
.review-done h2 {
  font-family: 'Fraunces', serif;
  font-size: 2rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}
.review-done h2 em { color: var(--accent); font-style: italic; }

/* ===== Settings ===== */
.settings-section {
  max-width: 720px;
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  margin-bottom: 1.5rem;
}

.settings-section h3 {
  font-family: 'Fraunces', serif;
  font-size: 1.2rem;
  margin-bottom: 1rem;
  font-weight: 500;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--line);
}
.settings-row:last-child { border-bottom: none; }

.settings-label {
  font-size: 0.95rem;
}
.settings-label small {
  display: block;
  color: var(--ink-light);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

.action-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1.2rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}
.action-btn.secondary {
  background: none;
  color: var(--ink);
  border: 1px solid var(--line);
}
.action-btn.danger { background: #c62828; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--ink);
  color: var(--bg);
  padding: 0.8rem 1.5rem;
  border-radius: 50px;
  font-size: 0.9rem;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}
.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  header { padding: 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .brand { font-size: 1.2rem; }
  nav { gap: 0.1rem; flex-wrap: wrap; }
  .nav-btn { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
  main { padding: 1.2rem; }
  .reader-tools { flex-wrap: wrap; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .review-word { font-size: 2.4rem; }
  .rating-buttons.visible { grid-template-columns: repeat(2, 1fr); }
  .section-actions { flex-direction: column; align-items: stretch; }
  .section-actions .action-btn { width: 100%; }
  .api-key-row { flex-wrap: wrap; }
  .api-key-row input { min-width: 0; flex: 1 1 100%; }
  .vocab-controls .search-input { flex: 1 1 100%; }
  .modal { padding: 1.5rem; }
}

/* ===== V2 additions: AI generation, source-jump, multi-mode review ===== */
.section-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.ai-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  background: var(--gold);
  color: white;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-left: 0.4rem;
}

.reader-text .word.highlight-source {
  background: var(--gold);
  color: white;
  animation: flash 1.5s ease-out;
}
@keyframes flash {
  0% { box-shadow: 0 0 0 6px rgba(201, 169, 97, 0.4); }
  100% { box-shadow: 0 0 0 0 rgba(201, 169, 97, 0); }
}

.vocab-source {
  font-size: 0.75rem;
  color: var(--ink-light);
  font-style: italic;
  margin-top: 0.4rem;
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.vocab-source:hover { color: var(--accent); }

.review-mode-tag {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  background: var(--gold);
  color: white;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.review-prompt {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink);
  font-size: 1.15rem;
  margin: 1rem 0;
}

.review-cloze {
  font-family: 'Fraunces', serif;
  font-size: 1.15rem;
  line-height: 1.7;
  color: var(--ink);
  margin: 1rem 0;
  padding: 1.2rem;
  background: var(--bg);
  border-radius: 10px;
  text-align: left;
}
.cloze-blank {
  display: inline-block;
  min-width: 90px;
  border-bottom: 2px solid var(--accent);
  padding: 0 0.4rem;
  color: var(--accent);
  font-weight: 600;
}

.review-input {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Fraunces', serif;
  font-size: 1.3rem;
  text-align: center;
  letter-spacing: 0.05em;
  margin: 0.8rem 0;
  outline: none;
  transition: border-color 0.2s;
}
.review-input:focus { border-color: var(--accent); }
.review-input.correct { border-color: var(--success); background: rgba(76, 175, 80, 0.08); }
.review-input.wrong { border-color: var(--error); background: rgba(198, 40, 40, 0.08); }

.review-source-link {
  margin-top: 1.2rem;
  font-size: 0.85rem;
  color: var(--ink-light);
}
.review-source-link a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.api-key-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  align-items: center;
}
.api-key-row input { flex: 1; font-family: 'Inter', monospace; font-size: 0.85rem; }
.api-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-light);
  margin-right: 0.4rem;
  flex-shrink: 0;
}
.api-status.connected { background: var(--success); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.3s;
}
.modal-backdrop.visible { display: flex; }

.modal {
  background: var(--bg-paper);
  border-radius: 16px;
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid var(--line);
}

.modal h3 {
  font-family: 'Fraunces', serif;
  font-size: 1.5rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}
.modal h3 em { font-style: italic; color: var(--accent); }

.modal p { color: var(--ink-muted); font-size: 0.92rem; margin-bottom: 1.2rem; }

.modal-form { display: flex; flex-direction: column; gap: 0.8rem; }

.modal-form label {
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: -0.4rem;
}

.modal-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1.5rem;
  justify-content: flex-end;
}

.gen-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 2rem 0;
  gap: 0.8rem;
}
.gen-progress.visible { display: flex; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.gen-status {
  font-size: 0.9rem;
  color: var(--ink-muted);
  font-family: 'Noto Serif TC', serif;
  text-align: center;
}

.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.source-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}
.source-option {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
}
.source-option:hover { border-color: var(--accent-soft); }
.source-option input[type="radio"] {
  margin-top: 0.2rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}
.source-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--highlight);
}
.source-option strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 0.1rem;
}
.source-option small {
  font-size: 0.8rem;
  color: var(--ink-muted);
  line-height: 1.4;
}

/* ===== Videos ===== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.2rem;
}

.video-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s;
}
.video-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--shadow);
  border-color: var(--accent-soft);
}

.video-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--bg);
  position: relative;
  background-size: cover;
  background-position: center;
}
.video-thumb::after {
  content: '▶';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  opacity: 0.85;
  transition: opacity 0.2s, transform 0.2s;
}
.video-card:hover .video-thumb::after {
  opacity: 1;
  transform: scale(1.1);
}

.video-meta-row { padding: 1rem 1.2rem; }
.video-cat {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}
.video-cat.youtube { background: #fee2e2; color: #b91c1c; }
.video-cat.ted { background: #ddd6fe; color: #6d28d9; }
.video-cat.short { background: #d1fae5; color: #065f46; }
.video-cat.fresh { background: #fef3c7; color: #b45309; }
[data-theme="dark"] .video-cat.youtube { background: #3a1a1a; color: #fca5a5; }
[data-theme="dark"] .video-cat.ted { background: #2a1f3a; color: #c4b5fd; }
[data-theme="dark"] .video-cat.short { background: #1a3a2a; color: #6ee7b7; }
[data-theme="dark"] .video-cat.fresh { background: #3a2f1a; color: #fcd34d; }

.video-card-title {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 0.3rem;
}
.video-card-desc {
  font-size: 0.85rem;
  color: var(--ink-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-player-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 2200;
  display: none;
  flex-direction: column;
  padding: 2rem;
  animation: fadeIn 0.3s;
}
.video-player-overlay.visible { display: flex; }

.video-player-close {
  align-self: flex-end;
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  margin-bottom: 1rem;
}

.video-player-body {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 1.5rem;
  flex: 1;
  min-height: 0;
}
@media (max-width: 900px) {
  .video-player-body { grid-template-columns: 1fr; }
}

.video-player-frame {
  background: black;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 16/9;
}
.video-player-frame iframe { width: 100%; height: 100%; border: 0; }

.video-transcript {
  background: var(--bg-paper);
  border-radius: 12px;
  padding: 1.2rem;
  overflow-y: auto;
  font-family: 'Fraunces', serif;
  line-height: 1.8;
  font-size: 1rem;
  max-height: 100%;
}
.video-transcript h4 {
  font-family: 'Fraunces', serif;
  font-size: 1rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink-muted);
  font-weight: 500;
}
.transcript-zh {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin-top: 0.4rem;
  margin-bottom: 1rem;
  padding-left: 0.6rem;
  border-left: 2px solid var(--gold);
}

/* ===== Speaking ===== */
.speaking-modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.mode-card {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.5rem 1.2rem;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: var(--ink);
  transition: all 0.2s;
}
.mode-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 8px 20px var(--shadow);
}
.mode-card.active {
  background: var(--highlight);
  border-color: var(--accent);
}
.mode-emoji { font-size: 2rem; margin-bottom: 0.5rem; }
.mode-title {
  font-family: 'Fraunces', serif;
  font-size: 1.15rem;
  font-weight: 500;
  margin-bottom: 0.3rem;
}
.mode-desc {
  font-size: 0.82rem;
  color: var(--ink-muted);
  line-height: 1.5;
}

.speaking-panel {
  background: var(--bg-paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
  max-width: 720px;
  margin: 0 auto;
}

.speech-bubble {
  padding: 1rem 1.2rem;
  border-radius: 14px;
  margin-bottom: 0.8rem;
  max-width: 85%;
  line-height: 1.6;
  font-size: 0.98rem;
  word-wrap: break-word;
}
.speech-bubble.ai {
  background: var(--bg);
  border: 1px solid var(--line);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.speech-bubble.user {
  background: var(--accent);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.speech-bubble small {
  display: block;
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.3rem;
}
.speech-bubble.ai small { color: var(--ink-light); }

.mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  margin: 1rem auto;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(184, 71, 59, 0.3);
}
.mic-btn:hover { transform: scale(1.05); }
.mic-btn.recording {
  background: var(--error);
  animation: pulse 1.2s infinite;
}
.mic-status {
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
  margin-bottom: 1rem;
  min-height: 1.2em;
}

.shadow-sentence {
  font-family: 'Fraunces', serif;
  font-size: 1.3rem;
  line-height: 1.6;
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--bg);
  border-radius: 12px;
  margin-bottom: 1rem;
}
.shadow-zh {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-muted);
  font-size: 0.95rem;
  text-align: center;
  margin-bottom: 1rem;
}

.shadow-controls {
  display: flex;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.feedback-block {
  background: var(--bg);
  border-left: 3px solid var(--gold);
  padding: 1rem 1.2rem;
  border-radius: 8px;
  margin-top: 1rem;
  font-size: 0.92rem;
  line-height: 1.6;
}
.feedback-block strong {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.scenario-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.6rem;
}
.scenario-btn {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 0.7rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
  font-size: 0.9rem;
  text-align: center;
  transition: all 0.2s;
}
.scenario-btn:hover {
  border-color: var(--accent);
  background: var(--highlight);
}

.no-speech-warning {
  text-align: center;
  padding: 1rem;
  background: rgba(239, 108, 0, 0.1);
  border: 1px solid var(--warning);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--warning);
  margin-bottom: 1rem;
}
[data-theme="dark"] .no-speech-warning { background: rgba(239, 108, 0, 0.2); }
/* Video fallback bar - 顯示「在 YouTube 開啟」備援按鈕 */
.video-fallback-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  margin-top: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: white;
  font-size: 0.85rem;
}
.video-fallback-bar a {
  color: white !important;
  border-color: rgba(255, 255, 255, 0.3) !important;
  background: rgba(255, 255, 255, 0.1) !important;
}

/* Word popup body 區可滾動，避免內容太長按鈕被擠掉 */
.word-popup .popup-body {
  max-height: 200px;
  overflow-y: auto;
}
