/* The instrument layer: HUD, compose line, previews, guides, snap pulses and build-mode reveal.
   Light only ever means something. Nothing here animates unless something real happened. */

/* ---------- HUD ------------------------------------------------------------------------------ */

.hud {
    position: sticky; top: 0; left: 0; z-index: 20;
    display: flex; gap: var(--s3); align-items: center;
    min-height: 26px; padding: 0 var(--s4);
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    border-bottom: 1px solid var(--hairline);
    font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; color: var(--ink-2);
    white-space: nowrap; overflow: hidden;
}
.hud.has-draft { min-height: 40px; padding-top: 3px; padding-bottom: 3px; }
/* Items wrap to a second row before anything is cut; the deck name is already in the console bar. */
.hud { flex-wrap: wrap; row-gap: 3px; }
.hud > * { flex: none; }
.hud .hud-where { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 1279px) { .hud .hud-where { display: none; } }
.hud > span + span::before { content: "·"; margin-right: var(--s3); color: var(--ink-3); }
.hud .hud-mark { color: var(--ink); font-weight: 500; }
.hud .hud-mark::before { content: none; }
.hud .ok { color: var(--sig-done-text); }
.hud .live { color: var(--sig-live-text); }
.hud .warn { color: var(--sig-you-text); }
.hud .hud-mode { color: var(--ink); font-weight: 500; }
.hud .hud-clock { margin-left: auto; }
.hud .hud-clock::before { content: none; }

/* ---------- Compose line -------------------------------------------------------------------- */

.compose {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto; column-gap: var(--s2);
    padding: var(--s2) var(--s4) var(--s2); border-bottom: 1px solid var(--hairline); background: var(--surface);
}
.compose-prompt { font-family: var(--font-mono); color: var(--accent); font-size: 14px; align-self: center; }
.compose-input {
    border: 0; background: transparent; font-family: var(--font-mono); font-size: 13px; height: 28px; outline: none;
    caret-color: var(--accent);
}
.compose-input::placeholder { color: var(--ink-2); }
.compose-input:focus-visible { outline: none; box-shadow: inset 0 -2px 0 var(--focus); }
.compose-read { grid-column: 2; display: flex; gap: var(--s2); align-items: center; font-size: 12px; min-height: 20px; }
.compose.ready { box-shadow: inset 3px 0 0 var(--sig-live-line); }
.compose.unsure { box-shadow: inset 3px 0 0 var(--sig-you-line); }
.compose-suggest { grid-column: 2; display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-top: 4px; min-width: 0; }
.compose-suggest .chip-text { flex: none; white-space: nowrap; }
.compose { min-width: 0; }
.compose-read { min-width: 0; }
.compose-read > span:not(.light):not(.kbd) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-text {
    border: 1px dashed var(--hairline); background: transparent; color: var(--ink-2); cursor: pointer;
    font-family: var(--font-mono); font-size: 11px; padding: 2px 8px; min-height: 24px;
}
.chip-text:hover, .chip-text:focus-visible { border-color: var(--accent); color: var(--ink); }

/* ---------- Validity meter ------------------------------------------------------------------- */

