:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --border-strong: #c9c8c1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7973;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fb;
  --metal: #d9dde3;
  --metal-edge: #9aa3ad;
  --rubber: #2b2b2a;
  --grid: #ebeae6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --cold: #2a78d6; --hot: #e34948;
  --ok: #008300; --warn: #b26b00; --err: #c62828; --info: #2a78d6;
  --warn-bg: #fff6e5; --err-bg: #fdecec; --info-bg: #eef4fc;
  --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: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c; --border-strong: #45453f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --accent-soft: #1d2b3d;
    --metal: #3a3f46; --metal-edge: #6b7480; --rubber: #d7d6d0; --grid: #2a2a28;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --cold: #3987e5; --hot: #e66767;
    --ok: #3fae3f; --warn: #e0a030; --err: #f07070; --info: #6aa8f0;
    --warn-bg: #2d2412; --err-bg: #331a1a; --info-bg: #17222f;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c; --border-strong: #45453f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-soft: #1d2b3d;
  --metal: #3a3f46; --metal-edge: #6b7480; --rubber: #d7d6d0; --grid: #2a2a28;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
  --cold: #3987e5; --hot: #e66767;
  --ok: #3fae3f; --warn: #e0a030; --err: #f07070; --info: #6aa8f0;
  --warn-bg: #2d2412; --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 .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%; } }
