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

:root {
  --primary: #667eea;
  --primary-dark: #5a67d8;
  --success: #48bb78;
  --success-dark: #38a169;
  --success-light: #f0fff4;
  --success-text: #276749;
  --error: #fc8181;
  --error-dark: #e53e3e;
  --error-light: #fff5f5;
  --error-text: #c53030;
  --text-dark: #1a202c;
  --text-mid: #2d3748;
  --text-light: #718096;
  --text-xlight: #a0aec0;
  --border: #e2e8f0;
  --border-mid: #cbd5e0;
  --bg: #f0f4f8;
  --bg-card: #fff;
  --bg-hover: #f7f8ff;
  --badge-bg: #ebf4ff;
  --badge-text: #3182ce;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}

/* Back navigation */
.back-nav {
  align-self: flex-start;
  margin-bottom: 16px;
  width: 100%;
  max-width: 500px;
}

.back-nav a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.back-nav a:hover { text-decoration: underline; }

/* Header */
header {
  text-align: center;
  margin-bottom: 28px;
}

header h1 {
  font-size: 1.8rem;
  color: var(--text-dark);
  letter-spacing: -0.5px;
}

header p {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* Home menu */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 500px;
}

.menu-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 24px 16px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  border: 2px solid transparent;
  transition: all 0.15s;
}

.menu-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 20px rgba(102,126,234,0.15);
  transform: translateY(-2px);
}

.menu-card-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 6px;
}

.menu-card h2 {
  font-size: 1.05rem;
  color: var(--text-dark);
  font-weight: 700;
}

.menu-card p {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Level / Category selector */
.levels {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.level-btn {
  padding: 8px 20px;
  border: 2px solid var(--border-mid);
  background: var(--bg-card);
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #4a5568;
  cursor: pointer;
  transition: all 0.15s;
}

.level-btn:hover { border-color: var(--primary); color: var(--primary); }

.level-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Card */
.card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  padding: 32px 28px;
  width: 100%;
  max-width: 480px;
}

/* Score */
.score {
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-xlight);
  margin-bottom: 20px;
  font-weight: 600;
}

/* Word / Character display */
.word-area {
  text-align: center;
  margin-bottom: 28px;
}

.word-ja {
  font-size: 3.2rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.1;
}

.char-display {
  font-size: 5rem;
  font-weight: 700;
  color: var(--text-dark);
  line-height: 1.1;
}

.word-reading {
  margin-top: 8px;
  font-size: 1rem;
  color: var(--text-light);
}

.word-level-badge {
  display: inline-block;
  margin-top: 10px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}

/* Choices */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.choice-btn {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  text-align: left;
  font-size: 0.95rem;
  color: var(--text-mid);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  line-height: 1.4;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--bg-hover);
}

.choice-btn:disabled { cursor: default; }

.choice-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success-text);
  font-weight: 600;
}

.choice-btn.wrong {
  border-color: var(--error);
  background: var(--error-light);
  color: var(--error-text);
}

/* Feedback */
.feedback {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  min-height: 24px;
  margin-bottom: 16px;
}

.feedback.correct { color: var(--success-dark); }
.feedback.wrong   { color: var(--error-dark); }

/* Post-answer actions */
.post-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.next-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.next-btn:hover { background: var(--primary-dark); }

.jisho-link {
  font-size: 0.875rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.jisho-link:hover { text-decoration: underline; }

/* Loading */
.loading {
  text-align: center;
  color: var(--text-xlight);
  font-size: 0.95rem;
  padding: 20px 0;
}

.hidden { display: none; }
