:root {
  --paper: #f4efe1;
  --paper-2: #ebe4d0;
  --grid: rgba(60, 90, 120, .10);
  --grid-major: rgba(60, 90, 120, .20);
  --ink: #1b1c20;
  --ink-2: #45464d;
  --red: #b5121b;
  --red-ink: #9e0f17;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --gutter: 16px;
  --max: 1180px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
  font: 400 1rem/1.6 var(--sans);
  overflow-x: hidden;
}

a { color: var(--red-ink); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

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

.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip {
  position: absolute; left: var(--gutter); top: -60px; z-index: 10;
  background: var(--ink); color: var(--paper); padding: .6rem 1rem; text-decoration: none;
}
.skip:focus { top: 8px; }

/* Reading progress — scroll-driven, hidden where unsupported */
.progress { display: none; }
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .progress {
      display: block; position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 20;
      background: var(--red); transform-origin: 0 50%; transform: scaleX(0);
      animation: grow linear both; animation-timeline: scroll(root);
    }
    @keyframes grow { to { transform: scaleX(1); } }

    .note, .prop-list > li {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 60%;
    }
    @keyframes settle { from { opacity: .25; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
  }
}

/* Masthead */
.masthead {
  max-width: var(--max); margin: 0 auto; padding: 14px var(--gutter);
  display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; justify-content: space-between;
  border-bottom: 1.5px solid var(--ink);
}
.home { font: 600 .95rem var(--mono); color: var(--ink); text-decoration: none; padding: .4rem 0; }
.home:hover { color: var(--red-ink); }
.masthead ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .1rem .9rem; }
.masthead nav a { display: inline-block; padding: .4rem 0; color: var(--ink-2); text-decoration: none; font-size: .92rem; }
.masthead nav a:hover { color: var(--red-ink); text-decoration: underline; }

main > section { max-width: var(--max); margin: 0 auto; padding: 48px var(--gutter); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .6rem; }
h2 { font-size: clamp(1.6rem, 4.5vw, 2.4rem); }
h2::before { content: "§ "; color: var(--red); }
h3 { font-size: 1.18rem; }
.sub { color: var(--ink-2); max-width: 62ch; }
.hint { font-weight: 400; color: var(--ink-2); font-size: .85em; }

/* Hero */
.hero { padding-top: 40px; }
.kicker { font: 600 .8rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--red-ink); margin: 0 0 .5rem; }
h1 { font-size: clamp(2.4rem, 11vw, 5.4rem); letter-spacing: -.02em; line-height: .98; }
h1 span { display: block; font-style: italic; font-weight: 400; font-size: .48em; color: var(--ink-2); margin-top: .35rem; letter-spacing: 0; }
.lede { font-size: clamp(1.08rem, 2.6vw, 1.3rem); max-width: 40ch; font-family: var(--serif); }
.warning {
  margin-top: 1.5rem; max-width: 62ch; padding: 1rem 1.1rem;
  border: 2px solid var(--red); background: var(--paper);
  box-shadow: 6px 6px 0 var(--red);
}
.warning strong { display: block; color: var(--red-ink); font-family: var(--mono); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .25rem; }

