:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-2: #f4f2ef;
  --text: #1c1917;
  --muted: #5c5650;
  --line: #e4e0db;
  --accent: #c2410c;
  --accent-ink: #9a3412;
  --accent-soft: #fff1e7;
  --ok: #166534;
  --ok-soft: #e7f4ea;
  --bad: #b91c1c;
  --bad-soft: #fdecec;
  --warn: #854d0e;
  --warn-soft: #fef5dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(28 25 23 / 6%), 0 4px 16px rgb(28 25 23 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131110;
    --surface: #1c1a18;
    --surface-2: #24211e;
    --text: #f3f1ee;
    --muted: #b3aca5;
    --line: #36322e;
    --accent: #fb8a4a;
    --accent-ink: #fdba8c;
    --accent-soft: #2d1d13;
    --ok: #6ee79a;
    --ok-soft: #13291b;
    --bad: #fca5a5;
    --bad-soft: #351717;
    --warn: #fcd77a;
    --warn-soft: #2f2610;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent-ink); text-underline-offset: 2px; }
a:hover { color: var(--accent); }

.wrap { max-width: 1140px; margin: 0 auto; padding: 0 16px; }

/* Header and footer */
.site-header { border-bottom: 1px solid var(--line); background: var(--surface); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.brand svg { width: 28px; height: 28px; }
.site-nav { display: flex; gap: 4px 18px; flex-wrap: wrap; padding: 8px 0; }
.site-nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--text); }
.site-nav a[aria-current="page"] { font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }

.site-footer { border-top: 1px solid var(--line); margin-top: 56px; padding: 24px 0 40px; color: var(--muted); font-size: 0.9rem; }
.site-footer p { margin: 0 0 8px; max-width: 80ch; }

/* Page intro */
.page-head { padding: 32px 0 8px; }
.page-head h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.02em; }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 75ch; margin: 0; }
.eyebrow { color: var(--accent-ink); font-weight: 600; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; margin: 0 0 6px; }

/* Home */
.hero { padding: 56px 0 24px; }
.hero h1 { font-size: clamp(1.9rem, 4.5vw, 2.9rem); line-height: 1.12; margin: 0 0 16px; letter-spacing: -0.025em; max-width: 22ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin: 28px 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.card h2, .card h3 { font-size: 1.1rem; margin: 0; }
.card p { margin: 0; color: var(--muted); }
.card .go { margin-top: auto; font-weight: 600; text-decoration: none; padding-top: 8px; }
.section { margin: 40px 0; }
.section h2 { font-size: 1.35rem; margin: 0 0 10px; letter-spacing: -0.01em; }
.section p { max-width: 75ch; }
.callout { background: var(--accent-soft); border-radius: var(--radius); padding: 22px; }
.callout h2 { margin-top: 0; }

/* Calculator layout */
.calc { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 24px; align-items: start; margin-top: 20px; }
@media (max-width: 860px) { .calc { grid-template-columns: minmax(0, 1fr); } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.panel + .panel { margin-top: 16px; }
.panel h2 { font-size: 1.05rem; margin: 0 0 12px; }
.inputs { position: sticky; top: 16px; }
@media (max-width: 860px) { .inputs { position: static; } }

fieldset { border: 0; padding: 0; margin: 0 0 14px; }
legend { font-weight: 600; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; padding: 0; }
.field { display: grid; grid-template-columns: minmax(0, 1fr) 150px; align-items: center; gap: 4px 10px; margin: 6px 0; }
.field label { font-size: 0.95rem; }
.field label .sym { color: var(--muted); font-style: italic; margin-left: 4px; }
.field .unit { color: var(--muted); font-size: 0.85rem; }
.field .control { display: grid; grid-template-columns: minmax(0, 1fr) 46px; align-items: center; gap: 6px; }
.field.wide { grid-template-columns: minmax(0, 1fr); }
input, select, button { font: inherit; color: inherit; }
input[type="number"], input[type="text"], select {
  width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2);
}
input[type="number"] { text-align: right; font-variant-numeric: tabular-nums; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }

button { cursor: pointer; border: 1px solid var(--line); background: var(--surface-2); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.engine-status { font-size: 0.85rem; color: var(--muted); margin: 0 0 12px; display: flex; gap: 8px; align-items: center; }
.engine-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.engine-status[data-state="ready"]::before { background: var(--ok); }
.engine-status[data-state="failed"] { color: var(--bad); }
.engine-status[data-state="failed"]::before { background: var(--bad); }

/* Results */
.headline { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.metric .label { color: var(--muted); font-size: 0.85rem; }
.metric .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.metric .value small { font-size: 0.9rem; font-weight: 500; color: var(--muted); margin-left: 4px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 0.85rem; font-weight: 600; margin-top: 6px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; margin: 0 0 12px; }
.has-error .result-body { opacity: 0.35; }
.warnings { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px 10px 30px; margin: 12px 0 0; }
.warnings li + li { margin-top: 4px; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.82rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.sym { font-style: italic; white-space: nowrap; }
td.expr { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.82rem; color: var(--muted); min-width: 16ch; }
td .note { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.report-sentence { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; margin: 12px 0 8px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 600; }

/* Diagrams and charts */
.figure { margin: 20px 0 0; }
.figure svg { width: 100%; max-width: 560px; height: auto; display: block; color: var(--text); }
.figure figcaption { color: var(--muted); font-size: 0.85rem; margin-top: 6px; max-width: 70ch; }
.dg-wall { stroke: currentColor; stroke-width: 6; stroke-linecap: butt; }
.dg-thin { stroke: currentColor; stroke-width: 1.5; fill: none; }
.dg-plane { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 6 5; }
.dg-emitter { stroke: var(--accent); stroke-width: 8; }
.dg-opening { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 2 4; }
.dg-dim { stroke: var(--muted); stroke-width: 1.2; fill: none; }
.dg-receiver { fill: var(--accent); }
.dg-text { fill: currentColor; font-size: 13px; font-family: inherit; }
.dg-text.muted { fill: var(--muted); }
.dg-text.em { font-style: italic; font-weight: 600; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .axis-title { fill: var(--muted); font-size: 12px; }
.chart .series { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .ref { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .ref.crit { stroke: var(--bad); }
.chart .ref.length { stroke: var(--ok); }
.chart .ref-label { fill: var(--muted); font-size: 12px; }
.chart .marker { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

.pass { color: var(--ok); font-weight: 600; }
.fail { color: var(--bad); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
