/* Home Build Math — tokens and components. Decisions: /DESIGN.md (repo root). */

@font-face {
  font-family: "Barlow SC";
  src: url("/assets/fonts/barlow-semi-condensed-latin-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: optional;
}
/* Fallback tuned to Barlow Semi Condensed's width so the swap does not shift layout. */
@font-face {
  font-family: "Barlow SC Fallback";
  src: local("Arial Bold"), local("Arial-BoldMT"), local("Arial");
  font-weight: 700; size-adjust: 88%; ascent-override: 106%; descent-override: 21%; line-gap-override: 0%;
}

:root {
  color-scheme: light dark;
  --drywall: #F2F3F1;
  --primer: #FFFFFF;
  --graphite: #1E2124;
  --pencil: #4C535A;
  --tape: #F2C230;
  --chalk: #1D5BA6;
  --keel: #B3261E;
  --field: #6B7279;
  --rule: #CDD1D3;
  --tape-ink: #1E2124;
  --tape-warn: #8A1C14;
  --neutral-panel: #E7E9E6;

  --display: "Barlow SC", "Barlow SC Fallback", sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --radius: 3px;
  --measure: 68ch;
  --page: 1080px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --drywall: #141719;
    --primer: #1D2124;
    --graphite: #E8EAEB;
    --pencil: #A6AEB5;
    --tape: #E2B526;
    --chalk: #86B6F0;
    --keel: #FF8F80;
    --field: #858D94;
    --rule: #353B40;
    --tape-ink: #E8EAEB;
    --tape-warn: #FF8F80;
    --neutral-panel: #1D2124;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--drywall); color: var(--graphite);
  font: 400 1.0625rem/1.6 var(--text);
  caret-color: var(--chalk);
}
::selection { background: color-mix(in srgb, var(--tape) 65%, transparent); color: #1E2124; }

a { color: var(--chalk); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--chalk); outline-offset: 2px; }

.skip { position: absolute; left: var(--s4); top: -100px; z-index: 10; background: var(--primer); color: var(--graphite); padding: var(--s3) var(--s4); border: 2px solid var(--graphite); border-radius: var(--radius); }
.skip:focus { top: var(--s3); }

.wrap { max-width: var(--page); margin: 0 auto; padding: 0 var(--s4); }
@media (min-width: 600px) { .wrap { padding: 0 var(--s5); } }

/* Header */
.site-head { border-bottom: 1px solid var(--rule); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; gap: 0 var(--s4); min-height: 56px; flex-wrap: wrap; }
@media (max-width: 599px) { .site-nav { margin: 0 calc(-1 * var(--s2)); } .site-nav a { font-size: 0.9rem; } }
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--graphite); text-decoration: none; font: 700 1.3rem/1 var(--display); letter-spacing: 0.005em; }
.brand svg { flex: none; }
.site-nav ul { display: flex; flex-wrap: wrap; gap: 0 var(--s1); margin: 0; padding: 0; list-style: none; }
.site-nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s2); color: var(--graphite); text-decoration: none; font-size: 0.95rem; }
.site-nav a:hover { text-decoration: underline; }
.site-nav a[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 2px; }

/* Type */
h1, h2 { font-family: var(--display); font-weight: 700; color: var(--graphite); text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 1.4rem + 2vw, 2.75rem); line-height: 1.05; letter-spacing: -0.005em; margin: var(--s3) 0 var(--s2); }
h2 { font-size: 1.5rem; line-height: 1.15; margin: var(--s7) 0 var(--s3); }
h3 { font-size: 1.0625rem; line-height: 1.3; margin: var(--s5) 0 var(--s2); }
p, li { max-width: var(--measure); }
.lede { font-size: 1.125rem; color: var(--pencil); margin: 0 0 var(--s5); }
.meta { font-size: 0.875rem; color: var(--pencil); }
main { padding-bottom: var(--s8); }
main > .wrap > :first-child { margin-top: var(--s4); }

