/* Ledger paper: pale green stock, green rulings, a red double margin, blue-black ink. */

:root {
  --paper: #EDF2E4;
  --paper-deep: #E0EAD4;
  --rule: #A9C2A0;
  --ink: #17263A;
  --ink-soft: #46556A;
  --red: #B4281E;
  --green: #1C4332;
  --green-pale: #F1F5E8;
  --green-rule: #3F6B56;

  --serif: "Libre Caslon Text", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --display: "Libre Caslon Display", "Libre Caslon Text", Georgia, serif;
  --sans: "Libre Franklin", "Franklin Gothic Medium", "Helvetica Neue", Arial, sans-serif;

  --gutter: clamp(20px, 7vw, 104px);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { color: var(--red); }

:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.skip {
  position: absolute; left: 12px; top: -60px; z-index: 30;
  background: var(--ink); color: var(--paper);
  padding: 10px 14px; font-family: var(--sans); font-size: 14px;
}
.skip:focus { top: 12px; color: var(--paper); }

/* The sheet: content column with the ledger's red double margin rule. */
.sheet {
  position: relative;
  max-width: 1240px;
  margin: 0 auto;
  padding-left: var(--gutter);
  padding-right: clamp(20px, 4vw, 56px);
}
main .sheet::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: calc(var(--gutter) - 28px);
  width: 5px;
  border-left: 1px solid var(--red);
  border-right: 1px solid var(--red);
  opacity: 0.55;
}

/* Masthead */
.masthead { border-bottom: 1px solid var(--rule); }
.masthead-inner {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
  padding-top: 18px; padding-bottom: 16px;
}
.wordmark { font-family: var(--display); font-size: 22px; text-decoration: none; }
.masthead nav { display: flex; gap: clamp(14px, 3vw, 32px); flex-wrap: wrap; font-family: var(--sans); font-size: 14px; }
.masthead nav a { text-decoration: none; padding: 4px 0; }
.masthead nav a:hover { text-decoration: underline; }

/* Hero */
.hero { padding-top: clamp(40px, 7vw, 88px); padding-bottom: clamp(48px, 7vw, 96px); }
.hero h1 {
  font-family: var(--sans);
  font-weight: 500;
  font-size: clamp(15px, 1.5vw, 18px);
  line-height: 1.4;
  color: var(--ink-soft);
  padding-bottom: 14px;
  border-bottom: 3px double var(--ink);
}

.rule-row {
  display: grid;
  grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
  align-items: baseline;
  column-gap: clamp(16px, 3vw, 40px);
  border-bottom: 1px solid var(--rule);
  padding: clamp(14px, 2.4vw, 30px) 0 clamp(10px, 1.8vw, 22px);
}
.rule-no {
  font-family: var(--sans);
  font-weight: 600;
  font-size: clamp(13px, 1.3vw, 16px);
  color: var(--red);
  white-space: nowrap;
}
.rule-text {
  font-family: var(--display);
  font-size: clamp(40px, 9.2vw, 132px);
  line-height: 1.02;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

@media (prefers-reduced-motion: no-preference) {
  .rule-text { clip-path: inset(-10% 100% -10% 0); animation: ink 1.1s cubic-bezier(.3, .1, .2, 1) forwards; }
  .rule-text-1 { animation-delay: 0.15s; }
  .rule-text-2 { animation-delay: 1.05s; }
  @keyframes ink { to { clip-path: inset(-10% 0 -10% 0); } }
}

.hero-foot {
  display: grid;
  grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
  column-gap: clamp(16px, 3vw, 40px);
  padding-top: clamp(24px, 3vw, 40px);
}
.lede { grid-column: 2; max-width: 62ch; font-size: clamp(18px, 1.6vw, 21px); line-height: 1.6; }
.hero-count { grid-column: 2; margin-top: 20px; font-family: var(--sans); font-size: 15px; font-weight: 500; }

/* Section headings */
h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(34px, 4.6vw, 60px);
  line-height: 1.08;
  letter-spacing: -0.01em;
}
.section-note { margin-top: 12px; max-width: 60ch; color: var(--ink-soft); }

/* Lessons */
.lessons { padding-top: clamp(40px, 6vw, 80px); border-top: 1px solid var(--rule); }
.lessons > .sheet:first-child { padding-bottom: 28px; }
.lessons > .sheet:last-child { padding-bottom: clamp(56px, 8vw, 112px); }

.filterbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper-deep);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.filterbar .sheet::before { display: none; }
.filterbar-inner {
  display: flex; align-items: center; gap: 12px 24px; flex-wrap: wrap;
  padding-top: 12px; padding-bottom: 12px;
}
.search { flex: 0 1 300px; min-width: 200px; }
.search-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.search input {
  width: 100%;
  font: 400 15px/1.3 var(--sans);
  color: var(--ink);
  background: var(--green-pale);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 9px 12px;
}
.search input::placeholder { color: var(--ink-soft); opacity: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 420px; }
.chip {
  font: 500 13.5px/1 var(--sans);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.status { font: 400 14px/1.4 var(--sans); color: var(--ink-soft); padding: 22px 0 0; }

.theme { padding-top: clamp(36px, 5vw, 64px); }
.theme-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  border-bottom: 3px double var(--ink);
  padding-bottom: 10px;
}
.theme-head h3 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(26px, 3vw, 38px); line-height: 1.15;
}
.theme-count { font: 400 14px/1 var(--sans); color: var(--ink-soft); white-space: nowrap; }

