/* ===== CSS Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #1a1a1a;
  --bg-hover: #252525;
  --border: #2a2a2a;
  --text-primary: #e8e8e8;
  --text-secondary: #909090;
  --accent: #6ee7b7;
  --accent-dim: rgba(110, 231, 183, 0.15);
  --error: #f87171;
  --error-dim: rgba(248, 113, 113, 0.15);
  --gold: #fbbf24;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.2s ease;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  user-select: none;
}

/* ===== Language Toggle (top-right) ===== */
.lang-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
  z-index: 100;
}
.lang-toggle button {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
}
.lang-toggle button.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* ===== Score (top-center) ===== */
.score-bar {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 1.2rem;
  font-size: 0.95rem;
  z-index: 100;
}
.score-bar .icon { font-size: 1.1rem; }
.score-bar .value {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: center;
}

/* ===== Containers ===== */
.container {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

/* ===== Welcome Screen ===== */
.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; align-items: center; gap: 2rem; }

.welcome h1 {
  font-size: 2.4rem;
  text-align: center;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.welcome h1 span { color: var(--accent); }

.subtitle {
  color: var(--text-secondary);
  text-align: center;
  font-size: 0.95rem;
  max-width: 400px;
  line-height: 1.6;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 2rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}
.btn-primary {
  background: var(--accent);
  color: #0a0a0a;
}
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Mode Selection ===== */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  width: 100%;
  max-width: 420px;
}
.mode-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-card .emoji { font-size: 2.4rem; margin-bottom: 0.6rem; }
.mode-card h3 { font-size: 1rem; margin-bottom: 0.3rem; }
.mode-card p { color: var(--text-secondary); font-size: 0.8rem; line-height: 1.5; }

/* ===== Quiz Area ===== */
.quiz-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 1rem;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* Flashcard */
.flashcard {
  width: 220px;
  height: 220px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5.5rem;
  letter-spacing: -0.02em;
  transition: all 0.3s ease;
}
.flashcard.correct { border-color: var(--accent); box-shadow: 0 0 30px rgba(110, 231, 183, 0.2); }
.flashcard.wrong   { border-color: var(--error); box-shadow: 0 0 30px rgba(248, 113, 113, 0.2); }

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
  max-width: 420px;
}
.option-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 0.8rem;
  color: var(--text-primary);
  font-size: 1.05rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.option-btn:hover:not(.disabled) { border-color: var(--accent); background: var(--bg-hover); }
.option-btn.correct { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); font-weight: 600; }
.option-btn.wrong   { border-color: var(--error); background: var(--error-dim); color: var(--error); }
.option-btn.disabled { pointer-events: none; opacity: 0.5; }

/* Missed indicator */
.missed-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error-dim);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.missed-toast.show { opacity: 1; }

/* ===== Results Screen ===== */
.results h2 { font-size: 1.8rem; text-align: center; margin-bottom: 0.5rem; }
.results .score-display {
  text-align: center;
  font-size: 3rem;
  font-weight: 700;
  color: var(--accent);
}
.results .stats {
  display: flex;
  gap: 2rem;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.missed-list {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.missed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.2rem;
}
.missed-item .kana { font-size: 1.6rem; }
.missed-item .answer { color: var(--text-secondary); font-size: 0.9rem; }

.results-actions { display: flex; gap: 1rem; margin-top: 1rem; }

/* ===== Animations ===== */
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: slideUp 0.35s ease forwards; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .flashcard { width: 170px; height: 170px; font-size: 4rem; }
  .mode-grid { grid-template-columns: 1fr; max-width: 280px; }
  .welcome h1 { font-size: 1.8rem; }
}
