:root {
  --bg: #fbf7ef;
  --paper: #fffaf2;
  --ink: #181614;
  --muted: #5b534a;
  --line: #ddd2c2;
  --digit-0: #f3f4f6;
  --digit-1: #2563eb;
  --digit-2: #0ea5e9;
  --digit-3: #16a34a;
  --digit-4: #84cc16;
  --digit-5: #eab308;
  --digit-6: #f59e0b;
  --digit-7: #ef4444;
  --digit-8: #ec4899;
  --digit-9: #8b5cf6;
  --shadow: 0 12px 30px rgba(42, 28, 11, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(216, 175, 23, 0.08), transparent 22%),
    linear-gradient(180deg, #fffdf9, var(--bg));
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.55;
}

img {
  max-width: 100%;
  display: block;
}

.page {
  width: min(980px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3rem 0 5rem;
}

.hero {
  padding: 1rem 0 3rem;
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.eyebrow,
.chapter-label,
.problem-label {
  margin: 0 0 0.75rem;
  font-family: "Menlo", "Monaco", monospace;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

h1,
h2,
h3 {
  margin: 0 0 0.75rem;
  line-height: 1.08;
}

h1 {
  max-width: 14ch;
  font-size: clamp(2.8rem, 7vw, 5rem);
  margin-inline: auto;
}

h2 {
  max-width: 18ch;
  font-size: clamp(1.9rem, 4vw, 3rem);
}

h3 {
  font-size: 1.2rem;
}

.hero-subtitle {
  max-width: 24ch;
  margin: 0.35rem auto 1.5rem;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  line-height: 1.18;
  color: var(--ink);
}

.hero-text,
.chapter-text,
.chapter-note,
.summary-line,
figcaption,
.problem-answer {
  color: var(--muted);
}

.hero-text {
  max-width: 58ch;
  font-size: 1.08rem;
}

.hero-copy {
  max-width: 58ch;
  margin: 0 auto;
  text-align: left;
}

.chapter {
  padding: 2.6rem 0;
  border-bottom: 1px solid var(--line);
}

.problem-block,
.history-note,
.lead-questions,
.objection-block,
.notation-panel,
.count-lab,
.challenge-panel,
.carry-figure,
.question-strip,
.takeaway-block {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.problem-block,
.history-note,
.lead-questions,
.objection-block,
.carry-figure,
.question-strip,
.takeaway-block {
  padding: 1.1rem 1.2rem;
  margin: 1.2rem 0;
}

.argument-copy p:first-child {
  margin-top: 0;
}

.argument-copy p:last-child {
  margin-bottom: 0;
}

.problem-line {
  margin: 0 0 0.3rem;
  font-size: 1.5rem;
}

.notation-panel,
.count-lab {
  border-radius: 18px;
  padding: 1rem;
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.tab-button,
.base-button,
.representation-button,
.challenge-button,
.mosaic-base-button,
.mosaic-count-button,
.reveal-button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.65rem 0.9rem;
  font-family: "Menlo", "Monaco", monospace;
  font-size: 0.88rem;
  cursor: pointer;
}

.tab-button.active,
.base-button.active,
.representation-button.active,
.challenge-button.active,
.mosaic-base-button.active,
.mosaic-count-button.active {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.notation-stage {
  display: grid;
  gap: 1rem;
}

.equation-display {
  min-height: 4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 1.7rem;
}

.equation-word {
  font-size: 1.8rem;
  letter-spacing: 0.08em;
}

.op {
  padding: 0 0.2rem;
  color: var(--muted);
}

.legend-display {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-family: "Menlo", "Monaco", monospace;
  font-size: 0.82rem;
}

.swatch,
.digit-chip {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 0.25rem;
  border: 1px solid rgba(0, 0, 0, 0.24);
  display: inline-block;
}

.equation-chunk {
  display: inline-flex;
  gap: 0.22rem;
  align-items: center;
}

.count-summary {
  margin-bottom: 1rem;
}

.summary-line {
  margin: 0.2rem 0;
}

.lead-questions ul {
  margin: 0.6rem 0 0;
  padding-left: 1.2rem;
}

.objection-block p {
  margin: 0.55rem 0 0;
  color: var(--muted);
}

.objection-block p:first-child {
  margin-top: 0;
}

.history-note p,
.takeaway-block p {
  margin: 0.55rem 0 0;
  color: var(--muted);
}

.history-note p:first-child,
.takeaway-block p:first-child {
  margin-top: 0;
}

.concept-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1.2rem;
}

.concept-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.1rem;
}

.concept-card p {
  margin: 0;
  color: var(--muted);
}

.basis-explainer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.3rem 0;
}

.symbol-cloud-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.1rem;
}

.symbol-cloud-card p {
  color: var(--muted);
}

.symbol-cloud {
  position: relative;
  min-height: 11rem;
  margin-top: 0.8rem;
  border-radius: 16px;
  border: 1px dashed var(--line);
  background:
    radial-gradient(circle at 20% 15%, rgba(216, 175, 23, 0.08), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(251, 247, 239, 0.95));
  overflow: hidden;
}

.symbol-cloud span {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.1rem;
  min-height: 2.1rem;
  padding: 0.2rem 0.35rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-family: "Menlo", "Monaco", monospace;
  font-size: 1rem;
}

.symbol-cloud-10 span:nth-child(1),
.symbol-cloud-6 span:nth-child(1) {
  background: var(--digit-0);
  color: #181614;
  border-color: rgba(0, 0, 0, 0.16);
}

.symbol-cloud-10 span:nth-child(2),
.symbol-cloud-6 span:nth-child(2) {
  background: var(--digit-1);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(3),
.symbol-cloud-6 span:nth-child(3) {
  background: var(--digit-2);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(4),
.symbol-cloud-6 span:nth-child(4) {
  background: var(--digit-3);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(5),
.symbol-cloud-6 span:nth-child(5) {
  background: var(--digit-4);
  color: #181614;
  border-color: rgba(0, 0, 0, 0.12);
}

.symbol-cloud-10 span:nth-child(6),
.symbol-cloud-6 span:nth-child(6) {
  background: var(--digit-5);
  color: #181614;
  border-color: rgba(0, 0, 0, 0.12);
}

.symbol-cloud-10 span:nth-child(7) {
  background: var(--digit-6);
  color: #181614;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(8) {
  background: var(--digit-7);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(9) {
  background: var(--digit-8);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.1);
}

.symbol-cloud-10 span:nth-child(10) {
  background: var(--digit-9);
  color: #fff;
  border-color: rgba(0, 0, 0, 0.08);
}

.symbol-cloud-10 span:nth-child(1) { top: 14%; left: 12%; transform: rotate(-10deg); }
.symbol-cloud-10 span:nth-child(2) { top: 18%; left: 46%; transform: rotate(8deg); }
.symbol-cloud-10 span:nth-child(3) { top: 12%; left: 74%; transform: rotate(-6deg); }
.symbol-cloud-10 span:nth-child(4) { top: 42%; left: 20%; transform: rotate(11deg); }
.symbol-cloud-10 span:nth-child(5) { top: 38%; left: 55%; transform: rotate(-14deg); }
.symbol-cloud-10 span:nth-child(6) { top: 48%; left: 78%; transform: rotate(9deg); }
.symbol-cloud-10 span:nth-child(7) { top: 68%; left: 10%; transform: rotate(-7deg); }
.symbol-cloud-10 span:nth-child(8) { top: 73%; left: 35%; transform: rotate(13deg); }
.symbol-cloud-10 span:nth-child(9) { top: 66%; left: 61%; transform: rotate(-9deg); }
.symbol-cloud-10 span:nth-child(10) { top: 78%; left: 82%; transform: rotate(6deg); }

.symbol-cloud-6 span:nth-child(1) { top: 18%; left: 16%; transform: rotate(-8deg); }
.symbol-cloud-6 span:nth-child(2) { top: 12%; left: 62%; transform: rotate(11deg); }
.symbol-cloud-6 span:nth-child(3) { top: 42%; left: 28%; transform: rotate(-13deg); }
.symbol-cloud-6 span:nth-child(4) { top: 36%; left: 74%; transform: rotate(7deg); }
.symbol-cloud-6 span:nth-child(5) { top: 70%; left: 18%; transform: rotate(9deg); }
.symbol-cloud-6 span:nth-child(6) { top: 72%; left: 58%; transform: rotate(-11deg); }

.pattern-mosaic-card {
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 18px;
  padding: 1rem;
  margin: 1.3rem 0;
}

.pattern-mosaic-layout {
  display: grid;
  grid-template-columns: minmax(13rem, 16rem) minmax(16rem, 26rem);
  gap: 1rem;
  align-items: start;
  justify-content: start;
  margin-top: 0.9rem;
}

.pattern-mosaic-controls {
  display: grid;
  gap: 0.85rem;
}

.pattern-mosaic-controls .tab-row {
  margin-bottom: 0;
}

.pattern-mosaic-stage {
  height: min(60vh, 28rem);
  width: clamp(16rem, 34vw, 26rem);
}

.pattern-mosaic-canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(circle at 18% 15%, rgba(216, 175, 23, 0.08), transparent 24%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(251, 247, 239, 0.95));
}

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

.pattern-grid {
  display: grid;
  gap: 0.34rem;
}

.pattern-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.5rem;
  gap: 0.8rem;
  align-items: center;
}

.pattern-symbols {
  display: flex;
  gap: 0.22rem;
  min-height: 1.3rem;
}

.pattern-symbols-digits {
  gap: 0.55rem;
}

.pattern-symbols-hands {
  gap: 0.28rem;
}

.challenge-panel {
  border-radius: 18px;
  padding: 1rem;
}

.challenge-line,
.challenge-answer {
  min-height: 4rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.challenge-answer {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.student-strip {
  margin-top: 1.4rem;
}

.student-line {
  margin-top: 0.8rem;
  justify-content: center;
}

.reveal-button {
  margin-top: 0.7rem;
  font-size: 0.9rem;
}

.challenge-fragment {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.05rem;
}

.base-sub {
  font-size: 0.8rem;
  line-height: 1;
}

.answer-label {
  font-family: "Menlo", "Monaco", monospace;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-right: 0.3rem;
}

.count-tag {
  font-family: "Menlo", "Monaco", monospace;
  font-size: 0.84rem;
  color: var(--muted);
}

.digit-token {
  min-width: 0.95rem;
  font-family: "Menlo", "Monaco", monospace;
  font-size: 1rem;
  color: var(--ink);
  text-align: center;
}

.hand-token {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.hand-token img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.argument-layout,
.closing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.closing-signoff {
  margin-top: 2.25rem;
  text-align: center;
}

.closing-signoff p {
  margin: 0.35rem 0;
}

.essay-byline {
  color: var(--muted);
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.carry-figure {
  margin: 1.2rem 0;
}

.hand-states-figure {
  margin: 1.4rem 0 0;
  padding: 1.1rem 1.2rem;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.carry-figure img {
  border-radius: 12px;
  border: 1px solid var(--line);
}

.carry-figure figcaption,
.hand-states-figure figcaption {
  margin-top: 0.8rem;
}

.hand-states-figure img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.question-strip ul {
  margin: 0.6rem 0 0;
  padding-left: 1.2rem;
}

.question-strip-title {
  margin: 0;
  font-weight: 600;
}

.final-note {
  margin-top: 1.2rem;
}

.mono {
  font-family: "Menlo", "Monaco", monospace;
}

@media (max-width: 760px) {
  .page {
    width: min(100% - 1rem, 980px);
  }

  .argument-layout,
  .basis-explainer,
  .concept-grid,
  .closing-grid,
  .pattern-mosaic-layout {
    grid-template-columns: 1fr;
  }

  .pattern-row {
    grid-template-columns: minmax(0, 1fr) 2rem;
    gap: 0.45rem;
    align-items: center;
  }

  .count-tag {
    text-align: right;
  }

  .tab-button,
  .base-button,
  .representation-button,
  .challenge-button,
  .mosaic-base-button,
  .mosaic-count-button,
  .reveal-button {
    flex: 1 1 calc(50% - 0.6rem);
  }

  .hand-token {
    width: 1.8rem;
    height: 1.8rem;
  }

  .pattern-mosaic-stage {
    width: 100%;
  }
}
