/* ============================================
   Chunk Master v3 - Design System
   Dark modern, Apple-inspired
   ============================================ */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #111118;
  --bg-card: #16161f;
  --bg-card-hover: #1c1c28;
  --bg-glass: rgba(16, 16, 24, 0.92);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.1);

  --text-primary: #f5f5f7;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --text-weak: #52525b;

  --accent: #4A9EFF;
  --accent-hover: #6BB3FF;
  --accent-subtle: rgba(74, 158, 255, 0.12);
  --accent-glow: rgba(74, 158, 255, 0.25);

  --chunk-active: #f5f5f7;

  --lv1: #10b981; --lv1-bg: rgba(16, 185, 129, 0.1); --lv1-border: rgba(16, 185, 129, 0.25);
  --lv2: #3b82f6; --lv2-bg: rgba(59, 130, 246, 0.1); --lv2-border: rgba(59, 130, 246, 0.25);
  --lv3: #f59e0b; --lv3-bg: rgba(245, 158, 11, 0.1); --lv3-border: rgba(245, 158, 11, 0.25);
  --lv4: #f97316; --lv4-bg: rgba(249, 115, 22, 0.1); --lv4-border: rgba(249, 115, 22, 0.25);
  --lv5: #ef4444; --lv5-bg: rgba(239, 68, 68, 0.1); --lv5-border: rgba(239, 68, 68, 0.25);

  --success: #10b981; --success-bg: rgba(16, 185, 129, 0.1);
  --danger: #ef4444; --danger-bg: rgba(239, 68, 68, 0.1);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Outfit', 'Inter', sans-serif;

  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px; --radius-xl: 20px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-normal: 250ms var(--ease-out);

  --nav-height: 64px;
  --header-height: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  height: var(--header-height);
}

.header-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  outline: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--text-primary);
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.logo-icon { color: var(--accent); font-size: 1rem; }
.logo-text { font-family: var(--font-display); font-weight: 600; font-size: 0.9375rem; letter-spacing: -0.02em; }

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.view-btn {
  background: none;
  border: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  color: var(--text-weak);
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.view-btn + .view-btn {
  border-left: 1px solid var(--border-subtle);
}

.view-btn:hover { color: var(--text-secondary); background: rgba(255, 255, 255, 0.03); }
.view-btn.active { color: var(--accent); background: var(--accent-subtle); }

/* Mastery ring */
.mastery-ring-wrapper {
  position: relative;
}

.mastery-ring {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mastery-text {
  position: absolute;
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.mastery-popup {
  position: absolute;
  top: 40px;
  right: 0;
  width: 220px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  z-index: 100;
  padding: 12px;
  animation: popupFadeIn 0.15s var(--ease-out);
}

.mastery-popup.hidden { display: none; }

@keyframes popupFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.mastery-popup-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.mastery-popup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.6875rem;
}

.mastery-popup-label {
  color: var(--text-secondary);
}

.mastery-popup-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin: 0 8px;
  overflow: hidden;
}

.mastery-popup-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s var(--ease-out);
}

.mastery-popup-count {
  color: var(--text-tertiary);
  font-size: 0.625rem;
  min-width: 32px;
  text-align: right;
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: center;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
}

.nav-item {
  flex: 1;
  max-width: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-weak);
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.nav-item:hover { color: var(--text-secondary); }
.nav-item.active { color: var(--accent); }

/* Content area with bottom padding for mobile nav */
.tab-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.tab-content.hidden { display: none; }

