/* Fonts: Barlow + Barlow Condensed (SIL Open Font License), self-hosted */
@font-face { font-family: "Barlow"; font-weight: 400; font-style: normal; font-display: swap; src: url(/assets/fonts/barlow-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-style: normal; font-display: swap; src: url(/assets/fonts/barlow-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-style: normal; font-display: swap; src: url(/assets/fonts/barlow-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-style: normal; font-display: swap; src: url(/assets/fonts/barlow-condensed-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-style: normal; font-display: swap; src: url(/assets/fonts/barlow-condensed-latin-700-normal.woff2) format("woff2"); }

:root {
  --paper: #F3F4F1;       /* drywall white */
  --field: #FFFFFF;
  --ink: #1C2629;         /* carpenter's pencil */
  --muted: #55625F;
  --rule: #CFD4CD;
  --rule-strong: #959F9A;
  --tape: #F2C12E;        /* tape measure blade */
  --on-tape: #1C2629;
  --link: #1F4F8F;
  --error: #B3261E;
  --footer-bg: #1C2629;
  --footer-ink: #D9DFDA;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --text: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14191B; --field: #1C2326; --ink: #E5E9E4; --muted: #9BA6A2;
    --rule: #2D3639; --rule-strong: #56625F; --link: #93B9EC; --error: #F2867D;
    --footer-bg: #0D1112; --footer-ink: #C3CBC6; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14191B; --field: #1C2326; --ink: #E5E9E4; --muted: #9BA6A2;
  --rule: #2D3639; --rule-strong: #56625F; --link: #93B9EC; --error: #F2867D;
  --footer-bg: #0D1112; --footer-ink: #C3CBC6; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 112.5%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--text); font-size: 1rem; line-height: 1.6;
  font-variant-numeric: lining-nums;
}
img, svg { max-width: 100%; }
a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 1rem; top: -4rem; background: var(--ink); color: var(--paper); padding: .5rem 1rem; z-index: 10; }
.skip:focus { top: 1rem; }

h1, h2 { font-family: var(--display); font-weight: 700; line-height: 1.05; letter-spacing: -0.005em; margin: 0; }
h1 { font-size: clamp(2.2rem, 5.5vw, 3.2rem); }
h2 { font-size: 1.7rem; }
h3 { font-family: var(--text); font-weight: 600; font-size: 1.08rem; line-height: 1.35; margin: 1.6rem 0 .35rem; }

.wrap { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 640px) { .wrap { padding: 0 28px; } }

/* ---- header ---- */
.site-header { border-bottom: 1px solid var(--rule); }
.header-inner { display: flex; align-items: center; justify-content: space-between; min-height: 64px; gap: 1rem; }
.wordmark { display: inline-flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 700; font-size: 1.45rem; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.wordmark-tab {
  width: 30px; height: 18px; border-radius: 2px; background-color: var(--tape); flex: none;
  background-image: repeating-linear-gradient(90deg, var(--on-tape) 0 1.5px, transparent 1.5px 6px);
  background-size: 100% 6px; background-repeat: no-repeat;
}
.site-header nav a { font-weight: 500; color: var(--ink); text-decoration: none; white-space: nowrap; }
.wordmark { white-space: nowrap; }
.nav-short { display: none; }
@media (max-width: 440px) { .wordmark { font-size: 1.25rem; gap: .45rem; } .wordmark-tab { width: 24px; height: 15px; } .nav-long { display: none; } .nav-short { display: inline; } }
.site-header nav a:hover { text-decoration: underline; }

/* ---- tape pattern (shared by hero band and result panel) ---- */
.tape, .hero-tape { background-color: var(--tape); color: var(--on-tape); }
.tape::before, .hero-tape::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 20px; pointer-events: none; opacity: .8;
  background:
    repeating-linear-gradient(90deg, var(--on-tape) 0 2px, transparent 2px 96px) 0 0 / 100% 20px no-repeat,
    repeating-linear-gradient(90deg, var(--on-tape) 0 1.5px, transparent 1.5px 48px) 0 0 / 100% 13px no-repeat,
    repeating-linear-gradient(90deg, var(--on-tape) 0 1px, transparent 1px 12px) 0 0 / 100% 7px no-repeat;
}

/* ---- home ---- */
.hero { padding: 3rem 0 0; }
.hero h1 { font-size: clamp(3rem, 10vw, 6rem); line-height: .92; max-width: 11ch; }
.hero-sub { font-size: 1.15rem; max-width: 34rem; margin: 1.1rem 0 1.6rem; color: var(--muted); }
.finder { max-width: 30rem; margin-bottom: 2.5rem; }
.finder label { display: block; font-weight: 600; margin-bottom: .35rem; }
.finder input { width: 100%; font: inherit; font-size: 1.1rem; min-height: 54px; padding: 0 1rem; border: 1.5px solid var(--rule-strong); border-radius: 6px; background: var(--field); color: var(--ink); }
.hero-tape { position: relative; height: 40px; }

.cat { padding: 2.75rem 0 .5rem; }
.cat-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; margin-bottom: .75rem; }
.cat-head p { margin: 0; color: var(--muted); }
.no-match { padding: 2rem 0; font-size: 1.1rem; }

.calc-list { list-style: none; margin: 0; padding: 0; }
@media (min-width: 760px) { .cat .calc-list { columns: 2; column-gap: 3rem; } }
.calc-list li { position: relative; break-inside: avoid; border-top: 1px solid var(--rule); padding: .85rem 0 .9rem; }
.calc-list a { display: block; font-family: var(--display); font-weight: 600; font-size: 1.35rem; line-height: 1.15; color: var(--ink); text-decoration: none; }
.calc-list a::after { content: ""; position: absolute; inset: 0; }
.calc-list li:hover a { text-decoration: underline; text-decoration-thickness: 2px; }
.calc-list span { display: block; color: var(--muted); font-size: .92rem; line-height: 1.45; margin-top: .2rem; }

/* ---- calculator page ---- */
.page-grid { display: grid; gap: 3rem; padding-top: 1.6rem; padding-bottom: 4rem; }
@media (min-width: 1000px) { .page-grid { grid-template-columns: minmax(0, 1fr) 300px; gap: 4rem; } }
.calc-main { max-width: 740px; min-width: 0; }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: .6rem; }
.crumbs a { color: var(--muted); }
.lede { font-size: 1.1rem; margin: .7rem 0 1.6rem; max-width: 62ch; }

.calc { margin: 0 0 1.25rem; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 1.05rem 1.25rem; }
.field label { display: block; font-weight: 500; font-size: .95rem; line-height: 1.3; margin-bottom: .35rem; }
.field input, .field select {
  width: 100%; min-height: 50px; font: inherit; font-size: 1.1rem; color: var(--ink);
  background: var(--field); border: 1.5px solid var(--rule-strong); border-radius: 6px; padding: 0 .85rem;
}
.field select { padding-right: 2.2rem; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 12px) 52%; background-size: 6px 6px; background-repeat: no-repeat; }
.field input[aria-invalid="true"] { border-color: var(--error); box-shadow: inset 0 0 0 1px var(--error); }
.num-wrap { position: relative; display: block; }
.num-wrap.has-unit input { padding-right: 4.2rem; }
.num-wrap .unit { position: absolute; right: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .95rem; pointer-events: none; }
.field input[type=number]::-webkit-inner-spin-button, .field input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.field input[type=number] { -moz-appearance: textfield; }
.help { font-size: .85rem; color: var(--muted); margin: .3rem 0 0; line-height: 1.4; }

