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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.7;
}

/* ===== Screen / Layout ===== */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ===== Top Screen ===== */
.top-container h1 {
  font-size: 1.9rem;
  font-weight: 800;
  text-align: center;
  color: var(--primary);
  padding: 32px 0 8px;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

.category-section,
.mode-section,
.count-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.category-section h2,
.mode-section h2,
.count-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
}

/* Category grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.cat-btn {
  padding: 10px 8px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  transition: all 0.15s;
  color: var(--text-muted);
  line-height: 1.3;
}

.cat-btn:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.cat-btn.selected { border-color: var(--primary); background: var(--primary); color: #fff; }

.cat-btn .cat-count {
  display: block;
  font-size: 0.72rem;
  font-weight: 400;
  margin-top: 2px;
  opacity: 0.8;
}

/* Radio buttons */
.mode-options,
.count-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
}

.radio-label input[type="radio"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* Start button */
.btn-start {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 8px;
}

/* ===== Buttons (common) ===== */
.btn {
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  transition: all 0.15s;
  padding: 12px 24px;
}

.btn:hover { filter: brightness(0.92); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-start { background: var(--primary); color: #fff; }
.btn-next  { background: var(--primary); color: #fff; margin-top: 16px; }
.btn-review { background: #f59e0b; color: #fff; }
.btn-top   { background: var(--text-muted); color: #fff; }

/* ===== Quiz Header ===== */
.quiz-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  background: #dbeafe;
  color: var(--primary);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-review { background: #fef3c7; color: #92400e; }

.progress-bar-wrap {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
  border-radius: 99px;
  transition: width 0.4s ease;
  width: 0%;
}

.score-display {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: right;
  font-weight: 600;
}

/* ===== Question Card ===== */
.question-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.question-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  border-left: 3px solid var(--primary);
  padding-left: 10px;
}

.question-text {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.8;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

/* ===== Options ===== */
.options-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-item {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1.6;
  background: var(--surface2);
  transition: all 0.15s;
  position: relative;
  padding-left: 48px;
}

.option-item::before {
  content: attr(data-label);
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.option-item:hover:not(.disabled) {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary);
}

.option-item:hover:not(.disabled)::before {
  background: var(--primary);
  color: #fff;
}

.option-item.correct {
  border-color: var(--success);
  background: #f0fdf4;
  color: var(--success);
  font-weight: 700;
}

.option-item.correct::before { background: var(--success); color: #fff; }

.option-item.incorrect {
  border-color: var(--danger);
  background: #fef2f2;
  color: var(--danger);
}

.option-item.incorrect::before { background: var(--danger); color: #fff; }

.option-item.disabled { cursor: default; }

/* ===== Explanation Box ===== */
.explanation-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

.explanation-box.hidden { display: none; }

.result-label {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 12px;
}

.result-label.correct { color: var(--success); }
.result-label.incorrect { color: var(--danger); }

.explanation-text {
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--text);
  white-space: pre-wrap;
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px 16px;
  border-left: 4px solid var(--primary);
}

/* ===== Result Screen ===== */
.result-container { text-align: center; padding-top: 48px; }

.result-container h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 24px;
}

.result-score-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  display: inline-block;
  margin-bottom: 24px;
  box-shadow: var(--shadow-lg);
  min-width: 260px;
}

.result-score {
  font-size: 4rem;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 12px;
}

.result-score .slash { font-size: 2.5rem; color: var(--text-muted); }
#final-total { font-size: 2.5rem; color: var(--text-muted); }

.result-rank {
  font-size: 1.3rem;
  font-weight: 800;
  margin-top: 8px;
}

.result-breakdown {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 0 auto 24px;
  max-width: 520px;
  box-shadow: var(--shadow);
  text-align: left;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.breakdown-row:last-child { border-bottom: none; }

.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.result-actions .btn { min-width: 180px; }

/* ===== Abort Button ===== */
.btn-abort {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  font-family: inherit;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s;
  white-space: nowrap;
  margin-left: auto;
}

.btn-abort:hover {
  background: #fef2f2;
  border-color: var(--danger);
  color: var(--danger);
}

/* ===== Responsive ===== */
@media (max-width: 500px) {
  .top-container h1 { font-size: 1.4rem; }
  .result-score { font-size: 3rem; }
  .container { padding: 16px 12px 40px; }
  .question-card { padding: 18px 16px; }
  .explanation-box { padding: 16px; }
  .category-grid { grid-template-columns: repeat(2, 1fr); }
}
