:root {
  --ink: #1c1612;
  --ink-soft: #5c5348;
  --paper: #f3ead8;
  --paper-deep: #e8dcc4;
  --bg: #161310;
  --bg-elev: #221c18;
  --line: rgba(28, 22, 18, 0.12);
  --gold: #e8b86d;
  --gold-ink: #3d2a10;
  --teal: #2f6f6a;
  --coral: #c45c3e;
  --green: #3d7a55;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Outfit", sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, #3a2a1c 0%, transparent 50%),
    radial-gradient(900px 500px at 100% 0%, #1d332e 0%, transparent 45%),
    var(--bg);
  color: var(--paper);
  line-height: 1.5;
}

.app {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--gold);
  color: var(--gold-ink);
  font-family: "Fraunces", serif;
  font-size: 14px;
  font-weight: 700;
}

.brand-tag {
  margin: 0;
  color: #c9bba6;
  font-size: 0.92rem;
}

.screen[hidden] {
  display: none;
}

.hero-card,
.question-card,
.results-hero,
.review-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-card,
.results-hero {
  padding: 36px 32px 28px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--teal);
}

h1 {
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.15;
  margin: 0 0 14px;
}

.lede {
  margin: 0 0 28px;
  color: var(--ink-soft);
  max-width: 42em;
}

.lede strong {
  color: var(--ink);
}

.text-back {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  padding: 0;
  margin: 0 0 16px;
  cursor: pointer;
}

.game-pick {
  display: grid;
  gap: 12px;
}

