:root {
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #c26a1f;
  --iso-rh: #98978b;
  --iso-wb: #1baf7a;
  --iso-v: #4a3aa7;
  --critical: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #e08a45;
    --iso-rh: #55544d;
    --iso-wb: #199e70;
    --iso-v: #9085e9;
    --critical: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

header.site {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
/* Header spans the full viewport so the brand sits in the far-left corner. */
header.site .inner {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
header.site a.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
header.site a.brand .logo { display: block; width: 26px; height: 26px; }
header.site a.back {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}
header.site a.back:hover { color: var(--text-primary); border-color: var(--text-secondary); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

/* Pages built around a large chart run wider, footer included. */
.wide-page main,
.wide-page footer.site { max-width: 1760px; }
.wide-page main { padding-top: 22px; }
.wide-page p.lede { margin-bottom: 18px; }

/* ---------- [inputs / outputs] | chart ---------- */
.tool-layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
/* Inputs and outputs share one rail. They live in a flex column rather than
   two grid rows so the tall chart beside them cannot stretch the rows apart. */
.col-side {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Chart first and full width once the rail stops fitting beside it */
@media (max-width: 1280px) {
  .tool-layout { grid-template-columns: 1fr; }
  .col-chart { order: -1; }
  .col-side { flex-direction: row; align-items: start; }
  .col-side > * { flex: 1 1 0; min-width: 0; }
}
@media (max-width: 820px) {
  .col-side { flex-direction: column; }
}

/* The side rails are narrow: trim padding and columns so the longest labels
   ("Dry-bulb temperature", "Atmospheric pressure") still hold one line. */
.col-inputs, .col-outputs { padding: 18px; }
.col-inputs .in-row {
  grid-template-columns: minmax(0, 1fr) 66px 24px;
  gap: 8px;
  padding: 7px 0;
}
.col-inputs .in-label { font-size: 13px; gap: 6px; }
.col-inputs input[type="number"] { padding: 7px 8px; font-size: 14px; }
.col-inputs .field { margin-bottom: 14px; }
.col-outputs .prow {
  grid-template-columns: minmax(0, 1fr) auto 48px;
  gap: 8px;
  font-size: 13px;
}
.col-outputs .prow .unit { font-size: 12px; }
.col-second .in-row { grid-template-columns: minmax(0, 1fr) 66px 24px; gap: 8px; padding: 7px 0; }
.col-second .in-label { font-size: 13px; }
.col-second input[type="number"] { padding: 7px 8px; font-size: 14px; }
.col-second select { padding: 5px 6px; font-size: 13px; }
.col-second .hint { margin-top: 10px; }

/* checkbox that reveals an optional block */
.chk {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}
.chk input[type="checkbox"] {
  accent-color: var(--series-1);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}
[hidden] { display: none !important; }

h1 { font-size: 24px; font-weight: 650; margin: 0 0 4px; }
p.lede { color: var(--text-secondary); margin: 0 0 24px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -18px rgba(0, 0, 0, 0.25);
}

/* ---------- tool index ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
a.tool-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
a.tool-card:hover { border-color: var(--series-1); }
.tool-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 12px;
  background: #141414;
}
a.tool-card h2 { margin: 0 0 6px; font-size: 16px; font-weight: 650; }
a.tool-card p { margin: 0; color: var(--text-secondary); font-size: 14px; }

/* ---------- calculator layout ---------- */
.calc-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 760px) { .calc-grid { grid-template-columns: 1fr; } }

.card h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.field { margin-bottom: 18px; }
.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* input rows: label | value | unit */
.in-rows { display: flex; flex-direction: column; }
.in-row {
  display: grid;
  grid-template-columns: 1fr 104px 44px;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--grid);
}
.in-rows .in-row:last-child { border-bottom: none; }
.in-label {
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.in-row input[type="radio"] {
  accent-color: var(--series-1);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}
label.in-row { cursor: pointer; }
.in-row.inactive .in-label { color: var(--text-muted); }
.in-row.inactive input[type="number"] {
  color: var(--text-muted);
  background: transparent;
  border-style: dashed;
}
.hint { font-size: 12.5px; color: var(--text-muted); margin: 12px 0 0; }

input[type="number"], select, input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
}
input[type="number"]:focus, select:focus, input[type="text"]:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: transparent;
}
.unit-suffix {
  color: var(--text-muted);
  font-size: 13px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.seg button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 6px 18px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.seg button[aria-pressed="true"] {
  background: var(--series-1);
  color: #fff;
}

.error {
  color: var(--critical);
  font-size: 13px;
  margin-top: 8px;
  min-height: 1.2em;
}

/* ---------- output properties: stacked name/value/unit rows ---------- */
/* One column in the narrow side rail, more when the panel sits full width
   under the chart — the track minimum is what keeps "Atmospheric pressure"
   on one line, so it splits only when a split still fits. */
.props {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  column-gap: 40px;
  align-content: start;
}
.prow {
  display: grid;
  grid-template-columns: 1fr auto 74px;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
  font-size: 14px;
}
.prow .name { color: var(--text-secondary); }
.prow .val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.prow .unit { color: var(--text-muted); font-size: 13px; padding-left: 2px; }

/* ---------- chart ---------- */
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -18px rgba(0, 0, 0, 0.25);
  padding: 20px 20px 12px;
  width: 100%;
  max-width: none;
  position: relative;
}
.chart-card h2 { margin-bottom: 4px; }
.chart-card p.sub { margin: 0 0 10px; color: var(--text-muted); font-size: 13px; }
/* legend reads as a caption centered over the chart; the side padding keeps it
   from running under the Hide-labels and Export controls flanking it */
.chart-card p.key {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 22px;
  margin: 0 0 12px;
  padding: 0 116px;
}
.key .k { display: inline-flex; align-items: center; gap: 7px; }
.key .k::before { content: ""; width: 16px; height: 0; border-top: 2px solid; }
.key .k-rh::before { border-color: var(--iso-rh); }
.key .k-wb::before { border-color: var(--iso-wb); opacity: 0.7; }
.key .k-v::before { border-color: var(--iso-v); opacity: 0.7; }
.key .k-cond::before { border-color: var(--critical); }
.key .k-evap::before { border-color: var(--series-1); }
/* state points read as dots, not line samples */
.key .k-p1::before, .key .k-p2::before {
  width: 9px;
  height: 9px;
  border: none;
  border-radius: 50%;
}
.key .k-p1::before { background: var(--series-1); }
.key .k-p2::before { background: var(--series-2); }
/*
 * Cap the chart by WIDTH, derived from the viewBox aspect (1080:680), rather
 * than by height. A max-height cap would leave the box wider than the aspect
 * ratio, so the SVG would letterbox its content — dead space either side, and
 * the overlaid controls no longer line up with the chart.
 */
.chart-holder {
  position: relative;
  width: 100%;
  max-width: calc(85vh * 1080 / 680);
  margin: 0 auto;
}
.chart-card svg { display: block; width: 100%; height: auto; touch-action: none; }

/* Chart-level toggle, mirroring Export across the legend row */
.chart-toggle {
  position: absolute;
  left: 20px;
  top: 16px;
  z-index: 3;
  color: var(--text-secondary);
  font-size: 13px;
}
.chart-toggle:hover { color: var(--text-primary); }

/* Export sits at the chart's top right, in the legend row rather than over the
   plot: the top-right corner carries the humidity-ratio axis, and the only
   blank corner (upper left) is where the saturation scale runs. */
.export {
  position: absolute;
  right: 20px;
  top: 16px;
  z-index: 3;
  font-size: 13px;
}
.export summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--series-1);
  color: #fff;
  font-weight: 550;
}
.export summary::-webkit-details-marker { display: none; }
.export summary::after { content: " ▾"; font-size: 11px; }
.export[open] summary, .export summary:hover { filter: brightness(1.12); }
.export .menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  padding: 4px;
}
.export .menu button {
  font: inherit;
  font-size: 13px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 7px 10px;
  border-radius: 5px;
  cursor: pointer;
}
.export .menu button:hover { background: var(--page); }

