/* How Much to Buy
   Palette: forest ink, clean paper, surveyor grid, tape-measure yellow.
   Type: Barlow Condensed (signage-style headings) + Atkinson Hyperlegible (body, built for legibility). */
:root {
  --ink: #1d3127;
  --ink-soft: #4d5e55;
  --paper: #fbfcfa;
  --surface: #ffffff;
  --grid: #e5ebe5;
  --line: #c9d3cb;
  --tape: #f3c332;
  --tape-deep: #d9a70f;
  --tape-ink: #2b2305;
  --link: #1f5a3d;
  --error: #a4221b;
  --focus: #1a5fd0;
  --radius-sm: 4px;
  --radius-lg: 10px;
  --measure: 68ch;
  --f-display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --f-body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7eee9; --ink-soft: #a9b8af; --paper: #152019; --surface: #1c2a22; --grid: #25352c;
    --line: #36483d; --link: #9fd8b5; --error: #ff9a8f; --focus: #7fb0ff; --tape-deep: #f3c332;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 1.0625rem/1.6 var(--f-body);
}
img, svg { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 0.5rem; top: -3rem; background: var(--surface); padding: 0.5rem 0.75rem; z-index: 10; }
.skip-link:focus { top: 0.5rem; }
.muted { color: var(--ink-soft); }

/* The one bold move: a tape-measure blade across the top of every page */
.tape {
  height: 14px; background-color: var(--tape);
  background-image:
    repeating-linear-gradient(90deg, var(--tape-ink) 0 1px, transparent 1px 12px),
    repeating-linear-gradient(90deg, var(--tape-ink) 0 2px, transparent 2px 96px);
  background-size: 100% 5px, 100% 10px;
  background-repeat: no-repeat;
  background-position: 0 0, 0 0;
}

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 1.25rem; }
.site-header { border-bottom: 1px solid var(--line); background: var(--paper); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; flex-wrap: wrap; }
.brand { font: 700 1.55rem/1 var(--f-display); letter-spacing: 0.01em; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; }
.brand-mark { width: 26px; height: 26px; }
.site-nav ul { list-style: none; display: flex; gap: 1.25rem; margin: 0; padding: 0; flex-wrap: wrap; }
.site-nav a { color: var(--ink); text-decoration: none; font-weight: 700; padding: 0.4rem 0; display: inline-flex; align-items: center; gap: 0.35rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--tape-deep); }
.count { background: var(--tape); color: var(--tape-ink); border-radius: 999px; font-size: 0.8rem; min-width: 1.4rem; padding: 0 0.4rem; text-align: center; line-height: 1.4rem; }

h1, h2, h3 { font-family: var(--f-display); line-height: 1.1; letter-spacing: 0.005em; }
h1 { font-size: clamp(2.2rem, 5.5vw, 3.4rem); font-weight: 700; margin: 0 0 0.5rem; }
h2 { font-size: 1.85rem; font-weight: 700; margin: 2.5rem 0 0.75rem; }
h3 { font-size: 1.35rem; font-weight: 600; margin: 1.75rem 0 0.5rem; }
p, li { max-width: var(--measure); }
.lede { font-size: 1.15rem; color: var(--ink-soft); margin: 0 0 1.5rem; }

.breadcrumbs { font-size: 0.9rem; margin: 1.25rem 0 0.75rem; }
.breadcrumbs ol { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; }
.breadcrumbs li + li::before { content: "/"; color: var(--ink-soft); margin-right: 0.25rem; }

/* ---------- Calculator layout ---------- */
.calc-layout { display: grid; gap: 1.5rem; grid-template-columns: 1fr; margin-bottom: 2rem; }
@media (min-width: 900px) { .calc-layout { grid-template-columns: minmax(0, 1.25fr) minmax(320px, 1fr); align-items: start; } .result-col { position: sticky; top: 1rem; } }