/* Tags */
.tag {
  display: inline-block; font: 700 .68rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase;
  padding: .3rem .45rem; border: 1.5px solid currentColor; vertical-align: .15em; margin-right: .35rem; background: var(--paper);
}
.tag-f { color: var(--ink); }
.tag-i { color: #1f4e79; }
.tag-s { color: var(--red-ink); }
.tag-m { color: #5a3e00; border-style: dashed; }

/* Engine */
.engine-head p { max-width: 64ch; color: var(--ink-2); }
.engine { container-type: inline-size; container-name: lab; }
.lab { display: grid; gap: 20px; margin-top: 1rem; }
.stage {
  margin: 0; background: var(--paper); border: 1.5px solid var(--ink); padding: 10px;
}
#curve { display: block; width: 100%; height: auto; }
.stage figcaption { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; padding: .6rem .2rem 0; border-top: 1px dashed var(--ink-2); margin-top: .5rem; }
.readout { font-family: var(--mono); font-size: .9rem; }
.readout-label { color: var(--ink-2); }
.readout output { font-weight: 700; }
#p-out { color: var(--red-ink); font-size: 1.15rem; }
.verdict { margin: .5rem .2rem 0; font-family: var(--serif); font-style: italic; min-height: 1.6em; }

.controls fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
.controls legend { font: 700 .78rem var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); padding: 0; margin-bottom: .3rem; }
.sign { color: var(--red-ink); text-transform: none; }
.ctl {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .1rem .8rem;
  padding: .55rem .7rem; border: 1.5px solid var(--ink); background: var(--paper); margin-bottom: -1.5px;
}
.ctl:has(input:focus-visible) { background: var(--paper-2); position: relative; z-index: 1; }
.ctl label { grid-column: 1 / -1; font-weight: 600; font-size: .95rem; }
.ctl output { font: 700 1rem var(--mono); min-width: 2.6ch; text-align: right; }

input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 44px; background: transparent; margin: 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: var(--ink); }
input[type=range]::-moz-range-track { height: 3px; background: var(--ink); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9.5px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--red);
}
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--paper); border: 3px solid var(--red); }
input[type=range]:focus-visible { outline-offset: 0; }

.btns { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .6rem; }
button {
  font: 600 .95rem var(--sans); min-height: 44px; padding: .55rem 1.1rem; cursor: pointer;
  color: var(--paper); background: var(--ink); border: 1.5px solid var(--ink); border-radius: 0;
  box-shadow: 3px 3px 0 var(--red); transition: transform .12s, box-shadow .12s;
}
button:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--red); }
button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--red); }
button.ghost { background: var(--paper); color: var(--ink); box-shadow: none; }
button.ghost:hover { background: var(--paper-2); }
@media (prefers-reduced-motion: reduce) { button { transition: none; } button:hover, button:active { transform: none; } }
.status { min-height: 1.4em; font-size: .9rem; color: var(--ink-2); margin: .4rem 0 0; }

@container lab (min-width: 760px) {
  .lab { grid-template-columns: minmax(0, 1.65fr) minmax(280px, 1fr); align-items: start; }
  .stage { position: sticky; top: 16px; }
}

/* Model notes */
.cols { display: grid; gap: 18px; container-type: inline-size; }
.note { background: var(--paper); border: 1.5px solid var(--ink); padding: 1.1rem 1.2rem; }
.note h3 .tag { display: table; margin-bottom: .5rem; }
.eq { font: 600 1rem var(--mono); background: var(--paper-2); padding: .5rem .7rem; overflow-x: auto; margin: .4rem 0; }
.eq.small { font-size: .88rem; font-weight: 400; }
@media (min-width: 768px) { .cols { grid-template-columns: 1fr 1fr; } }