.tape { position: relative; border-radius: 4px; padding: 2.1rem 1.25rem 1.3rem; }
@media (min-width: 640px) { .tape { padding: 2.3rem 1.75rem 1.5rem; } }
.tape-label { margin: 0; font-weight: 600; font-size: 1rem; }
.tape-value { margin: .1rem 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 .55rem; }
.tape-num { font-family: var(--display); font-weight: 700; font-size: clamp(3.2rem, 11vw, 4.8rem); line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.tape-unit { font-family: var(--display); font-weight: 600; font-size: 1.55rem; line-height: 1.1; }
.tape-list { margin: 1.1rem 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 0 1.5rem; }
.tape-list div { border-top: 1px solid rgba(28, 38, 41, .28); padding: .5rem 0 .4rem; }
.tape-list dt { font-size: .85rem; font-weight: 500; }
.tape-list dd { margin: 0; font-size: 1.05rem; line-height: 1.35; }
.tape-list strong { font-family: var(--display); font-weight: 700; font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.tape-note { margin: .9rem 0 0; font-weight: 500; }
.tape-empty { margin: .4rem 0 0; font-size: 1.15rem; font-weight: 500; }

.result-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: .8rem 0 0; }
.btn-quiet { font: inherit; font-weight: 500; font-size: .95rem; color: var(--ink); background: transparent; border: 1.5px solid var(--rule-strong); border-radius: 6px; padding: .45rem .9rem; cursor: pointer; }
.btn-quiet:hover { border-color: var(--ink); }
.copied { font-size: .9rem; color: var(--muted); word-break: break-all; }

.prose { max-width: 66ch; }
.prose h2 { margin: 2.75rem 0 .6rem; }
.prose p, .prose li { margin: 0 0 .9rem; }
.prose ul { padding-left: 1.2rem; margin: 0 0 1rem; }
.prose li::marker { color: var(--muted); }
.page { padding-top: 2.5rem; padding-bottom: 4rem; }
.page h1 { margin-bottom: 1.2rem; }
.narrow { max-width: 780px; }

.related { margin-top: 3rem; }
.related h2 { margin-bottom: .6rem; }

.rail h2 { font-size: 1.3rem; margin-bottom: .5rem; }
.rail ul { list-style: none; padding: 0; margin: 0 0 2rem; }
.rail li { border-top: 1px solid var(--rule); }
.rail li a { display: block; padding: .55rem 0; color: var(--ink); text-decoration: none; font-weight: 500; }
.rail li a:hover { text-decoration: underline; }
@media (max-width: 999px) { .rail { border-top: 1px solid var(--rule); padding-top: 2rem; } }

/* ---- US / metric switch ---- */
.unit-switch { margin: -.8rem 0 1.4rem; font-size: .95rem; color: var(--muted); }
.hero .unit-switch { margin: 0 0 2.5rem; }
.metric-band { margin: 3rem 0 1rem; padding: 1.4rem 0 0; border-top: 1px solid var(--rule); }
.metric-band h2 { margin-bottom: .4rem; }
.metric-band p { margin: 0 0 .5rem; max-width: 60ch; }
.metric-band a { font-weight: 600; }

/* ---- affiliate shop box ---- */
.shop { margin: 2rem 0 0; }
.shop h2 { font-size: 1.35rem; margin-bottom: .6rem; }
.shop ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.shop a { display: inline-block; padding: .5rem .9rem; border: 1.5px solid var(--rule-strong); border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; font-size: .95rem; }
.shop a:hover { border-color: var(--ink); text-decoration: underline; }
.shop-note { margin: .6rem 0 0; font-size: .8rem; color: var(--muted); }

/* ---- embed code box ---- */
.embed-box { margin: 2.5rem 0 0; border-top: 1px solid var(--rule); padding-top: 1rem; }
.embed-box summary { cursor: pointer; font-weight: 600; }
.embed-box p { margin: .6rem 0; font-size: .95rem; }
.embed-code { width: 100%; font: .82rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink); background: var(--field); border: 1.5px solid var(--rule-strong); border-radius: 6px; padding: .6rem; resize: vertical; }
.embed-box .btn-quiet { margin-top: .5rem; }
.embed-copied { font-size: .9rem; color: var(--muted); margin-left: .4rem; }
.prose .embed-box { margin-top: 1rem; }

