:root {
  --bg: #f3f1ec; --panel: #fbfaf7; --ink: #1c2321; --muted: #5f6a66; --line: #d8d4c9;
  --accent: #0a5c4a; --accent-ink: #fff; --hi: #0a66c2; --sel: #d95a00;
  --view1: #e7e9e6; --view2: #c5cbc7;
  --ok: #17794a; --bad: #b3261e; --man: #0a5c4a; --plate: #8a5a00; --prac: #51606b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131716; --panel: #1b201f; --ink: #e8ebe8; --muted: #9aa5a0; --line: #303836;
    --accent: #4fc3a5; --accent-ink: #06231c; --hi: #6fb1ff; --sel: #ff9040;
    --view1: #2a302e; --view2: #151918;
    --ok: #5fd39a; --bad: #ff8a80; --man: #4fc3a5; --plate: #e7b45a; --prac: #a9b7c2;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: clamp(1.15rem, 2.4vw, 1.5rem); margin: 0; line-height: 1.2; text-wrap: balance; }
h2 { font-size: 1.3rem; margin: .1em 0 .5em; line-height: 1.25; text-wrap: balance; }
h3 { font-size: 1rem; margin: 1.3em 0 .4em; }
p { margin: .6em 0; max-width: 68ch; }
.muted { color: var(--muted); font-weight: 400; font-size: .9em; }
.eyebrow { font-size: .74rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.pn { font-family: var(--mono); font-size: .88em; white-space: nowrap; }
button { font: inherit; color: inherit; cursor: pointer; }

.top { display: flex; justify-content: space-between; align-items: end; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topr { display: flex; gap: 12px; align-items: center; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); height: calc(100vh - 71px); }
.viewer { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-height: 0; }
#view { position: relative; flex: 1; min-height: 0; background: radial-gradient(ellipse at 50% 35%, var(--view1), var(--view2)); overflow: hidden; touch-action: none; }
#view canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.nogl-msg { display: none; position: absolute; inset: 0; place-items: center; padding: 30px; text-align: center; color: var(--muted); }
#view.nogl .nogl-msg { display: grid; }
.scale-note { position: absolute; left: 10px; bottom: 8px; font-size: .72rem; color: var(--muted); pointer-events: none; }
#labels { position: absolute; inset: 0; pointer-events: none; }
.lab { position: absolute; left: 0; top: 0; margin: -11px 0 0 10px; pointer-events: auto; background: var(--hi); color: #fff; border: 0; border-radius: 3px; padding: 1px 6px; font-size: .72rem; white-space: nowrap; box-shadow: 0 1px 4px #0005; }
.lab::before { content: ""; position: absolute; left: -10px; top: 50%; width: 10px; border-top: 1px solid var(--hi); }
.lab.sel { background: var(--sel); } .lab.sel::before { border-color: var(--sel); }
@media (prefers-color-scheme: dark) { .lab { color: #06182c; } }
#tip { position: absolute; background: #111c; color: #fff; padding: 4px 8px; border-radius: 4px; font-size: .78rem; pointer-events: none; max-width: 220px; backdrop-filter: blur(4px); }
#card { position: absolute; left: 10px; top: 10px; right: 10px; max-width: 430px; max-height: 60%; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--sel); border-radius: 6px; padding: 10px 34px 6px 12px; font-size: .88rem; box-shadow: 0 6px 24px #0003; }
#card .x { position: absolute; right: 6px; top: 2px; border: 0; background: none; font-size: 1.4rem; line-height: 1; color: var(--muted); }
#card .pr { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 3px 0; }
#card p { margin: .25em 0 .5em; }

.bar { padding: 8px 12px; border-top: 1px solid var(--line); background: var(--panel); display: grid; gap: 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tg, .chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 3px 11px; font-size: .82rem; }
.tg[aria-pressed="true"], .chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.sl { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); }
.sl.grow { flex: 1; min-width: 180px; } .sl.grow input { flex: 1; }
input[type=range] { accent-color: var(--accent); min-width: 90px; }
#riseout { font-family: var(--mono); font-size: .78rem; min-width: 22ch; }

.panel { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; flex: none; }
.tab { border: 0; background: none; padding: 11px 12px 9px; border-bottom: 3px solid transparent; color: var(--muted); white-space: nowrap; font-size: .93rem; }
.tab[aria-selected="true"] { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.pane { flex: 1; overflow: auto; padding: 18px 22px 40px; min-height: 0; }
#pane-guide { padding: 0; }
.guide { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100%; }
#stepnav { border-right: 1px solid var(--line); padding: 10px 8px 30px; font-size: .84rem; }
#stepnav .ph { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 12px 8px 4px; }
#stepnav ol { list-style: none; margin: 0; padding: 0; }
#stepnav button { display: grid; grid-template-columns: 22px 1fr; gap: 8px; width: 100%; text-align: left; border: 0; background: none; padding: 5px 8px; border-radius: 5px; line-height: 1.3; }
#stepnav button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
#stepnav button.on { background: var(--accent); color: var(--accent-ink); }
#stepnav .n { font-family: var(--mono); font-size: .78rem; text-align: right; opacity: .75; }
#stepnav button.done:not(.on) { color: var(--muted); } #stepnav button.done .n { color: var(--ok); opacity: 1; } #stepnav button.on .n { color: inherit; }
#stepbody { padding: 18px 22px 40px; }
.ref { font-size: .84rem; color: var(--muted); margin-bottom: 8px; }
.legend { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0 0 10px; }
.tag { display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; border: 1px solid; white-space: nowrap; cursor: help; }
.t-m { color: var(--man); } .t-d { color: var(--plate); } .t-p { color: var(--prac); border-style: dashed; }
.para { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; align-items: start; padding-left: 8px; border-left: 3px solid; margin: 9px 0; }
.para .tag { margin-top: 4px; text-align: center; }
.para p { margin: 0; }
.p-m { border-color: var(--man); } .p-d { border-color: var(--plate); } .p-p { border-color: color-mix(in srgb, var(--prac) 45%, transparent); border-left-style: dashed; }
.plain { padding-left: 1.1em; } .plain li { margin: .4em 0; max-width: 68ch; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 14px 0; padding: 8px 14px 12px; }
legend { font-weight: 600; font-size: .9rem; padding: 0 6px; }
#notes label { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 10px; align-items: center; padding: 5px 0; font-size: .9rem; }
#notes input, #notes textarea, #notesdump { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 5px 8px; width: 100%; }
code { font-family: var(--mono); font-size: .88em; }
.fig { display: block; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 0; overflow: hidden; text-align: left; margin: 14px 0; max-width: 340px; }
.fig img { display: block; width: 100%; height: 190px; object-fit: contain; background: #fff; }
#stepbody .fig { max-width: 460px; } #stepbody .fig img { height: auto; max-height: 300px; }
.fig span { display: block; padding: 6px 10px; font-size: .78rem; color: #333; border-top: 1px solid #ddd; }
.stepfoot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.chk { font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.btn { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 6px; padding: 7px 14px; font-weight: 600; font-size: .9rem; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
.btn:disabled { opacity: .35; cursor: default; }

.badge { display: inline-block; font-size: .68rem; padding: 1px 7px; border-radius: 999px; border: 1px solid; white-space: nowrap; vertical-align: 1px; }
.b-new { color: var(--bad); } .b-xfer { color: var(--plate); } .b-check { color: var(--hi); } .b-keep { color: var(--muted); }
.order { border: 1px solid var(--line); border-radius: 8px; padding: 4px 16px 8px; margin-bottom: 14px; }
.order ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.order .pn { display: inline-block; min-width: 13ch; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.tw { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
#parts tr[data-id] { cursor: pointer; } #parts tr[data-id]:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
#parts tr.on { background: color-mix(in srgb, var(--sel) 14%, transparent); }
.what { color: var(--muted); font-size: .92em; max-width: 60ch; }
details { margin-top: 16px; } summary { cursor: pointer; font-weight: 600; }

.simgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 20px; margin: 14px 0; }
.ctl { display: grid; gap: 14px; align-content: start; }
.ctl label { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: .9rem; }
.ctl label small { display: block; color: var(--muted); }
.ctl label input { grid-column: 1 / -1; width: 100%; }
.ctl output { font-family: var(--mono); font-size: .85rem; }
.rd { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rd .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); }
.rd.ok .dot { background: var(--ok); }
.rd .lb { font-size: .88rem; line-height: 1.3; } .rd .nt { font-size: .76rem; color: var(--muted); }
.rd .val { font-family: var(--mono); font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.rd.bad .val { color: var(--bad); } .rd.ok .val { color: var(--ok); }
.nextact { margin-top: 12px; padding: 10px 12px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 12%, transparent); font-size: .92rem; }

.tr h3 { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.ti { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; align-items: start; }
.ti .k { font-family: var(--mono); color: var(--muted); } .ti .rem { color: var(--muted); font-size: .92em; }
.lnk { border: 1px solid var(--line); background: none; border-radius: 5px; font-size: .78rem; padding: 2px 8px; white-space: nowrap; color: var(--accent); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.gallery .fig { margin: 0; max-width: none; }
.prose li { margin: .35em 0; max-width: 68ch; }

#lightbox { position: fixed; inset: 0; background: #000d; z-index: 50; overflow: auto; display: grid; place-items: start center; padding: 20px; cursor: zoom-out; }
#lightbox[hidden] { display: none; }
#lightbox figure { margin: 0; }
#lightbox img { display: block; max-width: min(100%, 900px); background: #fff; cursor: zoom-in; border-radius: 4px; }
#lightbox.zoom img { max-width: none; width: 1500px; cursor: zoom-out; }
#lightbox figcaption { color: #ddd; font-size: .85rem; padding: 8px 2px; }
#printsheet { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewer { border-right: 0; }
  #view { height: 46vh; flex: none; }
  .pane { overflow: visible; padding: 16px; }
  .guide { grid-template-columns: 1fr; }
  #stepnav { border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px; align-items: center; }
  #stepnav .ph { display: none; } #stepnav ol { display: flex; gap: 4px; }
  #stepnav button { grid-template-columns: auto; padding: 4px 9px; border: 1px solid var(--line); } #stepnav button span:last-child { display: none; }
  #stepnav .n { text-align: center; }
  #stepbody { padding: 16px; }
  .simgrid { grid-template-columns: 1fr; }
  #notes label { grid-template-columns: 1fr; gap: 3px; }
  .para { grid-template-columns: 1fr; gap: 2px; } .para .tag { justify-self: start; }
  .bar .row:first-child .sl { flex: 1; }
}
@media print {
  body > :not(#printsheet) { display: none !important; }
  #printsheet { display: block; color: #000; font: 10.5pt/1.4 Georgia, serif; }
  #printsheet h1 { font-size: 15pt; } #printsheet h2 { font-size: 13pt; margin-top: 16pt; } #printsheet h3 { font-size: 11pt; margin: 10pt 0 2pt; } #printsheet small { font-weight: normal; color: #444; }
  #printsheet p { margin: 2pt 0 2pt 16pt; max-width: none; } .ps { break-inside: avoid; }
}
