/* RoofGeometry — engineering gauge: cool concrete ground, deep slate bands,
   safety-orange marks, monospaced readouts. Flat surfaces, square-ish corners.
   Light and dark are both first-class; no framework, no webfonts. */

:root {
  color-scheme: light dark;
  --ink: #15191e;
  --ink-soft: #3d454e;
  --muted: #5a636d;
  --bg: #eef0f2;
  --surface: #ffffff;
  --panel: #f5f6f7;
  --line: #d3d8dd;
  --line-soft: #e4e7ea;
  --slate: #1c232b;
  --slate-2: #262f39;
  --on-slate: #e8eaed;
  --on-slate-soft: #9aa4ae;
  --orange: #ff6a1a;          /* marks, borders, strokes on any ground */
  --orange-ink: #c2410c;      /* orange used as text on light ground (5.2:1 on white) */
  --orange-bg: #fff3eb;
  --err: #b91c1c;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Theme: follows the OS until the visitor presses the header toggle, which sets
   <html data-theme="light|dark"> (stored in localStorage, applied in <head>
   before first paint). The dark token block is repeated once for each route. */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8eaed;
  --ink-soft: #b3bac2;
  --muted: #8b949e;
  --bg: #0f1317;
  --surface: #161b21;
  --panel: #1b2128;
  --line: #2c343d;
  --line-soft: #222930;
  --slate: #0a0d10;
  --slate-2: #141a20;
  --on-slate: #e8eaed;
  --on-slate-soft: #8b949e;
  --orange: #ff7a33;
  --orange-ink: #ff8f52;
  --orange-bg: #2a1a10;
  --err: #fca5a5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --err: #fca5a5;
    --ink: #e8eaed;
    --ink-soft: #b3bac2;
    --muted: #8b949e;
    --bg: #0f1317;
    --surface: #161b21;
    --panel: #1b2128;
    --line: #2c343d;
    --line-soft: #222930;
    --slate: #0a0d10;
    --slate-2: #141a20;
    --on-slate: #e8eaed;
    --on-slate-soft: #8b949e;
    --orange: #ff7a33;
    --orange-ink: #ff8f52;
    --orange-bg: #2a1a10;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 1.25rem; }

a {
  color: var(--ink); text-decoration: underline;
  text-decoration-color: var(--orange); text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}
a:hover { color: var(--orange-ink); }

.skip {
  position: absolute; left: 0.75rem; top: -10rem; z-index: 30;
  background: var(--surface); color: var(--ink); padding: 0.5rem 0.9rem;
  border: 2px solid var(--orange); border-radius: var(--radius);
}
.skip:focus { top: 0.75rem; }

:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem 1.5rem; padding-top: 0.65rem; padding-bottom: 0.65rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--ink); text-decoration: none;
  font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em;
}
.brand svg { border-radius: 5px; flex: none; }
.brand b { color: var(--orange-ink); font-weight: 700; }
.site-header nav { display: flex; gap: 0.2rem; flex-wrap: wrap; font-size: 0.93rem; }
.site-header nav a {
  color: var(--ink-soft); text-decoration: none;
  padding: 0.4rem 0.75rem; border-radius: var(--radius); font-weight: 500;
  border: 1px solid transparent;
}
.site-header nav a:hover { color: var(--ink); background: var(--panel); }
.site-header nav a[aria-current] {
  color: var(--ink); font-weight: 650;
  border-color: var(--line); background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--orange);
}

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; margin-left: 0.25rem; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: var(--orange); color: var(--ink); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
.site-header .nav-row { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; }

/* ---------- page head: the one dark band, with a roof profile drawn in ---------- */
main { padding-top: 1.5rem; padding-bottom: 2rem; }

