/* Mathing Is Hard
   The page is a sheet of notebook paper: a red margin line down the left,
   pencil notes in the margin, blue ruled lines where you're meant to write,
   graph paper where the arithmetic happens, and a yellow highlighter on
   the answers. Type is Atkinson Hyperlegible Next, drawn so 1, l and I, and
   0 and O, can't be confused; Kalam is the pencil, used only for notes. */

@font-face {
  font-family: "Atkinson Next";
  src: url("../fonts/atkinson-next.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Atkinson Next";
  src: url("../fonts/atkinson-next-italic.woff2") format("woff2");
  font-weight: 200 800; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Kalam";
  src: url("../fonts/kalam-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

:root {
  --paper: #fbfcfd;
  --graphite: #262a31;
  --pencil-grey: #59606c;
  --rule: #cfdcee;
  --ledger: #24589b;
  --ledger-dark: #173f73;
  --highlighter: #f7d23e;
  --margin-red: #e0605a;

  --body: "Atkinson Next", "Atkinson Hyperlegible", Verdana, sans-serif;
  --hand: "Kalam", "Segoe Print", "Bradley Hand", cursive;

  --step--1: 0.875rem;
  --step-0: 1.1875rem;   /* 19px body: generous, for tired eyes */
  --step-1: 1.4375rem;
  --step-2: 1.8125rem;
  --step-3: 2.375rem;
  --step-4: clamp(2.25rem, 5.2vw, 3.5rem);

  --line: 1.65;
  --measure: 40rem;
  --margin-col: 11rem;   /* width of the pencil-note column on wide screens */
  --gutter: 1.5rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--graphite);
  font-family: var(--body);
  font-size: var(--step-0);
  line-height: var(--line);
  font-variant-numeric: lining-nums;
}

a { color: var(--ledger); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--ledger-dark); text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--ledger);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip {
  position: absolute; left: -999px; top: 0.5rem;
  background: var(--graphite); color: #fff; padding: 0.5rem 1rem; z-index: 10;
}
.skip:focus { left: 0.5rem; }

/* ---------- Masthead ---------- */

.masthead {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: 0.5rem 2rem;
  padding: 1.25rem var(--gutter) 1rem;
  max-width: 76rem; margin: 0 auto;
}
.wordmark {
  font-weight: 800; font-size: 1.625rem; letter-spacing: -0.015em;
  color: var(--graphite); text-decoration: none; line-height: 1.1;
}
.wordmark:hover { color: var(--graphite); }
.mainnav ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; list-style: none; margin: 0; padding: 0; }
.mainnav a {
  color: var(--graphite); text-decoration: none; font-size: 1.0625rem;
  padding: 0.25rem 0; border-bottom: 2px solid transparent;
}
.mainnav a:hover { border-bottom-color: var(--rule); color: var(--graphite); }
.mainnav a[aria-current] { border-bottom-color: var(--margin-red); }

/* ---------- The sheet: margin line + content column ---------- */

.sheet {
  position: relative;
  max-width: 76rem; margin: 0 auto;
  padding: 1.5rem var(--gutter) 4rem calc(var(--gutter) + 1.25rem);
  border-top: 1px solid var(--rule);
}
.sheet::before {               /* the red margin line */
  content: ""; position: absolute; top: 0; bottom: 0;
  left: var(--gutter); width: 2px; background: var(--margin-red); opacity: 0.75;
}
.sheet > * { max-width: var(--measure); }
.sheet > .wide, .sheet > .calc, .sheet > .shelf, .sheet > .hero { max-width: 52rem; }

@media (min-width: 62rem) {
  .sheet { padding-left: calc(var(--margin-col) + 4.5rem); }
  .sheet::before { left: calc(var(--margin-col) + 3rem); }
}

/* Pencil notes: in the margin on wide screens, inline on narrow ones. */
.note {
  font-family: var(--hand); color: var(--pencil-grey);
  font-size: 1.0625rem; line-height: 1.35;
  margin: 0 0 1rem; padding-left: 0.75rem; border-left: 2px solid var(--rule);
}
@media (min-width: 62rem) {
  .note {
    float: left; clear: left;
    width: var(--margin-col); margin: 0.2rem 0 1rem calc(-1 * (var(--margin-col) + 3rem));
    padding: 0; border: 0; text-align: right;
  }
}

/* ---------- Type ---------- */

h1, h2, h3 { line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: var(--step-4); font-weight: 800; margin: 0.25rem 0 0.75rem; }
h2 { font-size: var(--step-2); font-weight: 750; margin: 2.75rem 0 0.75rem; }
h3 { font-size: var(--step-1); font-weight: 700; margin: 2rem 0 0.5rem; }
p, ul, ol, dl, table, figure { margin: 0 0 1.1rem; }
li { margin-bottom: 0.35rem; }
strong { font-weight: 750; }