/* ---- embedded calculator (inside other sites' iframes) ---- */
body.embed { background: var(--paper); }
.embed-main { padding: 14px 14px 10px; max-width: 680px; }
.embed-title { font-family: var(--display); font-weight: 700; font-size: 1.5rem; line-height: 1.1; margin: 0 0 .8rem; }
body.embed .fields { grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr)); gap: .8rem 1rem; }
body.embed .calc { margin-bottom: 1rem; }
body.embed .tape-num { font-size: clamp(2.6rem, 9vw, 3.6rem); }
.embed-credit { margin: .6rem 0 0; font-size: .85rem; }

/* ---- ads ---- */
.ad { margin: 2rem 0; min-height: 280px; }
.ad-rail { position: sticky; top: 1rem; min-height: 600px; }
.ad-label { margin: 0 0 .3rem; font-size: .75rem; color: var(--muted); }

/* ---- footer ---- */
.site-footer { background: var(--footer-bg); color: var(--footer-ink); padding: 2.5rem 0 3rem; }
.site-footer a { color: var(--footer-ink); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.footer-inner { display: grid; gap: 1.5rem; }
.footer-cats, .footer-pages { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; }
.footer-cats a { font-family: var(--display); font-weight: 600; font-size: 1.2rem; }
.fine { margin: 0; font-size: .85rem; line-height: 1.5; opacity: .85; }

@media print {
  .site-header, .site-footer, .rail, .ad, .result-actions, .related, .crumbs { display: none !important; }
  body { background: #fff; }
}
