:root {
  --paper: #fbfaf7;
  --paper-2: #f2f0ea;
  --ink: #16150f;
  --muted: #6b675c;
  --rule: #d9d5ca;
  --accent: #9b2c1f;
  --accent-soft: #f3dcd6;
  --good: #2f6b4f;
  --good-soft: #d8eadf;
  --board-a: #c9b28a;
  --board-b: #5d4a36;
  --board-bg: #efe6d4;
  --checker-light: #fdfbf5;
  --checker-dark: #1f1d19;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --measure: 40rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141412;
    --paper-2: #1d1c19;
    --ink: #ece9e1;
    --muted: #9a958a;
    --rule: #34322d;
    --accent: #e0826f;
    --accent-soft: #3d241f;
    --good: #7cc3a0;
    --good-soft: #1f3329;
    --board-a: #8a7657;
    --board-b: #4a3b2b;
    --board-bg: #2a261f;
    --checker-light: #ece9e1;
    --checker-dark: #0b0b0a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.6;
  font-optical-sizing: auto;
}

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
button { font: inherit; color: inherit; }

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }
.sans { font-family: var(--sans); }

/* masthead */
.masthead { border-bottom: 3px double var(--ink); padding: 1.5rem 0 0; text-align: center; }
.masthead .top {
  display: flex; justify-content: space-between; gap: 1rem;
  font-family: var(--sans); font-size: 0.72rem; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--muted);
}
.masthead h1 {
  font-size: clamp(2.4rem, 8vw, 4.5rem); font-weight: 600; letter-spacing: -0.02em;
  line-height: 1; margin: 0.6rem 0 0.35rem;
}
.masthead h1 a { text-decoration: none; }
.masthead .motto { font-style: italic; color: var(--muted); margin: 0; font-size: 1rem; }
.tabs {
  display: flex; justify-content: center; gap: 0.25rem 1.25rem; flex-wrap: wrap;
  font-family: var(--sans); font-size: 0.8rem; font-weight: 500;
  border-top: 1px solid var(--rule); padding: 0.55rem 0; margin-top: 0.9rem;
}
.tabs a { text-decoration: none; padding: 0.15rem 0; border-bottom: 2px solid transparent; }
.tabs a.on { border-bottom-color: var(--accent); }
.tabs.sub { border-top: 0; margin-top: 0; padding-top: 0; font-size: 0.74rem; font-weight: 400; color: var(--muted); }
.concepts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 2rem; }
.concept { border-top: 1px solid var(--rule); padding: 0.9rem 0; }
.concept h3 { margin: 0 0 0.25rem; font-size: 1.15rem; }
.concept p { margin: 0 0 0.35rem; font-size: 1rem; line-height: 1.5; }

/* shared bits */
.kicker {
  font-family: var(--sans); font-size: 0.68rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent);
}
.byline { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }
.section-head {
  font-family: var(--sans); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; border-top: 2px solid var(--ink); padding-top: 0.5rem; margin: 2rem 0 1.25rem;
  display: flex; justify-content: space-between; align-items: baseline;
}
.section-head a { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--muted); }
.note {
  font-family: var(--sans); font-size: 0.82rem; line-height: 1.5;
  border-left: 3px solid var(--accent); padding: 0.55rem 0.9rem; margin: 1.5rem 0; color: var(--muted);
}

/* front page */
.front { display: grid; grid-template-columns: 1.6fr 1fr; gap: 2rem; padding: 2rem 0 0; }
.lead { border-right: 1px solid var(--rule); padding-right: 2rem; }
.lead h2 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); line-height: 1.08; margin: 0.4rem 0 0.6rem; letter-spacing: -0.015em; }
.lead h2 a, .story h3 a { text-decoration: none; }
.dek { font-size: 1.2rem; color: var(--muted); margin: 0 0 1rem; line-height: 1.45; }

.side .story + .story { border-top: 1px solid var(--rule); margin-top: 1.1rem; padding-top: 1.1rem; }
.story h3 { font-size: 1.3rem; line-height: 1.2; margin: 0.3rem 0 0.35rem; }
.story p { margin: 0 0 0.3rem; font-size: 0.98rem; color: var(--muted); line-height: 1.45; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.75rem 2rem; }
.grid.four { grid-template-columns: repeat(4, 1fr); }

