/* ------------------------------------------------------------------ viewer
   The /view page: instructions on the left (a third of the screen by default,
   resizable), the model filling the rest. Touch devices get the same page with
   bigger targets; narrow portrait screens stack the model above the steps. */

body.viewer {
    /* One colour per kind of link, used everywhere that kind appears: in the
       text, on the chips, on the model, and in the Help legend. */
    --k-ann: #ff9f43;      --k-ann-bg: rgba(255, 159, 67, .14);
    --k-view: #22d3ee;     --k-view-bg: rgba(34, 211, 238, .13);
    --k-meas: #facc15;     --k-meas-bg: rgba(250, 204, 21, .13);
    --k-item: #4ade80;     --k-item-bg: rgba(74, 222, 128, .13);
    --k-img: #c084fc;      --k-img-bg: rgba(192, 132, 252, .15);
    --k-step: #f472b6;     --k-step-bg: rgba(244, 114, 182, .14);
    --k-url: #60a5fa;      --k-url-bg: rgba(96, 165, 250, .14);
    --k-todo: #f87171;     --k-todo-bg: rgba(248, 113, 113, .12);
    --k-broken: #7b8594;   --k-broken-bg: rgba(123, 133, 148, .12);
    --done: #3fb27f;       --done-bg: rgba(63, 178, 127, .14);

    --tap: 40px;           /* smallest thing you are expected to hit */
    --tap-s: 32px;         /* chips and inline controls */
    --pin: 26px;

    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

body.viewer.vw-touch {
    --tap: 54px;
    --tap-s: 46px;
    --pin: 36px;
    font-size: 17px;
}

body.viewer [hidden] { display: none !important; }
:where(body.viewer) button { font-size: inherit; }
body.vw-resizing, body.vw-resizing * { cursor: col-resize !important; user-select: none; }
body.vw-stacked.vw-resizing, body.vw-stacked.vw-resizing * { cursor: row-resize !important; }

/* ---------------------------------------------------------------- frame */

.vw { position: fixed; inset: 0; display: flex; }

.vw-panel {
    flex: 0 0 var(--vw-size, 33.333vw);
    width: var(--vw-size, 33.333vw);
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    overflow: hidden;
    z-index: 6;
}

.vw-resizer {
    flex: 0 0 10px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #130f0b;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    cursor: col-resize;
    touch-action: none;
    z-index: 7;
    outline: none;
}
.vw-grip { width: 4px; height: 48px; border-radius: 2px; background: #52463a; transition: background .15s; }
.vw-resizer:hover .vw-grip, .vw-resizer:focus-visible .vw-grip, .vw-resizer.dragging .vw-grip { background: var(--accent); }
body.vw-touch .vw-resizer { flex-basis: 22px; }
body.vw-touch .vw-grip { width: 6px; height: 64px; }

.vw-stage { flex: 1 1 auto; position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #16120e; }
.vw-stage #canvas { position: absolute; inset: 0 auto auto 0; display: block; touch-action: none; }
.vw-stage .loading { position: absolute; }

body.vw-collapsed .vw-panel, body.vw-collapsed .vw-resizer { display: none; }

/* Phones held upright: model on top, steps below, handle between. */
body.vw-stacked .vw { flex-direction: column-reverse; }
body.vw-stacked .vw-panel { flex-basis: var(--vw-size, 50vh); width: auto; }
body.vw-stacked .vw-resizer {
    flex-basis: 18px;
    cursor: row-resize;
    border: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
body.vw-stacked .vw-grip { width: 56px; height: 5px; }

/* ---------------------------------------------------------------- buttons */

.vw-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 6px 14px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.vw-btn:hover { background: #392f24; border-color: #52463a; color: var(--text); }
.vw-btn.vw-icon { width: var(--tap); padding: 0; flex: none; }
.vw-btn.vw-small { min-height: var(--tap-s); padding: 4px 10px; font-size: .88em; }
.vw-btn.vw-danger:hover { border-color: var(--danger); color: var(--danger); }
.vw-btn svg, .vw-ico svg {
    width: 1.2em;
    height: 1.2em;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}
.vw-ico { display: inline-flex; flex: none; }

/* ---------------------------------------------------------------- panel */

.vw-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: var(--panel-2);
    border-bottom: 1px solid var(--border);
}
.vw-titles { flex: 1; min-width: 0; }
.vw-title { font-weight: 650; font-size: 1.05em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vw-subtitle { font-size: .8em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.vw-panel-main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.vw-tabs { display: flex; padding: 0 8px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.vw-tab {
    flex: 1;
    min-height: var(--tap);
    padding: 6px 8px;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-weight: 650;
    justify-content: center;
}
.vw-tab:hover { background: transparent; color: var(--text); }
.vw-tab.on { color: var(--text); border-bottom-color: var(--accent); }

.vw-stepbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.vw-rail { flex: 1; display: flex; gap: 3px; min-width: 40px; align-items: center; }
.vw-rail i { flex: 1; height: 6px; border-radius: 3px; background: #3d342a; }
.vw-rail i.done { background: var(--done); }
.vw-rail i.cur { background: var(--accent); height: 10px; }
.vw-unit {
    max-width: 38%;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--done-bg);
    color: #9be3bd;
    font-size: .8em;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vw-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px 28px;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.vw-foot {
    display: flex;
    gap: 10px;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--panel-2);
}
.vw-nav { min-height: calc(var(--tap) + 10px); font-size: 1.05em; font-weight: 650; }
.vw-grow { flex: 1; }
.vw-foot .vw-nav:first-child { flex: 0 0 auto; min-width: 7.5em; }

.vw-empty { padding: 32px 12px; text-align: center; color: var(--muted); line-height: 1.6; }
.vw-empty b { display: block; color: var(--text); font-size: 1.1em; margin-bottom: 4px; }

/* ---------------------------------------------------------------- a step */

.vw-step-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: .82em;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.vw-cat {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    background: rgba(255, 122, 26, .15);
    color: #ffc9a0;
    font-size: .82rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
}
body.vw-touch .vw-cat { font-size: .92rem; }
.vw-step-title {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin: 8px 0 14px;
    font-size: 1.5em;
    line-height: 1.25;
    font-weight: 700;
}
.vw-step-num {
    flex: none;
    display: grid;
    place-items: center;
    min-width: 1.65em;
    height: 1.65em;
    padding: 0 .3em;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: .78em;
}
.vw-step.is-done .vw-step-num { background: var(--done); }

.vw-rich { white-space: pre-wrap; line-height: 1.65; overflow-wrap: anywhere; }
.vw-notes { font-size: 1.08em; }
body.vw-touch .vw-rich { line-height: 1.85; }

.vw-sec { margin-top: 22px; }
.vw-sec-title {
    margin: 0 0 9px;
    font-size: .76em;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
}

.vw-done-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0 14px;
    padding: 10px 12px;
    border: 1px solid rgba(63, 178, 127, .45);
    border-radius: 9px;
    background: var(--done-bg);
    color: #9be3bd;
    font-weight: 600;
}
.vw-done-banner > span:not(.vw-ico) { flex: 1; }

.vw-caution {
    display: flex;
    gap: 8px;
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(240, 97, 109, .1);
    border: 1px solid rgba(240, 97, 109, .35);
    color: #ffc2c7;
}
.vw-ol { margin: 0; padding-left: 1.3em; }
.vw-ol li { margin-bottom: 4px; }

/* ---------------------------------------------------------------- links */

.vw-link {
    --k: var(--k-url);
    --kb: var(--k-url-bg);
    display: inline;
    margin: 0 1px;
    padding: 1px 6px 1px 5px;
    border: 0;
    border-bottom: 2px solid var(--k);
    border-radius: 5px 5px 2px 2px;
    background: var(--kb);
    color: var(--k);
    font: inherit;
    font-weight: 600;
    line-height: inherit;
    text-decoration: none;
    white-space: normal;
    cursor: pointer;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    transition: filter .12s, background .12s;
}
.vw-link:hover { background: var(--kb); color: var(--k); filter: brightness(1.2); border-color: var(--k); }
.vw-link:focus-visible { outline: 2px solid var(--k); outline-offset: 2px; }
.vw-link .vw-ico { display: inline; }
.vw-link .vw-ico svg { width: .95em; height: .95em; margin-right: 4px; vertical-align: -.12em; }
body.vw-touch .vw-link { padding: 3px 8px 3px 6px; }

.vw-link.k-ann { --k: var(--k-ann); --kb: var(--k-ann-bg); }
.vw-link.k-view { --k: var(--k-view); --kb: var(--k-view-bg); }
.vw-link.k-meas { --k: var(--k-meas); --kb: var(--k-meas-bg); }
.vw-link.k-item { --k: var(--k-item); --kb: var(--k-item-bg); }
.vw-link.k-img { --k: var(--k-img); --kb: var(--k-img-bg); }
.vw-link.k-step { --k: var(--k-step); --kb: var(--k-step-bg); }
.vw-link.k-url { --k: var(--k-url); --kb: var(--k-url-bg); }
.vw-link.k-todo { --k: var(--k-todo); --kb: var(--k-todo-bg); border-bottom-style: dashed; }
.vw-link.k-broken { --k: var(--k-broken); --kb: var(--k-broken-bg); border-bottom-style: dashed; font-weight: 500; }

/* The same links as stand-alone chips. */
.vw-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.vw-sec .vw-chips { margin-top: 0; }
.vw-chips .vw-link, .vw-item-links .vw-link, .vw-reslist .vw-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap-s);
    margin: 0;
    padding: 4px 11px 4px 8px;
    border: 1px solid var(--k);
    border-radius: 8px;
}
.vw-chips .vw-link .vw-ico svg, .vw-item-links .vw-link .vw-ico svg, .vw-reslist .vw-link .vw-ico svg { vertical-align: 0; margin-right: 6px; }
.vw-chip-num {
    display: inline-grid;
    place-items: center;
    min-width: 1.45em;
    height: 1.45em;
    margin-right: 7px;
    padding: 0 .3em;
    border-radius: 999px;
    background: var(--k-ann);
    color: #1d1206;
    font-size: .8em;
    font-weight: 800;
}
.vw-annrow.focus { outline: 2px solid var(--k-ann); outline-offset: 2px; }

/* ---------------------------------------------------------------- parts, measurements, photos */

.vw-items, .vw-meas { display: flex; flex-direction: column; gap: 8px; }

.vw-item {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--k-item);
    border-radius: 9px;
    background: var(--panel-2);
}
.vw-item.flash { animation: vw-flash 1.6s ease-out; }
@keyframes vw-flash {
    0%, 30% { background: rgba(74, 222, 128, .28); box-shadow: 0 0 0 2px var(--k-item); }
    100% { background: var(--panel-2); box-shadow: none; }
}
.vw-qty { flex: none; min-width: 2.4em; color: var(--k-item); font-weight: 750; font-size: 1.08em; font-variant-numeric: tabular-nums; }
.vw-item-main { flex: 1; min-width: 0; }
.vw-item-name { font-weight: 600; overflow-wrap: anywhere; }
.vw-kind {
    display: inline-block;
    margin-left: 8px;
    padding: 0 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    font-size: .68em;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    vertical-align: .15em;
}
.vw-item-meta { color: var(--muted); font-size: .88em; overflow-wrap: anywhere; }
.vw-item-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 7px; }

.vw-measrow {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: var(--tap);
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--k-meas);
    border-radius: 9px;
    background: var(--panel-2);
    color: var(--text);
    text-align: left;
    white-space: normal;
}
.vw-measrow:hover { border-color: var(--k-meas); background: var(--k-meas-bg); }
.vw-measrow .vw-ico { color: var(--k-meas); }
.vw-measrow-name { flex: 1; }
.vw-measrow-val { color: var(--k-meas); font-weight: 750; font-variant-numeric: tabular-nums; }
.vw-measrow.focus { outline: 2px solid var(--k-meas); outline-offset: 1px; }

.vw-gallery { display: flex; gap: 8px; margin-top: 12px; padding-bottom: 4px; overflow-x: auto; }
.vw-thumb {
    flex: none;
    width: 124px;
    height: 92px;
    padding: 0;
    border: 2px solid var(--k-img);
    border-radius: 9px;
    overflow: hidden;
    background: #130f0b;
}
.vw-thumb:hover { border-color: var(--k-img); filter: brightness(1.12); }
.vw-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
body.vw-touch .vw-thumb { width: 156px; height: 116px; }

.vw-reslist { display: flex; flex-wrap: wrap; gap: 8px; }
.vw-resnote { flex-basis: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; white-space: pre-wrap; }

/* ---------------------------------------------------------------- sub-steps */

.vw-subs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.vw-sub { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.vw-sub-line { display: flex; align-items: flex-start; gap: 12px; }
label.vw-sub-line { cursor: pointer; }
.vw-sub-num {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.7em;
    height: 1.7em;
    border-radius: 999px;
    background: #3d342a;
    font-size: .85em;
    font-weight: 700;
}
.vw-sub-title { flex: 1; padding-top: 1px; }
.vw-check { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--done); cursor: pointer; }
body.vw-touch .vw-check { width: 32px; height: 32px; margin-top: -2px; }
.vw-sub.done { border-color: rgba(63, 178, 127, .4); }
.vw-sub.done .vw-sub-title { text-decoration: line-through; opacity: .6; }
.vw-sub-notes, .vw-sub .vw-chips, .vw-sub .vw-reslist { margin: 6px 0 0 calc(1.7em + 12px); font-size: .95em; }
.vw-when { margin: 4px 0 0 calc(1.7em + 12px); color: #7fd0a3; font-size: .82em; }

/* ---------------------------------------------------------------- overview */

.vw-ov-title { margin: 0 0 6px; font-size: 1.5em; line-height: 1.25; }
.vw-ov-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; color: var(--muted); }

.vw-build {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--panel-2);
}
.vw-build-label { font-size: .76em; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.vw-build-meta { color: var(--muted); font-size: .88em; }
.vw-newbuild { display: flex; flex-direction: column; gap: 8px; }
.vw-row { display: flex; gap: 8px; flex-wrap: wrap; }

body.viewer .vw-select, body.viewer .vw-input {
    width: 100%;
    min-width: 0;
    min-height: var(--tap);
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #130f0b;
    color: var(--text);
    font: inherit;
}
.vw-note { resize: vertical; }
.vw-search { margin-bottom: 6px; }

.vw-progress { height: 8px; border-radius: 4px; background: #130f0b; overflow: hidden; }
.vw-progress > i { display: block; height: 100%; background: var(--done); transition: width .2s; }

.vw-big { width: 100%; min-height: calc(var(--tap) + 12px); margin: 4px 0 20px; font-size: 1.1em; }

.vw-toc { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.vw-toc-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: var(--tap);
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--panel-2);
    color: var(--text);
    text-align: left;
    white-space: normal;
}
.vw-toc-row:hover { border-color: var(--accent); }
.vw-toc-num {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.9em;
    height: 1.9em;
    border-radius: 999px;
    background: #3d342a;
    font-size: .88em;
    font-weight: 750;
}
.vw-toc-row.done .vw-toc-num { background: var(--done); color: #fff; }
.vw-toc-row.done .vw-toc-title { color: var(--muted); }
.vw-toc-title { flex: 1; }

/* ---------------------------------------------------------------- annotations tab */

.vw-annlist { display: flex; flex-direction: column; gap: 8px; }
.vw-anncard { padding: 4px 12px 10px; border: 1px solid var(--border); border-left: 4px solid var(--k-ann); border-radius: 9px; background: var(--panel-2); }
.vw-anncard-head {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-height: var(--tap);
    padding: 4px 0;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    white-space: normal;
}
.vw-anncard-head:hover { background: transparent; color: var(--k-ann); }
.vw-anncard-head .vw-ico { color: var(--k-ann); }
.vw-anncard-title { flex: 1; font-weight: 650; }
.vw-anncard-text { color: #d9d1c9; font-size: .95em; }

/* ---------------------------------------------------------------- over the model */

.vw-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }

.vm-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.vm-svg.vm-off { display: none; }
.vm-svg line { stroke: var(--k-meas); stroke-width: 2; }
.vm-svg line.vm-halo { stroke: rgba(0, 0, 0, .55); stroke-width: 5; }
.vm-svg circle { fill: var(--k-meas); stroke: rgba(0, 0, 0, .75); stroke-width: 1.2; }
.vm-svg text {
    fill: var(--k-meas);
    font: 650 12px ui-monospace, "Cascadia Mono", Menlo, monospace;
    paint-order: stroke;
    stroke: rgba(0, 0, 0, .85);
    stroke-width: 3.5px;
}
body.vw-touch .vm-svg text { font-size: 14px; }
.vm-meas.vm-hot line { stroke-width: 3.5; }
.vm-meas.vm-hot line.vm-halo { stroke: rgba(250, 204, 21, .3); stroke-width: 14; animation: vm-pulse 1.4s ease-in-out infinite; }
.vm-meas.vm-hot circle { r: 6; }
.vm-meas.vm-hot text { font-size: 16px; }
@keyframes vm-pulse { 50% { stroke-opacity: .35; } }

.vw-markers { position: absolute; inset: 0; }
.vw-pin {
    position: absolute;
    left: 0;
    top: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 0;
    margin: calc(var(--pin) / -2) 0 0 calc(var(--pin) / -2);
    padding: 0;
    border: 0;
    background: none;
    pointer-events: auto;
    will-change: transform;
}
.vw-pin:hover { background: none; }
.vw-pin-dot {
    flex: none;
    display: grid;
    place-items: center;
    width: var(--pin);
    height: var(--pin);
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--k-ann);
    color: #1d1206;
    font-size: calc(var(--pin) * .46);
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .6);
}
.vw-pin-label {
    display: none;
    max-width: 240px;
    padding: 3px 9px;
    border: 1px solid var(--k-ann);
    border-radius: 6px;
    background: rgba(22, 18, 14, .9);
    color: #ffd6ad;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.vw-touch .vw-pin-label { font-size: 14px; }
.vw-pin.labeled .vw-pin-label, .vw-pin:hover .vw-pin-label, .vw-pin:focus-visible .vw-pin-label { display: block; }
.vw-pin.faint { opacity: .6; }
.vw-pin.faint .vw-pin-dot { transform: scale(.5); font-size: 0; }
.vw-pin.focus { z-index: 2; opacity: 1; }
.vw-pin.focus .vw-pin-dot { animation: vw-pin 1.6s ease-out infinite; }
@keyframes vw-pin {
    0% { box-shadow: 0 0 0 0 rgba(255, 159, 67, .7), 0 2px 8px rgba(0, 0, 0, .6); }
    100% { box-shadow: 0 0 0 16px rgba(255, 159, 67, 0), 0 2px 8px rgba(0, 0, 0, .6); }
}

.vw-card {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 6;
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100% - 24px));
    max-height: calc(100% - 84px);
    border: 1px solid var(--border);
    border-top: 4px solid var(--k-ann);
    border-radius: 11px;
    background: rgba(34, 28, 22, .97);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
}
.vw-card-head { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--border); }
.vw-card-num {
    display: grid;
    place-items: center;
    min-width: 1.6em;
    height: 1.6em;
    border-radius: 999px;
    background: var(--k-ann);
    color: #1d1206;
    font-size: .85em;
    font-weight: 800;
}
.vw-card-num:empty { display: none; }
.vw-card-title { flex: 1; min-width: 0; font-weight: 650; }
.vw-card-body { overflow-y: auto; padding: 10px 14px 14px; overscroll-behavior: contain; }
.vw-card-body > .vw-sec:first-child { margin-top: 0; }
body.vw-stacked .vw-card { left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 62%; }

