:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde1e7;
  --border-strong: #7d8592;
  --text: #14181f;
  --text-2: #4a525e;
  --text-3: #5a626e;
  --accent: #1f5ea8;
  --accent-ink: #ffffff;
  --accent-soft: #e6eef8;
  --metal: #dfe6ef;
  --metal-edge: #8f9bab;
  --rubber: #262b33;
  --grid: #e6e9ee;
  --s1: #1f5ea8; --s2: #c8501c; --s3: #117a52; --s4: #946200; --s5: #c2457a;
  --cold: #1f5ea8; --hot: #c8372f;
  --ok: #1d7a46; --warn: #8a4b00; --err: #b3261e; --info: #1f5ea8;
  --warn-bg: #fff4e5; --err-bg: #fdecec; --info-bg: #eaf1fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f252d; --border: #2b323c; --border-strong: #6b7482;
    --text: #e7eaef; --text-2: #b4bcc7; --text-3: #9aa3af;
    --accent: #6aa5ec; --accent-ink: #0b1018; --accent-soft: #1b2a3d;
    --metal: #2a3542; --metal-edge: #6b7a8c; --rubber: #d5dae1; --grid: #262c35;
    --s1: #6aa5ec; --s2: #f08a4b; --s3: #3fbf8a; --s4: #e0a030; --s5: #e87ba4;
    --cold: #6aa5ec; --hot: #f07070;
    --ok: #5cc98c; --warn: #f3c27a; --err: #ff8a80; --info: #6aa5ec;
    --warn-bg: #2e2312; --err-bg: #331a1a; --info-bg: #17222f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f252d; --border: #2b323c; --border-strong: #6b7482;
  --text: #e7eaef; --text-2: #b4bcc7; --text-3: #9aa3af;
  --accent: #6aa5ec; --accent-ink: #0b1018; --accent-soft: #1b2a3d;
  --metal: #2a3542; --metal-edge: #6b7a8c; --rubber: #d5dae1; --grid: #262c35;
  --s1: #6aa5ec; --s2: #f08a4b; --s3: #3fbf8a; --s4: #e0a030; --s5: #e87ba4;
  --cold: #6aa5ec; --hot: #f07070;
  --ok: #5cc98c; --warn: #f3c27a; --err: #ff8a80; --info: #6aa5ec;
  --warn-bg: #2e2312; --err-bg: #331a1a; --info-bg: #17222f;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 14px; letter-spacing: .01em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; flex: none; }