/* pull quotes */
.pull { margin: 0; }
.pull blockquote { margin: 0; font-size: 1.2rem; line-height: 1.4; font-style: italic; }
.pull blockquote::before { content: "“"; color: var(--accent); font-style: normal; font-size: 2rem; line-height: 0; vertical-align: -0.6rem; margin-right: 0.1rem; }
.pull figcaption { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); margin-top: 0.5rem; }
.pull figcaption a { color: var(--ink); }

/* people */
.person-card { display: block; text-decoration: none; }
.person-card .name { font-size: 1.2rem; font-weight: 600; line-height: 1.2; margin-top: 0.2rem; }
.person-card .role { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); line-height: 1.4; }
.person-card .count { font-family: var(--sans); font-size: 0.72rem; color: var(--accent); margin-top: 0.3rem; }
.initials {
  width: 3rem; height: 3rem; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--sans); font-weight: 600; font-size: 0.95rem;
  background: var(--paper-2); border: 1px solid var(--rule);
}

/* section page */
.section-intro { max-width: var(--measure); padding: 2rem 0 0; }
.section-intro h2 { font-size: clamp(2rem, 5vw, 2.8rem); margin: 0.3rem 0 0.5rem; line-height: 1.1; }

/* article + person pages */
.article { max-width: var(--measure); margin: 0 auto; padding: 2.25rem 0 4rem; }
.article h1 { font-size: clamp(2.1rem, 6vw, 3.1rem); line-height: 1.06; letter-spacing: -0.02em; margin: 0.45rem 0 0.7rem; }
.article > .byline { border-bottom: 1px solid var(--rule); padding-bottom: 1.2rem; margin-bottom: 1.75rem; }
.article h2 { font-size: 1.4rem; margin: 2.25rem 0 0.6rem; }
.article .pull { border-top: 1px solid var(--rule); padding-top: 1.25rem; margin-top: 1.25rem; }
.article .pull + .pull { margin-top: 1.5rem; }
.article .context { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); margin-bottom: 0.4rem; }
.body > p:first-of-type::first-letter {
  float: left; font-size: 3.5rem; line-height: 0.85; padding: 0.3rem 0.5rem 0 0; font-weight: 600;
}

.qa dt { font-family: var(--sans); font-weight: 600; font-size: 0.98rem; line-height: 1.5; margin-top: 1.2rem; }
.qa dt::before { content: "Q. "; color: var(--accent); }
.qa dd { margin: 0.25rem 0 0; color: var(--muted); font-style: italic; font-size: 1rem; }

/* widgets */
.widget {
  font-family: var(--sans); font-size: 0.9rem; line-height: 1.45;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px;
  padding: 1rem; margin: 1.5rem 0;
}
.widget .w-title { font-weight: 600; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.6rem; }
.widget .row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.5rem 0; }
.widget .big { font-family: var(--serif); font-size: 2rem; font-weight: 600; line-height: 1.1; }
.widget .small { font-size: 0.8rem; color: var(--muted); }
.widget svg { display: block; width: 100%; height: auto; }
.widget input[type=range] { flex: 1; min-width: 8rem; accent-color: var(--accent); }
.btn {
  border: 1px solid var(--ink); background: transparent; border-radius: 999px;
  padding: 0.35rem 0.85rem; font-size: 0.82rem; font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; background: transparent; color: var(--ink); }

.roll-grid { display: grid; grid-template-columns: auto repeat(6, 1fr); gap: 3px; max-width: 22rem; }
.roll-grid div { text-align: center; font-size: 0.72rem; padding: 0.3rem 0; border-radius: 4px; }
.roll-grid .h { color: var(--muted); font-weight: 600; }
.roll-grid .c { background: var(--paper); border: 1px solid var(--rule); color: var(--muted); }
.roll-grid .c.hit { background: var(--accent); border-color: var(--accent); color: var(--paper); font-weight: 600; }

