:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --error: #dc2626;
  --error-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
}

/* Dark mode */
[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-light: #1e3a5f;
  --success: #4ade80;
  --success-light: #14532d;
  --error: #f87171;
  --error-light: #450a0a;
  --warning: #fbbf24;
  --warning-light: #451a03;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
}

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

body {
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
[data-theme="dark"] .header {
  background: linear-gradient(135deg, #1e3a5f, #3b1f6e);
}
.header h1 { font-size: 1.5rem; font-weight: 700; }
.header-left { display: flex; align-items: center; gap: 16px; }
.header-stats {
  display: flex;
  gap: 24px;
  font-size: 0.9rem;
  opacity: 0.9;
}
.header-stats span { display: flex; align-items: center; gap: 6px; }

/* Theme toggle */
.theme-toggle {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.theme-toggle:hover { background: rgba(255,255,255,0.3); }

/* Navigation */
.nav {
  display: flex;
  gap: 8px;
  padding: 16px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  transition: background 0.3s;
}
.nav-btn {
  padding: 8px 20px;
  border: 2px solid var(--border);
  border-radius: 24px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-btn:hover { border-color: var(--primary); color: var(--primary); }
.nav-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Mode selector */
.mode-bar {
  display: flex;
  gap: 12px;
  padding: 12px 32px;
  align-items: center;
  flex-wrap: wrap;
}
.mode-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.mode-btn:hover { background: var(--primary-light); }
.mode-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Main content */
.main {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 32px;
}

/* Question card */
.question-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 20px;
  transition: background 0.3s;
}
.question-meta {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.badge {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-category { background: var(--primary-light); color: var(--primary); }
.badge-difficulty { background: var(--warning-light); color: #b45309; }
[data-theme="dark"] .badge-difficulty { color: var(--warning); }
.badge-source { background: var(--border); color: var(--text-muted); }
.badge-weak { background: var(--error-light); color: var(--error); }

.question-number {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.question-text {
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 24px;
  line-height: 1.8;
  white-space: pre-wrap;
}

/* Term links */
.term-link {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-style: dotted;
  cursor: pointer;
  transition: color 0.2s;
}
.term-link:hover { color: #7c3aed; }

/* Choices */
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  text-align: left;
  transition: all 0.2s;
  line-height: 1.6;
}
.choice-btn:hover:not(.disabled) {
  border-color: var(--primary);
  background: var(--primary-light);
}
.choice-label {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
}
.choice-btn.correct .choice-label { background: var(--success); color: white; }
.choice-btn.wrong {
  border-color: var(--error);
  background: var(--error-light);
}
.choice-btn.wrong .choice-label { background: var(--error); color: white; }
.choice-btn.disabled { pointer-events: none; opacity: 0.7; }
.choice-btn.disabled.correct { opacity: 1; }

/* Fill-in */
.fill-input {
  width: 100%;
  padding: 14px 20px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.2s;
}
.fill-input:focus { outline: none; border-color: var(--primary); }
.submit-btn {
  margin-top: 12px;
  padding: 12px 32px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.submit-btn:hover { background: #1d4ed8; }

/* Explanation */
.explanation {
  margin-top: 20px;
  padding: 20px;
  border-radius: 10px;
  background: var(--bg);
  border-left: 4px solid var(--primary);
  display: none;
}
.explanation.show { display: block; }
.explanation h3 { font-size: 0.95rem; color: var(--primary); margin-bottom: 8px; }
.explanation p { font-size: 0.95rem; line-height: 1.8; }

/* Term popup */
.term-popup {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 500px;
  width: 90%;
  z-index: 1000;
  max-height: 80vh;
  overflow-y: auto;
}
.term-popup.show { display: block; }
.term-popup h2 { font-size: 1.2rem; margin-bottom: 4px; }
.term-popup .one-liner { color: var(--text-muted); margin-bottom: 16px; font-size: 0.9rem; }
.term-popup .detail { line-height: 1.8; margin-bottom: 16px; }
.term-popup .related { font-size: 0.85rem; color: var(--text-muted); }
.term-popup .close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}
.overlay.show { display: block; }

/* Next button */
.next-btn {
  margin-top: 16px;
  padding: 12px 32px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  display: none;
  transition: background 0.2s;
}
.next-btn:hover { background: #15803d; }
.next-btn.show { display: inline-block; }

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  border-radius: 3px;
  transition: width 0.3s;
}

/* Results */
.results-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.results-card h2 { font-size: 1.5rem; margin-bottom: 20px; }
.results-score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.results-detail { color: var(--text-muted); margin-bottom: 24px; }
.results-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h2 { font-size: 1.3rem; margin-bottom: 12px; color: var(--text); }

/* Coach section */
.coach-card {
  background: linear-gradient(135deg, var(--primary-light), var(--success-light));
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}
.coach-card h3 { color: var(--primary); margin-bottom: 8px; }
.coach-card p { font-size: 0.9rem; color: var(--text-muted); }

/* Stats dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  text-align: center;
}
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}
.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Category progress bars */
.category-progress {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}
.category-progress h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  color: var(--text);
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.cat-name {
  font-size: 0.85rem;
  min-width: 180px;
  color: var(--text);
}
.cat-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.cat-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s;
}
.cat-bar-fill.good { background: var(--success); }
.cat-bar-fill.medium { background: var(--warning); }
.cat-bar-fill.low { background: var(--error); }
.cat-bar-fill.none { background: var(--border); }
.cat-pct {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

/* Session timer */
.session-timer {
  font-size: 0.85rem;
  opacity: 0.8;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Keyboard hint */
.keyboard-hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}
.keyboard-hint kbd {
  background: var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.75rem;
}

/* Home button */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.home-btn {
  padding: 6px 16px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: all 0.2s;
}
.home-btn:hover { background: var(--primary-light); border-color: var(--primary); }

/* Timer buttons */
.timer-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.timer-btn:hover { background: rgba(255,255,255,0.3); }
#sessionTimer.paused { opacity: 0.4; text-decoration: line-through; }

/* Reference nav button */
.nav-btn-ref {
  background: var(--warning-light);
  border-color: var(--warning);
  color: var(--warning);
  font-weight: 600;
}
[data-theme="dark"] .nav-btn-ref { color: var(--warning); }
.nav-btn-ref:hover { background: var(--warning); color: white; }

/* Reference tabs */
.ref-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* Reference items (term list) */
.ref-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
}
.ref-item:hover { background: var(--primary-light); }
.ref-item:last-child { border-bottom: none; }
.ref-summary {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 1;
}

/* Workflow steps */
.wf-phase {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--primary);
  margin-top: 16px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.wf-phase:first-child { margin-top: 0; }
.wf-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.6;
}
.wf-step input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--primary);
}
.wf-step input[type="checkbox"]:checked + span {
  text-decoration: line-through;
  opacity: 0.5;
}
.wf-time {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Genre filter */
.genre-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.genre-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.genre-btn:hover { border-color: var(--primary); color: var(--primary); }
.genre-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Workflow detail */
.wf-detail {
  margin: 4px 0 12px 28px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text-muted);
  border-left: 3px solid var(--primary);
  white-space: pre-wrap;
}

/* Sync bar */
.sync-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  justify-content: center;
}

/* Responsive */
@media (max-width: 640px) {
  .header { padding: 16px 20px; flex-direction: column; gap: 12px; }
  .nav { padding: 12px 16px; }
  .main { padding: 16px; }
  .question-card { padding: 20px; }
  .mode-bar { padding: 12px 16px; }
  .cat-name { min-width: 120px; font-size: 0.75rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