.validity { display: inline-flex; gap: 6px; align-items: center; font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; padding: 0 6px; border-left: 1px solid var(--hairline); }
.validity.warn { color: var(--sig-you-text); }
button.validity { background: none; border: 0; border-left: 1px solid var(--hairline); height: 24px; cursor: pointer; color: inherit; }
button.validity.warn { color: var(--sig-you-text); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Previews (hover a Tray module to see every place it could go) --------------------- */

.previewing [data-dock].dock-preview { outline: 1px dashed color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: -2px; }
[data-dock].dock-proposed { outline: 2px solid var(--accent); outline-offset: -2px; background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Silhouettes: a valid dock draws the outline of the module you are holding. */
.dragging.holding-gate .seam-dock.dock-valid::after,
.keyboard-holding.holding-gate .seam-dock.dock-valid::after,
.previewing.preview-gate .seam-dock.dock-preview::after {
    content: ""; position: absolute; left: 50%; top: 44px; width: 12px; height: 12px; transform: translateX(-50%) rotate(45deg);
    border: 1.5px dashed var(--accent);
}
.dragging.holding-agent [data-dock^="stage:"].dock-valid::after,
.keyboard-holding.holding-agent [data-dock^="stage:"].dock-valid::after,
.previewing.preview-agent [data-dock^="stage:"].dock-preview::after {
    content: ""; position: absolute; right: 14px; bottom: 10px; width: 34px; height: 34px; border-radius: 50%;
    border: 1.5px dashed var(--accent);
}
.dragging.holding-stage .spine-dock.dock-valid::after,
.keyboard-holding.holding-stage .spine-dock.dock-valid::after,
.previewing.preview-stage .spine-dock.dock-preview::after {
    content: ""; position: absolute; inset: 0 8px; border: 1.5px dashed var(--accent);
    clip-path: polygon(8px 0, 100% 0, 100% 100%, 0 100%, 0 8px);
}
.previewing.preview-stage .spine-slot { width: 30px; transition: width var(--t-settle) var(--ease-settle); }
.dragging.holding-reflex .stage-edge-dock.dock-valid::after,
.keyboard-holding.holding-reflex .stage-edge-dock.dock-valid::after,
.previewing.preview-reflex .stage-edge-dock.dock-preview::after {
    content: ""; position: absolute; top: 6px; left: 8px; width: 12px; height: 12px; border: 1.5px dashed var(--accent);
    clip-path: polygon(0 0, 100% 50%, 0 100%);
}

/* ---------- Guides and pulses ----------------------------------------------------------------- */

#w2f-guides { position: fixed; inset: 0; pointer-events: none; z-index: 900; opacity: 0; transition: opacity 120ms; }
#w2f-guides.on { opacity: 1; }
#w2f-guides .gx { position: absolute; left: 0; right: 0; top: var(--gy); border-top: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); }
#w2f-guides .gy { position: absolute; top: 0; bottom: 0; left: var(--gx); border-left: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); }
#w2f-guides .guide-box { position: absolute; border: 1px solid var(--accent); }
#w2f-guides .guide-box::before, #w2f-guides .guide-box::after {
    content: ""; position: absolute; width: 8px; height: 8px; border: 2px solid var(--accent);
}
#w2f-guides .guide-box::before { left: -5px; top: -5px; border-right: 0; border-bottom: 0; }
#w2f-guides .guide-box::after { right: -5px; bottom: -5px; border-left: 0; border-top: 0; }
#w2f-guides .guide-label {
    position: absolute; background: var(--accent); color: var(--accent-ink); font-family: var(--font-mono); font-size: 10px;
    padding: 3px 8px; max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    clip-path: polygon(6px 0, 100% 0, 100% 100%, 0 100%, 0 6px);
}

.lock-pulse { position: fixed; z-index: 950; pointer-events: none; border: 2px solid var(--accent); animation: lock 520ms var(--ease-settle) forwards; }
@keyframes lock {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.14); opacity: 0; }
}

/* ---------- Build mode reveal ---------------------------------------------------------------- */

.stage-area.lifted::after {
    content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; pointer-events: none; z-index: 30;
    background: var(--accent); box-shadow: 0 0 6px color-mix(in srgb, var(--accent) 60%, transparent);
    animation: scan 700ms var(--ease-settle) forwards;
}
@keyframes scan { from { transform: translateY(0); opacity: 1; } to { transform: translateY(70vh); opacity: 0; } }

.lifted .plate { transform: translateY(-6px); }
.lifted .plate-inner::before, .lifted .plate-inner::after {
    content: ""; position: absolute; width: 10px; height: 10px; pointer-events: none; z-index: 6;
    border-color: color-mix(in srgb, var(--accent) 80%, transparent); border-style: solid;
}
.lifted .plate-inner::before { right: 6px; top: 6px; border-width: 1px 1px 0 0; }
.lifted .plate-inner::after { left: 6px; bottom: 6px; border-width: 0 0 1px 1px; }
.lifted .plate-head .count { color: var(--ink-3); }
.lifted .plate-head .count::after { content: attr(data-coord); display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; color: var(--accent); margin-top: 6px; }

