/* ── Design Tokens ── */
:root {
  --ink: #1a1a1a;
  --paper: #f5f0e8;
  --paper-dark: #e8e0d0;
  --accent: #c0392b;
  --accent-light: #e74c3c;
  --green: #27ae60;
  --green-light: #2ecc71;
  --muted: #7f8c8d;
  --code-bg: #2d2d2d;
  --shadow: rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.7;
  min-height: 100vh;
}

/* Texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
}

.container {
  max-width: 740px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 60px 0 40px;
  border-bottom: 3px double var(--ink);
  margin-bottom: 48px;
}

header .overline {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}

header h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

header h1 em {
  font-style: italic;
  color: var(--accent);
}

header .subtitle {
  font-size: 15px;
  color: var(--muted);
  font-weight: 300;
  max-width: 520px;
  margin: 0 auto;
}

/* ── Progress ── */
.progress-wrap {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--paper);
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--paper-dark);
  backdrop-filter: blur(8px);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--muted);
}

.progress-section-name {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1px;
}

.progress-bar {
  height: 3px;
  background: var(--paper-dark);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--ink);
  border-radius: 2px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Quiz Card ── */
.quiz-card {
  opacity: 0;
  transform: translateY(20px);
  animation: fadeUp 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes fadeUp {
  to { opacity: 1; transform: translateY(0); }
}

.question-number {
  font-family: 'Playfair Display', serif;
  font-size: 64px;
  font-weight: 700;
  color: var(--paper-dark);
  line-height: 1;
  margin-bottom: -8px;
  user-select: none;
}

.question-category {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
  display: inline-block;
  border-bottom: 1px solid var(--accent);
  padding-bottom: 2px;
}

.question-text {
  font-size: 20px;
  font-weight: 500;
  line-height: 1.6;
  margin-bottom: 32px;
}

.question-text code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  background: var(--paper-dark);
  padding: 2px 6px;
  border-radius: 3px;
}

/* ── Options ── */
.options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 32px;
}

.option {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  border: 1.5px solid transparent;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px var(--shadow);
}

.option:hover {
  border-color: var(--ink);
  transform: translateX(4px);
}

.option.selected {
  border-color: var(--ink);
  background: white;
}

.option.correct {
  border-color: var(--green);
  background: #f0faf4;
}

.option.incorrect {
  border-color: var(--accent);
  background: #fdf2f2;
}

.option.disabled {
  pointer-events: none;
}

.option-marker {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.2s ease;
  margin-top: 1px;
}

.option.selected .option-marker {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}

.option.correct .option-marker {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.option.incorrect .option-marker {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.option-text {
  font-size: 15px;
  line-height: 1.6;
}

.option-text code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  background: var(--paper-dark);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Explanation ── */
.explanation {
  display: none;
  padding: 24px;
  background: white;
  border-left: 3px solid var(--ink);
  margin-bottom: 32px;
  border-radius: 0 4px 4px 0;
  animation: fadeUp 0.3s ease forwards;
}

.explanation.show {
  display: block;
}

.explanation-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.explanation p {
  font-size: 14px;
  line-height: 1.7;
  color: #444;
}

/* ── Code Block ── */
.code-block {
  background: var(--code-bg);
  color: #e0e0e0;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  line-height: 1.65;
  padding: 20px 24px;
  border-radius: 4px;
  margin: 16px 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-block .label {
  color: var(--accent-light);
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  display: block;
  margin-bottom: 8px;
  opacity: 0.7;
}

.code-block .good { color: var(--green-light); }
.code-block .bad { color: var(--accent-light); }

/* ── Navigation ── */
.nav-row {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 48px;
  border-bottom: 1px solid var(--paper-dark);
  margin-bottom: 48px;
}

.btn {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 32px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

.btn:hover {
  background: transparent;
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn:disabled:hover {
  background: var(--ink);
  color: white;
}

/* ── Results ── */
.results {
  text-align: center;
  padding: 60px 0 80px;
  animation: fadeUp 0.6s ease forwards;
}

.results .score-display {
  font-family: 'Playfair Display', serif;
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 8px;
}

.results .score-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 32px;
}

.results .grade {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 12px;
}

.results .grade-desc {
  font-size: 15px;
  color: var(--muted);
  max-width: 400px;
  margin: 0 auto 40px;
  font-weight: 300;
  line-height: 1.7;
}

.score-bar-wrap {
  max-width: 360px;
  margin: 0 auto 40px;
}

.score-bar {
  height: 6px;
  background: var(--paper-dark);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
  background: var(--ink);
}

.score-bar-fill.high { background: var(--green); }
.score-bar-fill.mid { background: #f39c12; }
.score-bar-fill.low { background: var(--accent); }

/* Results breakdown */
.breakdown {
  text-align: left;
  max-width: 520px;
  margin: 0 auto 48px;
}

.breakdown-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--paper-dark);
}

.breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--paper-dark);
  font-size: 14px;
}

.breakdown-item .q-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--muted);
  width: 32px;
}

.breakdown-item .q-title {
  flex: 1;
  margin: 0 12px;
}

.breakdown-item .q-result {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
}

.breakdown-item .q-result.pass { color: var(--green); }
.breakdown-item .q-result.fail { color: var(--accent); }

.btn-restart {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
}

.btn-restart:hover {
  background: var(--ink);
  color: white;
}

/* ── Start screen ── */
.start-screen {
  text-align: center;
  padding: 40px 0 80px;
  animation: fadeUp 0.5s ease forwards;
}

.start-screen .intro {
  font-size: 15px;
  color: #555;
  max-width: 480px;
  margin: 0 auto 40px;
  line-height: 1.8;
  font-weight: 300;
}

.start-screen .meta-row {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 40px;
}

.meta-item {
  text-align: center;
}

.meta-item .meta-val {
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  font-weight: 700;
}

.meta-item .meta-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
}

.topics {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 40px;
}

.topic-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 6px 14px;
  border: 1px solid var(--paper-dark);
  border-radius: 20px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* ── Section Selection ── */
.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 40px;
}

.section-card {
  background: white;
  border: 1.5px solid transparent;
  border-radius: 4px;
  padding: 24px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px var(--shadow);
}

.section-card:hover {
  border-color: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

.section-card.completed {
  border-color: var(--green);
  background: #f8fdf9;
}

.section-icon {
  font-family: 'JetBrains Mono', monospace;
  font-size: 24px;
  margin-bottom: 12px;
  color: var(--accent);
}

.section-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.section-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 12px;
  font-weight: 300;
}

.section-meta {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

.section-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--green);
  margin-top: 8px;
  font-weight: 500;
}

/* ── Total Progress on Start Screen ── */
.total-progress {
  max-width: 400px;
  margin: 0 auto 32px;
  padding: 20px 24px;
  background: white;
  border-radius: 4px;
  box-shadow: 0 1px 3px var(--shadow);
}

.total-progress-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.total-progress-bar {
  height: 4px;
  background: var(--paper-dark);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.total-progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.total-progress-text {
  font-size: 13px;
  color: var(--muted);
}

/* ── Dividers ── */
.divider {
  border: none;
  border-top: 1px solid var(--paper-dark);
  margin: 48px 0;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 32px 0;
  border-top: 1px solid var(--paper-dark);
  margin-top: 40px;
}

footer p {
  font-size: 12px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  header { padding: 40px 0 32px; }
  .question-number { font-size: 48px; }
  .question-text { font-size: 17px; }
  .option { padding: 14px 16px; }
  .meta-row { gap: 24px; }
  .section-grid { grid-template-columns: 1fr; }
}
