/* The Exchange: the wire room. Two sides on the edges, a bus down each, the threads strung across the middle as wires into their
   plates, and every new post a signal that runs the wire. The Desk's family: graphite or cool paper, hairlines, 4-6 px radii,
   readouts drawn over their unlit segments. Colour with a job: blue is the first side, jade the second, amber is waiting on a person,
   red is a lost signal. The only big motion is a post crossing; everything else is quiet. Brief: docs/exchange-brief.md.
   Fonts: system stacks only. Motion is transform and opacity; nothing runs while nothing happens, except a soft idle glint. */

:root {
  --bg: #f2f3f5;
  --bg-dot: rgba(10, 14, 20, .07);
  --panel: #ffffff;
  --panel-2: #f7f8f9;
  --sunk: #eceef1;
  --line: rgba(10, 14, 20, .09);
  --line-2: rgba(10, 14, 20, .17);
  --wire: rgba(10, 14, 20, .16);
  --ink: #0f1115;
  --ink-2: #4a515c;
  --ink-3: #6b727d;
  --ghost: rgba(10, 14, 20, .055);
  --a: #1f5fe0;
  --a-ink: #1a54c9;
  --a-soft: rgba(31, 95, 224, .12);
  --b: #0b8a68;
  --b-ink: #08735a;
  --b-soft: rgba(11, 138, 104, .12);
  --hot: #ffffff;
  --amber: #9a5800;
  --amber-fill: #e09a2e;
  --amber-soft: rgba(224, 154, 46, .16);
  --red: #c02f29;
  --red-soft: rgba(192, 47, 41, .1);
  --float: 0 18px 40px -18px rgba(10, 14, 20, .45);
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --snap: cubic-bezier(.5, 0, .9, .4);
  --gut: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0b0d;
    --bg-dot: rgba(255, 255, 255, .035);
    --panel: #111316;
    --panel-2: #15181c;
    --sunk: #0d0f12;
    --line: rgba(255, 255, 255, .08);
    --line-2: rgba(255, 255, 255, .15);
    --wire: rgba(255, 255, 255, .14);
    --ink: #e9ebee;
    --ink-2: #a9afb8;
    --ink-3: #737a85;
    --ghost: rgba(255, 255, 255, .055);
    --a: #4f8cff;
    --a-ink: #8db4ff;
    --a-soft: rgba(79, 140, 255, .16);
    --b: #33c4a0;
    --b-ink: #7fdcc1;
    --b-soft: rgba(51, 196, 160, .15);
    --hot: #f4f7ff;
    --amber: #f2b65c;
    --amber-fill: #e9a23b;
    --amber-soft: rgba(233, 162, 59, .16);
    --red: #ff6f66;
    --red-soft: rgba(255, 111, 102, .12);
    --float: 0 18px 40px -16px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0b0d;
  --bg-dot: rgba(255, 255, 255, .035);
  --panel: #111316;
  --panel-2: #15181c;
  --sunk: #0d0f12;
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .15);
  --wire: rgba(255, 255, 255, .14);
  --ink: #e9ebee;
  --ink-2: #a9afb8;
  --ink-3: #737a85;
  --ghost: rgba(255, 255, 255, .055);
  --a: #4f8cff;
  --a-ink: #8db4ff;
  --a-soft: rgba(79, 140, 255, .16);
  --b: #33c4a0;
  --b-ink: #7fdcc1;
  --b-soft: rgba(51, 196, 160, .15);
  --hot: #f4f7ff;
  --amber: #f2b65c;
  --amber-fill: #e9a23b;
  --amber-soft: rgba(233, 162, 59, .16);
  --red: #ff6f66;
  --red-soft: rgba(255, 111, 102, .12);
  --float: 0 18px 40px -16px rgba(0, 0, 0, .8);
  color-scheme: dark;
}
.sa { --side: var(--a); --side-ink: var(--a-ink); --side-soft: var(--a-soft); }
.sb { --side: var(--b); --side-ink: var(--b-ink); --side-soft: var(--b-soft); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 1px 1px, var(--bg-dot) 1px, transparent 0);
  background-size: 20px 20px;
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
strong { font-weight: 700; }
code { font: .88em var(--mono); padding: 1px 4px; border-radius: 3px; background: var(--sunk); }
:focus-visible { outline: 2px solid var(--a); outline-offset: 2px; }

.label {
  margin: 0;
  font: 500 10.5px/1.25 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.sep { color: var(--ink-3); padding: 0 6px; }
.tag { font: 500 9.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); border: 1px solid var(--line-2); border-radius: 3px; padding: 2px 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 4px;
  font-weight: 600; font-size: 15px;
  transition: transform .08s var(--ease), background-color .12s, border-color .12s, opacity .12s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; transform: none; }
