:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b2330;
  --muted: #5d6878;
  --border: #d8dde5;
  --accent: #2f6fb0;
  --accent-text: #ffffff;
  --accent-soft: #e3edf8;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --stop-bg: #fde8e8;
  --stop-text: #8a1f1f;
  --info-bg: #eaf3ec;
  --info-text: #255c33;
  --hl: rgba(255, 196, 0, 0.38);
  --row-hover: #e6eef8;
  --pin-bg: #2f6fb0;
  --pin-text: #ffffff;
  --pop-bg: #ffffff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #232b35;
    --text: #e4e8ee;
    --muted: #97a2b2;
    --border: #2f3946;
    --accent: #5d9de0;
    --accent-text: #0d1520;
    --accent-soft: #1f3247;
    --warn-bg: #3a2b10;
    --warn-text: #f3c77a;
    --stop-bg: #3d1a1a;
    --stop-text: #f2a3a3;
    --info-bg: #17301e;
    --info-text: #9fd8ac;
    --hl: rgba(255, 196, 0, 0.32);
    --row-hover: #263241;
    --pin-bg: #5d9de0;
    --pin-text: #0d1520;
    --pop-bg: #2a3440;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12161c; --surface: #1a2028; --surface-2: #232b35; --text: #e4e8ee; --muted: #97a2b2;
  --border: #2f3946; --accent: #5d9de0; --accent-text: #0d1520; --accent-soft: #1f3247;
  --warn-bg: #3a2b10; --warn-text: #f3c77a; --stop-bg: #3d1a1a; --stop-text: #f2a3a3;
  --info-bg: #17301e; --info-text: #9fd8ac; --hl: rgba(255, 196, 0, 0.32); --row-hover: #263241; --pin-bg: #5d9de0; --pin-text: #0d1520; --pop-bg: #2a3440; color-scheme: dark;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top-inner, .tabs, main, footer { max-width: 920px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding-top: 12px; padding-bottom: 10px; }