/* Diagnose */
.diag { margin-top: 1rem; max-width: 760px; }
.steps { list-style: none; counter-reset: s; margin: 0; padding: 0; }
.steps > li {
  counter-increment: s; position: relative; padding: 0 0 1.4rem 3rem; border-left: 1.5px dashed var(--ink-2); margin-left: 1rem;
}
.steps > li:last-child { border-left-color: transparent; }
.steps > li::before {
  content: counter(s); position: absolute; left: -1rem; top: -.1rem; width: 2rem; height: 2rem;
  display: grid; place-items: center; font: 700 .95rem var(--mono); background: var(--ink); color: var(--paper);
}
.steps > li:has(input:user-invalid)::before { background: var(--red); }
.steps fieldset { border: 0; padding: 0; margin: 0; }
.steps legend { font: 600 1.15rem var(--serif); padding: 0; margin-bottom: .4rem; }
.diag label { display: block; font-weight: 600; font-size: .93rem; margin: .7rem 0 .25rem; }
.diag input[type=text], .diag input[type=date], .diag input[type=number] {
  width: 100%; min-height: 44px; font: 1rem var(--sans); color: var(--ink);
  background: #fffdf6; border: 1.5px solid var(--ink); border-radius: 0; padding: .5rem .65rem;
}
.diag input::placeholder { color: #75736c; }
.diag input:user-invalid { border-color: var(--red); }
.prefix, .ifthen { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.prefix span, .ifthen span { font-family: var(--serif); font-style: italic; }
.prefix input { flex: 1 1 14rem; }
.ifthen input { flex: 1 1 12rem; }
.rate-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 .8rem; }
.rate-grid label { font-size: .88rem; }
.rate-grid input { margin-top: .25rem; font-family: var(--mono) !important; }
@media (min-width: 768px) { .rate-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.err { color: var(--red-ink); font-weight: 600; min-height: 1.4em; margin: 0; }

/* Card */
.card {
  margin-top: 2rem; max-width: 760px; background: #fffdf6; border: 2px solid var(--ink);
  padding: 1.4rem; box-shadow: 8px 8px 0 var(--ink); view-transition-name: card;
}
.card:focus { outline: none; }
.card:focus-visible { outline: 3px solid var(--red); }
.card-top { border-bottom: 2px solid var(--ink); padding-bottom: .7rem; margin-bottom: 1rem; }
.card-kicker { font: 700 .74rem var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--red-ink); margin: 0 0 .3rem; }
.card h3 { font-size: clamp(1.4rem, 4vw, 2rem); }
.card-id { font-family: var(--serif); font-style: italic; margin: 0; color: var(--ink-2); }
.card-body { display: grid; gap: 1.2rem; }
.card-gauge canvas { width: 100%; max-width: 360px; height: auto; display: block; border: 1px solid var(--ink-2); background: var(--paper); }
.card-p { font: 700 1rem var(--mono); margin: .5rem 0 0; }
.card-list { margin: 0; }
.card-list dt { font: 700 .74rem var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-top: .7rem; }
.card-list dt:first-child { margin-top: 0; }
.card-list dd { margin: .15rem 0 0; font-family: var(--serif); font-size: 1.05rem; }
.card-foot { font-size: .8rem; color: var(--ink-2); border-top: 1px dashed var(--ink-2); padding-top: .6rem; margin: 1.2rem 0 0; }
@media (min-width: 768px) { .card-body { grid-template-columns: 300px 1fr; } }

::view-transition-old(card), ::view-transition-new(card) { animation-duration: .35s; }

/* Propositions */
.prop-list { list-style: none; padding: 0; margin: 1.2rem 0 0; display: grid; gap: 16px; }
.prop-list > li { background: var(--paper); border: 1.5px solid var(--ink); border-left: 6px solid var(--red); padding: 1rem 1.2rem; }
.prop-list p { margin: .3rem 0; max-width: 70ch; }
.fals { font-size: .93rem; color: var(--ink-2); border-top: 1px dashed var(--ink-2); padding-top: .4rem; }
.fals strong { color: var(--red-ink); }
@media (min-width: 1024px) { .prop-list { grid-template-columns: 1fr 1fr; } }

.close p { max-width: 64ch; font-family: var(--serif); font-size: 1.1rem; }

.foot { border-top: 1.5px solid var(--ink); max-width: var(--max); margin: 0 auto; padding: 24px var(--gutter) 40px; font-size: .92rem; }
.foot .small, .small { font-size: .85rem; color: var(--ink-2); }

/* Sources page */
.src { max-width: 820px; margin: 0 auto; padding: 40px var(--gutter); }
.src h1 { font-size: clamp(2rem, 8vw, 3.4rem); }
.src ol { padding-left: 1.3rem; }
.src li { margin-bottom: 1.2rem; }
.src cite { font-style: italic; }
.src .rel { color: var(--ink-2); font-size: .95rem; display: block; margin-top: .2rem; }

@media (min-width: 1440px) {
  :root { --gutter: 32px; }
}

/* Print: only the card */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .skip, .masthead, .foot, main > section:not(#diagnose), #diagnose > :not(.card) { display: none !important; }
  main > section#diagnose { padding: 0; }
  .card { width: 100%; max-width: none; margin: 0; box-shadow: none; border: 1.5px solid #000; break-inside: avoid; }
  .card canvas { max-width: 240px; }
  .card-body { grid-template-columns: 260px 1fr; }
  .no-print, .progress { display: none !important; }
  .tag { border-color: #000; color: #000; }
}