@media (prefers-reduced-motion: reduce) {
    .stage-area.lifted::after, .lock-pulse { animation: none; display: none; }
}
:root[data-motion="calm"] .stage-area.lifted::after, :root[data-motion="calm"] .lock-pulse { display: none; }

/* Handshake: connecting an outside assistant. Each allowed scope lights a strand of the wire. */
.handshake { min-height: 100vh; display: grid; grid-template-columns: minmax(280px, 42%) 1fr; background: var(--bg); }
.handshake-art { position: sticky; top: 0; height: 100vh; overflow: hidden; border-right: 1px solid var(--hairline); padding: var(--s12); display: grid; grid-template-columns: minmax(0, 1fr); align-content: space-between; background:
    radial-gradient(120% 80% at 20% 30%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%), var(--surface); }
.handshake-art .giant { font-family: var(--font-display); font-size: clamp(56px, 7.5vw, 128px); line-height: 0.85; letter-spacing: -0.06em; color: var(--ink); opacity: 0.9; }
.handshake-rig { display: grid; grid-template-columns: 72px 1fr 72px; align-items: center; gap: 0; margin: var(--s6) 0; }
.rig-node { width: 72px; height: 72px; border: 1px solid var(--hairline); display: grid; place-items: center; background: var(--bg); font-family: var(--font-mono); font-size: 18px;
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 0%, transparent); transition: box-shadow 400ms ease, border-color 400ms ease; }
.handshake-rig.live .rig-node { border-color: var(--accent); box-shadow: 0 0 32px -6px color-mix(in srgb, var(--accent) 70%, transparent); }
.rig-wire { display: grid; gap: 3px; padding: 0 2px; }
.rig-wire i { display: block; height: 2px; background: var(--hairline); transform-origin: left; transform: scaleX(0.25); opacity: 0.5; transition: transform 380ms cubic-bezier(.2,.8,.2,1), background 380ms, opacity 380ms; }
.rig-wire i.on { transform: scaleX(1); opacity: 1; background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 40%, var(--sig-live))); }
.handshake-form { padding: var(--s6); display: grid; gap: var(--s4); align-content: start; max-width: 720px; }
.handshake-block h2 { margin: 0; font-weight: 400; }
.handshake-connect { height: 44px; padding: 0 var(--s6); font-size: 15px; }
.handshake-form h1 { font-family: var(--font-display); font-size: clamp(26px, 3.2vw, 40px); line-height: 1.05; letter-spacing: -0.03em; font-weight: 600; }
.handshake-origin { display: flex; flex-wrap: wrap; gap: var(--s3); font-size: 13px; }
.handshake-origin .verified { color: var(--sig-live-text); }
.handshake-origin .unverified { color: var(--ink); }
/* An unverified name is the one thing a person must read: ink on a plate with an amber edge, never amber text. */
.handshake-warning { display: grid; grid-template-columns: 20px 1fr; gap: var(--s2); align-items: start; padding: var(--s3); border: 1px solid var(--hairline); border-left: 4px solid var(--sig-you-line); background: var(--raised); color: var(--ink); font-size: 14px; }
.handshake-warning svg { width: 20px; height: 20px; margin-top: 1px; }
.handshake-warning svg path { fill: var(--sig-you); stroke: var(--ink); stroke-width: 1; }
.handshake-warning svg rect, .handshake-warning svg circle { fill: var(--ink); }
.handshake-form h1 .claimed { font-family: var(--font-mono); font-size: 0.8em; letter-spacing: -0.02em; }
.handshake-block { display: grid; gap: var(--s2); }
.plug { display: grid; grid-template-columns: 22px 1fr; column-gap: var(--s2); padding: 10px 12px; border: 1px solid var(--hairline); background: var(--surface); cursor: pointer;
    transition: border-color 200ms, background 200ms; }