.brand { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 20px; font-weight: 650; margin-right: auto; }
.brand svg { width: 24px; height: 24px; color: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 14px 9px; cursor: pointer; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 550; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

main { padding-top: 18px; padding-bottom: 8px; }
.panel[hidden] { display: none; }

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.geo td:first-child { font-weight: 600; }
.sub { color: var(--muted); font-size: 13px; }
.sub.line { display: block; line-height: 1.3; }
.fine-print, .small { font-size: 13px; }
.muted { color: var(--muted); }

.inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
select, input[type="number"] {
  width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.engage-row { display: flex; align-items: center; gap: 8px; }
.engage-row .num { position: relative; flex: 1; min-width: 0; }
.engage-row .num input { padding-right: 62px; }
.engage-row .num em { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }
.eq { color: var(--muted); }

.result { margin: 18px 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.result .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.big { font-size: 34px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.big .unit { font-size: 18px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.alt { color: var(--muted); font-variant-numeric: tabular-nums; }
.result-grid { display: flex; flex-wrap: wrap; gap: 8px 32px; align-items: flex-end; }
.note { margin: 10px 0 0; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.note.warn { background: var(--warn-bg); color: var(--warn-text); }
.note.stop { background: var(--stop-bg); color: var(--stop-text); }
.note.info { background: var(--info-bg); color: var(--info-text); }
.note.plain { background: var(--surface-2); color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 4px 16px 14px; margin-bottom: 14px; }
.card > summary { cursor: pointer; font-weight: 650; padding: 10px 0 6px; }
.card > summary .muted { font-weight: 500; font-family: var(--mono); font-size: 13px; margin-left: 6px; }

.steps { margin: 6px 0 12px; padding-left: 22px; }
.steps li { margin: 6px 0; }
.formula { font-family: var(--mono); font-size: 13.5px; background: var(--surface-2); border-radius: 6px; padding: 6px 10px; margin-top: 4px; overflow-x: auto; white-space: nowrap; }
.pagebtn { border: 1px solid var(--border); background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 9px; font-size: 12.5px; cursor: pointer; white-space: nowrap; margin-left: 4px; font-weight: 600; }
.pagebtn:hover { border-color: var(--accent); }
.rows td, .rows th { padding: 5px 10px; font-size: 13.5px; }
.rows tr.hit td { background: var(--hl); }
tr[data-pin] { cursor: pointer; }
tr[data-pin]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (hover: hover) { tbody tr[data-pin]:hover td { background: var(--row-hover); } }
tbody tr[data-pin].pinned td, tbody tr[data-pin].pinned:hover td { background: var(--pin-bg); color: var(--pin-text); }
tr.pinned .sub { color: inherit; opacity: 0.8; }
.rows tr.plateau td { color: var(--muted); }

.calc { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 6px 0 12px; }
.calc-field { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.calc-field.solved { border-color: var(--accent); background: var(--accent-soft); }
.calc-field .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.calc-field .head label { font-weight: 500; display: flex; gap: 4px; align-items: center; cursor: pointer; white-space: nowrap; }
.calc-field input[readonly] { background: transparent; border-style: dashed; font-weight: 700; }
.calc-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 3px 11px; cursor: pointer; font-size: 13px; }
.chip.ghost { background: transparent; }

.tq { cursor: help; border-bottom: 1px dotted var(--muted); }
.tq:hover, .tq:focus-visible, .tq.open { border-bottom-color: var(--accent); color: var(--accent); outline: none; }
tr.pinned .tq:hover, tr.pinned .tq.open { color: inherit; border-bottom-style: solid; }
.tq-pop {
  position: absolute; z-index: 60; display: block; width: max-content; min-width: 13rem; max-width: min(22rem, calc(100vw - 16px));
  background: var(--pop-bg); border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); font-size: 13px; font-weight: normal; color: var(--text); text-align: left;
}
.tq-pop-formula { display: block; color: var(--muted); font-style: italic; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.tq-pop-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }
.tq-pop-num { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.tq-pop-note { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }

footer { padding-top: 6px; padding-bottom: 28px; color: var(--muted); font-size: 13px; }

dialog#viewer { width: min(960px, calc(100vw - 16px)); height: calc(100vh - 32px); max-height: none; max-width: none; padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }
dialog#viewer::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog#viewer[open] { display: flex; flex-direction: column; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.viewer-bar #v-title { flex: 1; font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; padding: 3px 11px; cursor: pointer; }
.viewer-bar a { font-size: 13px; white-space: nowrap; }
.viewer-page { flex: 1; overflow: auto; background: var(--surface-2); padding: 10px; }
.page-box { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.page-box canvas { display: block; width: 100%; height: auto; }
.page-box .mark { position: absolute; background: rgba(255, 196, 0, 0.4); outline: 2px solid rgba(220, 150, 0, 0.9); border-radius: 2px; pointer-events: none; }

@media (max-width: 640px) {
  .inputs, .calc { grid-template-columns: minmax(0, 1fr); }
  .big { font-size: 28px; }
  .seg button { padding: 6px 10px; }
  th, td { padding: 7px 7px; }
  .geo .sub.line { white-space: normal; }
}

/* ---------- eng: tabs, cards, footer ---------- */
.main-tabs { overflow-x: auto; scrollbar-width: thin; }
.main-tabs button { white-space: nowrap; }
.tab-panel[hidden] { display: none; }
.subbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: -6px 0 14px; border-bottom: 1px solid var(--border); }
.sub-tabs button { padding: 6px 12px 7px; font-size: 14px; }
.sources { color: var(--muted); font-size: 13px; margin: 18px 0 0; }
.ai-note { margin: 0 0 8px; padding: 8px 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; text-align: center; }
.card.plain { padding: 14px 16px; }
.card.plain h2 { font-size: 17px; margin: 0 0 6px; }
.mono { font-family: var(--mono); font-size: 13px; font-weight: 500; margin-left: 6px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > span { color: var(--text); font-weight: 500; font-size: 14px; }
.field.narrow { max-width: 420px; margin-bottom: 10px; }
.seg.small button { padding: 3px 9px; font-size: 13px; }
.beam-svg { display: block; width: 100%; max-width: 420px; margin: 14px auto 0; color: var(--text); }

/* ---------- materials ---------- */
.mat-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 10px; }
.mat-tools input[type="search"] { flex: 1 1 220px; min-width: 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.selbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 10px; min-height: 30px; }
.chip.sel { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; flex: none; }
.chip.sel .sw { margin-right: 0; }
.mat-list { min-width: 560px; }
.mat-list th[data-sort] { cursor: pointer; user-select: none; }
.mat-list th .sub.line { font-weight: 500; }
.mat-list tbody tr[data-mat] { cursor: pointer; }
@media (hover: hover) { .mat-list tbody tr[data-mat]:hover td { background: var(--row-hover); } }
.mat-list tbody tr.pinned td, .mat-list tbody tr.pinned:hover td { background: var(--pin-bg); color: var(--pin-text); }
.mat-list .chk { width: 34px; padding-right: 0; }
.mat-list tr.pinned .sub { color: inherit; opacity: .8; }
.table-wrap:has(.mat-list) { max-height: 460px; overflow: auto; }
.mat-list thead th { position: sticky; top: 0; z-index: 1; }
.cmp td:first-child { white-space: normal; min-width: 150px; }
.cmp th a { color: var(--text); }
.cmp tr.grp th { background: var(--surface); color: var(--text); font-size: 13px; padding-top: 12px; }
sup { font-size: 0.7em; line-height: 0; }

/* stress–strain plot */
.ss-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.legend span { display: inline-flex; align-items: center; }
.ss-wrap { position: relative; }
svg.ss { display: block; width: 100%; height: auto; touch-action: pan-y; }
svg.ss .grid { stroke: var(--border); stroke-width: 1; }
svg.ss .axis { stroke: var(--muted); stroke-width: 1; }
svg.ss .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.ss .axis-label { fill: var(--muted); font-size: 12px; }
svg.ss .series path { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg.ss .series path.assumed { stroke-opacity: 0.5; stroke-dasharray: 6 4; }
svg.ss .mk { stroke: var(--surface); stroke-width: 2; fill: var(--c); }
svg.ss .mk.stress, svg.ss .mk.strain, svg.ss .mk.none { fill: var(--surface); stroke: var(--c); stroke-width: 2; }
svg.ss .mk.strain { stroke-dasharray: 2 2; }
svg.ss .dlabel { fill: var(--text); font-size: 12px; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
svg.ss .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
svg.ss .hit { fill: transparent; cursor: crosshair; }
.ss-tip { position: absolute; top: 10px; z-index: 2; min-width: 180px; background: var(--pop-bg); border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 12.5px; pointer-events: none; }
.ss-tip .row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.ss-tip .row .v { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.ss-key span[class^="k-"] { display: inline-block; vertical-align: middle; margin-right: 3px; }
.k-real, .k-assumed { width: 22px; height: 0; border-top: 2px solid var(--text); }
.k-assumed { border-top-style: dashed; opacity: .5; }
.k-mk { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--text); }
.k-mk.full { background: var(--text); }
.k-mk.strain { border-style: dotted; }

/* favorites, export */
.star { border: 0; background: none; cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 4px; color: var(--muted); }
.star[aria-pressed="true"] { color: #d99a00; }
tr.pinned .star, tr.pinned .star[aria-pressed="true"] { color: inherit; }
label.radio { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--text); font-weight: 400; margin: 3px 0; cursor: pointer; }
label.radio input { margin-top: 3px; }
.chip.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 6px 16px; font-weight: 600; font-size: 14px; }
.chip.primary[disabled] { opacity: .5; cursor: default; }
.cmp th .src { font-weight: 500; white-space: nowrap; }
.cmp th .src a { color: var(--accent); }
code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

/* electrical: AWG table, recommendation */
.awg-wrap { max-height: 560px; overflow: auto; }
.awg thead th { position: sticky; top: 0; z-index: 1; }
.awg tr.hit td, .rec tr.hit td { background: var(--hl); }
.awg td, .awg th { padding: 5px 9px; font-size: 13.5px; }
.rec tr.plateau td { color: var(--muted); }
.refs ul { margin: 4px 0 0; padding-left: 20px; }
.refs li { margin: 4px 0; }
/* the comparison's property column stays put while the materials scroll */
.cmp td:first-child, .cmp thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.cmp thead th:first-child { background: var(--surface-2); }
@media (max-width: 640px) { .cmp td:first-child { min-width: 118px; max-width: 140px; } }
.result-line { margin: 10px 0 4px; font-size: 15px; }

/* account, settings, request form */
.acct { display: inline-flex; gap: 8px; align-items: center; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.plain-list { list-style: none; padding: 0; margin: 6px 0; }
.plain-list li { margin: 6px 0; }
.settings-table td { white-space: normal; vertical-align: top; }
.settings-table select { width: auto; padding: 3px 6px; }
.links-wrap { max-height: 520px; overflow: auto; }
.settings-table tr.bad td { background: var(--stop-bg); }
.settings-table tr.warnrow td { background: var(--warn-bg); }
.star.rm { font-size: 14px; }

.srcline { display: block; white-space: nowrap; font-weight: 500; }
.srcref { font-size: 11px; font-weight: 700; margin-left: 3px; padding: 0 4px; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; background: var(--accent-soft); }

/* ---------- fits, strength, fluids ---------- */
.fit-svg, .mohr-svg { display: block; width: 100%; max-width: 420px; margin: 14px auto 0; color: var(--text); }
.fit-svg .zone-hole { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.fit-svg .zone-shaft { fill: var(--warn-bg); stroke: var(--warn-text); stroke-width: 1.5; }
.mohr-svg circle.mohr { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.mohr-svg .axis { stroke: var(--muted); stroke-width: 1; }
.mohr-svg .pt { fill: var(--text); }
.mohr-svg text { fill: var(--text); font-size: 11px; }
.card.plain .inputs + div:not(:empty), .card.plain .inputs + .calc-actions { margin-top: 14px; }
.sheet-btns { float: right; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; margin: 0 0 6px 10px; }
.sheet-btns .chip { font-size: 12.5px; padding: 3px 10px; }
.sheet-msg { flex-basis: 100%; text-align: right; }
@media (max-width: 640px) { .sheet-btns { float: none; justify-content: flex-start; margin: 0 0 8px; } .sheet-msg { text-align: left; } }