.calc-form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1.25rem; }
fieldset { border: 0; padding: 0; margin: 0 0 1.25rem; min-width: 0; }
legend { font: 600 1.2rem/1.2 var(--f-display); margin-bottom: 0.6rem; padding: 0; }
.fields { display: grid; gap: 0.9rem 1rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field label, .field .label { font-weight: 700; font-size: 0.95rem; }
.field .hint { font-size: 0.85rem; color: var(--ink-soft); }
.input-unit { display: flex; align-items: stretch; }
.input-unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-unit.prefix input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-unit.prefix .unit { border-left: 1px solid var(--line); border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-unit .unit { display: flex; align-items: center; padding: 0 0.6rem; border: 1px solid var(--line); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--grid); font-size: 0.9rem; color: var(--ink-soft); white-space: nowrap; }
input[type=text], input[type=number], input:not([type]), select {
  font: inherit; color: var(--ink); background: var(--paper); width: 100%; min-height: 46px;
  padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
input[aria-invalid="true"] { border-color: var(--error); box-shadow: 0 0 0 1px var(--error); }
.err { color: var(--error); font-size: 0.875rem; font-weight: 700; min-height: 0; }
.err:empty { display: none; }
.check { display: flex; gap: 0.6rem; align-items: center; font-weight: 700; min-height: 44px; }
.check input { width: 1.25rem; height: 1.25rem; accent-color: var(--ink); }

.area-row { border-top: 1px dashed var(--line); padding-top: 0.9rem; margin-top: 0.9rem; }
.area-row:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.area-row-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.5rem; }
.area-name { font: 600 1.05rem var(--f-display); }
[data-add-area] { margin-top: 0.9rem; }

.btn, .btn-ghost, .link-btn { font: 700 1rem var(--f-body); cursor: pointer; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0.55rem 1.1rem; border-radius: var(--radius-sm); border: 2px solid var(--ink); background: var(--ink); color: var(--paper); text-decoration: none; }
.btn:hover { background: var(--ink-soft); border-color: var(--ink-soft); }
.btn-ghost { display: inline-flex; align-items: center; min-height: 44px; padding: 0.45rem 0.9rem; border-radius: var(--radius-sm); border: 2px solid var(--line); background: transparent; color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
.btn:disabled, .btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0.25rem; color: var(--link); text-decoration: underline; min-height: 44px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }

/* Results: styled like a yard ticket with the tape blade as its header */
.receipt { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.receipt-body { padding: 1.1rem 1.25rem 1.25rem; }
.receipt h2 { margin: 0 0 0.5rem; font-size: 1.15rem; color: var(--ink-soft); font-weight: 600; }
.result-primary { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.4rem; }
.result-qty { font: 700 clamp(2.8rem, 8vw, 3.8rem)/1 var(--f-display); }
.result-unit { font: 600 1.35rem var(--f-display); }
.result-note { margin: 0.5rem 0 0; }
.result-rows { margin: 1rem 0 0; border-top: 1px solid var(--line); }
.result-rows div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.45rem 0; border-bottom: 1px solid var(--grid); font-size: 0.95rem; }
.result-rows dt { color: var(--ink-soft); flex: 0 0 auto; max-width: 48%; }
.result-rows dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { color: var(--ink-soft); margin: 0.25rem 0; }
.empty.is-error { color: var(--error); font-weight: 700; }
.receipt-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; padding: 0 1.25rem 1.25rem; }
.receipt-actions .btn { flex: 1 1 auto; }

.mobile-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.7rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--paper); text-decoration: none;
  border-top: 4px solid var(--tape); font-weight: 700; }
.mobile-bar-cta { color: var(--tape); white-space: nowrap; }
#mobile-bar-text { font: 700 1.2rem/1.2 var(--f-display); }
@media (min-width: 900px) { .mobile-bar { display: none !important; } }
@media (max-width: 899px) { body.has-bar .site-footer { padding-bottom: 5rem; } body.has-bar .toast { bottom: 4.5rem; } }
@media (max-width: 560px) {
  .nav-long { display: none; }
  .site-nav ul { gap: 1rem; }
  .site-header .wrap { min-height: 52px; padding-top: 0.25rem; padding-bottom: 0.25rem; }
  .brand { font-size: 1.35rem; }
}
.toast { position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 0.75rem 1rem; border-radius: var(--radius-sm); max-width: calc(100% - 2rem); z-index: 20; }
.toast a { color: var(--tape); font-weight: 700; }

/* ---------- Content ---------- */
.content { max-width: var(--measure); }
.content table, .ref-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; margin: 1rem 0; }
.content th, .content td, .ref-table th, .ref-table td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
.content th, .ref-table th { font-size: 0.9rem; }
.formula { background: var(--grid); border-left: 4px solid var(--tape-deep); padding: 0.75rem 1rem; font-variant-numeric: tabular-nums; margin: 1rem 0; max-width: var(--measure); }
.verify { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0.75rem 1rem; background: var(--surface); max-width: var(--measure); }
details { border-bottom: 1px solid var(--line); padding: 0.5rem 0; max-width: var(--measure); }
summary { cursor: pointer; font-weight: 700; padding: 0.4rem 0; min-height: 44px; display: flex; align-items: center; }
.related { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.related a { display: inline-block; padding: 0.45rem 0.8rem; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--surface); }
.related a:hover { border-color: var(--ink); }