.page-head {
  position: relative; overflow: hidden;
  margin: 0 0 1.75rem; padding: 2.4rem 2.25rem 2.1rem;
  border-radius: var(--radius);
  background-color: var(--slate);
  color: var(--on-slate);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 140'%3E%3Cpath d='M20 124 L110 40 L210 40 L300 124 Z' fill='none' stroke='%23ff6a1a' stroke-width='2.5' stroke-linejoin='round'/%3E%3Cpath d='M110 40 L210 40' stroke='%23e8eaed' stroke-width='1.5' stroke-dasharray='5 5'/%3E%3Cpath d='M110 40 L110 124 M210 40 L210 124' stroke='%239aa4ae' stroke-width='1' stroke-dasharray='2 4'/%3E%3Cpath d='M20 132 L300 132' stroke='%239aa4ae' stroke-width='1'/%3E%3Cpath d='M20 128 L20 136 M300 128 L300 136' stroke='%239aa4ae' stroke-width='1'/%3E%3C/svg%3E"),
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-repeat: no-repeat, repeat, repeat;
  background-size: 300px auto, 24px 24px, 24px 24px;
  background-position: right 1.75rem bottom 1.4rem, 0 0, 0 0;
}
.page-head h1 {
  margin: 0 0 0.8rem; max-width: 19ch;
  font-size: clamp(1.9rem, 1.2rem + 2.6vw, 2.9rem); line-height: 1.06;
  letter-spacing: -0.035em; font-weight: 750; color: var(--on-slate);
}
.page-head .lead {
  margin: 0; max-width: 60ch; color: var(--on-slate-soft); font-size: 1.06rem;
}
.page-head .lead a { color: var(--on-slate); }

h2 {
  margin: 2.6rem 0 0.75rem; font-size: 1.5rem; line-height: 1.25;
  letter-spacing: -0.025em; font-weight: 720;
}
h3 { margin: 1.4rem 0 0.35rem; font-size: 1.08rem; font-weight: 680; letter-spacing: -0.01em; }

.prose { max-width: 74ch; }
.prose > h2:first-child { margin-top: 2.2rem; }
.prose h2 { padding-top: 0.9rem; border-top: 1px solid var(--line); }
.prose h2::before {
  content: ""; display: block; width: 2.25rem; height: 3px;
  margin: -0.95rem 0 0.8rem; background: var(--orange);
}
.prose p { margin: 0 0 1rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.35rem; }
.prose li { margin: 0.35rem 0; }
.prose li::marker { color: var(--orange-ink); }
.prose b { font-weight: 680; }
.prose .table-scroll { max-width: none; }

.disclaimer {
  margin: 2.2rem 0 0; padding: 1rem 1.15rem;
  border: 1px solid var(--line); border-left: 3px solid var(--orange);
  background: var(--surface); border-radius: var(--radius);
  font-size: 0.94rem; color: var(--ink-soft);
}

/* ---------- calculator ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.calc { margin: 0 0 2rem; padding: 1.5rem 1.6rem 1.35rem; }
.calc h2 {
  margin: 0 0 1.15rem; font-size: 0.8rem; font-weight: 700;
  font-family: var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: 0.6rem;
}
.calc h2::before {
  content: ""; width: 0.6rem; height: 0.6rem; flex: none;
  background: var(--orange); border-radius: 1px;
}
.calc-grid {
  display: grid; gap: 1rem 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.calc-grid label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.9rem; font-weight: 600; color: var(--ink);
}
.calc-grid .field {
  display: flex; align-items: stretch; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.calc-grid .field:hover { border-color: var(--muted); }
.calc-grid .field:focus-within {
  border-color: var(--orange); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 22%, transparent);
}
.calc-grid input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: 600 1.12rem/1 var(--mono); padding: 0.75rem 0.8rem;
  font-variant-numeric: tabular-nums;
}
.calc-grid input:focus { outline: none; }
.calc-grid .unit {
  display: flex; align-items: center; padding: 0 0.75rem;
  font: 500 0.78rem/1 var(--mono); color: var(--muted);
  border-left: 1px solid var(--line);
}
.calc-grid .hint {
  font-size: 0.78rem; font-weight: 400; color: var(--muted); line-height: 1.45;
}

.calc-result {
  display: grid; gap: 0;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 1.5rem 0 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
/* hairlines drawn by each cell (right + bottom), clipped at the outer edge,
   so an unfilled last row stays plain surface instead of a grey block */