/* Breadcrumb */
.crumbs ol { display: flex; flex-wrap: wrap; margin: var(--s3) 0 0; padding: 0; list-style: none; font-size: 0.875rem; color: var(--pencil); }
.crumbs li + li::before { content: "/"; padding: 0 var(--s2); color: var(--field); }
.crumbs a { color: var(--pencil); display: inline-block; padding: 11px 0; }

/* Tool: form + results */
.tool { display: grid; gap: var(--s5); margin: 0 0 var(--s4); }
@media (min-width: 960px) {
  .tool { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: var(--s6); align-items: start; }
  .tool .result { position: sticky; top: var(--s5); }
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s4) var(--s4); align-content: start; }
.fields fieldset { grid-column: 1 / -1; min-width: 0; margin: var(--s2) 0 0; padding: var(--s4) 0 0; border: 0; border-top: 1px solid var(--rule); }
.fields fieldset .sub { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s4); }
.fields legend { padding: 0; font-weight: 600; font-size: 0.95rem; margin-bottom: var(--s3); }
.fields legend .opt { font-weight: 400; color: var(--pencil); }
.field.wide { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: 0.95rem; line-height: 1.3; margin-bottom: 6px; }
.opt { font-weight: 400; color: var(--pencil); }
.hint { display: block; font-weight: 400; font-size: 0.875rem; color: var(--pencil); line-height: 1.35; }