.plug input { grid-row: span 2; margin-top: 3px; accent-color: var(--accent); }
.plug.on { border-color: color-mix(in srgb, var(--accent) 70%, var(--hairline)); background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.plug-title { font-weight: 600; }
.plug-line { font-size: 13px; color: var(--ink-2); }
.handshake-never { font-size: 13px; color: var(--ink-2); border-left: 2px solid var(--sig-you-line); padding-left: var(--s2); }
.handshake-actions { display: flex; gap: var(--s3); align-items: center; }
.small { font-size: 12px; }
@media (max-width: 820px) {
    .handshake { grid-template-columns: 1fr; }
    .handshake-art { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--hairline); padding: var(--s4); }
    .handshake-art .giant { font-size: 72px; }
    .handshake-form { padding: var(--s4); }
}
@media (prefers-reduced-motion: reduce) { .rig-wire i, .rig-node { transition: none; } }

.connect-howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s3); }
.connect-howto .panel-body { min-width: 0; }
.connect-howto .panel { min-width: 0; }
.copy-line { min-width: 0; display: flex; gap: var(--s2); align-items: center; border: 1px solid var(--hairline); background: var(--bg); padding: 6px 8px; }
.copy-line code { flex: 1; min-width: 0; white-space: pre-wrap; word-break: break-all; font-size: 12px; }
.token-reveal { display: grid; gap: var(--s2); border: 1px solid var(--accent); padding: var(--s4); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.scope-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s2); }

/* The guide: only for signed-in people. */
.docs { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); grid-template-rows: auto 1fr; background: var(--bg); }
.docs-head { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s6); border-bottom: 1px solid var(--hairline); background: var(--surface); }
.docs-head .wordmark { margin: 0; }
.docs-nav { display: flex; flex-direction: column; gap: 2px; padding: var(--s4); border-right: 1px solid var(--hairline); position: sticky; top: 0; align-self: start; }
.docs-nav a { text-decoration: none; padding: 8px 10px; border-left: 2px solid transparent; font-size: 14px; }
.docs-nav a.on { border-left-color: var(--accent); background: var(--surface); }
.docs-body { padding: var(--s8) clamp(16px, 5vw, 64px) var(--s12); max-width: 860px; display: grid; gap: var(--s4); align-content: start; line-height: 1.6; }
.docs-body h1 { font-family: var(--font-display); font-size: clamp(32px, 4vw, 48px); letter-spacing: -0.035em; line-height: 1; }
.docs-body h2 { font-family: var(--font-display); font-size: 22px; letter-spacing: -0.02em; margin-top: var(--s4); }
.docs-body ul, .docs-body ol { padding-left: 1.3em; display: grid; gap: 4px; }
.docs-body code { font-family: var(--font-mono); font-size: 0.9em; background: var(--surface); padding: 1px 5px; border: 1px solid var(--hairline); }
.docs-body pre { background: var(--surface); border: 1px solid var(--hairline); padding: var(--s3) var(--s4); overflow-x: auto; }
.docs-body pre code { border: 0; padding: 0; background: transparent; }
.docs-body table { border-collapse: collapse; width: 100%; font-size: 14px; }
.docs-body th, .docs-body td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
.docs-body th { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-2); }
.docs-body a { color: var(--accent); }
@media (max-width: 760px) {
    .docs { grid-template-columns: 1fr; }
    .docs-nav { position: static; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--hairline); }
}

