/* Styles for the interactive tool pages:
   Where the Heat Goes and the Attic Infiltration Calculator.
   Loaded after site.css, which supplies the colors, fonts and .wrap width. */

:root {
  /* --heat comes from site.css */
  --good: #2f6f1c;
  --caution: #8a6100;
  --warn: #a3401b;
}

/* ---------- Page intro ---------- */

.tool-intro { padding-top: 40px; padding-bottom: 24px; }
.tool-intro h1 { font-size: 52px; }
.tool-intro .lead { color: var(--ink-soft); max-width: 65ch; margin-top: 12px; }

.banner {
  margin-top: 16px;
  padding: 10px 14px;
  border-left: 4px solid var(--accent);
  background: var(--panel);
  max-width: 75ch;
  font-weight: 500;
}

.tool-body { padding-bottom: 56px; }
.tool-body .wrap { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 18px 20px 20px;
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0 0 4px;
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 4px 0 -6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.hint { margin: 0; font-size: 14px; color: var(--muted); }
.notes { color: var(--muted); font-size: 14px; max-width: 80ch; margin: 0; }
.notes code { color: var(--ink); font-size: 13px; }
.notes blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--ink);
}

/* ---------- Form controls ---------- */

.field { display: flex; flex-direction: column; gap: 4px; }
.field-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.field label { font-weight: 500; font-size: 15px; }