.vw-tools {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    max-width: calc(100% - 20px);
}
.vw-tool { background: rgba(22, 18, 14, .82); backdrop-filter: blur(6px); padding: 6px 11px; }
.vw-tool-state { padding: 1px 6px; border-radius: 4px; background: rgba(255, 255, 255, .08); font-size: .8em; }
.vw-tool-state:empty { display: none; }
#labels.on { border-color: var(--k-ann); color: var(--k-ann); }
#measure.on { border-color: var(--k-meas); color: var(--k-meas); }
#ruler.on { border-color: var(--k-view); color: var(--k-view); }

/* the visitor's own, session-only measurements */
.vr-svg line { stroke: var(--k-view); stroke-dasharray: 7 4; }
.vr-svg line.vm-halo { stroke-dasharray: none; }
.vr-svg circle { fill: var(--k-view); }
.vr-svg text { fill: var(--k-view); }
.vr-meas.vr-pending line { stroke-dasharray: 3 4; opacity: .85; }
body.vw-ruling #canvas { cursor: crosshair; }
body.vw-ruling #canvas.vr-nothing { cursor: not-allowed; }
.vw-ruler {
    position: absolute;
    bottom: 14px;
    left: 50%;
    z-index: 6;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: calc(100% - 20px);
    padding: 6px 6px 6px 12px;
    transform: translateX(-50%);
    border: 1px solid var(--k-view);
    border-radius: 10px;
    background: rgba(22, 18, 14, .88);
    backdrop-filter: blur(6px);
}
.vw-ruler[hidden] { display: none; }
.vw-ruler-hint { color: var(--text); font-size: 13px; }
body.vw-stacked .vw-ruler, body.vw-touch .vw-ruler { flex-wrap: wrap; justify-content: center; }
body.vw-touch .vw-ruler { max-width: calc(100% - 100px); }
body.vw-ruling .vw-hint { display: none; }
.vw-reopen { position: absolute; top: 10px; left: 10px; z-index: 5; background: rgba(22, 18, 14, .82); }
body.vw-stacked .vw-tool-label, body.vw-touch .vw-tool-label { display: none; }
body.vw-stacked .vw-tool, body.vw-touch .vw-tool { min-width: var(--tap); }