/* ---------- Home ---------- */
.hero { padding: 2.25rem 0 1rem; }
.hero h1 { font-size: clamp(2.6rem, 7vw, 4.4rem); max-width: 14ch; }
.question-index { list-style: none; margin: 0 0 2rem; padding: 0; border-top: 2px solid var(--ink); }
.question-index li { max-width: none; border-bottom: 1px solid var(--line); }
.question-index a { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; align-items: baseline; padding: 1rem 0.25rem; color: var(--ink); text-decoration: none; }
.question-index a:hover { background: var(--grid); }
.question-index .q { font: 600 clamp(1.3rem, 3.2vw, 1.75rem)/1.15 var(--f-display); }
.question-index .tool { color: var(--ink-soft); font-size: 0.95rem; white-space: nowrap; }
@media (max-width: 560px) { .question-index a { grid-template-columns: 1fr; } }
.two-col { display: grid; gap: 2rem; grid-template-columns: 1fr; }
@media (min-width: 860px) { .two-col { grid-template-columns: 1fr 1fr; } }

/* ---------- Project list ---------- */
.project-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0 1.5rem; }
.project-list { list-style: none; padding: 0; margin: 0; }
.project-item { max-width: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.project-item-head { display: flex; justify-content: space-between; gap: 0.5rem 1rem; flex-wrap: wrap; align-items: baseline; }
.project-item h2 { margin: 0; font-size: 1.35rem; }
.project-item-links { display: flex; gap: 0.75rem; align-items: center; font-size: 0.95rem; }
.project-lines { width: 100%; border-collapse: collapse; margin-top: 0.75rem; }
.project-lines th, .project-lines td { text-align: left; padding: 0.45rem 0.4rem; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.project-lines th { font-size: 0.85rem; color: var(--ink-soft); }
.project-lines .qty { font-weight: 700; }
.price-input { max-width: 7.5rem; min-height: 40px; }
.line-total { font-variant-numeric: tabular-nums; }
.project-grand { font-size: 1.2rem; }
.empty-state { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-lg); padding: 1.5rem; }
@media (max-width: 560px) {
  .project-lines thead { display: none; }
  .project-lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--grid); }
  .project-lines td { border: 0; padding: 0.15rem 0; }
}

/* ---------- Ads (only rendered when ads are switched on in build config) ---------- */
.ad-slot { margin: 2rem 0; padding-top: 0.25rem; border-top: 1px solid var(--line); min-height: 280px; }
.ad-slot .ad-label { font-size: 0.75rem; color: var(--ink-soft); display: block; margin-bottom: 0.25rem; }
.ad-slot.ad-rail { min-height: 250px; margin-top: 1.25rem; }
@media (max-width: 899px) { .ad-slot.ad-rail { display: none; } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); margin-top: 3rem; padding: 2rem 0 3rem; font-size: 0.95rem; background: var(--surface); }
.footer-grid { display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.site-footer h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin: 0.2rem 0; }

@media print {
  .site-header, .site-footer, .tape, .mobile-bar, .project-actions, .project-item-links, .ad-slot, .skip-link, .mobile-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.7rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--paper); text-decoration: none;
  border-top: 4px solid var(--tape); font-weight: 700; }
.mobile-bar-cta { color: var(--tape); white-space: nowrap; }
#mobile-bar-text { font: 700 1.2rem/1.2 var(--f-display); }
@media (min-width: 900px) { .mobile-bar { display: none !important; } }
@media (max-width: 899px) { body.has-bar .site-footer { padding-bottom: 5rem; } body.has-bar .toast { bottom: 4.5rem; } }
@media (max-width: 560px) {
  .nav-long { display: none; }
  .site-nav ul { gap: 1rem; }
  .site-header .wrap { min-height: 52px; padding-top: 0.25rem; padding-bottom: 0.25rem; }
  .brand { font-size: 1.35rem; }
}
.toast { display: none !important; }
  body { background: #fff; color: #000; }
  .project-item { border: 1px solid #999; break-inside: avoid; }
  .price-input { border: 0; padding: 0; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