.lesson {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 8fr) minmax(0, 3fr);
  column-gap: clamp(20px, 3vw, 44px);
  align-items: start;
  padding: 24px 0 26px;
  border-bottom: 1px solid var(--rule);
}
.lesson h4 {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(19px, 1.7vw, 22px); line-height: 1.3;
  text-wrap: balance;
}
.lesson-body p { max-width: 62ch; }
.lesson-quote {
  margin: 12px 0 0;
  padding-left: 16px;
  border-left: 2px solid var(--red);
  font-style: italic;
  font-size: 1.06em;
  max-width: 56ch;
}
.lesson-src { font: 400 13.5px/1.45 var(--sans); color: var(--ink-soft); padding-top: 5px; }

.empty { padding: 48px 0; max-width: 52ch; }
.empty button {
  margin-top: 16px;
  font: 500 14px/1 var(--sans);
  color: var(--paper); background: var(--ink);
  border: 0; border-radius: 0; padding: 12px 16px; cursor: pointer;
}
.empty button:hover { background: var(--red); }

/* Compounding */
.compound { background: var(--green); color: var(--green-pale); padding: clamp(56px, 8vw, 112px) 0; }
.compound .sheet::before { border-color: #E9A39C; opacity: 0.5; }
.compound-intro { margin-top: 16px; max-width: 60ch; font-size: clamp(17px, 1.5vw, 19px); }
.compound :focus-visible { outline-color: var(--green-pale); }

.calc {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 9fr);
  gap: clamp(28px, 5vw, 72px);
  margin-top: clamp(32px, 4vw, 56px);
  padding-top: 28px;
  border-top: 3px double var(--green-pale);
}
.calc-controls { display: grid; align-content: start; gap: 8px; font: 400 14.5px/1.4 var(--sans); }
.calc-controls label:not(:first-child) { margin-top: 20px; }
.calc-controls input[type="number"] {
  width: 100%; max-width: 240px;
  font: 500 20px/1.2 var(--sans); font-variant-numeric: tabular-nums;
  color: var(--green-pale); background: transparent;
  border: 1px solid var(--green-pale); border-radius: 0; padding: 10px 12px;
}
.calc-controls input[type="range"] { width: 100%; accent-color: var(--green-pale); }
#years-out { font-weight: 600; font-variant-numeric: tabular-nums; }

.result { padding: 0 0 22px; }
.result + .result { padding-top: 22px; border-top: 1px solid var(--green-rule); }
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.result-name { font: 400 15px/1.3 var(--sans); }
.result-value {
  font-family: var(--display);
  font-size: clamp(30px, 4.4vw, 58px); line-height: 1.1;
  font-variant-numeric: lining-nums tabular-nums;
}
.bar { margin-top: 12px; height: 10px; background: rgba(241, 245, 232, 0.12); }
.bar-fill { display: block; height: 100%; min-width: 2px; transition: width 0.25s ease-out; }
.bar-brk { background: var(--green-pale); }
.bar-spx { background: #E9A39C; }
.calc-summary { margin-top: 6px; padding-top: 18px; border-top: 1px solid var(--green-rule); max-width: 56ch; }
.fineprint { margin-top: 36px; max-width: 68ch; font: 400 13.5px/1.55 var(--sans); color: #C3D3C0; }

/* Life */
.life { padding: clamp(56px, 8vw, 112px) 0; }
.timeline { margin-top: clamp(24px, 3vw, 40px); border-top: 3px double var(--ink); }
.timeline li {
  display: grid;
  grid-template-columns: minmax(0, 150px) minmax(0, 1fr);
  column-gap: clamp(16px, 3vw, 40px);
  align-items: baseline;
  padding: 13px 0 12px;
  border-bottom: 1px solid var(--rule);
}
.timeline time { font: 600 15px/1.4 var(--sans); font-variant-numeric: tabular-nums; color: var(--red); }
.timeline p { max-width: 64ch; }

/* Read */
.read { padding: clamp(48px, 7vw, 96px) 0 clamp(56px, 8vw, 112px); border-top: 1px solid var(--rule); background: var(--paper-deep); }
.sources {
  margin-top: clamp(24px, 3vw, 40px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0 clamp(24px, 4vw, 56px);
  border-top: 3px double var(--ink);
}
.sources li { padding: 18px 0 20px; border-bottom: 1px solid var(--rule); }
.sources a, .source-title { font-weight: 700; font-size: 18px; line-height: 1.35; }
.sources p { margin-top: 4px; color: var(--ink-soft); font-size: 16px; line-height: 1.55; }

/* Colophon */
.colophon { background: var(--ink); color: #C9D2DC; padding: 32px 0 40px; }
.colophon p { max-width: 80ch; font: 400 13.5px/1.6 var(--sans); }

/* Narrow screens */
@media (max-width: 860px) {
  .lesson { grid-template-columns: minmax(0, 1fr); row-gap: 8px; }
  .lesson-src { padding-top: 4px; }
  .calc { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  main .sheet::before { display: none; }
  .rule-row, .hero-foot, .timeline li { grid-template-columns: minmax(0, 1fr); }
  .rule-row { row-gap: 6px; }
  .lede, .hero-count { grid-column: 1; }
  .timeline li { row-gap: 0; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
  .chip { white-space: nowrap; flex: none; }
  .search { flex-basis: 100%; }
  .theme-head { flex-direction: column; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bar-fill { transition: none; }
}