.field output {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.field input[type="range"] { width: 100%; margin: 0; accent-color: var(--heat); }
.field .ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

input[type="number"],
input[type="text"],
select {
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 9px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible { outline: 2px solid var(--cold); outline-offset: 2px; }

.ticks {
  position: relative;
  height: 1.2rem;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ticks span { position: absolute; top: 0; transform: translateX(-50%); font-weight: 600; color: var(--ink); }
.ticks span::before { content: ""; display: block; width: 1px; height: 5px; background: var(--ink); margin: 0 auto 1px; }

.codeline { margin: 0; font-size: 13px; color: var(--muted); }
.codeline strong { color: var(--ink); }

.nrow { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.nrow input { width: 5rem; }

/* ---------- Buttons ---------- */

.presets { display: flex; flex-wrap: wrap; gap: 8px; }

.presets button,
.plain-btn {
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 7px 11px;
  cursor: pointer;
}

.presets button:hover,
.plain-btn:hover { border-color: var(--ink); }
.presets button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }

.linkbtn {
  align-self: flex-start;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.linkbtn:hover { color: var(--ink); }

/* ---------- Where the Heat Goes: the house ---------- */

.stage-card { padding: 12px 12px 10px; }
.stage { position: relative; width: 100%; aspect-ratio: 720 / 400; }
.stage svg, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage canvas { pointer-events: none; }

.ground { stroke: var(--line); stroke-width: 2; }
.room { fill: var(--warm-room); }
.shell { fill: none; stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; }
.roof { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linejoin: round; }
.duct { fill: var(--panel); stroke: var(--ink); stroke-width: 2; }
.register { stroke: var(--warm-room); stroke-width: 5; }
.glass { stroke: var(--cold); stroke-width: 7; stroke-linecap: butt; }
.glow { fill: var(--heat); opacity: 0.18; }
.heater { fill: var(--heat); }

.lbl-name { font-family: var(--font-body); font-size: 14px; font-weight: 500; fill: var(--muted); }
.lbl-val { font-family: var(--font-display); font-size: 22px; font-weight: 600; fill: var(--ink); font-variant-numeric: tabular-nums; }
.lbl-cold { font-family: var(--font-body); font-size: 13px; fill: var(--cold); font-weight: 500; }
.lbl-duct { font-family: var(--font-body); font-size: 10px; font-weight: 600; fill: var(--muted); letter-spacing: 0.08em; }
.lbl-temp { font-family: var(--font-display); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.lbl-temp.in { fill: var(--heat); }
.lbl-temp.out { fill: var(--cold); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 8px 4px 0;
  font-size: 14px;
  color: var(--muted);
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.solid { background: var(--heat); }
.dot.ring { border: 2px solid var(--heat); }
.dot.coldring { border: 2px solid var(--cold); }
.sq { width: 9px; height: 9px; display: inline-block; border: 2px solid var(--heat); }
.sq.cold { border-color: var(--cold); }

/* ---------- Where the Heat Goes: controls ---------- */

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px 28px;
  align-items: start;
}

.controls > h2,
.controls > h3,
.controls > .presets,
.controls > .hint,
.controls > .codebox { grid-column: 1 / -1; }

.codebox { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
#codeForm { display: flex; flex-direction: column; gap: 8px; }
#codeForm label { font-weight: 500; font-size: 15px; }
.coderow { display: flex; flex-wrap: wrap; gap: 8px; }

.coderow input {
  flex: 1 1 22rem;
  min-width: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 15px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.coderow button {
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  border-radius: 4px;
  padding: 7px 12px;
  cursor: pointer;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.coderow button.ghost { background: var(--bg); color: var(--ink); border-color: var(--line); }

/* ---------- Where the Heat Goes: results ---------- */

.results {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(0, 1.6fr);
  gap: 24px;
  align-items: start;
}

.total-num {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 54px;
  line-height: 1;
  color: var(--heat);
  font-variant-numeric: tabular-nums;
}

.total-num small { font-size: 21px; color: var(--ink); font-weight: 500; }
.total p { margin: 8px 0 0; max-width: 40ch; }
.total .muted { color: var(--muted); font-size: 15px; }

.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

.bar-row {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr) 6.5rem 3rem;
  gap: 10px;
  align-items: center;
  font-size: 15px;
}

.bar-track { height: 14px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--heat); width: 0; transition: width 0.2s ease; }
.bar-row .num, .bar-row .pct { text-align: right; font-variant-numeric: tabular-nums; }
.bar-row .pct { color: var(--muted); }

.insight { margin: 14px 0 0; font-weight: 500; }
.pressure { margin: 10px 0 0; max-width: 65ch; }
.pressure strong.neg { color: var(--cold); }
.pressure strong.pos { color: var(--heat); }

/* ---------- Attic calculator ---------- */

.calc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.calc-grid form { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.calc-grid form .plain-btn { align-self: flex-start; }
.calc-grid .field .row { display: flex; align-items: center; gap: 8px; }
.calc-grid .field .unit { color: var(--muted); font-size: 14px; }
.calc-grid .field input[type="number"], .calc-grid .field select { width: 120px; }

.result-label { color: var(--muted); font-size: 14px; margin: 0; }

.result-value {
  font-family: var(--font-display);
  font-size: 54px;
  line-height: 1.1;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  margin: 2px 0 0;
}

.result-value small { font-size: 18px; font-weight: 500; color: var(--muted); }

#message { color: var(--warn); font-size: 14px; margin: 10px 0 0; min-height: 1.5em; }

table.work {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

table.work td { padding: 5px 0; border-top: 1px solid var(--line); }
table.work td:last-child { text-align: right; }

.check { margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--line); }
.check h3 { font-family: var(--font-display); font-size: 20px; margin: 0 0 8px; padding-top: 0; border-top: 0; }
.check p { margin: 8px 0 0; font-size: 14px; }
.check .range { font-variant-numeric: tabular-nums; font-weight: 600; }

.chip {
  display: inline-block;
  font-weight: 600;
  font-size: 14px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 2px solid currentColor;
  color: var(--muted);
}

.chip.good { color: var(--good); }
.chip.fair { color: var(--caution); }
.chip.poor { color: var(--warn); }

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
  .results, .calc-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .tool-intro h1 { font-size: 36px; }
  .side-label { display: none; }
  .bar-row { grid-template-columns: 5.2rem minmax(0, 1fr) 5.4rem 2.6rem; gap: 6px; font-size: 14px; }
  .total-num { font-size: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