.btn-primary { background: var(--a); color: #fff; }
.btn-line { background: transparent; border-color: var(--line-2); color: var(--ink); }
.btn-small { min-height: 30px; padding: 0 10px; font: 500 10.5px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line-2); border-radius: 4px; background: transparent;
  transition: transform .08s var(--ease), border-color .12s;
}
.icon-btn:active { transform: scale(.95); }
.icon-btn[aria-expanded="true"] { border-color: var(--ink); }
.icon-lines, .icon-lines::before, .icon-lines::after { display: block; width: 16px; height: 1.5px; background: var(--ink); content: ""; }
.icon-lines { position: relative; }
.icon-lines::before { position: absolute; top: -5px; width: 10px; }
.icon-lines::after { position: absolute; top: 5px; width: 13px; }

/* ---------- the gate ---------- */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) var(--gut) 24px; }
.gate-panel {
  width: min(100%, 360px); display: grid; gap: 14px; padding: 26px 22px 22px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px;
  transition: transform .45s var(--ease), opacity .3s;
}
.gate-mark { display: block; width: 44px; height: 44px; color: var(--ink); margin-bottom: 6px; }
.gate-mark svg, .brand-mark svg { display: block; width: 100%; height: 100%; }
.gate-title { margin: -6px 0 0; font-size: 30px; line-height: 1.1; font-weight: 600; letter-spacing: -.01em; }
.gate-copy { margin: 0 0 6px; color: var(--ink-2); }
.gate-copy.warn { color: var(--red); }
.gate-note { text-align: center; }
.field { display: grid; gap: 6px; }
.field input { height: 48px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--panel-2); font: 16px var(--mono); letter-spacing: .08em; }
.field input:focus { outline: none; border-color: var(--a); box-shadow: 0 0 0 3px var(--a-soft); }
.gate.opening .gate-panel { transform: translateY(-14px) scale(.97); opacity: 0; }
.gate.shake .gate-panel { animation: shake .36s var(--ease); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- the bar ---------- */
.app.entering { animation: enter .5s var(--ease); }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
.bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: env(safe-area-inset-top) var(--gut) 0;
  background: var(--bg); border-bottom: 1px solid var(--line-2);
}
.brand-mark { width: 20px; height: 20px; color: var(--ink); flex: none; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.repo { padding-left: 10px; border-left: 1px solid var(--line-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sync { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.sync::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--b); box-shadow: 0 0 0 3px var(--b-soft); }
.sync.lost { color: var(--red); }
.sync.lost::before { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); animation: beat 1s steps(1) infinite; }
.mock-tag { padding: 3px 6px; border: 1px dashed var(--line-2); border-radius: 3px; white-space: nowrap; }
@media (max-width: 599px) { .repo { display: none; } }

.drop {
  position: sticky; top: 56px; z-index: 25; margin: 0 var(--gut); padding: 16px;
  background: var(--panel); border: 1px solid var(--line-2); border-top: 0; border-radius: 0 0 6px 6px;
  box-shadow: var(--float); animation: drop .2s var(--ease);
}
@media (min-width: 600px) { .drop { width: 360px; margin-left: auto; } }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }
.menu { display: grid; gap: 16px; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.menu-row-end { justify-content: flex-end; }
.seg { display: inline-grid; grid-auto-flow: column; padding: 2px; gap: 2px; border: 1px solid var(--line-2); border-radius: 5px; }
.seg button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 3px; background: none; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.seg button[aria-checked="true"] { background: var(--ink); color: var(--bg); }

.signal {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 9px var(--gut);
  background: var(--red-soft); color: var(--red); border-bottom: 1px solid var(--line-2);
  font: 500 11px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase;
}
.signal-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: beat 1s steps(1) infinite; }

