@font-face {
  font-family: "IBM Plex Sans";
  src: url("/fonts/ibm-plex-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/fonts/ibm-plex-sans-400-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/fonts/ibm-plex-sans-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/fonts/ibm-plex-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("/fonts/ibm-plex-mono-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #e5dfd3;
  --ink: #1c1915;
  --muted: #4e473e;
  --header: #1b1916;
  --paper: #f7f4ee;
  --card: #fbfaf6;
  --line: #d9d1c3;
  --teal: #0e5f68;
  --teal-ink: #ffffff;
  --bronze: #8a3f1d;
  --ok: #1c5c34;
  --ok-bg: #e5f2e8;
  --warn: #8a5a12;
  --warn-bg: #fbf3df;
  --bad: #8d2b2b;
  --bad-bg: #f8e8e4;
  --focus: #0e5f68;
  --shadow: 0 1px 0 rgba(28, 25, 21, 0.04), 0 16px 40px rgba(28, 25, 21, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
body.modal-open { overflow: hidden; }
img { max-width: 100%; }
a { color: var(--teal); text-underline-offset: 0.18em; }
a:hover { color: #08464d; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: #d5ecea; }

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  background: white;
  color: var(--ink);
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { top: 12px; }

.site-header {
  background: var(--header);
  color: #f3eee6;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 12px 22px;
}
.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.wordmark em { font-style: italic; font-weight: 400; color: #e4b79a; }
.wordmark svg { display: block; }
.nav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.nav a, .learn summary {
  color: #e7e1d6;
  text-decoration: none;
  font-size: 0.95rem;
}
.nav a:hover, .learn summary:hover { color: white; }
.nav a[aria-current="page"] { color: white; box-shadow: inset 0 -2px 0 #e0a07a; }
.nav a.affiliate { color: #f0d2c2; }
.learn { position: relative; }
.learn summary { list-style: none; cursor: pointer; padding: 4px 0; }
.learn summary::-webkit-details-marker { display: none; }
.learn summary::after { content: " ▾"; font-size: 0.75em; }
.learn-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  min-width: 230px;
  padding: 6px;
  z-index: 8;
  box-shadow: var(--shadow);
}
.learn-menu a { display: block; color: var(--ink); text-decoration: none; padding: 7px 10px; }
.learn-menu a:hover { background: #f1ebe2; }

.wrap { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }
.layout {
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 18px 0 8px;
}
.titleblock {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 10px;
}
h1 { font-size: 1.7rem; line-height: 1.15; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.02em; }
.lede { margin: 0; color: var(--muted); max-width: 62ch; }
.title-meta {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  padding-bottom: 4px;
}

.controls, .metrics, .cta, .doc {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.controls { padding: 14px; }
.controls h2, .metrics h2 {
  margin: 14px 0 8px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--muted);
}
.controls h2:first-child { margin-top: 2px; }
.seg, .presets { display: flex; gap: 6px; margin-bottom: 10px; }
.seg button, .presets button, .tabs button {
  font: inherit;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 10px;
  cursor: pointer;
}
.seg button[aria-pressed="true"], .presets button[aria-pressed="true"], .tabs button[aria-selected="true"] {
  background: var(--ink);
  color: #f6f1e8;
  border-color: var(--ink);
}
.field { display: block; margin: 0 0 10px; }
.field span:first-child { display: block; font-size: 0.92rem; margin-bottom: 3px; }
.field-row, .with-suffix { display: flex; align-items: center; gap: 8px; }
.suffix, .hint, .field small { color: var(--muted); font-size: 0.8rem; }
input[type="number"], input[type="email"], input[type="text"] {
  font: inherit;
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 16px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #c9c0b2;
  background: white;
  color: var(--ink);
}
input[aria-invalid="true"] { border-color: var(--bad); background: #fff7f5; }
.err:empty { display: none; }
.err { color: var(--bad); font-size: 0.8rem; }
#form-error {
  background: var(--bad-bg);
  color: var(--bad);
  padding: 8px 10px;
  margin: 0 0 10px;
  font-size: 0.9rem;
}
#form-error ul { margin: 0; padding-left: 1.1em; }

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.tabs { display: flex; }
.actions { display: flex; gap: 8px; }
.btn, button.btn {
  font: inherit;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #f6f1e8;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: #312c26; }
.btn-ghost, a.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover { background: rgba(28, 25, 21, 0.05); }
.btn-pro { background: transparent; color: var(--bronze); border-color: var(--bronze); }
.btn-pro:hover { background: #f8efe9; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tag {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  padding: 0 4px;
}
.sheet {
  height: min(64vh, 620px);
  min-height: 380px;
  border: 1px solid #cfc6b6;
  background-color: #f6f3ec;
  background-image:
    linear-gradient(to right, rgba(28, 25, 21, 0.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(28, 25, 21, 0.055) 1px, transparent 1px);
  background-size: 22px 22px;
  position: relative;
}
#viewport, #viewport svg { width: 100%; height: 100%; display: block; }
.sheet-note { margin: 8px 0 0; color: var(--muted); font-size: 0.88rem; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.82rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 14px; height: 3px; display: inline-block; background: var(--ink); }
.swatch.pitch { background: #0e6e78; }
.swatch.base { background: #a24b24; }
.swatch.od { background: #1d6b42; }
.swatch.root { background: #8d2f2a; }
.swatch.mate { background: #1f4e79; }
.swatch.action { background: #1d4e89; }

.note { margin: 8px 0 0; padding: 8px 10px; font-size: 0.92rem; }
.note-bad { background: var(--bad-bg); color: #6e2222; }
.note-warn { background: var(--warn-bg); color: #6d4810; }
.note-ok { background: var(--ok-bg); color: var(--ok); }

.metrics { margin: 16px 0; padding: 8px 16px 16px; }
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; margin: 0; }
.metric-grid div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px dotted #ddd4c6;
  padding: 5px 0;
}
.metric-grid dt { color: var(--muted); font-weight: 450; }
.metric-grid dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 560; text-align: right; }
.calc-note { color: var(--muted); font-size: 0.9rem; }

.cta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 18px;
  margin: 8px 0 22px;
}
.cta h2 { margin: 0 0 4px; font-size: 1.05rem; }
.cta p { margin: 0; color: var(--muted); }
.cta-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px;
  color: var(--muted);
  font-size: 0.92rem;
}
.site-footer .wrap { display: grid; gap: 8px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.legal { font-size: 0.82rem; }

.doc { padding: 8px 22px 28px; margin: 22px auto; width: min(820px, calc(100% - 28px)); }
.prose h1 { font-size: 2rem; margin-top: 18px; }
.byline { color: var(--muted); margin-top: 0; }
.prose h2 { font-size: 1.25rem; margin-top: 1.6em; }
.prose p { max-width: 68ch; }
.formula {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  background: #f6f3ec;
  border-left: 3px solid var(--bronze);
  padding: 10px 14px;
  overflow-x: auto;
  font-size: 0.92rem;
  max-width: 68ch;
}
.related { padding-left: 1.1em; }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(28, 25, 21, 0.46); }
.modal-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  width: min(480px, 100%);
  padding: 18px;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 10px; }
.modal-aside { color: var(--muted); font-size: 0.9rem; }
.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stage { order: -1; }
  .titleblock { flex-direction: column; align-items: start; }
  .title-meta { white-space: normal; }
  .metric-grid { grid-template-columns: 1fr; }
  .cta { flex-direction: column; align-items: stretch; }
  .sheet { height: 72vw; min-height: 280px; }
  .learn-menu { position: static; box-shadow: none; margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
@media print {
  .site-header, .controls, .actions, .site-footer, .cta, .skip { display: none !important; }
  body { background: white; }
  .layout { display: block; width: auto; }
  .sheet { height: 420px; border: none; }
  .metrics { box-shadow: none; }
}
