:root {
  color-scheme: light;
  --ink: #202630;
  --muted: #515a67;
  --accent: #2c3542;
  --paper: #fff;
  --panel: #fff;
  --line: #e2e5e9;
  --control-line: #c8ced6;
  --soft: #f3f4f6;
  --link: #314761;
  --focus: #196aab;
  --body: "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.45 var(--body); }
a { color: inherit; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.shell { width: min(1160px, calc(100% - 64px)); margin-inline: auto; }

.sr-only, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link:focus { position: fixed; z-index: 5; top: 8px; left: 8px; padding: 12px; background: white; }

.site-header { border-bottom: 1px solid var(--line); background: #fff; }
.site-header-inner { display: flex; justify-content: space-between; align-items: center; min-height: 64px; gap: 16px; }
.wordmark { display: inline-flex; align-items: center; min-height: 44px; gap: 9px; font-size: 24px; font-weight: 670; letter-spacing: -.06em; text-decoration: none; white-space: nowrap; }
.brand-mark { position: relative; width: 25px; height: 25px; border: 1.5px solid #3d495a; border-radius: 50%; display: inline-block; }
.brand-mark i { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #3d495a; left: 9px; top: 4.5px; }
.brand-mark i:nth-child(2) { left: 4.5px; top: 13px; }
.brand-mark i:nth-child(3) { left: 13.5px; top: 13px; }
.site-nav, .footer-nav { display: flex; align-items: center; gap: 5px; }
.site-nav a, .footer-nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 6px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 580; white-space: nowrap; }
.site-nav a:hover, .footer-nav a:hover { background: var(--soft); color: var(--ink); }
.site-nav .source-nav { margin-left: 5px; color: var(--ink); background: var(--soft); border: 1px solid var(--line); }
.site-nav .source-nav:hover { background: #e9edf1; }

.page-intro { padding: 26px 0 22px; }
.page-intro h1 { margin: 0; font-size: clamp(38px, 5vw, 56px); line-height: 1.06; font-weight: 600; letter-spacing: -.054em; }
.page-intro p { margin: 8px 0 0; color: var(--muted); font-size: 15px; }
.page-intro p span { margin-inline: 3px; }
.page-intro a { text-decoration-color: #8a94a2; text-underline-offset: 3px; }
.mobile-modes { display: none; }

.workspace { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 18px; align-items: start; margin-bottom: 22px; }
.panel { min-width: 0; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; scroll-margin-top: 10px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 17px 18px 13px; }
.panel-header h2, .scope h2 { margin: 0; font-weight: 650; line-height: 1.2; letter-spacing: -.025em; font-size: 24px; }
.panel-header p, .scope p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.field-label { display: block; margin: 0 0 6px; font-weight: 620; font-size: 14px; }

.button, .segmented button, .wire-row button, .gauge-options button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 6px 10px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--control-line); border-radius: 6px; text-decoration: none; font-weight: 600;
}
.button:hover, .segmented button:hover, .wire-row button:hover, .gauge-options button:hover { background: var(--soft); }
.print-button { font-size: 14px; white-space: nowrap; }

.chart-controls { padding: 0 18px 12px; }
.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(44px, 1fr)); gap: 4px; }
.segmented button { height: 44px; padding: 0 3px; white-space: nowrap; font-size: 17px; font-variant-numeric: tabular-nums; }
.segmented button[aria-pressed="true"], .gauge-options button[aria-pressed="true"] { color: #fff; background: var(--accent); border-color: var(--accent); }
.table-wrap { overflow-x: auto; margin-inline: 18px; border: 1px solid var(--line); border-radius: 6px; }
.reference-table { width: 100%; min-width: 160px; border-collapse: separate; border-spacing: 0; text-align: center; font-variant-numeric: tabular-nums; }
.reference-table[data-all="true"] { min-width: 570px; }
.reference-table thead { background: var(--soft); }
.reference-table th { font-size: 15px; font-weight: 630; white-space: nowrap; padding: 7px; }
.reference-table th:first-child { text-align: left; padding-left: 12px; }
.reference-table tbody th { width: 23%; }
.reference-table tbody tr:nth-child(even) { background: #fafbfc; }
.reference-table tbody th, .reference-table td { border-top: 1px solid var(--line); }
.reference-table td { padding: 0; }
.chart-value {
  display: block; width: 100%; min-width: 44px; min-height: 44px; padding: 3px 4px;
  background: transparent; border: 0; color: var(--ink); font-size: 19px; font-weight: 630; font-variant-numeric: tabular-nums;
}
.chart-value:hover { background: #edf0f3; }
.chart-value[aria-pressed="true"] { background: #e6ebf0; box-shadow: inset 0 0 0 2px #8494a7; }
.chart-value:focus-visible { outline-offset: -3px; }
.table-help { margin: 10px 18px 14px; color: var(--muted); font-size: 14px; }
.print-note { display: none; }

.calculator-panel .panel-header { padding-bottom: 10px; }
.calc-inputs { margin-inline: 18px; }
.rows-header, .wire-row { display: grid; align-items: center; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) 44px; gap: 6px; }
.rows-header { margin: 11px 0 4px; color: var(--muted); font-size: 14px; font-weight: 560; }
.wire-row + .wire-row { margin-top: 5px; }
.wire-row .wire-gauge { justify-content: space-between; gap: 4px; padding-inline: 9px; white-space: nowrap; font-size: 17px; }
.gauge-action { color: var(--muted); font-size: 12px; font-weight: 550; }
.wire-count, #copy-fallback { min-height: 44px; width: 100%; padding: 6px 10px; color: var(--ink); background: #fff; border: 1px solid var(--control-line); border-radius: 6px; font-size: 18px; font-variant-numeric: tabular-nums; }
.wire-count { appearance: textfield; }
.wire-count::-webkit-inner-spin-button, .wire-count::-webkit-outer-spin-button { appearance: none; margin: 0; }
.wire-count[aria-invalid="true"] { border-color: #a83e28; }
.field-error { grid-column: 1 / -1; margin: 0 0 3px; color: #8e3525; font-size: 14px; }
.wire-row .remove-row { padding: 0; font-size: 23px; line-height: 1; font-weight: 450; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0 14px; }
.text-button { min-height: 44px; padding: 0; text-align: left; color: var(--link); background: transparent; border: 0; font-size: 14px; font-weight: 620; }
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }
.add-button { font-size: 15px; }

.result { margin: 2px 18px 1px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 7px; background: var(--soft); }
.result-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.result-heading .field-label { margin: 0; }
.result-status { color: #24543e; font-size: 14px; font-weight: 640; text-align: right; }
.result[data-state="over"] .result-status { color: #8e3525; }
.result[data-state="pending"] .result-status { color: var(--muted); }
.result-total { margin: 2px 0 8px; font-size: 46px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.07; letter-spacing: -.05em; }
#fill-unit { margin-left: 3px; font-size: .58em; }
.fill-track { position: relative; height: 6px; border-radius: 3px; background: #d7dce2; }
.fill-bar { display: block; height: 100%; max-width: 100%; background: #527b64; border-radius: 3px; }
.result[data-state="over"] .fill-bar { background: #a7442d; }
.limit-mark { position: absolute; top: -3px; width: 2px; height: 12px; background: #495462; }
.result-metrics { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; margin-top: 10px; }
.result-metrics span { display: block; font-size: 14px; color: var(--muted); }
.result-metrics strong { display: block; font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 640; }
.result-note { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.compare-button { margin-top: 2px; }
.calculation-actions { display: flex; justify-content: space-between; gap: 8px; padding: 0 18px 6px; }
.calculation-actions details { min-width: 0; }
.calculation-actions summary { list-style: none; min-height: 44px; padding: 11px 0; cursor: pointer; color: var(--link); font-size: 14px; font-weight: 620; }
.calculation-actions summary::-webkit-details-marker { display: none; }
.calculation-actions summary::before { content: "+"; display: inline-block; width: 1em; font-size: 17px; line-height: 0; margin-right: 3px; }
.calculation-actions details[open] summary::before { content: "−"; }
.math-content { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.math-content p { margin: 0 0 5px; }
.copy-button { white-space: nowrap; align-self: flex-start; }
#copy-fallback { display: block; width: calc(100% - 36px); margin: 0 18px 12px; }

.site-footer { border-top: 1px solid var(--line); background: #f6f7f8; }
.scope { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 70px); padding: 24px 0; scroll-margin-top: 12px; }
.scope h2 { font-size: 23px; }
.scope-summary p { max-width: 500px; margin: 9px 0 0; }
.scope-facts { margin: 14px 0 0; color: var(--ink); font-size: 14px; }
.scope-facts > div { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.scope-facts dt { color: var(--muted); }
.scope-facts dd { margin: 0; font-weight: 590; }
.source-panel h3 { margin: 3px 0 7px; font-size: 16px; font-weight: 650; }
.source-panel ul { padding: 0; margin: 0; list-style: none; }
.source-panel li + li { border-top: 1px solid var(--line); }
.source-panel a { display: block; padding: 7px 0; min-height: 44px; text-decoration: none; }
.reference-name { color: var(--link); font-size: 14px; font-weight: 630; text-decoration: underline; text-decoration-color: #8795a6; text-underline-offset: 3px; }
.source-panel a:hover .reference-name { text-decoration-color: currentColor; }
.reference-description { display: block; margin-top: 1px; color: var(--muted); font-size: 13px; }
.footer-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; min-height: 60px; padding: 5px 0; border-top: 1px solid var(--line); }
.footer-wordmark { display: inline-flex; align-items: center; min-height: 44px; width: max-content; color: var(--ink); font-weight: 670; text-decoration: none; }
.footer-bar p { justify-self: end; margin: 0; color: var(--muted); font-size: 13px; }

.gauge-dialog { width: min(410px, calc(100% - 28px)); max-height: calc(100% - 40px); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 0; }
.gauge-dialog::backdrop { background: #20263066; }
.gauge-dialog-content { padding: 15px; }
.gauge-dialog header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.gauge-dialog h2 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.025em; }
.gauge-dialog header button { font-size: 14px; }
.gauge-options { display: grid; grid-template-columns: repeat(3, minmax(44px, 1fr)); gap: 6px; }
.gauge-options button { min-height: 49px; font-size: 19px; }

@media (max-width: 820px) {
  .shell { width: min(610px, calc(100% - 24px)); }
  .site-header-inner { min-height: 52px; }
  .site-nav a[data-tool-link] { display: none; }
  .site-nav .source-nav { margin-left: 0; }
  .page-intro { padding: 12px 0 9px; }
  .page-intro h1 { font-size: 36px; }
  .page-intro p { margin-top: 4px; }
  .mobile-modes {
    position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 1fr 1fr;
    gap: 5px; margin: 0 0 7px; padding: 4px 0; background: var(--paper);
  }
  .mobile-modes button { min-height: 44px; color: var(--ink); background: var(--soft); border: 1px solid var(--line); border-radius: 6px; font-size: 16px; font-weight: 620; }
  .mobile-modes button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: white; }
  .workspace { display: block; margin-bottom: 16px; }
  .panel { scroll-margin-top: 55px; }
  .workspace[data-tool="chart"] #calculator, .workspace[data-tool="calculator"] #chart { display: none; }
  #chart-filters [data-size="all"] { display: none; }
  .panel-header { padding: 10px 12px 7px; }
  .panel-header h2 { font-size: 21px; }
  .panel-header p { line-height: 1.25; }
  .chart-controls { padding: 0 12px 8px; }
  .table-wrap, .calc-inputs, .result, .table-help { margin-inline: 12px; }
  .reference-table tbody th { width: 50%; font-size: 16px; }
  .chart-value { font-size: 21px; }
  .calculation-actions { padding-inline: 12px; }
  #copy-fallback { margin-inline: 12px; width: calc(100% - 24px); }
  .scope { grid-template-columns: 1fr; gap: 17px; scroll-margin-top: 55px; }
  .footer-bar { grid-template-columns: 1fr auto; gap: 0 12px; padding-bottom: 10px; }
  .footer-bar p { grid-column: 1 / -1; justify-self: start; }
}

@media (max-width: 520px) {
  .gauge-dialog { position: fixed; inset: auto 0 0; width: min(100%, 480px); max-height: calc(100% - 40px); margin: 0 auto; border-radius: 12px 12px 0 0; }
  .gauge-dialog-content { padding-bottom: max(15px, env(safe-area-inset-bottom)); }
}

@media (max-width: 355px) {
  .segmented { gap: 1px; }
  .panel-header { gap: 6px; }
  .print-button { padding-inline: 7px; }
  .wire-row .wire-gauge { padding-inline: 6px; }
}

@media print {
  @page { size: letter landscape; margin: 12mm; }
  body { background: white; color: #000; }
  .shell { width: 100%; }
  .site-header, .page-intro, .mobile-modes, #calculator, .chart-controls, .print-button,
  .table-help, .footer-bar, .skip-link, .gauge-dialog { display: none !important; }
  .workspace { display: block; margin: 0 0 12px; }
  #chart { display: block !important; border: 0; }
  .chart-panel .panel-header { padding: 0 0 10px; }
  .table-wrap { margin: 0; overflow: visible; }
  .reference-table { width: 100%; }
  .reference-table th, .chart-value { padding-block: 4px; min-height: 0; color: #000 !important; }
  .chart-value { background: transparent !important; box-shadow: none !important; }
  .print-note { display: block; margin: 8px 0 0; color: #353535; font-size: 12px; }
  .site-footer { background: white; }
  .scope { grid-template-columns: 1fr 1fr; padding: 7px 0 0; gap: 12px; }
  .scope h2 { font-size: 15px; }
  .scope p, .scope-facts, .reference-name, .reference-description { font-size: 11px; }
  .source-panel a { min-height: 0; padding: 3px 0; }
}

.public-method { max-width: 760px; padding: 10px 0 25px; }
.public-method h2 { font-size: 23px; margin: 0 0 8px; font-weight: 620; letter-spacing: -.02em; }
.public-method h3 { font-size: 17px; margin: 14px 0 4px; font-weight: 620; }
.public-method p { margin: 0; color: var(--muted); }
.public-method ul { margin: 12px 0 0; padding-inline-start: 20px; color: var(--link); }
.public-method a { display: inline-flex; align-items: center; min-height: 44px; }
.public-limit { font-size: 13px; color: var(--muted); margin: 9px 0 0; }
.reference-table td { min-height: 44px; }
@media print { .public-method { display: none; } }