/* ---------- split system cross plot layout ---------- */
.cross-stack { display: flex; flex-direction: column; gap: 16px; }
.inputs-card { max-width: 520px; width: 100%; margin: 0 auto; }
.chart-card-full { width: 100%; }

/* Cross plot: inputs on the left, chart to the right; stacks on narrow screens */
.cross-page main, .cross-page footer.site { max-width: 1440px; }
.cross-split {
  display: grid;
  grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.cross-split .inputs-card { max-width: none; margin: 0; }
@media (max-width: 960px) {
  .cross-split { grid-template-columns: 1fr; }
  .cross-split .inputs-card { max-width: 520px; margin: 0 auto; }
}

/* tighter label → input spacing, capacity groups side by side */
.inputs-card .in-row {
  grid-template-columns: auto 84px auto;
  justify-content: start;
  gap: 10px;
}
.cap-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 24px;
}
@media (max-width: 560px) {
  .cap-cols { grid-template-columns: 1fr; }
}
#cross-chart { display: block; width: 100%; height: auto; }
.card p.sub { margin: 0 0 10px; color: var(--text-muted); font-size: 13px; }
.card p.key { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 10px 0 0; }

/* ---------- result stat tiles ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.stat {
  flex: 1 1 150px;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat.primary { border-color: var(--series-1); }
.stat .label { font-size: 12px; color: var(--text-secondary); line-height: 1.3; }
.stat .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .value .u { font-size: 13px; color: var(--text-muted); font-weight: 400; margin-left: 4px; }

.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  padding: 6px 9px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  display: none;
  z-index: 2;
}
.chart-tip .t { color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---------- cross plot controls ---------- */
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.series-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}
.series-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 90px 100px;
  gap: 8px;
  align-items: center;
}
.series-row input, .series-row select {
  min-width: 0;
}
@media (max-width: 760px) {
  .field-grid { grid-template-columns: 1fr; }
  .series-row { grid-template-columns: 1fr; }
}