.unit { position: relative; display: flex; align-items: stretch; background: var(--primer); border: 1.5px solid var(--field); border-radius: var(--radius); min-height: 48px; }
.unit:hover { border-color: var(--graphite); }
.unit:focus-within { outline: 3px solid var(--chalk); outline-offset: 2px; border-color: var(--graphite); }
.unit input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--graphite); font: 400 1.0625rem/1 var(--text); font-variant-numeric: tabular-nums; padding: 0 var(--s3); text-align: right; }
.unit input:focus { outline: none; }
.unit .u { display: flex; align-items: center; padding: 0 var(--s3); border-left: 1px solid var(--rule); color: var(--pencil); font-size: 0.95rem; font-weight: 600; white-space: nowrap; }
.unit:has(input[aria-invalid="true"]) { border-color: var(--keel); border-width: 2px; }
select {
  width: 100%; min-height: 48px; padding: 0 40px 0 var(--s3); font: 400 1rem/1.2 var(--text); color: var(--graphite);
  background: var(--primer) no-repeat right 14px center / 12px 8px; border: 1.5px solid var(--field); border-radius: var(--radius);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236B7279' stroke-width='2'/%3E%3C/svg%3E");
}
select:hover { border-color: var(--graphite); }
.field label.check-row, .check-row { display: flex; margin: 0; align-items: center; gap: var(--s3); min-height: 48px; font-weight: 600; font-size: 0.95rem; cursor: pointer; }
.check-row input { width: 22px; height: 22px; margin: 0; accent-color: var(--graphite); flex: none; }
.error { display: flex; gap: 6px; align-items: flex-start; margin: 6px 0 0; color: var(--keel); font-size: 0.9rem; line-height: 1.35; font-weight: 600; }
.error::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 1px; background: currentColor; -webkit-mask: var(--icon-alert) center / contain no-repeat; mask: var(--icon-alert) center / contain no-repeat; }
:root { --icon-alert: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M8 4v5' stroke='black' stroke-width='2'/%3E%3Ccircle cx='8' cy='11.6' r='1.2'/%3E%3C/svg%3E"); --icon-ok: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='7' fill='none' stroke='black' stroke-width='2'/%3E%3Cpath d='M4.5 8.2l2.3 2.3 4.7-4.8' fill='none' stroke='black' stroke-width='2'/%3E%3C/svg%3E"); }

.actions { grid-column: 1 / -1; display: flex; gap: var(--s3); flex-wrap: wrap; }
.btn-quiet { min-height: 44px; padding: 0 var(--s4); font: 600 0.95rem/1 var(--text); color: var(--graphite); background: transparent; border: 1.5px solid var(--field); border-radius: var(--radius); cursor: pointer; }
.btn-quiet:hover { border-color: var(--graphite); }
.btn-calc { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* The tape: results panel */
.result { border: 1px solid var(--graphite); border-radius: var(--radius); background: var(--tape); color: #1E2124; overflow: hidden; }
.result .ticks {
  height: 16px; border-bottom: 1px solid #1E2124; background-color: var(--tape);
  background-image:
    repeating-linear-gradient(90deg, #1E2124 0 1.5px, transparent 1.5px 64px),
    repeating-linear-gradient(90deg, #1E2124 0 1px, transparent 1px 32px),
    repeating-linear-gradient(90deg, #1E2124 0 1px, transparent 1px 16px),
    repeating-linear-gradient(90deg, #1E2124 0 1px, transparent 1px 8px);
  background-size: 100% 15px, 100% 11px, 100% 8px, 100% 5px;
  background-repeat: no-repeat; background-position: 12px 0;
}
.result .body { padding: var(--s4) var(--s4) var(--s4); }
.result .label { margin: 0; font-size: 0.9rem; font-weight: 600; }
.result .primary { display: block; font: 700 clamp(2.1rem, 1.7rem + 1.2vw, 2.6rem)/1.05 var(--display); font-variant-numeric: tabular-nums; margin: 2px 0 var(--s3); overflow-wrap: anywhere; }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 6px var(--s3); margin: 0; padding-top: var(--s3); border-top: 1px solid rgb(30 33 36 / 0.35); font-size: 0.95rem; }
.result dt { color: inherit; }
.result dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.result .status { margin: 2px 0 var(--s1); font-size: 0.9rem; line-height: 1.4; }
.result .codecheck { display: flex; gap: var(--s2); align-items: flex-start; margin: var(--s3) 0 0; padding: var(--s2) var(--s3); background: rgb(255 255 255 / 0.55); border-radius: var(--radius); font-size: 0.9rem; line-height: 1.4; font-weight: 600; }
.result .codecheck::before { content: ""; flex: none; width: 16px; height: 16px; margin-top: 2px; background: currentColor; -webkit-mask: var(--icon-ok) center / contain no-repeat; mask: var(--icon-ok) center / contain no-repeat; }
.result:has([data-check-state="warn"]) .codecheck { color: #8A1C14; }
.result:has([data-check-state="warn"]) .codecheck::before { -webkit-mask-image: var(--icon-alert); mask-image: var(--icon-alert); }
.result .codecheck span { display: block; }
.result .status-line { margin: var(--s3) 0 0; font-size: 0.9rem; }
.result[data-state="stale"], .result[data-state="empty"] { background: var(--neutral-panel); color: var(--graphite); border-color: var(--field); }
.result[data-state="stale"] .ticks, .result[data-state="empty"] .ticks { background-color: var(--neutral-panel); filter: grayscale(1); opacity: 0.5; }
.result[data-state="stale"] .primary { color: var(--pencil); }
.result[data-state="stale"] dl, .result[data-state="empty"] dl { border-top-color: var(--rule); }
.result[data-state="stale"] .status, .result[data-state="empty"] .status { font-weight: 600; }
.result[data-state="stale"] .codecheck, .result[data-state="empty"] .codecheck { visibility: hidden; }

@media (prefers-color-scheme: dark) {
  .result { background: var(--primer); color: var(--graphite); border-color: var(--field); }
  .result .ticks { background-color: var(--tape); }
  .result[data-state="ok"] .primary, .result[data-state="warn"] .primary { color: var(--tape); }
  .result dl { border-top-color: var(--rule); }
  .result .codecheck { background: rgb(255 255 255 / 0.06); }
  .result:has([data-check-state="warn"]) .codecheck { color: var(--keel); }
  .result[data-state="stale"] .ticks, .result[data-state="empty"] .ticks { background-color: var(--primer); }
}

.after-tool { margin: var(--s2) 0 0; }

/* Prose blocks */
.formula { margin: var(--s4) 0; padding: var(--s4); background: var(--primer); border: 1px solid var(--rule); border-radius: var(--radius); font-variant-numeric: tabular-nums; line-height: 1.75; max-width: var(--measure); overflow-wrap: anywhere; }
.formula b { font-weight: 600; }
.example { max-width: var(--measure); }
.sources { padding-left: 1.4em; }
.sources li { margin-bottom: var(--s2); font-size: 0.95rem; }
.note { font-size: 0.95rem; color: var(--pencil); }

/* Related calculators */
.related ul { display: flex; flex-wrap: wrap; gap: var(--s3); margin: 0; padding: 0; list-style: none; }
.related a { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4); border: 1.5px solid var(--field); border-radius: var(--radius); color: var(--graphite); text-decoration: none; font-weight: 600; background: var(--primer); }
.related a:hover { border-color: var(--graphite); }
.related a span { color: var(--pencil); font-weight: 400; }

/* Home: ruled rows */
.tools { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--graphite); }
.tools li { max-width: none; border-bottom: 1px solid var(--rule); }
.tools a { display: grid; gap: var(--s1) var(--s5); padding: var(--s4) 0; color: var(--graphite); text-decoration: none; min-height: 44px; }
.tools .name { font: 700 1.5rem/1.1 var(--display); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; text-decoration-color: var(--field); }
.tools a:hover .name { text-decoration-color: currentColor; text-decoration-thickness: 2px; }
.tools .enter { color: var(--pencil); font-size: 0.95rem; }
.tools .chip { justify-self: start; display: inline-block; padding: 2px var(--s2); background: var(--tape); color: #1E2124; border-radius: var(--radius); font-size: 0.9rem; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (min-width: 760px) {
  .tools a { grid-template-columns: 15rem 1fr auto; align-items: baseline; }
}
@media (prefers-color-scheme: dark) { .tools .chip { background: transparent; color: var(--tape); border: 1px solid var(--tape); } .tools { border-top-color: var(--field); } }

/* Footer */
.site-foot { border-top: 1px solid var(--rule); padding: var(--s6) 0 var(--s7); font-size: 0.95rem; color: var(--pencil); }
.site-foot .cols { display: grid; gap: var(--s5); grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.site-foot h2 { font: 600 0.95rem/1.3 var(--text); color: var(--graphite); margin: 0 0 var(--s1); }
.site-foot ul { margin: 0; padding: 0; list-style: none; }
.site-foot a { display: inline-block; padding: 10px 0; color: var(--pencil); }
.site-foot .fine { margin-top: var(--s5); }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }

@media (forced-colors: active) {
  .result, .unit, select, .related a { border: 1px solid CanvasText; }
  .result .ticks { forced-color-adjust: none; background-color: Canvas; }
  .error::before, .result .codecheck::before { background: CanvasText; }
}

@media print {
  :root { color-scheme: light; --drywall: #fff; --primer: #fff; --graphite: #000; --pencil: #333; --chalk: #000; --keel: #8A1C14; --field: #555; --rule: #999; --tape: #fff; --neutral-panel: #fff; }
  .result .primary { color: #000 !important; }
  .site-head nav, .skip, .actions, .related, .site-foot .cols, .crumbs { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .tool { grid-template-columns: 1fr 1fr; }
  .result { background: #fff !important; color: #000 !important; border: 1px solid #000; position: static !important; }
  .result .ticks { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .unit { border: 1px solid #000; }
  a { color: #000; }
  .sources a::after { content: " (" attr(href) ")"; font-size: 9pt; word-break: break-all; }
}
