/* ── Design tokens ── */
:root {
  --ink: #1a1a1a;
  --ink-muted: #6b6b6b;
  --ink-faint: #6d6d6d; /* was #b0b0b0 — failed WCAG contrast on white */
  --surface: #faf9f6;
  --surface-card: #ffffff;
  --surface-hover: #f2f0eb;
  --accent: #c04d28;
  --accent-light: #f5ede9;
  --correct: #2d6a4f;
  --correct-light: #d8f0e6;
  --wrong: #9b2226;
  --wrong-light: #fce8e8;
  --border: rgba(26,26,26,0.1);
  --border-strong: rgba(26,26,26,0.2);
  --radius: 4px;
  --radius-lg: 12px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--surface);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Utility ── */
.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Headings receive programmatic focus for screen readers only */
.question-text:focus,
.end-title:focus { outline: none; }

kbd {
  font-family: inherit;
  font-size: 0.72rem;
  font-style: normal;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-card);
  color: var(--ink-muted);
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 249, 246, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 48px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}
.header-logo span { color: var(--accent); }

nav a {
  font-size: 0.875rem;
  color: var(--ink-muted);
  text-decoration: none;
  display: inline-block;
  padding: 10px 14px;
  border-radius: 100px;
  transition: all 0.2s var(--ease);
}
nav a:hover { color: var(--ink); background: var(--surface-hover); }

/* ── Hero ── */
.hero {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 72px 48px 56px;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 20px;
}
.hero-eyebrow::before {
  content: '';
  display: block;
  width: 24px;
  height: 1px;
  background: var(--accent);
}

.hero h1 {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(2.8rem, 6vw, 4.5rem);
  line-height: 1.0;
  letter-spacing: -0.03em;
  margin-bottom: 20px;
}
.hero h1 em { font-style: italic; color: var(--accent); }

.hero-description {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink-muted);
  max-width: 440px;
  font-weight: 300;
}

.hero-rule {
  /* Align with the hero's content column (760px minus 48px gutters) */
  width: calc(100% - 96px);
  max-width: 664px;
  margin: 0 auto;
  height: 1px;
  background: linear-gradient(90deg, var(--border-strong) 0%, transparent 100%);
  position: relative;
  z-index: 1;
}

/* ── Main layout ── */
.main-content {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 48px 100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Card ── */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
}

.card-label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.card-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
  margin-bottom: 28px;
}

/* ── Settings sections ── */
.setting-section {
  margin-bottom: 24px;
}

.setting-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 10px;
}

/* ── Challenge type picker ── */
.type-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.type-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: left;
  font-family: 'DM Sans', sans-serif;
}

.type-btn:hover {
  border-color: var(--ink);
  background: var(--surface-hover);
}

.type-btn.active {
  border-color: var(--ink);
  background: var(--surface-card);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.type-icon {
  font-size: 1.1rem;
  line-height: 1;
  margin-bottom: 4px;
  color: var(--ink);
}

.type-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1;
}

.type-desc {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-weight: 300;
}

/* ── Pill group ── */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  padding: 8px 16px;
  min-height: 36px;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}

.pill:hover { color: var(--ink); border-color: var(--ink); }
.pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ── Two-col layout ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Toggle row ── */
.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  width: fit-content;
}
/* Visually hidden but still keyboard-focusable (display:none removed it
   from the tab order) */
.toggle { position: relative; }
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.toggle input:focus-visible + .toggle-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--border-strong);
  border-radius: 100px;
  position: relative;
  transition: background 0.2s var(--ease);
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 14px; height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s var(--ease);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-track { background: var(--ink); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle-label { font-size: 0.875rem; color: var(--ink); }

/* Faded = visually disabled */
.faded { opacity: 0.35; pointer-events: none; }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  color: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 12px 24px;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.25s var(--ease);
  letter-spacing: 0.01em;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); transform: translateY(-1px); }
.btn-primary:disabled { cursor: not-allowed; }

.btn-ghost-sm {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--ink-muted);
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  padding: 8px 14px;
  min-height: 36px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost-sm:hover { color: var(--ink); border-color: var(--ink); }

.btn-ghost-outline {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  color: var(--ink-muted);
  background: none;
  border: 1px solid var(--border-strong);
  border-radius: 100px;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-ghost-outline:hover { color: var(--ink); border-color: var(--ink); }

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 24px;
}

