:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1d2733; --muted: #6b7785; --line: #d5dbe1;
  --accent: #1f6fd1; --sel: #f08c00; --pass: #2f8a4f; --fail: #c83b3b; --warn: #b7791f;
  --concrete: #e6e9ed; --steel: #8a2f12; --stirrup: #2e7d32;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d; --card: #1d232a; --ink: #e3e8ee; --muted: #93a0ae; --line: #36404b;
    --accent: #5aa2ff; --concrete: #3a424c; --steel: #e07850; --stirrup: #66bb6a;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink);
       font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { font-size: 14px; margin: 0 0 6px; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
select, input { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.hint { color: var(--muted); font-size: 12px; }
.help { margin: 2px 4px 8px; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
       padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; margin-right: 8px; }
.brand span { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.spacer { flex: 1; }
.status.ok { color: var(--pass); } .status.busy { color: var(--muted); }
.verdict { font-weight: 700; padding: 2px 10px; border-radius: 12px; color: #fff; background: var(--muted); }
.verdict.pass { background: var(--pass); } .verdict.fail { background: var(--fail); } .verdict.nc { background: var(--muted); }

main { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(320px, 1fr); gap: 14px; padding: 14px 16px; }
@media (max-width: 1100px) { main { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.sec-col { flex: 0 0 340px; max-width: 100%; }
.mat-col { flex: 1; min-width: 280px; }

#palette { display: flex; gap: 4px; align-items: center; }
#palette .case { width: 30px; padding: 4px 0; font-weight: 700; }
#palette .case.on[data-case="G"] { background: #5f6b7a; color: #fff; }
#palette .case.on[data-case="Q"] { background: #1f6fd1; color: #fff; }
#palette .tool.on { background: var(--accent); color: #fff; }

svg.draw { width: 100%; display: block; user-select: none; touch-action: none; }
svg.sec { max-width: 340px; }
#beam.placing { cursor: crosshair; }
.beam { fill: var(--ink); }
.sup { fill: var(--card); stroke: var(--ink); stroke-width: 1.5; }
.ground { stroke: var(--ink); stroke-width: 1.2; }
.free { fill: var(--card); stroke: var(--ink); stroke-width: 1.5; }
.support { cursor: pointer; } .support.drag-x { cursor: ew-resize; }
.support.sel .sup, .support.sel .free { stroke: var(--sel); stroke-width: 2.5; }
.span { cursor: pointer; }
.span.sel .dimtxt { fill: var(--sel); font-weight: 700; }
.dim { stroke: var(--muted); stroke-width: 1; }
.dimtxt { font-size: 12px; fill: var(--ink); cursor: pointer; }
.load { cursor: pointer; } .load.drag-x { cursor: ew-resize; }
.load.sel rect, .load.sel line { stroke: var(--sel) !important; stroke-width: 2; }
.lbl { font-size: 11px; font-weight: 600; }
.handle { fill: var(--sel); fill-opacity: .25; cursor: ew-resize; }
.ghost { cursor: pointer; } .ghost line { stroke: var(--muted); stroke-dasharray: 4 3; stroke-width: 2; }
.ghost circle { fill: var(--card); stroke: var(--accent); stroke-width: 1.5; }
.ghost text { fill: var(--accent); font-size: 16px; font-weight: 700; }
.ghost:hover circle { fill: var(--accent); } .ghost:hover text { fill: #fff; }
.uc { cursor: pointer; } .uc:hover rect { stroke: var(--ink); stroke-width: 1.5; }
.uctxt { font-size: 11px; font-weight: 700; fill: #fff; pointer-events: none; }
.uc-none { fill: var(--line); }
.placing { stroke: var(--accent); stroke-dasharray: 4 3; }
text.big { font-size: 15px; }

.diag-wrap { position: relative; }
.ptitle { font-size: 11px; fill: var(--muted); }
.axis { stroke: var(--ink); stroke-width: 1; }
.env-max { fill: none; stroke: #c0392b; stroke-width: 1.6; }
.env-min { fill: none; stroke: #1f6fd1; stroke-width: 1.6; }
.fill-max { fill: #c0392b; fill-opacity: .08; } .fill-min { fill: #1f6fd1; fill-opacity: .08; }
.t-max { fill: #c0392b; } .t-min { fill: #1f6fd1; }
.pt { fill: var(--ink); } .val { font-size: 11px; fill: var(--ink); font-weight: 600; }
.cross { stroke: var(--sel); stroke-width: 1; stroke-dasharray: 3 3; }
.tip { display: none; position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line);
       border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.15); white-space: nowrap; }

.concrete { fill: var(--concrete); stroke: var(--ink); stroke-width: 1.5; cursor: pointer; }
.stirrup { fill: none; stroke: var(--stirrup); pointer-events: none; }
.stirrup-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
.part.sel .stirrup { stroke: var(--sel); } .part.sel .bar { stroke: var(--sel); stroke-width: 2; }
.bar { fill: var(--steel); stroke: var(--ink); stroke-width: .8; cursor: pointer; }
.add { fill: var(--accent); font-size: 12px; cursor: pointer; }
.edge { fill: transparent; } .edge:hover { fill: var(--sel); fill-opacity: .3; }
.edge.ew { cursor: ew-resize; } .edge.ns { cursor: ns-resize; }
.dimg { cursor: pointer; }
.cover { font-size: 11px; fill: var(--muted); cursor: pointer; }

.materials { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 10px; margin-bottom: 12px; }
.materials label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.materials select, .materials input { color: var(--ink); margin-top: 2px; }
table.readouts { border-collapse: collapse; width: 100%; font-size: 13px; }
table.readouts th { text-align: left; padding: 4px 8px 4px 0; }
table.readouts td { padding: 4px 6px; border-top: 1px solid var(--line); }
table.readouts td sub { white-space: nowrap; }

.popover { position: fixed; z-index: 20; min-width: 250px; max-width: 340px; background: var(--card);
           border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.pop-title { display: flex; justify-content: space-between; align-items: center; font-weight: 700;
             padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pop-close { border: none; font-size: 18px; padding: 0 4px; line-height: 1; }
.pop-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.pop-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pop-row > span { min-width: 90px; color: var(--muted); font-size: 12px; }
.pop-row input { width: 90px; } .pop-row em { color: var(--muted); font-style: normal; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 28px; padding: 2px 0; font-weight: 700; }
.stepper b { min-width: 22px; text-align: center; }
.pop-btn.danger { color: var(--fail); border-color: var(--fail); align-self: flex-start; }
.pop-note { margin: 0; font-size: 12px; color: var(--muted); }

.right { position: sticky; top: 58px; align-self: start; max-height: calc(100vh - 72px); overflow: auto;
         background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
@media (max-width: 1100px) { .right { position: static; max-height: none; } }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }
.toggle { font-size: 12px; color: var(--muted); }
.box { border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.box.err { background: #fbe9e9; color: #7a1d1d; border: 1px solid #f0b8b8; }
.box.warn { background: #fdf4e3; color: #6b4a0e; border: 1px solid #efd59a; }
.stage h3 { font-size: 13px; margin: 14px 0 4px; padding-bottom: 3px; border-bottom: 2px solid var(--accent); }
.step.hidden { display: none; }
.step.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: rgba(240,140,0,.45); } 100% { background: transparent; } }
.st { font-size: 11px; padding: 0 6px; border-radius: 8px; }
.st.pass { background: var(--pass); color: #fff; } .st.fail { background: var(--fail); color: #fff; }
.st.warn { color: var(--warn); } .st.ok { color: var(--muted); }
details.more { margin-top: 10px; font-size: 12.5px; }
details.more summary { cursor: pointer; font-weight: 600; }
table.na { border-collapse: collapse; width: 100%; font-size: 12px; }
table.na td, table.na th { border-bottom: 1px solid var(--line); padding: 2px 4px; text-align: left; }

fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; }
legend { font-weight: 700; padding: 0 4px; }
table.grid { border-collapse: collapse; margin-bottom: 8px; }
table.grid td, table.grid th { padding: 2px 4px; font-size: 12px; }
table.grid input { width: 80px; }
.frow { display: grid; grid-template-columns: 260px 140px 50px; gap: 6px; align-items: center; margin: 3px 0; font-size: 13px; }
.frow em { color: var(--muted); font-style: normal; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
         padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* ---- narrative derivation panel ------------------------------------------------------- */
.toggles { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.box.plain { background: rgba(31,111,209,.07); border: 1px solid rgba(31,111,209,.25); color: var(--ink); }
.box.plain p { margin: 4px 0 0; }
.step { border-bottom: 1px solid var(--line); padding: 4px 2px 6px; }
.srow { display: flex; align-items: baseline; gap: 6px; }
.srow .n { color: var(--muted); font-size: 11px; min-width: 22px; text-align: right; }
.stitle { border: none; background: none; padding: 0; text-align: left; font-size: 12.5px; color: var(--ink);
          cursor: pointer; flex: 1; }
.stitle:hover { color: var(--accent); text-decoration: underline; }
.step.headline .stitle { font-weight: 700; }
.step.headline { background: rgba(31,111,209,.05); }
.eq { margin: 2px 0 0 28px; font-size: 14px; line-height: 1.75; font-family: "Cambria Math", Cambria, Georgia, serif; }
.eq .hint { font-family: system-ui, sans-serif; }
/* hoverable symbols (Student mode): a soft tinted chip, never an underline (readable subscripts) */
.tk { background: rgba(31,111,209,.08); border-radius: 4px; padding: 0 2px; cursor: help; }
.tk:hover, .tk:focus { background: rgba(31,111,209,.22); outline: none; }
.tk.num { color: var(--accent); background: none; }
.tk.num:hover, .tk.num:focus { background: rgba(31,111,209,.15); }
.tk.lhs { font-weight: 700; }
.cref { display: none; margin: 1px 0 0 28px; font-size: 11px; color: var(--muted); }
.show-refs .cref { display: block; }
.xcard { margin: 6px 0 4px 28px; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--bg);
         border-radius: 0 8px 8px 0; font-size: 13px; }
.xcard .xhead { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 4px; }
.xcard .xclose { border: none; background: none; font-size: 18px; line-height: 1; padding: 0 4px; }
.xcard .lead { font-style: italic; margin: 2px 0 6px; }
.xcard h5 { margin: 8px 0 2px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; }
.xcard p { margin: 2px 0 4px; }
.xcard ul { margin: 2px 0; padding-left: 18px; }
.xcard .foot { margin-top: 8px; font-size: 11px; color: var(--muted); }
.xcard .mono { font-family: "Cambria Math", Cambria, Georgia, serif; }
.xcard .warn, .hovercard .warn { color: var(--warn); }
.xcard .ok, .hovercard .ok { color: var(--pass); }
.hovercard { display: none; position: fixed; z-index: 30; max-width: 340px; background: var(--card); color: var(--ink);
             border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
             padding: 8px 10px; font-size: 12.5px; pointer-events: none; }
.hc-head { font-weight: 700; font-size: 14px; } .hc-head span { font-weight: 600; font-size: 12.5px; margin-left: 4px; }
.hc-val { margin: 3px 0; font-family: "Cambria Math", Cambria, Georgia, serif; font-size: 14px; }
.hc-short { margin: 4px 0; }
.hc-src, .hc-clause { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.hc-more { margin-top: 6px; font-size: 11px; color: var(--accent); }

/* subscripts: smaller, slightly lowered, without pushing lines apart */
sub { font-size: .72em; vertical-align: -.28em; line-height: 0; }
tspan.sub { font-size: 80%; }

/* ---- Engineer view / Student mode -------------------------------------------------------- */
body:not(.mode-student) .student-only { display: none !important; }
.modeswitch { display: flex; align-items: center; gap: 5px; padding: 3px 10px; border: 1px solid var(--line);
              border-radius: 14px; cursor: pointer; font-size: 13px; user-select: none; }
.mode-student .modeswitch { background: rgba(31,111,209,.1); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.stage.hidden { display: none; }
.eq .why { color: var(--muted); font-size: 12px; font-family: system-ui, sans-serif; }
.box.slim { padding: 4px 10px; font-size: 12px; }

/* unity-check table */
table.ucs { width: 100%; border-collapse: collapse; margin: 8px 0 4px; font-size: 12.5px; }
table.ucs th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: 3px 4px; }
table.ucs td { padding: 3px 4px; border-bottom: 1px solid var(--line); }
table.ucs td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.ucs td.uc { font-weight: 700; }
table.ucs tr.ucrow { cursor: pointer; }
table.ucs tr.ucrow:hover { background: rgba(240,140,0,.12); }
table.ucs tr.gov td { font-weight: 700; }

/* highlight of the step under the mouse */
.step:hover { background: rgba(240,140,0,.07); }
.hl-line { stroke: var(--sel); stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; }
.hl-dot { fill: var(--sel); fill-opacity: .25; stroke: var(--sel); stroke-width: 2.5; pointer-events: none;
          animation: hlpulse 1.1s ease-in-out infinite alternate; }
@keyframes hlpulse { from { stroke-opacity: 1; } to { stroke-opacity: .35; } }
.hl-val { font-size: 12px; font-weight: 700; fill: var(--sel); pointer-events: none; }
.uc-lit { fill: none; stroke: var(--sel); stroke-width: 3; pointer-events: none; }

/* steel / timber / prestressed sections and the material switch */
.profile { fill: #b9c4cf; stroke: var(--ink); stroke-width: 1; }
.timber { fill: #e8c99a; stroke: #8a5a2b; stroke-width: 1.2; }
.grain { stroke: #b58a55; stroke-width: .6; opacity: .6; }
.conc { fill: var(--concrete, #d9d9d9); stroke: var(--ink); stroke-width: 1; }
.strand { fill: #843c0c; stroke: #fff; stroke-width: .6; }
.centroid { stroke: var(--muted); stroke-dasharray: 6 3; stroke-width: .8; }
.loadarrow { stroke: var(--fail); stroke-width: 1.6; marker-end: none; }
.matswitch { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.matswitch button { border: 0; border-radius: 0; padding: 4px 10px; background: transparent; }
.matswitch button + button { border-left: 1px solid var(--line); }
.matswitch button.on { background: var(--accent); color: #fff; }
.results-table { border-collapse: collapse; font-size: 13px; }
.results-table th { text-align: left; font-weight: 400; color: var(--muted); padding: 2px 10px 2px 0; }
.results-table td { padding: 2px 0; font-variant-numeric: tabular-nums; }
body:not(.mat-rc) .rc-only, body.mat-rc .non-rc { display: none; }
.materials label span { overflow: hidden; text-overflow: ellipsis; }
.mblock { grid-column: 1 / -1; font-weight: 600; font-size: 12px; color: var(--muted); margin-top: 6px; border-bottom: 1px solid var(--line); }

/* Tools page */
.navlink { color: var(--accent, #1f4e79); text-decoration: none; font-weight: 600; padding: 2px 6px; border-radius: 6px; }
.navlink:hover { background: var(--line); }
.specfig { width: 100%; height: auto; display: block; }

.notice { padding: 6px 16px; font-size: 12px; color: var(--ink); background: color-mix(in srgb, var(--warn) 14%, var(--card));
          border-bottom: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line)); }
.notice b { color: var(--warn); }
a.brand { color: inherit; text-decoration: none; margin-right: 0; }