.game-card {
  appearance: none;
  width: 100%;
  border: 1.5px solid rgba(28, 22, 18, 0.12);
  background: #fff8ec;
  border-radius: 18px;
  padding: 18px 18px 16px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.game-card:hover {
  transform: translateY(-2px);
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(28, 22, 18, 0.08);
  background: #fff;
}

.game-no {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 4px;
}

.game-name {
  display: block;
  font-family: "Fraunces", serif;
  font-size: 1.45rem;
  font-weight: 700;
}

.game-copy {
  display: block;
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.field {
  margin-bottom: 22px;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

#question-count-value {
  font-family: "Fraunces", serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.diff-card {
  appearance: none;
  border: 1.5px solid rgba(28, 22, 18, 0.14);
  background: #fff8ec;
  border-radius: 16px;
  padding: 14px 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.diff-card:hover {
  transform: translateY(-1px);
}

.diff-card.is-selected {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(28, 22, 18, 0.08);
  background: #fff;
}

.diff-name {
  display: block;
  font-weight: 700;
}

.diff-range {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
}

.btn {
  appearance: none;
  border: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 14px;
  padding: 14px 18px;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  width: 100%;
  background: var(--ink);
  color: var(--paper);
}

.btn-secondary {
  background: #efe4cf;
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: #e8dcc4;
  padding: 8px 12px;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

.howto {
  margin-top: 22px;
  color: var(--ink-soft);
}

.howto summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink);
}

.howto ul {
  padding-left: 18px;
}

.howto code {
  font-family: "Outfit", sans-serif;
  background: #efe4cf;
  padding: 1px 6px;
  border-radius: 6px;
}

.quiz-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.progress-wrap {
  flex: 1;
}

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: #e8dcc4;
  font-weight: 600;
}

.badge {
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(232, 184, 109, 0.16);
  color: var(--gold);
  border: 1px solid rgba(232, 184, 109, 0.35);
  padding: 4px 8px;
  border-radius: 999px;
}

.badge.is-prime {
  background: rgba(47, 111, 106, 0.2);
  border-color: rgba(47, 111, 106, 0.45);
  color: #9ad4cd;
}

.progress-bar {
  height: 6px;
  background: rgba(243, 234, 216, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 10%;
  background: var(--gold);
  border-radius: inherit;
  transition: width 0.25s ease;
}

.question-card {
  padding: 32px 28px 28px;
  text-align: center;
}

.prompt {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-weight: 600;
}

.big-number {
  font-family: "Fraunces", serif;
  font-size: clamp(4.4rem, 16vw, 7.2rem);
  line-height: 1;
  margin: 8px 0 22px;
  letter-spacing: -0.04em;
}

.big-number.is-pair {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.28em;
  font-size: clamp(2.8rem, 11vw, 4.8rem);
}

.num-and {
  font-family: "Outfit", sans-serif;
  font-size: 0.38em;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-soft);
}

.answer-input {
  width: 100%;
  border: 1.5px solid rgba(28, 22, 18, 0.16);
  background: #fff8ec;
  border-radius: 14px;
  padding: 14px 16px;
  font: inherit;
  font-size: 1.15rem;
  color: var(--ink);
  text-align: center;
}

.answer-input:focus {
  outline: 3px solid rgba(47, 111, 106, 0.28);
  border-color: var(--teal);
}

.hint {
  margin: 10px 0 18px;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.input-error {
  margin: -8px 0 16px;
  color: var(--coral);
  font-weight: 600;
  font-size: 0.92rem;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 22px 0 26px;
}

.score-stamp {
  flex: 0 0 auto;
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border: 4px solid var(--coral);
  color: var(--coral);
  border-radius: 50%;
  font-family: "Fraunces", serif;
  font-size: 1.7rem;
  font-weight: 700;
  transform: rotate(-8deg);
  background: rgba(196, 92, 62, 0.06);
}

.score-stamp.is-high {
  border-color: var(--green);
  color: var(--green);
  background: rgba(61, 122, 85, 0.08);
}

.score-stamp.is-mid {
  border-color: #b45309;
  color: #b45309;
  background: rgba(232, 184, 109, 0.16);
}

.score-copy p {
  margin: 0 0 6px;
}

.muted {
  color: var(--ink-soft);
}

.results-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}

.review-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.review-section {
  margin: 10px 0 0;
  font-family: "Fraunces", serif;
  font-size: 1.2rem;
  color: #e8dcc4;
}

.review-card {
  padding: 18px 18px 16px;
  border-left: 6px solid var(--green);
}

.review-card.is-wrong {
  border-left-color: var(--coral);
}

.review-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.review-kicker {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.review-title {
  margin: 2px 0 0;
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
}

.pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(61, 122, 85, 0.12);
  color: var(--green);
}

.review-card.is-wrong .pill {
  background: rgba(196, 92, 62, 0.12);
  color: var(--coral);
}

.answer-compare {
  display: grid;
  gap: 6px;
  margin: 14px 0;
  font-size: 0.95rem;
}

.answer-compare span {
  color: var(--ink-soft);
}

.viz {
  background: #fff8ec;
  border-radius: 16px;
  padding: 16px 12px;
  overflow-x: auto;
}

.viz-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 36px;
  align-items: start;
  justify-items: center;
}

.viz-caption {
  margin: 0 0 12px;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: center;
}

.pair-list {
  display: grid;
  gap: 10px;
}

.pair-row {
  display: grid;
  grid-template-columns: 44px 44px;
  column-gap: 14px;
  justify-content: center;
}

.pair-node {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #1c1612;
  background: #fff8ec;
  color: #1c1612;
  display: grid;
  place-items: center;
  font-family: "Fraunces", serif;
  font-weight: 700;
  font-size: 16px;
}

.pair-node.is-prime {
  background: #2f6f6a;
  border-color: #2f6f6a;
  color: #f3ead8;
}

.pair-node.is-compact {
  font-size: 13px;
}

.pair-node.is-shared {
  background: var(--gold);
  border-color: #3d2a10;
  color: #3d2a10;
}

.node-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.viz-stack {
  grid-template-columns: 1fr;
  justify-items: stretch;
}

.joint-table {
  display: inline-grid;
  grid-template-columns: auto auto auto;
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
  line-height: 1.35;
  column-gap: 0;
}

.joint-num {
  text-align: right;
  padding: 0 10px 0 0;
}

.joint-num + .joint-num {
  padding: 0 12px 0 10px;
  border-right: 2px solid var(--ink);
}

.bolen-div.is-shared-div {
  font-weight: 700;
}

.factor-eq {
  margin: 12px 0 0;
  text-align: center;
  font-family: "Fraunces", serif;
  font-size: 1.15rem;
}

.tree-svg {
  display: block;
  margin: 0 auto;
  overflow: visible;
}

.bolen-table {
  display: inline-grid;
  grid-template-columns: auto auto;
  font-family: "Fraunces", serif;
  font-size: 1.45rem;
  line-height: 1.35;
  margin: 0 auto;
}

.bolen-wrap {
  display: flex;
  justify-content: center;
}

.bolen-num {
  text-align: right;
  padding: 0 12px 0 0;
  border-right: 2px solid var(--ink);
}

.bolen-div {
  padding: 0 0 0 12px;
  color: var(--coral);
  min-width: 1.4em;
}

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

@media (max-width: 640px) {
  .app {
    width: min(100% - 20px, 760px);
    padding-top: 18px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .hero-card,
  .results-hero,
  .question-card {
    padding: 24px 18px 20px;
  }

  .difficulty,
  .results-actions {
    grid-template-columns: 1fr;
  }

  .score-row {
    flex-direction: column;
    align-items: flex-start;
  }

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