.doors { display: flex; gap: 0.75rem; margin: 0.75rem 0; }
.door {
  flex: 1; aspect-ratio: 3/4; max-width: 7rem; border: 2px solid var(--ink); border-radius: 8px 8px 2px 2px;
  background: var(--paper); cursor: pointer; display: grid; place-items: center; font-size: 1.8rem;
}
.door.picked { outline: 3px solid var(--accent); outline-offset: 2px; }
.door.open { background: var(--paper-2); cursor: default; }

.flips { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.82rem; letter-spacing: 0.08em; word-break: break-all; line-height: 1.7; background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 0.5rem 0.7rem; }
.flips .run { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

.dice-row { display: flex; gap: 0.35rem; }
.die {
  width: 2.1rem; height: 2.1rem; border-radius: 6px; border: 1.5px solid var(--ink); background: var(--paper);
  display: grid; place-items: center; font-weight: 600; font-size: 0.95rem;
}
.die-pick { cursor: pointer; padding: 0.5rem; border-radius: 8px; border: 1px solid var(--rule); background: var(--paper); text-align: left; }
.die-pick.on { border-color: var(--accent); outline: 2px solid var(--accent); }
.die-pick .dice-row .die { width: 1.6rem; height: 1.6rem; font-size: 0.8rem; }

.people-dots { display: flex; flex-wrap: wrap; gap: 4px; margin: 0.6rem 0; }
.people-dots span { width: 14px; height: 14px; border-radius: 50%; background: var(--rule); }
.people-dots span.match { background: var(--accent); }

.meter { height: 10px; background: var(--paper); border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.meter.good > i { background: var(--good); }

.reveal { border-top: 1px dashed var(--rule); margin-top: 0.75rem; padding-top: 0.75rem; }
.verdict-good { color: var(--good); font-weight: 600; }
.verdict-bad { color: var(--accent); font-weight: 600; }

/* course (numbered chapters) */
.course { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 2rem; }
.course li { border-bottom: 1px solid var(--rule); }
.course a { display: flex; gap: 0.9rem; padding: 0.8rem 0; text-decoration: none; line-height: 1.35; }
.course .num { font-family: var(--sans); font-weight: 600; font-size: 0.8rem; min-width: 1.8rem; height: 1.8rem; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--ink); flex-shrink: 0; }
.course a:hover .num { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.chapter-nav { display: flex; justify-content: space-between; gap: 1rem; border-top: 2px solid var(--ink); margin-top: 2.5rem; padding-top: 0.75rem; font-size: 0.85rem; }
.body figure.diagram { margin: 1.5rem 0; }
.body figure.diagram figcaption { font-family: var(--sans); font-size: 0.78rem; color: var(--muted); margin-top: 0.4rem; }
.timeline { list-style: none; padding: 0; margin: 1.5rem 0; border-left: 2px solid var(--rule); }
.timeline li { position: relative; padding: 0 0 1.25rem 1.25rem; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 0.45rem; width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 2px solid var(--accent); }
.timeline .year { font-family: var(--sans); font-weight: 600; font-size: 0.8rem; color: var(--accent); }
.timeline p { margin: 0.15rem 0 0; }

/* problems */
.problem { border-top: 1px solid var(--rule); padding: 1.5rem 0; }
.problem h3 { margin: 0.2rem 0 0.4rem; font-size: 1.35rem; }
.problem input[type=number] { width: 5rem; padding: 0.3rem 0.5rem; font: inherit; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); color: var(--ink); }

footer { border-top: 1px solid var(--rule); margin-top: 3rem; padding: 1.5rem 0 3rem; font-family: var(--sans); font-size: 0.75rem; color: var(--muted); text-align: center; }

@media (max-width: 860px) {
  .grid.four { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .concepts { grid-template-columns: 1fr; }
  .course { grid-template-columns: 1fr; }
  .front { grid-template-columns: 1fr; }
  .lead { border-right: 0; padding-right: 0; border-bottom: 1px solid var(--rule); padding-bottom: 1.5rem; }
  .grid { grid-template-columns: 1fr; gap: 1.25rem; }
  .masthead .top span:last-child { display: none; }
  .tabs { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
}