.out {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.75rem 0.9rem; background: var(--surface);
  box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line);
}
.out-primary {
  grid-column: span 2; background: var(--slate); color: var(--on-slate);
  box-shadow: inset 4px 0 0 var(--orange), 1px 0 0 var(--line), 0 1px 0 var(--line);
}
.out-label {
  font: 600 0.7rem/1.3 var(--mono); letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.out-primary .out-label { color: var(--on-slate-soft); }
.out-value { display: flex; align-items: baseline; gap: 0.35rem; }
.out-value b {
  font: 650 1.3rem/1.2 var(--mono); color: var(--ink);
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.out-primary .out-value b { font-size: 2.3rem; color: var(--on-slate); }
.out-value i { font: 500 0.78rem/1 var(--mono); color: var(--muted); font-style: normal; }
.out-primary .out-value i { color: var(--orange); }

.calc-error {
  margin: 0.9rem 0 0; padding: 0.65rem 0.8rem; border-radius: var(--radius);
  background: color-mix(in srgb, #b91c1c 10%, transparent);
  border-left: 3px solid var(--err);
  color: var(--err); font-size: 0.9rem; font-weight: 600;
}
.calc-note {
  margin: 1rem 0 0; font-size: 0.86rem; line-height: 1.55; color: var(--muted);
  max-width: 80ch;
}

/* ---------- tables ---------- */
.table-scroll {
  margin: 1.3rem 0; overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
caption {
  caption-side: top; text-align: left; padding: 0.8rem 0.95rem;
  font-size: 0.86rem; line-height: 1.5; color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
th, td {
  padding: 0.55rem 0.95rem; text-align: right;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 0.9rem;
}
thead th {
  background: var(--slate); color: var(--on-slate-soft);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; white-space: nowrap; border-bottom: 0;
}
thead th:first-child, tbody th { text-align: left; }
tbody th { font-weight: 650; color: var(--ink); }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--orange-bg); }

/* ---------- faq ---------- */
.faq { margin: 3rem 0 0; max-width: 74ch; }
.faq details { border-bottom: 1px solid var(--line); padding: 0.9rem 0; }
.faq details:first-of-type { border-top: 1px solid var(--line); }
.faq summary {
  cursor: pointer; font-weight: 650; font-size: 1.02rem;
  list-style: none; display: flex; gap: 0.75rem; align-items: baseline;
}
.faq summary:hover { color: var(--orange-ink); }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before {
  content: "+"; font-family: var(--mono); font-weight: 700;
  color: var(--orange-ink); flex: none; width: 1ch;
}
.faq details[open] summary::before { content: "\2212"; }
.faq-body { padding: 0.55rem 0 0.2rem 1.75ch; color: var(--ink-soft); }

/* ---------- index cards ---------- */
.tool-grid {
  list-style: none; padding: 0; margin: 1rem 0 2rem;
  display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.tool-card {
  display: flex; flex-direction: column; gap: 0.45rem; height: 100%;
  padding: 1.3rem 1.35rem; border-radius: var(--radius); text-decoration: none;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-top: 3px solid var(--slate);
  transition: border-color 0.15s;
}
.tool-card:hover { border-color: var(--orange); color: var(--ink); }
.tool-kind {
  font: 600 0.7rem/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--orange-ink);
}
.tool-card h3 { margin: 0.15rem 0 0.15rem; font-size: 1.2rem; letter-spacing: -0.02em; }
.tool-card p { margin: 0; font-size: 0.93rem; color: var(--ink-soft); flex: 1; }
.tool-go { font: 600 0.82rem/1 var(--mono); color: var(--ink); margin-top: 0.4rem; }
.tool-card:hover .tool-go { color: var(--orange-ink); }

/* ---------- footer ---------- */
.site-footer {
  margin-top: 4rem; padding: 2.2rem 0 2.4rem;
  background: var(--slate); color: var(--on-slate-soft);
  border-top: 3px solid var(--orange);
  font-size: 0.9rem;
}
.site-footer p { margin: 0 0 0.75rem; max-width: 70ch; }
.site-footer .footer-brand { color: var(--on-slate); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.3rem 1.5rem; margin: 0 0 1rem; }
.site-footer nav a { color: var(--on-slate); text-decoration: none; }
.site-footer nav a:hover { color: var(--orange); text-decoration: underline; }
.site-footer .footer-note { font-size: 0.82rem; line-height: 1.6; }

@media (max-width: 760px) {
  .page-head { background-size: 190px auto, 24px 24px, 24px 24px; background-position: right 1rem bottom 1rem, 0 0, 0 0; padding-bottom: 6.5rem; }
}
@media (max-width: 640px) {
  .site-header .wrap { position: relative; }
  .theme-toggle { position: absolute; right: 1rem; top: 0.6rem; margin: 0; }
  body { font-size: 1rem; }
  .wrap { padding: 0 1rem; }
  .page-head { padding: 1.6rem 1.25rem 6rem; }
  .calc { padding: 1.2rem 1.1rem 1.1rem; }
  .calc-grid { grid-template-columns: 1fr; }
  .calc-result { grid-template-columns: 1fr 1fr; }
  .out-primary { grid-column: 1 / -1; }
  .out-primary .out-value b { font-size: 2rem; }
  .site-header nav { font-size: 0.88rem; }
  .site-header nav a { padding: 0.35rem 0.55rem; }
  th, td { padding: 0.5rem 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