/* --- Level Filter --- */
.level-filter {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.level-filter::-webkit-scrollbar { display: none; }

.level-btn {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 100px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.level-btn:hover { border-color: var(--border-light); }
.level-btn.active { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent-hover); }

/* --- Chunk List --- */
.chunk-list { display: flex; flex-direction: column; gap: 10px; }

/* LIST VIEW (default) - unchanged, uses chunk-card below */

/* GRID VIEW */
.chunk-list.view-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

@media (min-width: 600px) {
  .chunk-list.view-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.chunk-list.view-grid .chunk-card {
  border-radius: var(--radius-md);
}

/* In grid: hide the normal header, show grid-face instead */
.chunk-list.view-grid .chunk-card-header { display: none; }
.chunk-list.view-grid .chunk-card-body { display: none; }

.chunk-grid-face {
  display: none;
}

.chunk-list.view-grid .chunk-grid-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 12px 16px;
  cursor: pointer;
  min-height: 120px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.grid-level {
  position: absolute;
  top: 10px;
  left: 10px;
}

.grid-mastered {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 0.75rem;
  color: var(--success);
  font-weight: 700;
  display: none;
}

.chunk-card.mastered .grid-mastered {
  display: block;
}

.grid-chunk-name {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--chunk-active);
  line-height: 1.2;
  margin-bottom: 4px;
  word-break: break-word;
}

.grid-meaning {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.grid-ipa {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-family: 'Segoe UI', 'Noto Sans', serif;
  line-height: 1.3;
}

.grid-weak {
  font-size: 0.6875rem;
  color: var(--chunk-active);
  opacity: 0.65;
  line-height: 1.3;
}

.grid-play {
  margin-top: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.grid-play:hover { background: rgba(74, 158, 255, 0.2); transform: scale(1.1); }
.grid-play.playing { animation: pulse-accent 1.5s infinite; }
.grid-play svg { width: 12px; height: 12px; }

/* --- Chunk Card --- */
.chunk-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-lg);
  overflow: visible;
  transition: all var(--transition-normal);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chunk-card:hover {
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 20px rgba(0, 0, 0, 0.2);
}

/* Mastered state */
.chunk-card.mastered {
  border-color: rgba(16, 185, 129, 0.2);
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  border-left: 3px solid var(--success);
  opacity: 0.5;
}

.view-grid .chunk-card.mastered {
  border-left: 1px solid rgba(16, 185, 129, 0.2);
  opacity: 0.5;
}


.card-check {
  display: none;
  position: absolute;
  top: -5px;
  left: -5px;
  width: 16px;
  height: 16px;
  background: var(--success);
  color: #fff;
  font-size: 0.5rem;
  font-weight: 700;
  border-radius: 50%;
  line-height: 16px;
  text-align: center;
  z-index: 1;
}

.chunk-card.mastered .card-check {
  display: block;
}

.chunk-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.chunk-level-badge {
  font-size: 0.5625rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 100px;
  flex-shrink: 0;
}

.chunk-level-badge.lv1 { background: var(--lv1-bg); color: var(--lv1); border: 1px solid var(--lv1-border); }
.chunk-level-badge.lv2 { background: var(--lv2-bg); color: var(--lv2); border: 1px solid var(--lv2-border); }
.chunk-level-badge.lv3 { background: var(--lv3-bg); color: var(--lv3); border: 1px solid var(--lv3-border); }
.chunk-level-badge.lv4 { background: var(--lv4-bg); color: var(--lv4); border: 1px solid var(--lv4-border); }
.chunk-level-badge.lv5 { background: var(--lv5-bg); color: var(--lv5); border: 1px solid var(--lv5-border); }

.chunk-card-title { flex: 1; min-width: 0; }

.chunk-original {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.chunk-meaning-line {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  margin-top: 1px;
  line-height: 1.3;
}

.chunk-ipa-line {
  font-size: 0.6875rem;
  color: var(--text-tertiary);
  font-family: 'Segoe UI', 'Noto Sans', serif;
  margin-top: 1px;
  line-height: 1.3;
}

.chunk-weak-line {
  font-size: 0.6875rem;
  color: var(--chunk-active);
  opacity: 0.7;
  margin-top: 1px;
}

.chunk-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chunk-play-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.chunk-play-btn:hover { background: rgba(74, 158, 255, 0.2); transform: scale(1.05); }
.chunk-play-btn.playing { animation: pulse-accent 1.5s infinite; }
.chunk-play-btn svg { width: 14px; height: 14px; }

@keyframes pulse-accent {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 10px 3px var(--accent-glow); }
}

/* Accordion styles removed - list view uses modal now */

.chunk-detail-row {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.chunk-detail-row:last-of-type { border-bottom: none; }

.chunk-detail-label {
  font-size: 0.5625rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 28px;
  padding-top: 2px;
}

.chunk-detail-value {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.chunk-ipa { color: var(--text-primary); font-family: 'Segoe UI', 'Noto Sans', serif; }

.mastery-toggle-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.mastery-toggle-btn:hover {
  border-color: var(--success);
  color: var(--success);
}

.mastery-toggle-btn.is-mastered {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

.chunk-examples-title {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 10px 0 6px;
}

.chunk-example {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 5px;
}

.example-play-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 1px;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.example-play-btn:hover { border-color: var(--accent); color: var(--accent); }
.example-play-btn.playing { border-color: var(--accent); color: var(--accent); animation: pulse-accent 1.5s infinite; }
.example-play-btn svg { width: 11px; height: 11px; }

.example-text { flex: 1; min-width: 0; }
.example-en { font-size: 0.8125rem; font-weight: 500; color: var(--text-primary); line-height: 1.4; }
.example-ja { font-size: 0.6875rem; color: var(--text-tertiary); margin-top: 1px; }

.chunk-bottom-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chunk-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.chunk-action-btn:hover { border-color: var(--border-light); color: var(--text-primary); }
.chunk-action-btn svg { width: 12px; height: 12px; }

.chunk-action-btn.youtube-btn { border-color: rgba(239, 68, 68, 0.25); color: #ef4444; }
.chunk-action-btn.youtube-btn:hover { background: var(--danger-bg); }

.chunk-action-btn.pron-btn { border-color: rgba(74, 158, 255, 0.25); color: var(--accent); }
.chunk-action-btn.pron-btn:hover { background: var(--accent-subtle); }

/* --- Quiz / Test Panel --- */
.test-mode-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.test-mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.test-mode-btn:hover { border-color: var(--border-light); }
.test-mode-btn.active { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); }

.test-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
}

.test-panel.hidden { display: none; }

/* Quiz header */
.quiz-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.quiz-progress {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.quiz-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

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

.quiz-level-select select,
.quiz-header-controls select {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  color: var(--text-primary);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

/* Quiz top bar (mode + level pills) */
.quiz-top-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.quiz-level-pills {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
}

.level-pill {
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.level-pill:hover { border-color: var(--border-light); }
.level-pill.active { background: var(--accent-subtle); border-color: var(--accent); color: var(--accent-hover); }

.level-pill.lv1.active { background: var(--lv1-bg); border-color: var(--lv1); color: var(--lv1); }
.level-pill.lv2.active { background: var(--lv2-bg); border-color: var(--lv2); color: var(--lv2); }
.level-pill.lv3.active { background: var(--lv3-bg); border-color: var(--lv3); color: var(--lv3); }
.level-pill.lv4.active { background: var(--lv4-bg); border-color: var(--lv4); color: var(--lv4); }
.level-pill.lv5.active { background: var(--lv5-bg); border-color: var(--lv5); color: var(--lv5); }

/* Quiz header controls (legacy compat) */
.quiz-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-mode-toggle {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  width: 100%;
}

.quiz-mode-btn {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-weak);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.quiz-mode-btn + .quiz-mode-btn {
  border-left: 1px solid var(--border-subtle);
}

.quiz-mode-btn:hover { color: var(--text-secondary); background: rgba(255,255,255,0.02); }
.quiz-mode-btn.active { color: var(--text-primary); background: var(--accent-subtle); }

/* Quiz typing mode */
.quiz-typing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
}

.quiz-typing.hidden { display: none; }

.typing-input {
  width: 100%;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-primary);
  text-align: center;
  outline: none;
  transition: border-color var(--transition-fast);
}

.typing-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.typing-input::placeholder {
  color: var(--text-weak);
  font-weight: 400;
}

.typing-submit-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 10px 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.typing-submit-btn:hover { background: var(--accent-hover); }

/* Quiz body */
.quiz-instruction {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: center;
  margin-bottom: 16px;
}

.quiz-play-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: var(--accent-subtle);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin: 0 auto 20px;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.quiz-play-btn:hover { background: rgba(74, 158, 255, 0.2); transform: scale(1.05); }
.quiz-play-btn.playing { animation: pulse-accent 1.5s infinite; }

/* Quiz choices */
.quiz-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.quiz-choices.hidden { display: none; }

.choice-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 12px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.choice-btn:hover { border-color: var(--accent); background: rgba(74, 158, 255, 0.05); }
.choice-btn.correct { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.choice-btn.wrong { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.choice-btn.disabled { pointer-events: none; opacity: 0.4; }
.choice-btn.show-correct { border-color: var(--success); color: var(--success); opacity: 1; }

/* Quiz answer feedback */
.quiz-answer {
  text-align: center;
  padding: 16px;
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-md);
}

.quiz-answer.hidden { display: none; }

.quiz-answer-status {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.quiz-answer-status.correct { color: var(--success); }
.quiz-answer-status.wrong { color: var(--danger); }

.quiz-answer-detail {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.5;
}

.quiz-next-btn, .quiz-restart-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.quiz-next-btn:hover, .quiz-restart-btn:hover { background: var(--accent-hover); }

/* Quiz final */
.quiz-final {
  text-align: center;
  padding: 24px 16px;
}

.quiz-final.hidden { display: none; }

.quiz-final-score {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.quiz-final-message {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* --- Speaking Test --- */
.speaking-body { text-align: center; }

.speaking-target {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--chunk-active);
  margin-bottom: 4px;
}

.speaking-hint {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}

.speaking-visualizer {
  margin-bottom: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.3);
}

.speaking-visualizer canvas {
  width: 100%;
  height: 70px;
  display: block;
}

.speaking-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 14px;
}

.speaking-listen-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.speaking-listen-btn:hover { border-color: var(--accent); color: var(--accent); }

.record-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.record-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--danger);
  display: block;
  transition: all var(--transition-fast);
}

.record-btn:hover .record-icon { transform: scale(1.05); }

.record-btn.recording .record-icon {
  animation: recording-pulse 1.5s infinite;
  border-radius: 8px;
  width: 32px;
  height: 32px;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 14px rgba(239, 68, 68, 0); }
}

.speaking-live-text {
  font-size: 0.75rem;
  color: var(--accent);
  text-align: center;
  min-height: 1.2em;
  margin-bottom: 8px;
}

.speaking-eval-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.speaking-eval-btn:hover:not(:disabled) { background: var(--accent-hover); }

.speaking-eval-btn:disabled,
.speaking-eval-btn.disabled {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-weak);
  cursor: not-allowed;
  opacity: 0.5;
}

.speaking-recognized {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.speaking-troubleshoot {
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: rgba(255, 165, 0, 0.08);
  border: 1px solid rgba(255, 165, 0, 0.2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 10px;
  line-height: 1.6;
}

.speaking-answer-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.speaking-answer-actions > .speaking-playback-btn,
.speaking-answer-actions > .quiz-next-btn {
  flex: 1;
  white-space: nowrap !important;
  padding: 10px 8px !important;
  font-size: 0.8rem;
  min-width: 0;
}

.speaking-answer-actions > .speaking-playback-btn.hidden {
  display: none;
}

.speaking-playback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 10px 24px;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.speaking-playback-btn:hover { background: var(--accent-subtle); }
.speaking-playback-btn.hidden { display: none; }

/* --- Chunk Detail Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}

.modal-overlay.hidden { display: none; }

.modal-overlay.closing {
  animation: modalFadeOut 0.25s ease forwards;
}

.modal-overlay.closing .modal-content {
  animation: modalSlideDown 0.25s var(--ease-out) forwards;
}

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

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

@keyframes modalSlideDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 20px 24px;
  position: relative;
  animation: modalSlideUp 0.25s var(--ease-out);
}

@keyframes modalSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.modal-close:hover { color: var(--text-primary); }

.modal-chunk-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--chunk-active);
  margin-bottom: 2px;
}

.modal-meaning {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal-ipa {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  font-family: 'Segoe UI', 'Noto Sans', serif;
  margin-bottom: 4px;
}

.modal-level {
  display: inline-block;
  margin-bottom: 12px;
}

.modal-notes {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-examples-title {
  font-size: 0.625rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.modal-example {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 5px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

@media (min-width: 768px) {
  .modal-overlay {
    align-items: center;
  }

  .modal-content {
    border-radius: var(--radius-xl);
    max-height: 80vh;
    padding-bottom: 24px;
  }
}

/* --- Progress Note --- */
.progress-note {
  text-align: center;
  font-size: 0.5625rem;
  color: var(--text-weak);
  padding: 12px 0 0;
}

/* --- Responsive --- */

/* Desktop: keep bottom nav but slightly refined */
@media (min-width: 768px) {
  .nav-item {
    flex-direction: row;
    gap: 6px;
    font-size: 0.8125rem;
    max-width: 200px;
  }

  .quiz-choices {
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 400px) {
  .quiz-choices { grid-template-columns: 1fr; }
  .chunk-card-header { padding: 10px 12px; }
  .chunk-card-body-inner { padding: 0 12px 12px; }
  .test-mode-btn { font-size: 0.75rem; padding: 8px; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.hidden { display: none !important; }