.vw-zoom { position: absolute; right: 12px; bottom: 14px; z-index: 5; display: none; flex-direction: column; gap: 10px; }
body.vw-touch .vw-zoom { display: flex; }
.vw-zoom .vw-btn { background: rgba(22, 18, 14, .82); }

.vw-hint {
    position: absolute;
    left: 50%;
    bottom: 14px;
    z-index: 4;
    max-width: calc(100% - 150px);
    padding: 7px 14px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(22, 18, 14, .8);
    color: var(--muted);
    font-size: 12.5px;
    text-align: center;
    pointer-events: none;
    transition: opacity .8s;
}
.vw-hint.gone { opacity: 0; }

/* ---------------------------------------------------------------- dialogs */

.vw-help {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(0, 0, 0, .6);
}
.vw-help-card {
    width: min(540px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 6px 18px 18px;
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--panel);
}
.vw-help-head { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 6px; font-size: 1.05em; }
.vw-help-row { display: flex; gap: 14px; padding: 7px 0; border-bottom: 1px solid #30281f; }
.vw-help-row b { flex: 0 0 42%; }
.vw-help-row span { color: #d9d1c9; }
.vw-legend { display: flex; flex-direction: column; gap: 6px; }
.vw-legend-row { display: flex; align-items: center; gap: 12px; }
.vw-legend-row .vw-link { flex: 0 0 auto; cursor: default; }
.vw-legend-hint { color: var(--muted); font-size: .9em; }
.vw-seg { display: flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.vw-seg button { flex: 1; min-height: var(--tap); justify-content: center; border: 0; border-radius: 0; background: transparent; }
.vw-seg button + button { border-left: 1px solid var(--border); }
.vw-seg button.on { background: var(--accent); color: var(--on-accent); }
.vw-help-note { margin-top: 8px; color: var(--muted); font-size: .86em; }

.vw-lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, .93);
}
.vw-lightbox { overflow: hidden; touch-action: none; }
#lightbox-img {
    position: relative;
    z-index: 0;
    max-width: 100%;
    max-height: calc(100% - 84px);
    object-fit: contain;
    border-radius: 6px;
    user-select: none;
    -webkit-user-drag: none;
    touch-action: none;
    transform-origin: 50% 50%;
    cursor: zoom-in;
    will-change: transform;
}
#lightbox-img.zoomed { cursor: grab; border-radius: 0; }
#lightbox-img.zoomed:active { cursor: grabbing; }
/* the controls stay on top of a zoomed-in photo */
.vw-lightbox-bar { position: relative; z-index: 1; padding: 6px 10px; border-radius: 12px; background: rgba(0, 0, 0, .55); }

/* Hover preview of a photo link. */
.vw-peek {
    position: fixed;
    z-index: 65;
    width: 240px;
    padding: 5px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    box-shadow: 0 14px 36px rgba(0, 0, 0, .55);
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .12s, transform .12s;
}
.vw-peek.on { opacity: 1; transform: none; }
.vw-peek img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 6px; }
.vw-peek span { display: block; padding: 5px 3px 1px; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vw-peek span:empty { display: none; }
.vw-lightbox-bar { display: flex; align-items: center; gap: 12px; margin-top: 12px; color: #ddd; }

.vw-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 70;
    max-width: calc(100% - 32px);
    padding: 11px 18px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    box-shadow: 0 10px 34px rgba(0, 0, 0, .5);
    text-align: center;
}
.vw-toast.warn { border-color: var(--k-todo); }
.vw-toast.error { border-color: var(--danger); color: #ffb3b9; }