/* Table lens: the same cards as rows. */
.card-table-wrap { overflow: auto; height: 100%; padding: var(--s4) var(--s6); }
.card-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.card-table th { position: sticky; top: 0; background: var(--bg); text-align: left; border-bottom: 1px solid var(--hairline); z-index: 1; }
.card-table th button { all: unset; cursor: pointer; display: block; padding: 8px 10px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.card-table th button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.card-table td { padding: 9px 10px; border-bottom: 1px solid var(--hairline); vertical-align: middle; }
.card-table td.title { font-weight: 500; max-width: 420px; }
.card-table tbody tr { cursor: pointer; transition: background 120ms; }
.card-table tbody tr:hover, .card-table tbody tr:focus-within { background: var(--surface); }
.card-table tbody tr.live td:first-child { box-shadow: inset 2px 0 0 var(--sig-live-line); }
.card-table tbody tr.you td:first-child { box-shadow: inset 2px 0 0 var(--sig-you-line); }
.card-table td:first-child, .card-table td:last-child { white-space: nowrap; }
.card-table .row-link { all: unset; cursor: pointer; overflow-wrap: anywhere; }
.card-table .row-link:hover { text-decoration: underline; }
.card-table .row-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.stage-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.stage-chip::before { content: ""; width: 8px; height: 8px; background: var(--cat); }
.tray-edit { align-self: end; margin-left: -6px; }
.source-edit { width: 100%; font-size: 12px; line-height: 1.5; resize: vertical; }

/* Pocket: phones steer, they do not build. */
.pocket { display: none; }
@media (max-width: 767px) {
    .shell { display: none; }
    .pocket { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; background: var(--bg); }
    .pocket-main { display: block; min-width: 0; }
    .pocket-head { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--hairline); background: var(--surface);
        position: sticky; top: 0; z-index: 3; }
    .pocket-head .wordmark { margin: 0; }
    .pocket-deck { flex: 1; min-width: 0; height: 36px; font-family: var(--font-display); font-weight: 600; }
    .pocket-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--hairline); position: sticky; top: 61px; z-index: 2; background: var(--bg); }
    .pocket-tabs button { all: unset; text-align: center; padding: 12px 4px; font-size: 14px; border-bottom: 2px solid transparent; cursor: pointer; }
    .pocket-tabs button:focus-visible, .pocket-row:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; }
    .pocket-tabs button.on { border-bottom-color: var(--accent); font-weight: 600; }
    .pocket-tabs b { font-family: var(--font-mono); font-weight: 500; margin-left: 4px; color: var(--ink-2); }
    .pocket-tabs b.you { color: var(--sig-you-text); }
    .pocket-tabs b.live { color: var(--sig-live-text); }
    .pocket-body { padding: var(--s3) var(--s3) var(--s12); display: grid; gap: var(--s2); align-content: start; }
    .pocket-body:focus-visible { outline-offset: -2px; }
    .pocket-body .inbox { display: block; position: static; width: auto; height: auto; border: 0; background: transparent; }
    .pocket-body .inbox-head { display: none; }
    .pocket-body .ticket .btn.small { height: 44px; padding: 0 16px; font-size: 15px; }
    .pocket-body .ticket textarea { min-height: 88px; font-size: 16px; }
    .pocket-row { all: unset; box-sizing: border-box; width: 100%; display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--hairline); background: var(--surface); cursor: pointer; }
    .pocket-row.live { box-shadow: inset 3px 0 0 var(--sig-live-line); }
    .pocket-row.you { box-shadow: inset 3px 0 0 var(--sig-you-line); }
    .pocket-title { font-weight: 600; font-size: 16px; }
    .pocket-line { font-size: 13px; color: var(--ink-2); }
    .pocket-stage { border: 1px solid var(--hairline); }
    .pocket-stage summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; cursor: pointer; list-style: none;
        box-shadow: inset 3px 0 0 var(--cat); }
    .pocket-stage[open] summary { border-bottom: 1px solid var(--hairline); }
    .pocket-stage .pocket-row { border: 0; border-bottom: 1px solid var(--hairline); }
    .pocket-stage-name { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
    .pocket-empty { padding: var(--s4) var(--s2); }
}
.plug.sensitive .tag { font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink); border: 1px solid var(--sig-you-line); padding: 0 4px; margin-left: 6px; }
.plug.sensitive.on { border-color: var(--sig-you-line); background: color-mix(in srgb, var(--sig-you) 7%, var(--surface)); }
.plug.confirm { border-style: dashed; }