.dek { font-size: var(--step-1); line-height: 1.45; color: var(--graphite); margin-bottom: 1rem; }
.byline, .crumb { font-size: var(--step--1); color: var(--pencil-grey); margin: 0 0 1.75rem; }
.crumb { margin: 0 0 0.25rem; }
.crumb a { color: var(--pencil-grey); }

/* The highlighter: used on answers, and nowhere else. */
.answer, .calc-results output, .hero output {
  background: linear-gradient(transparent 38%, var(--highlighter) 38%, var(--highlighter) 92%, transparent 92%) no-repeat;
  background-size: 100% 100%;
  padding: 0 0.15em; margin: 0 -0.05em;
  font-variant-numeric: tabular-nums;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.fresh { animation: swipe 0.45s ease-out; }
@keyframes swipe { from { background-size: 0% 100%; } to { background-size: 100% 100%; } }

/* ---------- Home: the sentence on ruled paper ---------- */

.hero {
  --row: 1.5em;
  margin: 1rem 0 3rem;
  font-size: clamp(1.75rem, 4.6vw, 3.125rem);
  font-weight: 650; letter-spacing: -0.015em;
  line-height: var(--row);
  background-image: linear-gradient(transparent calc(var(--row) - 2px), var(--rule) calc(var(--row) - 2px), var(--rule) var(--row), transparent var(--row));
  background-size: 100% var(--row);
  background-position: 0 0.12em;
}
.hero p { margin: 0; }
.hero .blank {
  font: inherit; color: var(--ledger); letter-spacing: inherit;
  background: transparent; border: 0; border-bottom: 3px solid var(--ledger);
  padding: 0; margin: 0 0.05em; text-align: center; min-width: 2ch;
  border-radius: 0;
}
.hero .blank:focus-visible { outline: 0; border-bottom-color: var(--margin-red); background: #fff; }
.hero-after { font-size: var(--step-1); line-height: 1.5; max-width: 38rem; }

/* Home: section index ("shelf") */
.shelf { list-style: none; padding: 0; margin: 1rem 0 3rem; border-top: 2px solid var(--graphite); }
.shelf > li {
  display: grid; grid-template-columns: 1fr; gap: 0.25rem 2rem;
  padding: 1.25rem 0 1.1rem; border-bottom: 1px solid var(--rule); margin: 0;
}
@media (min-width: 46rem) { .shelf > li { grid-template-columns: 13rem 1fr; } }
.shelf h3 { margin: 0; font-size: var(--step-1); }
.shelf h3 a { color: var(--graphite); text-decoration: none; }
.shelf h3 a:hover { color: var(--ledger); text-decoration: underline; }
.shelf p { margin: 0 0 0.4rem; }
.shelf .shelf-links { font-size: 1.0625rem; margin: 0; padding: 0; list-style: none; }
.shelf .shelf-links li { margin: 0.15rem 0; }
.shelf .soon { color: var(--pencil-grey); font-family: var(--hand); font-size: 1.0625rem; }

/* ---------- Lists of pages ---------- */

.index { list-style: none; padding: 0; margin: 1.5rem 0 2rem; border-top: 2px solid var(--graphite); }
.index li { padding: 1rem 0; border-bottom: 1px solid var(--rule); margin: 0; }
.index a { font-weight: 700; font-size: var(--step-1); line-height: 1.3; }
.index p { margin: 0.3rem 0 0; color: var(--pencil-grey); font-size: 1.0625rem; }

.empty { border: 2px dashed var(--rule); border-radius: 8px; padding: 1.25rem 1.5rem; margin: 1.5rem 0; }
.empty p:last-child { margin-bottom: 0; }

/* ---------- Worked math on graph paper ---------- */

.work {
  --sq: 1.25rem;
  background-color: #fff;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: var(--sq) var(--sq);
  border: 1px solid var(--rule);
  padding: 1rem 1.25rem; margin: 1.25rem 0 1.5rem;
  font-variant-numeric: tabular-nums;
}
.work p { margin: 0.2rem 0; }
.work .step { color: var(--pencil-grey); font-family: var(--hand); font-size: 1.0625rem; }
.formula { font-size: var(--step-1); font-weight: 650; }
var { font-style: italic; }

/* ---------- Tables ---------- */

.table-scroll { overflow-x: auto; }
.numbers { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 1.0625rem; }
.numbers th, .numbers td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--rule); text-align: right; white-space: nowrap; }
.numbers th:first-child, .numbers td:first-child { text-align: left; }
.numbers thead th { border-bottom: 2px solid var(--graphite); font-weight: 700; vertical-align: bottom; }
.numbers caption { text-align: left; font-weight: 700; padding-bottom: 0.5rem; }