.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-num {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.stat-lbl {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.stat-divider { width: 1px; height: 32px; background: var(--border); }

.stats-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ── Progress ── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.progress-track {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 100px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  border-radius: 100px;
  transition: width 0.35s var(--ease);
}
.progress-label {
  font-size: 0.75rem;
  color: var(--ink-faint);
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

/* ── Quiz card ──
   Only animates once on mount; answers animate individually thereafter. ── */
.quiz-card {
  animation: fadeUp 0.35s var(--ease) both;
  /* After first render the card stays put — answers handle their own entrance */
}

.question-wrap {
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
  margin-bottom: 20px;
}

.question-num {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
}

.question-text {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  line-height: 1.3;
  letter-spacing: -0.01em;
}

/* ── Answer grid ── */
.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ordering-grid { grid-template-columns: 1fr; }

/* Revelation name-to-type: two large centred buttons */
.answers-grid--two {
  grid-template-columns: 1fr 1fr;
}
.answers-grid--two .answer-btn {
  justify-content: center;
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  padding: 20px 16px;
}

/* Each answer fades up individually — staggered via inline animation-delay */
.answer-btn {
  position: relative;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 13px 16px;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.18s var(--ease);
  line-height: 1.4;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: answerIn 0.3s var(--ease) both;
}

.answer-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--ink);
  transform: translateY(-1px);
}

.answer-btn:disabled { cursor: default; transform: none; }

.answer-btn.selected {
  background: var(--surface-hover);
  border-color: var(--ink);
  border-width: 2px;
  color: var(--ink);
  font-weight: 500;
}

.answer-btn.correct {
  background: var(--correct-light);
  border-color: var(--correct);
  color: var(--correct);
  font-weight: 500;
}

.answer-btn.wrong {
  background: var(--wrong-light);
  border-color: var(--wrong);
  color: var(--wrong);
}

/* ── Confirm bar ── */
.confirm-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  animation: fadeUp 0.2s var(--ease) both;
}

.kbd-hint {
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--ink-faint);
}
.kbd-hint:empty { display: none; }

.confirm-hint {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-style: italic;
}

/* ── Order badge ── */
.order-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 500;
  flex-shrink: 0;
}

.order-hint {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--wrong);
  opacity: 0.8;
  white-space: nowrap;
}

/* ── End screen ── */
.end-card {
  text-align: center;
  padding: 48px 32px;
  animation: fadeUp 0.45s var(--ease) both;
}

.end-icon { font-size: 2rem; color: var(--accent); margin-bottom: 16px; }

.end-title {
  font-family: 'DM Serif Display', serif;
  font-size: 2rem;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.end-mode-label {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 28px;
}

.end-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 36px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.end-stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.end-stat-num {
  font-family: 'DM Serif Display', serif;
  font-size: 2.2rem;
  line-height: 1;
  color: var(--ink);
  letter-spacing: -0.03em;
}
.end-stat-lbl {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

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

/* ── Disputed revelation note ── */
.disputed-note {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fffbf0;
  border: 1px solid #e8c84a;
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #6b5a00;
  animation: fadeUp 0.25s var(--ease) both;
}

.disputed-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.disclaimer {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  opacity: 0.8;
}

.disclaimer-banner {
  position: relative;
  z-index: 1;
  margin: 1.5rem auto 0;
  width: calc(100% - 96px);
  max-width: 664px;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
  background: #fffbf0;
  border: 1px solid rgba(232, 200, 74, 0.5);
  border-radius: 8px;
  text-align: center;
}

/* ── Footer ── */
footer {
  position: relative;
  z-index: 1;
  border-top: 1px solid var(--border);
  padding: 28px 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
footer p { font-size: 0.8rem; color: var(--ink-faint); }
footer a { color: var(--ink-muted); text-decoration: none; font-size: 0.8rem; }
footer a:hover { color: var(--ink); }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Answer buttons animate in on each new question */
@keyframes answerIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Wrong answer shake */
@keyframes shake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(5px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

.shake { animation: shake 0.4s var(--ease) both; }

/* ── Mobile ── */
@media (max-width: 640px) {
  header { padding: 0 20px; }
  .hero { padding: 48px 20px 40px; }
  .hero-rule,
  .disclaimer-banner { width: calc(100% - 40px); }
  .disclaimer-banner { text-align: left; }
  .main-content { padding: 32px 20px 80px; }
  .card { padding: 20px; }
  .type-picker { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; gap: 16px; }
  .answers-grid { grid-template-columns: 1fr; }
  .stats-bar { flex-wrap: wrap; gap: 12px; }
  .stats-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
  .end-stats { gap: 20px; }
  .confirm-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .confirm-bar .btn-primary { justify-content: center; }
  .kbd-hint { display: none; } /* touch devices rarely have number keys */
  .end-stat-num { font-size: 1.8rem; }
  footer { padding: 24px 20px; }
}

@media (max-width: 380px) {
  .type-picker { grid-template-columns: 1fr; }
  .stat-divider { display: none; }
  .end-stats { gap: 14px; }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}