/* ---------- duct calculator ---------- */
.duct-page .tool-layout { grid-template-columns: 360px minmax(0, 1fr); }
@media (max-width: 1280px) {
  .duct-page .tool-layout { grid-template-columns: 1fr; }
}
.col-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.seg-row { display: flex; flex-wrap: wrap; gap: 0 16px; }
.duct-in .seg button { padding: 6px 12px; }
.duct-in .in-row { grid-template-columns: minmax(0, 1fr) 84px 62px; }
.duct-in .in-label input[type="checkbox"] {
  accent-color: var(--series-1);
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
}
.duct-in label.in-label { cursor: pointer; }
.duct-in .sub-label { margin: 14px 0 0; }
.duct-in .mat-field { display: block; margin: 16px 0 0; }
.fr-help { margin-top: 10px; }
.fr-help summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 550;
  color: var(--series-1);
}
.fr-help summary:hover { text-decoration: underline; }
.fr-help .in-rows { margin-top: 4px; }
.duct-page .col-outputs .stats { margin-top: 0; }
.duct-page .col-outputs .props { margin-top: 10px; }
.duct-page .col-outputs .prow { grid-template-columns: minmax(0, 1fr) auto 62px; }
.duct-page .chart-card p.key { padding: 0; justify-content: flex-start; }
.key .k-dia::before { border-color: var(--iso-rh); }
.key .k-vel::before { border-color: var(--iso-wb); border-top-style: dashed; }
.key .k-p2::before { background: var(--surface-1); box-shadow: inset 0 0 0 2px var(--series-2); }
#duct-holder { max-width: calc(78vh * 900 / 600); }
#duct-chart { cursor: crosshair; }

.tbl-wrap { overflow-x: auto; }
table.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.dtable th {
  text-align: right;
  font-size: 12px;
  font-weight: 550;
  color: var(--text-secondary);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.dtable td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--grid); }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable tbody tr:last-child td { border-bottom: none; }
.dtable tr.muted td { color: var(--text-muted); }

footer.site {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px 32px;
  color: var(--text-muted);
  font-size: 12px;
}
footer.site p {
  margin: 4px 0 0;
}
footer.site p:first-child {
  margin-top: 0;
}
footer.site a {
  color: inherit;
}