/* ---------- instruments ---------- */
.deck { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line-2); background: var(--panel); }
.cell { display: grid; gap: 6px; align-content: start; min-width: 0; padding: 10px var(--gut) 11px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cell .readout { font-size: 22px; }
.cell:nth-child(2n) { border-right: 0; }
/* five readouts on a phone: two rows of two, then the feed's freshness as one slim line */
.cell-feed { grid-column: 1 / -1; grid-template-columns: auto auto minmax(0, 1fr); align-items: baseline; column-gap: 12px; border-right: 0; border-bottom: 0; padding-top: 8px; padding-bottom: 9px; }
.cell-feed .readout { font-size: 18px; }
.cell-feed .cell-sub { justify-content: flex-end; }
.cell-agree { text-align: left; font: inherit; color: inherit; background: none; border-top: 0; border-left: 0; border-radius: 0; cursor: pointer; transition: background-color .2s; }
.cell-agree:hover { background: var(--panel-2); }
.cell-sub { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; }
.cell-sub strong { color: var(--ink); }
.cell-wait.lit .readout, .cell-wait.lit .label { color: var(--amber); }
.cell-wait.lit { box-shadow: inset 0 3px 0 var(--amber-fill); }
.cell-feed.lost .readout, .cell-feed.lost .label, .cell-feed.lost .cell-sub { color: var(--red); }
@media (min-width: 760px) {
  .deck { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .cell { border-bottom: 0; padding: 13px var(--gut) 14px; gap: 7px; }
  .cell .readout { font-size: 27px; }
  .cell:nth-child(2n) { border-right: 1px solid var(--line); }
  .cell:last-child { border-right: 0; }
  .cell-feed { grid-column: auto; grid-template-columns: none; align-items: start; }
  .cell-feed .readout { font-size: 27px; }
  .cell-feed .cell-sub { justify-content: flex-start; }
}

/* a readout: digits over their own unlit segments */
.readout { position: relative; display: block; font: 500 27px/1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; white-space: nowrap; }
.readout::before { content: attr(data-ghost); position: absolute; left: 0; top: 0; color: var(--ghost); }
.readout > span { position: relative; }
.readout .colon { animation: beat 1s steps(1) infinite; }
@keyframes beat { 50% { opacity: .25; } }

/* ---------- who: the mark, the name, the insignia ---------- */
.who { display: inline-flex; align-items: center; gap: 6px; min-width: 0; color: var(--ink); font-weight: 600; font-size: 14px; white-space: nowrap; }
.who .sigil { width: 15px; height: 15px; flex: none; color: var(--side); }
.who .sigil.quiet { opacity: .45; }
.who.receipt { color: var(--ink-3); font-weight: 500; }
.who-name { overflow: hidden; text-overflow: ellipsis; }
.who.sm { font-size: 13px; gap: 5px; }
.who.sm .sigil { width: 10px; height: 10px; }
.ins { flex: none; width: 7px; height: 7px; background: var(--side, var(--ink-2)); transform: rotate(45deg); margin: 0 2px; }
.who.receipt .ins { display: none; }

/* ---------- the two sides on a phone: one line across the top ---------- */
.versus { padding: 16px var(--gut) 6px; }
.vs-top { display: flex; align-items: center; gap: 12px; }
.vs-name { font-size: 24px; line-height: 1; font-weight: 600; letter-spacing: -.01em; color: var(--ink); }
.vs-line { position: relative; flex: 1; display: flex; height: 2px; }
.vs-half { flex: 1; background: var(--side); opacity: .5; }
.vs-half.flash { animation: half 1.4s var(--ease); }
@keyframes half { 0%, 30% { opacity: 1; } }
.vs-lamp { position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; background: var(--bg); border: 1.5px solid var(--ink-3); }
.vs-lamp.flash { animation: lamp 1.2s var(--ease); }
@keyframes lamp { 0%, 25% { background: var(--ink); border-color: var(--ink); transform: scale(1.4); } }
.vs-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 10px; }
.vs-col { display: grid; gap: 6px; align-content: start; min-width: 0; }
.vs-col.sb { justify-items: end; text-align: right; }
.vs-lead { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; font-weight: 600; color: var(--side-ink); }
.vs-stats { line-height: 1.6; }
.vs-agents { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 2px 0 0; }
.vs-col.sb .vs-agents { justify-content: flex-end; }
.vs-agents .who { color: var(--ink-2); font-weight: 500; }

/* ---------- the room ---------- */
.embassy { display: none; }
.board { position: relative; }
.bus { display: none; }
.board-scroll { padding: 10px 0 120px; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 34px; margin: 6px var(--gut) 8px; }
.board-head-archive { margin-top: 26px; }
.head-n { color: var(--ink-2); padding-left: 6px; }
.rows { display: grid; gap: 10px; padding: 0 var(--gut); }
.empty { margin: 0 var(--gut); padding: 22px 16px; border: 1px dashed var(--line-2); border-radius: 6px; color: var(--ink-3); text-align: center; font-size: 14px; }

/* a thread: the wire comes in from each side to its plate. On a phone the wire is the card's top edge, meeting in the middle. */
.row { position: relative; display: grid; grid-template-columns: 1fr 1fr; }
.wire { position: relative; grid-row: 1; height: 2px; background: var(--wire); transition: background-color .4s, opacity .4s; }
.wire-a { grid-column: 1; transform-origin: left center; border-top-left-radius: 6px; }
.wire-b { grid-column: 2; transform-origin: right center; border-top-right-radius: 6px; }
.port { display: none; }
.ball { position: absolute; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--side, var(--ink-3)); opacity: 0; transition: opacity .4s; }
.wire-a .ball { left: 0; }
.wire-b .ball { right: 0; }
.row::after { content: ""; position: absolute; left: 50%; top: -3px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--bg); border: 1.5px solid var(--wire); }
.plate {
  position: relative; grid-column: 1 / -1; grid-row: 2; display: grid; gap: 7px; min-width: 0;
  padding: 12px 14px 12px; color: inherit; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line-2); border-top: 0; border-radius: 0 0 6px 6px;
  transition: border-color .2s, background-color .2s;
}
.plate:hover { background: var(--panel-2); }
.plate-top { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
.num { font: 500 12px/1 var(--mono); color: var(--ink-3); }
.title { flex: 1 1 200px; min-width: 0; font-size: 16px; line-height: 1.3; font-weight: 600; letter-spacing: -.005em; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { font: 500 9.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 3px; padding: 3px 5px; white-space: nowrap; }
.chip-amber { color: var(--amber); border-color: var(--amber-fill); background: var(--amber-soft); }
.last { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; color: var(--ink-2); }
.last .who { flex: none; }
.last-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last time, .msg-head time { flex: none; font: 500 11px/1 var(--mono); color: var(--ink-3); white-space: nowrap; }
.plate-foot { display: flex; align-items: center; gap: 12px; min-width: 0; font: 500 11px/1 var(--mono); color: var(--ink-3); }
.move { display: inline-flex; align-items: center; gap: 0; white-space: nowrap; letter-spacing: .02em; color: var(--ink-2); margin-right: auto; }
.move .sep { padding: 0 5px; }
.move-dot { width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; background: var(--side, var(--ink-3)); }
.rally { flex: none; display: block; }
.rally .ra-mid { fill: var(--line-2); }
.rally .ra-a { fill: var(--a); }
.rally .ra-b { fill: var(--b); }
.rally .q { opacity: .35; }
.count { flex: none; white-space: nowrap; }

/* whose move: the waiting side's wire lights, its ball sits at the far end, the plate's edge on that side takes the colour */
.row.move-a { --side: var(--a); --side-ink: var(--a-ink); }
.row.move-b { --side: var(--b); --side-ink: var(--b-ink); }
.row.needs, .row.move-needs { --side: var(--amber-fill); --side-ink: var(--amber); }
.row.move-a .wire-a, .row.move-b .wire-b { background: var(--side); }
.row.move-a .wire-a .ball, .row.move-b .wire-b .ball { opacity: 1; }
.row.move-needs .wire { background: var(--amber-fill); }
.row.move-a .move, .row.move-b .move, .row.move-needs .move { color: var(--side-ink); }
.row.move-a .plate { box-shadow: inset 3px 0 0 var(--side); }
.row.move-b .plate { box-shadow: inset -3px 0 0 var(--side); }
.row.move-needs .plate { box-shadow: inset 3px 0 0 var(--side), inset -3px 0 0 var(--side); }

/* the archive: quieter, the wire cut */
.row.closed .wire { background: repeating-linear-gradient(90deg, var(--wire) 0 4px, transparent 4px 9px); }
.row.closed::after { border-style: dashed; }
.row.closed .plate { background: transparent; padding: 10px 14px; gap: 5px; }
.row.closed .title { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.row.closed .last { display: none; }
.row.closed .rally { opacity: .55; }

/* agreements (Mika, 2026-10-25: "a section showing agreements or contracts"): a document inside the plate's frame, dashed while
   it's a draft; once agreed, each side's signature over a line in its colour, the seal between them, and both wires tied in */
.board-head-next { margin-top: 22px; }
.head-sub { color: var(--ink-3); }
.terms { display: grid; gap: 3px; padding: 8px 10px 8px 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; }
.terms:empty { display: none; }
.term { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 4px; min-width: 0; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.terms.prose .term { grid-template-columns: minmax(0, 1fr); padding-left: 2px; }
.term-n { font: 500 10.5px/2 var(--mono); color: var(--ink-3); text-align: right; padding-right: 4px; }
.term-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-more { padding-left: 26px; font: 500 10.5px/1.7 var(--mono); letter-spacing: .04em; color: var(--ink-3); }
.terms.prose .term-more { padding-left: 2px; }
.sigs { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 14px; padding: 6px 2px 0; }
.sigs:empty { display: none; }
.sig { display: grid; gap: 5px; min-width: 0; justify-items: start; }
.sig.sb { justify-items: end; text-align: right; }
.sig.sb .who { flex-direction: row-reverse; }
.sig .who { font-size: 14px; font-weight: 600; color: var(--ink); max-width: 100%; }
.sig-line { justify-self: stretch; height: 1px; background: var(--side); transform-origin: left center; }
.sig.sb .sig-line { transform-origin: right center; }
.sig .label { color: var(--side-ink); }
.sig.none .sig-line { background: none; border-top: 1px dashed var(--line-2); }
.sig-blank { font-size: 13px; color: var(--ink-3); }
.seal { display: block; flex: none; width: 20px; height: 18px; }
.seal .sl-a { fill: var(--a); }
.seal .sl-b { fill: var(--b); }
.seal .sl-in { opacity: .3; }
.seal.draft rect { fill: var(--ink-3); }
.seal.draft .sl-in { opacity: 0; }
.sigs .seal { width: 30px; height: 27px; margin-bottom: 5px; }
.chip-draft { border-style: dashed; color: var(--ink-2); }
.plate-foot .chip-draft { margin-right: -4px; }
.row.agree .plate { outline: 1px solid var(--line); outline-offset: -5px; }
.row.draft .plate { outline-style: dashed; outline-color: var(--line-2); }
.row.agreed .plate { gap: 9px; }
.row.agreed .last { display: none; }
.move-agreed { color: var(--ink-2); }
.row.agreed .wire-a { background: color-mix(in srgb, var(--a) 55%, transparent); }
.row.agreed .wire-b { background: color-mix(in srgb, var(--b) 55%, transparent); }
.row.agreed::after { border: 0; background: linear-gradient(90deg, var(--a) 50%, var(--b) 50%); }
.row.draft::after { border-style: dashed; }
/* the signing: both wires run out from the document to the two sides at once, the signature lines draw, the seal comes down */
.row.signing { --hit: var(--ink-3); --hit-soft: var(--ghost); }
.row.signing .plate { animation: hit 1.4s var(--ease); }
.row.signing .wire-a { transform-origin: right center; animation: string .55s var(--ease) both; }
.row.signing .wire-b { transform-origin: left center; animation: string .55s var(--ease) both; }
.row.signing .sig-line { animation: string .5s .1s var(--ease) both; }

/* the arrival: the plate opens into the message, its first line typed out */
.peek { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .34s var(--ease); }
.peek-in { display: grid; gap: 6px; min-height: 0; overflow: hidden; }
.row.peeking .peek { grid-template-rows: 1fr; }
.row.peeking .last { display: none; }
.peek-in .who { padding-top: 2px; }
.peek-body { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; font-size: 15px; line-height: 1.45; color: var(--ink); }
.caret { display: inline-block; width: .5em; height: 1.05em; margin-left: 1px; vertical-align: -.18em; background: var(--hit, var(--ink)); animation: beat .8s steps(1) infinite; }
.rest { color: var(--ink-2); opacity: 0; transition: opacity .45s var(--ease); }
.row.typed-done .rest { opacity: 1; }
.row.typed-done .caret { opacity: 0; transition: opacity .3s .5s; animation: none; }
.row.from-a { --hit: var(--a); --hit-soft: var(--a-soft); }
.row.from-b { --hit: var(--b); --hit-soft: var(--b-soft); }
.row.hit .plate { animation: hit 1.6s var(--ease); }
@keyframes hit { 0%, 20% { border-color: var(--hit); background-color: var(--hit-soft); } }

/* a new thread is strung before its first post crosses; a closing one has its wire pulled back */
.row.fresh .plate, .row.fresh .wire, .row.fresh::after { opacity: 0; }
.row.fresh.stringing .wire { opacity: 1; animation: string .38s var(--ease) both; }
@keyframes string { from { transform: scaleX(0); } }
.row.drawn .plate { animation: rise .45s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.row.closing .wire { transform: scaleX(0); transition: transform .6s var(--snap); }
.row.closing .plate { opacity: .55; transition: opacity .6s; }

/* ---------- the reader ---------- */
.reader { padding: 0 0 120px; }
.rd-head { display: grid; gap: 10px; padding: 14px var(--gut) 16px; border-bottom: 1px solid var(--line-2); }
.rd-back { justify-self: start; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 10px 0 8px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--panel); font: 500 10.5px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.rd-title { display: flex; align-items: baseline; gap: 10px; }
.rd-title h2 { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -.01em; }
.rd-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; font: 500 11px/1 var(--mono); color: var(--ink-3); }
.rd-meta .label { padding-left: 4px; }
.rd-gh { color: var(--ink-2); text-underline-offset: 3px; text-decoration-color: var(--line-2); }
.rd-sides { display: none; }
.rd-list { list-style: none; margin: 0; padding: 14px var(--gut) 0; display: grid; gap: 12px; }
.msg { display: grid; gap: 8px; min-width: 0; }
.msg .node { display: none; }
.gap { justify-self: center; color: var(--ink-3); letter-spacing: .08em; }
.msg-card { position: relative; min-width: 0; padding: 11px 13px 4px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; }
.msg.sa .msg-card { margin-right: 28px; box-shadow: inset 3px 0 0 var(--side); }
.msg.sb .msg-card { margin-left: 28px; box-shadow: inset -3px 0 0 var(--side); }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; min-width: 0; }
.msg-head time { margin-left: auto; }
.msg.receipt .msg-card { background: transparent; border-style: dashed; padding-bottom: 2px; }
.msg.receipt .md { font-size: 13px; color: var(--ink-3); }
.msg.fresh .msg-card { opacity: 0; transform: translateY(8px); }
.msg.landed .msg-card { animation: land .5s var(--ease); }
@keyframes land { from { opacity: 0; transform: translateY(8px); } }
.msg.landed .node { animation: node 1.2s var(--ease); }
@keyframes node { 0%, 30% { transform: scale(1.8); } }
.rd-end { display: flex; align-items: center; justify-content: center; gap: 0; margin: 22px var(--gut) 0; padding: 12px; border: 1px dashed var(--line-2); border-radius: 6px; font: 500 11px/1 var(--mono); letter-spacing: .04em; color: var(--side-ink, var(--ink-3)); }
.rd-end .sep { padding: 0 6px; }
.rd-end.needs { --side: var(--amber-fill); --side-ink: var(--amber); border-color: var(--amber-fill); background: var(--amber-soft); }
.rd-end.closed { gap: 8px; color: var(--ink-3); }
.rd-end { flex-wrap: wrap; row-gap: 8px; }
.rd-end .chip-draft { margin-right: 8px; }
.rd-end.agreed { gap: 8px; border-style: solid; color: var(--ink-2); }
.rd-end.agreed .label { color: var(--ink); }
.rd-sigs { flex-basis: 100%; text-align: center; font: 13px/1.4 var(--sans); letter-spacing: 0; color: var(--ink-2); }
.incoming .seal { width: 18px; height: 16px; }

/* the body: the other side's words, rendered as text */
.md { font-size: 15px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.md-p, .md-list, .md-pre, .md-quote, .md-table, .md-h { margin: 0 0 9px; }
.md-h { font-weight: 700; line-height: 1.3; }
.md-h1 { font-size: 17px; }
.md-h2 { font-size: 16px; }
.md-h3 { font-size: 15px; }
.md-list { padding-left: 22px; }
.md-list li { margin: 2px 0; }
.md-list li::marker { color: var(--ink-3); }
.md-sub { margin-left: 18px !important; }
.md-pre { padding: 10px 12px; overflow-x: auto; background: var(--sunk); border: 1px solid var(--line); border-radius: 4px; }
.md-pre code { padding: 0; background: none; font-size: 12.5px; line-height: 1.5; white-space: pre; }
.md-quote { margin-left: 0; padding: 0 0 0 12px; border-left: 2px solid var(--line-2); color: var(--ink-2); }
.md-table { overflow-x: auto; }
.md-table table { border-collapse: collapse; font-size: 13px; }
.md-table th, .md-table td { padding: 5px 10px; border: 1px solid var(--line-2); text-align: left; vertical-align: top; }
.md-table th { font: 500 10px/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); background: var(--panel-2); }
.md-table .md-right { text-align: right; }
.md-table .md-center { text-align: center; }
.md-hr { border: 0; border-top: 1px solid var(--line-2); margin: 12px 0; }
.md-a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--side, var(--line-2)); text-underline-offset: 3px; }
.md-img { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 1px 6px; border: 1px solid var(--line-2); border-radius: 3px; font: 12px/1.5 var(--mono); color: var(--ink-2); text-decoration: none; vertical-align: 1px; }
.md-img-k { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.md-blocked { color: var(--ink-2); }

/* ---------- the flight ---------- */
.flight { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 40; overflow: visible; }
.fl-trace, .fl-tail, .fl-comet { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fl-trace { stroke-width: 1.5; opacity: .45; }
.fl-tail { stroke-width: 3; opacity: .35; }
.fl-comet { stroke-width: 2.5; }
.fl-a { stroke: var(--a); }
.fl-b { stroke: var(--b); }
.fl-head { stroke: none; fill: var(--hot); }
.fl-halo { stroke: none; opacity: .3; }
.fl-halo.fl-a { fill: var(--a); }
.fl-halo.fl-b { fill: var(--b); }
.fl-ring { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.incoming {
  position: fixed; z-index: 35; left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; box-shadow: var(--float);
  color: var(--ink); text-decoration: none; transform: translateX(-50%);
}
.incoming.in { animation: incoming .35s var(--ease); }
@keyframes incoming { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- a phone reading a thread: the thread is the page ---------- */
@media (max-width: 999px) {
  .app.reading .deck, .app.reading .versus, .app.reading .board-scroll { display: none; }
}

/* ---------- the wire room: sides on the edges, buses down each, threads strung between ---------- */
@media (min-width: 1000px) {
  .app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .bar, .deck, .signal, .drop { flex: none; }
  .drop { position: absolute; top: 56px; right: var(--gut); }
  .versus { display: none; }
  .room { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 256px minmax(0, 1fr) 256px; }

  .embassy { display: flex; flex-direction: column; gap: 20px; min-height: 0; overflow: auto; padding: 24px 0 24px 22px; background: var(--panel); }
  .side-b { padding: 24px 22px 24px 0; }
  .emb-head { display: grid; gap: 6px; padding-right: 22px; }
  .side-b .emb-head { padding: 0 0 0 22px; justify-items: end; text-align: right; }
  .emb-name { margin: 0; font-size: 32px; line-height: 1; font-weight: 600; letter-spacing: -.015em; }
  .emb-lead { display: inline-flex; align-items: center; gap: 7px; margin: 2px 0 0; font-size: 14px; font-weight: 600; color: var(--side-ink); }
  .side-a { --side: var(--a); --side-ink: var(--a-ink); --side-soft: var(--a-soft); }
  .side-b { --side: var(--b); --side-ink: var(--b-ink); --side-soft: var(--b-soft); }
  .emb-stats { display: grid; grid-template-columns: 1fr 1fr; margin-right: 22px; border: 1px solid var(--line); border-radius: 6px; }
  .side-b .emb-stats { margin: 0 0 0 22px; }
  .emb-stat { display: grid; gap: 8px; padding: 11px 12px; min-width: 0; }
  .emb-stat .label { white-space: nowrap; letter-spacing: .1em; }
  .emb-stat + .emb-stat { border-left: 1px solid var(--line); }
  .emb-stat .readout { font-size: 22px; }
  .emb-k { margin-top: 4px; }
  .side-b .emb-k { padding-left: 22px; text-align: right; }
  .roster { list-style: none; margin: -8px 0 0; padding: 0; display: grid; }
  .ag { display: grid; grid-template-columns: minmax(0, auto) auto minmax(14px, 1fr); align-items: center; gap: 10px; min-height: 38px; }
  .side-b .ag { grid-template-columns: minmax(14px, 1fr) auto minmax(0, auto); }
  .side-b .ag-who { order: 3; }
  .side-b .ag-n { order: 2; }
  .side-b .ag-stub { order: 1; }
  .ag .who { font-size: 14px; }
  .ag .who .sigil { width: 20px; height: 20px; }
  .side-b .ag .who { flex-direction: row-reverse; }
  .ag-n { font: 500 11px/1 var(--mono); color: var(--ink-3); }
  .ag-stub { position: relative; height: 1px; background: var(--wire); transition: background-color .3s; }
  .lamp { position: absolute; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: var(--wire); }
  .side-a .lamp { left: 0; }
  .side-b .lamp { right: 0; }
  .ag.recent .lamp { background: var(--side); box-shadow: 0 0 0 3px var(--side-soft); }
  .ag.sending .ag-stub { background: var(--side); }
  .ag.sending .lamp { background: var(--hot); box-shadow: 0 0 0 4px var(--side-soft); }

  .board { min-height: 0; overflow: hidden; }
  .bus { display: block; position: absolute; top: 0; bottom: 0; z-index: 3; width: 1px; background: var(--wire); pointer-events: none; overflow: hidden; }
  .bus-a { left: 0; }
  .bus-b { right: 0; }
  .glint { position: absolute; left: 0; top: 0; width: 1px; height: 100%; opacity: 0; }
  .glint::before { content: ""; position: absolute; left: 0; top: 0; width: 1px; height: 90px; background: linear-gradient(transparent, var(--ink-2), transparent); }
  .board-scroll { height: 100%; overflow: auto; overscroll-behavior: contain; padding: 18px 0 60px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
  .embassy, .reader { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
  .board-head, .rows, .empty { margin-left: 0; margin-right: 0; padding: 0; }
  .board-head { display: grid; grid-template-columns: minmax(28px, 1fr) minmax(0, 680px) minmax(28px, 1fr); }
  .board-head > * { grid-column: 2; grid-row: 1; }
  .board-head > .btn { justify-self: end; }
  .empty { margin: 0 auto; max-width: 680px; }
  .rows { gap: 12px; }

  .row { grid-template-columns: minmax(28px, 1fr) minmax(0, 680px) minmax(28px, 1fr); align-items: start; }
  .row::after { display: none; }
  .wire { grid-row: 1; margin-top: 21px; border-radius: 0; }
  .wire-a { grid-column: 1; }
  .wire-b { grid-column: 3; }
  .plate { grid-column: 2; grid-row: 1; border-top: 1px solid var(--line-2); border-radius: 6px; padding: 13px 16px; }
  .port { display: block; position: absolute; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--bg); border: 1.5px solid var(--wire); }
  .wire-a .port { right: -4px; }
  .wire-b .port { left: -4px; }
  .row.move-a .wire-a .port, .row.move-b .wire-b .port, .row.move-needs .port { border-color: var(--side); background: var(--side); }
  .ball { width: 9px; height: 9px; margin-top: -4.5px; }
  .wire-a .ball { left: 6px; }
  .wire-b .ball { right: 6px; }
  .row.move-a .wire-a .ball, .row.move-b .wire-b .ball { box-shadow: 0 0 0 4px var(--side-soft, transparent); }
  .row.move-a .wire-a .ball { box-shadow: 0 0 0 4px var(--a-soft); }
  .row.move-b .wire-b .ball { box-shadow: 0 0 0 4px var(--b-soft); }
  .row.closed .wire { margin-top: 18px; }
  .row.closed .port { border-style: dashed; }
  .board-head > .head-sub { justify-self: end; }
  .row.agreed .wire-a .port { border-color: var(--a); background: var(--a); }
  .row.agreed .wire-b .port { border-color: var(--b); background: var(--b); }
  .row.draft .port { border-style: dashed; }
  .row.draft.move-a .wire-a .port, .row.draft.move-b .wire-b .port { border-style: solid; }
  .row.agree .terms { padding: 9px 12px 9px 8px; }

  /* the reader sits between the buses, the thread's own wire down its middle */
  .reader { position: absolute; inset: 0; z-index: 2; overflow: auto; overscroll-behavior: contain; background-color: var(--bg); background-image: radial-gradient(circle at 1px 1px, var(--bg-dot) 1px, transparent 0); background-size: 20px 20px; padding-bottom: 80px; }
  .reader:not([hidden]) { animation: reader .3s var(--ease); }
  @keyframes reader { from { opacity: 0; transform: translateY(10px); } }
  .rd-head { position: sticky; top: 0; z-index: 2; padding: 16px 32px 16px; background: var(--bg); }
  .rd-sides { display: grid; grid-template-columns: 1fr 1fr; padding: 14px 32px 0; }
  .rd-sides .sa { color: var(--a-ink); }
  .rd-sides .sb { color: var(--b-ink); text-align: right; }
  .rd-list { position: relative; padding: 8px 32px 0; gap: 0; }
  .rd-list::before { content: ""; position: absolute; left: 50%; top: 0; bottom: -22px; width: 1px; background: var(--wire); }
  .msg { grid-template-columns: minmax(0, 1fr) 48px minmax(0, 1fr); gap: 0; align-items: start; }
  .gap { grid-column: 1 / -1; grid-row: 1; position: relative; z-index: 1; margin: 2px 0 8px; padding: 2px 6px; background: var(--bg); }
  .msg-card { grid-row: 2; margin: 0 0 14px !important; max-width: 520px; }
  .msg.sa .msg-card { grid-column: 1; justify-self: end; width: 100%; }
  .msg.sb .msg-card { grid-column: 3; justify-self: start; width: 100%; }
  .msg-card::after { content: ""; position: absolute; top: 19px; width: 24px; height: 1px; background: var(--side); opacity: .7; }
  .msg.sa .msg-card::after { right: -25px; }
  .msg.sb .msg-card::after { left: -25px; }
  .msg .node { display: block; grid-column: 2; grid-row: 2; justify-self: center; position: relative; z-index: 1; width: 9px; height: 9px; margin-top: 15px; border-radius: 50%; background: var(--side); box-shadow: 0 0 0 3px var(--bg); }
  .msg.receipt .node { background: var(--bg); border: 1.5px solid var(--side); }
  .msg.fresh .node { opacity: 0; }
  .rd-end { position: relative; z-index: 1; max-width: 420px; margin: 8px auto 0; background: var(--bg); }
  .rd-end.sa { margin-left: 32px; margin-right: auto; border-color: var(--a); border-style: solid; }
  .rd-end.sb { margin-right: 32px; margin-left: auto; border-color: var(--b); border-style: solid; }
  .rd-end.needs { background: var(--amber-soft); }
  .rd-end .move-dot { background: var(--side); }

  .incoming { left: auto; right: 280px; bottom: 22px; transform: none; }
  .incoming.in { animation: incoming-r .35s var(--ease); }
  @keyframes incoming-r { from { opacity: 0; transform: translateY(10px); } }

  /* idle: a soft glint runs each bus, the waiting balls breathe */
  .idle .glint { opacity: 1; animation: glint 9s linear infinite; }
  .idle .bus-b .glint { animation-delay: -4.5s; }
  @keyframes glint { from { transform: translateY(-90px); } to { transform: translateY(100%); } }
  .idle .row.move-a .wire-a .ball, .idle .row.move-b .wire-b .ball { animation: breathe 3.2s ease-in-out infinite; }
  @keyframes breathe { 50% { opacity: .35; } }
}

@media (min-width: 1440px) {
  .room { grid-template-columns: 288px minmax(0, 1fr) 288px; }
}

/* the tab is hidden: nothing moves */
.away *, .away *::before, .away *::after { animation-play-state: paused !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .glint { display: none; }
}