/* ---------- Calculators ---------- */

.calc {
  background: #fff;
  border: 2px solid var(--graphite); border-radius: 10px;
  padding: 1.25rem 1.25rem 1rem; margin: 2rem 0 2.5rem;
}
.calc h2 { margin: 0 0 1rem; font-size: var(--step-1); }
.calc-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.calc label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 650; font-size: 1rem; line-height: 1.3; }
.field { position: relative; display: flex; align-items: center; }
.field input {
  width: 100%; font: inherit; font-weight: 500; font-size: 1.1875rem;
  font-variant-numeric: tabular-nums;
  padding: 0.55rem 0.7rem; color: var(--graphite);
  border: 2px solid #9aa6b8; border-radius: 6px; background: var(--paper);
}
.field input:focus-visible { outline: 3px solid var(--ledger); outline-offset: 1px; border-color: var(--ledger); }
.field.money input { padding-left: 1.6rem; }
.field.money::before { content: "$"; position: absolute; left: 0.7rem; color: var(--pencil-grey); pointer-events: none; }
.field.pct input { padding-right: 1.8rem; }
.field.pct::after { content: "%"; position: absolute; right: 0.7rem; color: var(--pencil-grey); pointer-events: none; }

.calc-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.25rem 1.5rem; border-top: 1px solid var(--rule); padding-top: 1rem; margin-bottom: 0.75rem; }
.calc-results div { margin-bottom: 0.75rem; }
.calc-results dt { font-size: 1rem; color: var(--pencil-grey); line-height: 1.3; }
.calc-results dd { margin: 0.2rem 0 0; font-size: var(--step-2); font-weight: 750; line-height: 1.2; }
.has-error .calc-results { opacity: 0.35; }
.calc-error { color: #a3231d; font-weight: 650; margin: -0.5rem 0 1rem; }
.calc-math { border-top: 1px solid var(--rule); padding-top: 0.75rem; font-variant-numeric: tabular-nums; }
.calc-math p { margin: 0.15rem 0; }
.calc-math p:first-child { color: var(--pencil-grey); font-size: 1rem; }
.calc-note { font-size: 1rem; color: var(--pencil-grey); margin: 0.5rem 0 0; }
.calc-table summary { cursor: pointer; font-weight: 650; color: var(--ledger); margin: 0.25rem 0 0.75rem; }
.calc-table .table-scroll { max-height: 26rem; overflow-y: auto; margin-bottom: 0.75rem; }
.calc-table thead th { position: sticky; top: 0; background: #fff; }

.pair { border-left: 4px solid var(--highlighter); padding: 0.25rem 0 0.25rem 1rem; }

/* ---------- Puzzles ---------- */

.puzzle-q { font-size: var(--step-1); line-height: 1.45; font-weight: 600; }
.reveal { border: 2px solid var(--graphite); border-radius: 10px; padding: 0 1.25rem; margin: 1.5rem 0 2rem; background: #fff; }
.reveal summary {
  cursor: pointer; font-weight: 750; padding: 0.9rem 0; color: var(--ledger);
  list-style-position: inside;
}
.reveal[open] summary { border-bottom: 1px solid var(--rule); margin-bottom: 1rem; }
.reveal > :last-child { margin-bottom: 1.25rem; }

/* ---------- Buttons, video ---------- */

.btn {
  display: inline-block; background: var(--ledger); color: #fff; font-weight: 700;
  text-decoration: none; padding: 0.6rem 1.1rem; border-radius: 6px; line-height: 1.3;
}
.btn:hover { background: var(--ledger-dark); color: #fff; }

.video { aspect-ratio: 16 / 9; margin: 1.5rem 0 2rem; background: var(--graphite); max-width: 52rem; }
.video iframe { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Footer ---------- */

.colophon {
  max-width: 76rem; margin: 0 auto; padding: 2rem var(--gutter) 3rem;
  border-top: 2px solid var(--graphite); font-size: 1rem;
}
.colophon-name { font-weight: 800; margin: 0 0 0.5rem; }
.colophon ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1.5rem; list-style: none; padding: 0; margin: 0 0 1rem; }
.colophon-small { color: var(--pencil-grey); font-size: var(--step--1); max-width: 40rem; }

@media (prefers-reduced-motion: reduce) {
  .fresh { animation: none; }
}

@media print {
  .masthead nav, .colophon ul, .skip { display: none; }
  .sheet::before { display: none; }
  .calc { break-inside: avoid; }
}

/* Home title sits under the sentence, quieter than it. */
.home-title { font-size: var(--step-2); font-weight: 800; margin: 0 0 0.5rem; }

.nobr { white-space: nowrap; }
.hero .blank { padding: 0 0.1em; }