.logo rect { fill: var(--accent); }
.logo path { stroke: var(--accent-ink); stroke-width: 2; fill: none; stroke-linecap: round; }
h1 { font-size: 16px; }
.subtitle { margin: 0; color: var(--text-3); font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

select, input[type="number"] {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 7px;
  padding: 6px 8px; width: 100%; min-width: 0; height: 32px;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:invalid, input.bad { border-color: var(--err); }
.lang select { width: auto; }

.btn {
  font: inherit; font-weight: 500; height: 32px; padding: 0 12px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-icon { width: 32px; padding: 0; display: inline-grid; place-items: center; }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; background: var(--surface-2); }
.seg button {
  font: inherit; font-weight: 500; border: 0; background: transparent; color: var(--text-2);
  padding: 4px 12px; border-radius: 6px; cursor: pointer; height: 26px;
}
.seg button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg-wide { display: flex; margin-bottom: 10px; }
.seg-wide button { flex: 1; white-space: nowrap; padding: 4px 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 20px;
  padding: 20px; max-width: 1440px; margin: 0 auto;
}
.inputs { display: flex; flex-direction: column; gap: 14px; }
fieldset {
  margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
legend { font-weight: 600; padding: 0 6px; margin-left: -6px; display: flex; align-items: center; gap: 8px; float: left; width: 100%; margin-bottom: 2px; }
legend + * { clear: both; }
.step {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700;
}
label { display: grid; grid-template-columns: auto 1fr; align-content: start; column-gap: 4px; row-gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
label > input, label > select { grid-column: 1 / -1; }
label .u { color: var(--text-3); font-weight: 400; }
label.check { display: flex; flex-direction: row; align-items: center; gap: 8px; align-self: end; height: 32px; }
label.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.hint { margin: 0; font-size: 12px; color: var(--text-3); }
.hint:empty { display: none; }
[hidden] { display: none !important; }

.layout-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.layout-picker button {
  font: inherit; font-size: 12px; font-weight: 500; color: var(--text-2);
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 6px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.layout-picker svg { width: 60px; height: 36px; }
.layout-picker path { fill: none; stroke: var(--text-3); stroke-width: 2.5; stroke-linejoin: round; }
.layout-picker path.metal { stroke-width: 2; }
.layout-picker .ring { fill: var(--text-3); stroke: none; }
.layout-picker .ring-path { display: none; }
.layout-picker button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.layout-picker button[aria-checked="true"] path { stroke: var(--accent); }
.layout-picker button[aria-checked="true"] .ring { fill: var(--accent); }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card > h2 { margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-note { margin: -4px 0 10px; color: var(--text-3); font-size: 12px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }

.hero { display: flex; gap: 20px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.hero-label { color: var(--text-2); font-weight: 500; }
.hero-value { font-size: 40px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.hero-sub { color: var(--text-3); font-size: 12px; }
.hero-side { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 24px; margin: 0; }
.hero-side div { display: flex; flex-direction: column; }
.hero-side dt { color: var(--text-3); font-size: 12px; }
.hero-side dd { margin: 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hero.invalid .hero-value { color: var(--text-3); }

/* Source results table */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th { text-align: right; font-weight: 500; color: var(--text-3); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
table.data td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.strong { font-weight: 600; }
.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.over { color: var(--err); }

.issues { display: flex; flex-direction: column; gap: 6px; padding: 12px; }
.issue { display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px; border-radius: 7px; font-size: 13px; }
.issue .tag { flex: none; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding-top: 1px; min-width: 44px; }
.issue.error { background: var(--err-bg); } .issue.error .tag { color: var(--err); }
.issue.warn { background: var(--warn-bg); } .issue.warn .tag { color: var(--warn); }
.issue.info { background: var(--info-bg); } .issue.info .tag { color: var(--info); }

.section-wrap { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.section-title { font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.section svg { max-height: 150px; }
.temp-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.map-wrap { position: relative; }
.map-wrap svg { display: block; width: 100%; height: auto; max-height: 460px; }
.temp-legend .ramp { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--cold), var(--hot)); }

.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.metric { background: var(--surface); padding: 10px 12px; }
.metric .k { font-size: 12px; color: var(--text-3); }
.metric .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .s { font-size: 11px; color: var(--text-3); }

.notes summary { cursor: pointer; font-weight: 600; }
.notes-body { color: var(--text-2); font-size: 13px; }
.notes-body ul { padding-left: 18px; }
.notes-body li { margin-bottom: 6px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 20;
}

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .inputs { order: 0; }
}
@media (max-width: 640px) {
  .grid4 { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 10px 16px; position: static; }
  .grid-cards { grid-template-columns: 1fr; }
  .hero-value { font-size: 32px; }
  .hero-side { grid-template-columns: repeat(2, auto); }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .toolbar { width: 100%; }
}

@media print {
  .topbar .toolbar, .toast, .site-footer, .about, .lib-tools, #suggest, #apply-rec, .tip { display: none; }
  .topbar { position: static; }
  body { background: #fff; }
  .layout { grid-template-columns: 300px 1fr; padding: 0; gap: 12px; }
  .card, fieldset { box-shadow: none; break-inside: avoid; }
  .notes { display: block; }
  .notes[open] summary ~ *, .notes summary ~ * { display: block; }
}
/* Footer and About dialog */
.site-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; padding: 18px 16px 28px; color: var(--text-3); font-size: 12px; }
.site-footer a { color: var(--text-2); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }
.about { width: min(520px, calc(100vw - 32px)); padding: 22px 24px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.about::backdrop { background: rgba(0, 0, 0, 0.4); }
.about-close { position: absolute; top: 12px; right: 12px; }
.about-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding-right: 36px; }
.about-head img { width: 44px; height: 44px; border-radius: 10px; }
.about h2 { margin: 0; font-size: 18px; }
.about-head p { margin: 2px 0 0; color: var(--text-3); font-size: 12px; }
.about p { line-height: 1.55; margin: 0 0 10px; }
.about a { color: var(--accent); }
.about-support { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--accent-soft); }
.about-support p { margin: 0 0 10px; }
.about a.btn-support { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; background: #d6303a; color: #fff; font-weight: 600; font-size: 13px; text-decoration: none; }
.about a.btn-support:hover { background: #c42b35; }
.about .about-meta { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12px; }

/* ---------- O-ring designer additions ---------- */
.mini-label { font-size: 12px; color: var(--text-2); font-weight: 500; margin-bottom: 4px; }
.grid2 > div > .seg-wide { margin-bottom: 0; }
fieldset > .btn { align-self: flex-start; }
input[type="number"]:disabled { color: var(--text-2); background: var(--surface-2); }
details.sub { border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 10px; }
details.sub summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-2); }
details.sub[open] { gap: 10px; }
details.sub > * + * { margin-top: 10px; }
label.check { height: auto; font-weight: 500; }

.hero { position: relative; }
.status-chip { position: absolute; top: 14px; right: 16px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 99px; }
.status-chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.status-chip.warn { color: var(--warn); background: var(--warn-bg); }
.status-chip.error { color: var(--err); background: var(--err-bg); }
.hero-main { padding-right: 70px; }
.hero-value.ok { color: var(--text); }
.hero-value.warn { color: var(--warn); }
.hero-value.error { color: var(--err); }

.drawing { display: flex; justify-content: center; }
.drawing svg { display: block; width: 100%; height: auto; max-height: 340px; }
.legend-key { font-size: 12px; color: var(--text-3); display: inline-flex; align-items: center; gap: 6px; }
.legend-key .k-free { width: 14px; height: 0; border-top: 1.5px dashed var(--text-3); }
svg .metal { fill: var(--metal); stroke: var(--metal-edge); stroke-width: 1; }
svg .hatch line { stroke: var(--metal-edge); stroke-width: .8; }
svg .oring { fill: var(--rubber); }
svg .oring-free { fill: none; stroke: var(--text-3); stroke-width: 1.2; stroke-dasharray: 4 3; }
svg .oring-line { fill: none; stroke: var(--rubber); }
svg .wall { fill: none; stroke: var(--metal-edge); stroke-width: 1.5; }
svg .groove-fill { fill: var(--accent-soft); stroke: none; }
svg .dim { stroke: var(--text-3); stroke-width: 1; fill: none; }
svg .dim-text { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
svg .dim-text.strong { fill: var(--text); font-weight: 600; }
svg .axis { stroke: var(--text-3); stroke-width: 1; stroke-dasharray: 10 3 2 3; }
svg .press { stroke: var(--hot); stroke-width: 2; fill: none; }
svg .press-head { fill: var(--hot); }
svg .press-text { fill: var(--hot); font-size: 11px; font-weight: 700; }
svg .gap-hl { fill: var(--hot); opacity: .35; }

.badge { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 2px 8px; }
table.data td.hl, table.data tr.hl td { background: var(--accent-soft); }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data td.left, table.data th.left { text-align: left; }
table.data td.wrap { white-space: normal; text-align: left; min-width: 180px; color: var(--text-2); font-size: 12px; }
.lib summary { cursor: pointer; font-weight: 600; }
.lib[open] summary { margin-bottom: 10px; }
.lib-tools { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.lib-tools select { width: auto; }
.lib-tools input[type="search"] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 6px 8px; height: 32px; flex: 1; min-width: 160px; }
.lib-scroll { max-height: 420px; overflow-y: auto; }
.lib-scroll thead th { position: sticky; top: 0; background: var(--surface); }

.metric.warn .v { color: var(--warn); }
.metric.error .v { color: var(--err); }

.converter { width: min(560px, calc(100vw - 32px)); }
.converter h2 { margin-bottom: 12px; padding-right: 40px; }
.conv-tabs { flex-wrap: wrap; }
.conv-tabs button { flex: 1 0 auto; }
.conv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.conv-grid label { grid-template-columns: 1fr; }

@media (max-width: 640px) {
  .status-chip { position: static; }
  .hero-main { padding-right: 0; }
  .layout-picker button span { font-size: 11px; }
}
@media print {
  .lib:not([open]) { display: none; }
}

/* Five seal types, tooltips, help */
.layout-picker.five { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.layout-picker.five button { padding: 6px 2px 5px; font-size: 11px; }
.layout-picker.five svg { width: 46px; height: 28px; }
.lt { display: inline-flex; align-items: center; gap: 4px; }
.tip { display: inline-grid; place-items: center; width: 15px; height: 15px; border-radius: 50%; font-size: 11px; line-height: 1; color: var(--accent); cursor: help; font-weight: 600; }
.tip:hover, .tip:focus-visible { background: var(--accent-soft); outline: none; }
.help { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; }
.help h3 { font-size: 14px; margin: 16px 0 6px; }
.help ol, .help ul { padding-left: 20px; margin: 0 0 10px; line-height: 1.55; }
.help li { margin-bottom: 4px; }
.help dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 10px; }
.help dt { font-weight: 600; }
.help dd { margin: 0; color: var(--text-2); }
.help svg { display: block; width: 100%; max-width: 420px; height: auto; margin: 6px auto 4px; }
.help svg .metal { fill: var(--metal); stroke: var(--metal-edge); }
.help svg .oring { fill: var(--rubber); }
.help svg .dim { stroke: var(--text-3); fill: none; }
.help svg text { fill: var(--text-2); font-size: 12px; font-weight: 600; }
.toast { max-width: min(520px, calc(100vw - 32px)); text-align: center; }
@media (max-width: 640px) {
  .help dl { grid-template-columns: 1fr; }
  .help dd { margin-bottom: 6px; }
}
.preset select { width: auto; max-width: 200px; }
.toolbar { gap: 6px; }
.toolbar .btn { padding: 0 10px; }
@media (max-width: 640px) { .preset, .preset select { width: 100%; max-width: 100%; } }


/* ---------- MIL-STD-810 selector ---------- */
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.theory h3 { font-size: 14px; color: var(--text); margin: 18px 0 6px; }
.theory h3:first-child { margin-top: 10px; }
.theory p { margin: 0 0 8px; line-height: 1.6; }
.formula { font-family: var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 8px 12px; display: inline-block; color: var(--text); }
.refs { padding-left: 22px; margin: 10px 0 0; line-height: 1.55; }
.refs li { margin-bottom: 8px; }
.ref-use { display: block; color: var(--text-3); font-size: 12px; }
.notes-body .about-meta { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-3); font-size: 12px; }

.layout { grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
legend { line-height: 1.3; }
.phases { display: flex; flex-direction: column; gap: 6px; }
.phase-group { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin: 6px 0 0; }
.phase { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); transition: border-color .15s, background .15s; }
.phase.on { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.phase-head { display: flex !important; flex-direction: row; gap: 10px; align-items: flex-start; padding: 8px 10px; cursor: pointer; color: var(--text); font-size: 13px; }
.phase-head input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.phase-head b { font-weight: 600; display: block; }
.phase-head small { display: block; color: var(--text-3); font-weight: 400; font-size: 12px; margin-top: 1px; }
.phase-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 10px 10px 36px; }
.phase-opts label:has(select) { grid-column: 1 / -1; }

.hero { flex-wrap: wrap; }
.hero-side { grid-template-columns: repeat(3, auto); }
.hero-side dd { font-size: 18px; }

table.plan td small.ref { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; white-space: normal; max-width: 340px; }
table.plan td small { color: var(--text-3); }
table.plan td { vertical-align: top; }
table.plan tr.hl td { background: var(--accent-soft); }
table.plan tr.click:hover td { background: var(--surface-2); }
table.plan tr.click.hl:hover td { background: var(--accent-soft); }
table.plan tr.shock-row { cursor: pointer; }
table.data tr.muted td { color: var(--text-3); }
table.data td.left, table.data th.left { text-align: left; }
.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.over { color: var(--err); }

.viewer-tools { display: flex; gap: 8px; align-items: center; }
.viewer-tools select { width: auto; max-width: 320px; }
.viewer-opts:empty { display: none; }
.viewer-opts { margin-bottom: 8px; }
.viewer-opts .seg { flex-wrap: wrap; }
.sub-h { font-size: 13px; margin: 14px 0 6px; }
.sub-h small { color: var(--text-3); font-weight: 400; }
.viewer-detail { margin-top: 4px; }
.viewer-detail .table-wrap { max-height: 380px; overflow-y: auto; }
.viewer-detail thead th { position: sticky; top: 0; background: var(--surface); }
.metrics { margin-top: 12px; }

.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .grid-major { stroke: var(--border-strong); stroke-width: 1; opacity: .7; }
.chart .tick { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .tick.minor { font-size: 10px; opacity: .8; }
.chart .axis-title { fill: var(--text-3); font-size: 11px; }
.chart .curve, .pulse-wrap .curve { fill: none; stroke-width: 2.2; stroke-linejoin: round; }
.chart .curve.dash { stroke-dasharray: 6 4; }
.chart .tone { stroke: var(--s5); stroke-width: 2; }
.chart .tone.out { stroke: var(--text-3); stroke-dasharray: 3 3; }
.chart .tone-dot { fill: var(--s5); }
.chart .tone.out-dot { fill: var(--text-3); }
.chart .tone-label, .pulse-wrap .tone-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .tone-tick { fill: var(--s5); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-2); margin-top: 4px; padding-left: 62px; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.chart-legend .k-tone { background: var(--s5); width: 3px; height: 12px; }

.pulse-wrap { margin: 10px 0 4px; }
.pulse-wrap svg { display: block; width: 100%; height: auto; }
.pulse-wrap .grid { stroke: var(--grid); }
.pulse-wrap .tick, .pulse-wrap .axis-title { fill: var(--text-3); font-size: 11px; }
.drop-desc { margin: 8px 0; color: var(--text-2); }

.psd-tool { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 14px; }
.psd-tool textarea { width: 100%; font: 13px/1.5 var(--mono); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 7px; padding: 8px; resize: vertical; }
.psd-tool .metrics { margin-top: 0; margin-bottom: 10px; }
.psd-tool .table-wrap { max-height: 240px; overflow-y: auto; }
.lib-tools { margin-top: 8px; align-items: center; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
label.inline input { width: 80px; }
#tool-comp .grid4 { margin-bottom: 4px; }

@media (max-width: 1000px) { .psd-tool { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .grid4 { grid-template-columns: 1fr 1fr; }
  .phase-opts { padding-left: 10px; }
  .hero-side { grid-template-columns: repeat(3, auto); gap: 4px 14px; }
  .viewer-tools { width: 100%; }
  .viewer-tools select { flex: 1; max-width: none; }
  .chart-legend { padding-left: 0; }
}
@media print {
  .lib, #viewer-select, #csv, .viewer-opts, .phase:not(.on) { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .inputs fieldset:nth-child(3) { display: none; }
  .phase-head input { display: none; }
  .card { page-break-inside: auto; }
  #theory, #refs { display: none; }
}
/* layout fixes */
table.data td small.ref { display: block; font-size: 11px; color: var(--text-3); font-weight: 400; white-space: normal; }
table.plan { table-layout: auto; }
table.plan td, table.plan th { white-space: normal; }
table.plan td:first-child { min-width: 210px; }
table.plan td:nth-child(3) { min-width: 110px; }
.viewer-detail .table-wrap { max-height: none; overflow-y: visible; }
.metrics { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
table.plan td:nth-child(n+5), table.plan th:nth-child(n+5) { white-space: nowrap; }
.hero-main { padding-right: 0; }
@media (max-width: 1000px) { .layout { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .hero-side { grid-template-columns: repeat(3, minmax(0, auto)); }
  .hero-side dd { font-size: 15px; }
  .card-head { align-items: flex-start; }
}

/* Phones: every panel stays inside the screen width, in every language
   (same rules in all ehcrea calculators). Grid and flex children may shrink below their
   content width, long labels wrap, wide tables scroll inside their own box. */
.layout > *, .results > *, fieldset, .card, .grid2 > *, .grid3 > *, .grid-cards > *, .layout-picker > *, .stack-legend > * { min-width: 0; }
.layout-picker button { overflow-wrap: anywhere; }
input, select, textarea { max-width: 100%; }
.legend-key { display: inline-flex; flex-wrap: wrap; align-items: center; row-gap: 4px; max-width: 100%; }
.table-wrap { max-width: 100%; }
@media (max-width: 640px) {
  table.data td:first-child { white-space: normal; }
  /* Field label and unit wrap onto two lines instead of widening the form. */
  .layout label:not(.check) { display: flex; flex-wrap: wrap; align-items: baseline; }
  .layout label:not(.check) > input, .layout label:not(.check) > select { flex: 1 0 100%; min-width: 0; }
}

/* Theme switch: square icon button with the icon exactly centred (same in every ehcrea
   calculator). ".toolbar .btn" padding must not apply to it, or the 16 px icon is pushed right. */
.toolbar .btn-icon, #theme { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; }
