/* ============================================================
   NALARUPA — visual system
   A studio instrument: paper, ink, hairlines, proportion.
   Images are the only colour. No radius, no glow, no sparkle.
   ============================================================ */

:root {
  /* Direction §2–§4 — frozen T1 tokens (DESIGN_T1 §1). */
  --paper: #F7F7F2;
  --field: #ECEDE8;
  --surface: #FFFFFF;
  --ink: #131311;
  --ink-2: #62675F;
  --rule: #CDD0C7;
  --hover: #E6E8E0;
  --fail: #A32B24;
  /* Legacy aliases: Browse / Selected / Detail keep reading the old
     names until T3 retokenises them. */
  --matte: var(--surface);
  --line: var(--ink);
  --hairline: var(--rule);
  --gray: var(--ink-2);
  --fd: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  --fb: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  --fm: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
  /* T1 plate geometry */
  --media-h: clamp(360px, 46vh, 560px);
  --cap-h: 34px;
  --plate-gap: 24px;
  --gutter: 28px;
}

* { box-sizing: border-box; border-radius: 0 !important; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--fb);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: inherit; background: transparent; }

.mono { font-family: var(--fm); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.dim { color: var(--gray); }

/* ---------- Shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#app[hidden], #gate[hidden] { display: none; } /* [hidden] must beat the flex display rules */

header.top {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 20px 28px 16px;
}
.brand-block { display: flex; flex-direction: column; }
.brand-line { display: flex; align-items: baseline; gap: 6px; line-height: 1; }
.brand {
  font-family: var(--fd); font-weight: 700; font-size: 21px;
  letter-spacing: .42em; line-height: 1;
}
.brand-line .ver { font-family: var(--fm); font-size: 10px; letter-spacing: .12em; color: var(--gray); }
.top-meta { display: flex; align-items: baseline; gap: 22px; }
.top-meta .tagline { font-family: var(--fm); font-size: 11px; letter-spacing: .3em; color: var(--ink); }
.top-meta .who { font-family: var(--fm); font-size: 11px; letter-spacing: .14em; }
.brand-block .statement { font-family: var(--fb); font-size: 12px; line-height: 16px; color: var(--gray); max-width: 52ch; margin-top: 4px; }

nav.main {
  display: flex; align-items: stretch;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
nav.main a {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 24px;
  font-family: var(--fm); font-size: 12px; letter-spacing: .2em; text-transform: uppercase;
  text-decoration: none; border-right: 1px solid var(--line);
}
nav.main a .cnt { font-size: 10px; color: var(--gray); letter-spacing: .1em; }
nav.main a.on { background: var(--ink); color: var(--paper); }
nav.main a.on .cnt { color: #9d9b94; }
nav.main .spacer { flex: 1; border-right: none; }
.nav-new { min-width: 64px; min-height: 44px; padding: 0 14px; border-left: 1px solid var(--line); font: 11px var(--fm); letter-spacing: .18em; }
.nav-new:hover, .nav-new:focus-visible { background: var(--ink); color: var(--paper); }
.nav-new:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.runflag { width: 8px; height: 8px; background: var(--ink); animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { opacity: .2; } }

/* ---------- W2.6 — the persistent job strip ----------
   Mounted outside #view, so it survives every route change; derived from
   the server, so it survives every reload. Same mono voice as the plates. */
.jobstrip {
  border-bottom: 1px solid var(--line);
  background: var(--field);
  font-family: var(--fm); font-size: 11px; letter-spacing: .14em; text-transform: uppercase;
}
.jobstrip[hidden] { display: none; }
.jobstrip-row {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0 12px; padding: 0 var(--gutter);
}
.jobstrip-state { display: inline-flex; align-items: center; gap: 8px; padding: 2px 0; color: var(--ink); }
.jobstrip-act { display: inline-flex; align-items: center; gap: 4px; }
.jobstrip-act .quiet { padding: 0 10px; }

main#view { flex: 1; padding: 26px 28px 40px; }

footer.bot {
  display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px 24px;
  border-top: 1px solid var(--hairline);
  padding: 12px 28px;
  font-family: var(--fm); font-size: 10px; letter-spacing: .14em; color: var(--gray);
}
footer.bot .bot-credit { font-family: var(--fb); font-size: 11px; letter-spacing: 0; }
footer.bot .maker { font-weight: 500; color: var(--ink); }
footer.bot button, footer.bot a { font: inherit; color: var(--gray); letter-spacing: .14em; min-height: 44px; padding: 0 8px; margin: -10px -8px; display: inline-flex; align-items: center; text-decoration: none; }
footer.bot a.on, footer.bot a:hover, footer.bot button:hover { color: var(--ink); }
footer.bot button:hover { color: var(--ink); }

/* ---------- Gate ---------- */
#gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--paper); z-index: 10; }
.gate-box { width: 360px; }
.gate-box .g-brand { font-family: var(--fd); font-weight: 700; font-size: 34px; letter-spacing: .34em; }
.gate-box .g-tag { font-family: var(--fm); font-size: 11px; letter-spacing: .34em; color: var(--gray); margin-top: 10px; }
.gate-box .g-rule { border-top: 1px solid var(--line); margin: 26px 0; }
.gate-box input {
  width: 100%; height: 50px; border: 1px solid var(--line);
  padding: 0 14px; font-size: 14px; background: var(--matte);
}
.gate-box input:focus { outline: 1px solid var(--line); outline-offset: 2px; }
.gate-box .btn { width: 100%; margin-top: 12px; height: 46px; }
.gate-box .g-note { margin-top: 22px; font-family: var(--fm); font-size: 10px; letter-spacing: .12em; color: var(--gray); }
.gate-box .g-statement { font-family: var(--fb); font-size: 13px; line-height: 19px; color: var(--gray); max-width: 44ch; margin-top: 14px; }
.gate-box .g-credit { margin-top: 22px; font-family: var(--fb); font-size: 11px; line-height: 16px; color: var(--gray); }
.gate-box .g-credit .maker { font-weight: 500; color: var(--ink); }

/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--line);
  font-family: var(--fm); font-size: 11px; letter-spacing: .16em; text-transform: uppercase;
  text-decoration: none; color: var(--ink); background: transparent;
  white-space: nowrap;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: transparent; color: var(--ink); }
.btn.on { background: var(--ink); color: var(--paper); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.ghost { border-color: var(--hairline); color: var(--gray); }
.btn.ghost:hover { border-color: var(--line); color: var(--paper); }

.chip {
  border: 1px solid var(--hairline); padding: 16px 14px;
  font-family: var(--fm); font-size: 10px; letter-spacing: .16em;
}
.chip:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Generate layout ---------- */
.gen { display: grid; grid-template-columns: 1fr 320px; gap: 26px; align-items: start; }

.stage {
  border: 1px solid var(--line);
  background: var(--matte);
  height: clamp(380px, 54vh, 620px);
  position: relative;
  overflow: hidden;
}
.stage figure { height: 100%; display: flex; align-items: center; justify-content: center; padding: 22px; position: relative; }
.stage figure img { max-height: 100%; object-fit: contain; box-shadow: 0 0 0 1px var(--hairline); }
.stage figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px 12px; border-top: 1px solid var(--hairline);
  background: var(--paper); color: var(--gray);
  display: flex; justify-content: space-between; gap: 12px;
}
.stage .clear {
  position: absolute; top: 0; right: 0; width: 34px; height: 34px;
  border-left: 1px solid var(--line); border-bottom: 1px solid var(--line);
  background: var(--paper); font-size: 16px; line-height: 1;
}
.stage .clear:hover { background: var(--ink); color: var(--paper); }

/* empty state (DESIGN_UX_P1 §2) — one primary action, one tab stop */
.stage.is-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; }
.drop { text-align: center; padding: 30px; cursor: pointer; }
.drop:hover { background: var(--hover); }
.drop:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.drop .plus { position: relative; width: 46px; height: 46px; margin: 0 auto 22px; }
.drop .plus::before, .drop .plus::after { content: ''; position: absolute; background: var(--ink); }
.drop .plus::before { left: 50%; top: 0; width: 1px; height: 100%; }
.drop .plus::after { top: 50%; left: 0; height: 1px; width: 100%; }
.drop .drop-t { font-size: 16px; letter-spacing: .02em; }
.drop .drop-s { font-family: var(--fm); font-size: 10px; letter-spacing: .16em; color: var(--gray); margin-top: 8px; text-transform: uppercase; }
/* the visual primary action is a span: no control nested in a control */
.drop .drop-btn { margin-top: 20px; pointer-events: none; }
.drop .drop-meta { margin-top: 18px; display: flex; flex-direction: column; gap: 3px; font-family: var(--fm); font-size: 10px; letter-spacing: .16em; color: var(--gray); text-transform: uppercase; }
.stage.is-empty .samples { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.samples .sample-note { margin: 0; font-size: 12px; line-height: 17px; color: var(--gray); max-width: 46ch; }
.samples .chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.stage.dragover { background: var(--ink); }
.stage.dragover .drop:hover { background: transparent; }
.stage.dragover .drop .plus::before, .stage.dragover .drop .plus::after { background: var(--paper); }
.stage.dragover .drop-t, .stage.dragover .drop-s, .stage.dragover .drop-meta { color: var(--paper); }

/* working state */
.stage .working img { opacity: .92; filter: saturate(.85); }
.scan { position: absolute; z-index: 0; left: 0; right: 0; top: 0; height: 1px; background: var(--ink); opacity: .65; animation: scan 1.7s linear infinite; pointer-events: none; }
.scan-muted { opacity: .2; }
@keyframes scan { to { top: 100%; } }
.status .dot { display: inline-block; width: 8px; height: 8px; background: var(--ink); margin-right: 8px; animation: pulse 1s steps(2) infinite; }

/* failed state */
.failed { text-align: center; padding: 24px; }
.failed .f-t { font-family: var(--fm); font-size: 11px; letter-spacing: .16em; color: var(--fail); text-transform: uppercase; }
.failed .f-s { margin-top: 8px; color: var(--gray); }
.failed .btn { margin-top: 18px; }

/* compare */
.compare { position: absolute; inset: 0; overflow: hidden; cursor: ew-resize; background: var(--matte); }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 22px; }
.compare .im-src-wrap { position: absolute; top: 0; left: 0; bottom: 0; overflow: hidden; border-right: 1px solid var(--ink); }
.compare .im-src-wrap img { max-width: none; }
.compare .c-line { position: absolute; top: 0; bottom: 0; width: 44px; transform: translateX(-50%); cursor: ew-resize; }
.compare .c-line::before { content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%); background: var(--ink); pointer-events: none; }
.compare .c-line i { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 44px; height: 44px; background: transparent; pointer-events: none; }
.compare .c-line i::before { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 13px; height: 13px; background: var(--ink); }
.compare .c-line:focus-visible i { outline: 2px solid var(--paper); box-shadow: 0 0 0 4px var(--ink); }
.compare .tag {
  position: absolute; top: 12px;
  font-family: var(--fm); font-size: 9px; letter-spacing: .14em;
  background: var(--ink); color: var(--paper); padding: 4px 8px;
}
.compare .t-l { left: 12px; } .compare .t-r { right: 12px; }

/* simulated tonal treatments (stand-in for provider output) */
.t-render { filter: contrast(1.07) saturate(1.14) sepia(.07) brightness(1.02); }
.t-eve    { filter: brightness(.84) contrast(1.1) sepia(.32) saturate(1.05); }
.t-tro    { filter: saturate(1.32) contrast(1.05) hue-rotate(6deg); }
.t-light  { filter: brightness(1.12) contrast(.96) saturate(.95); }

/* composer — the command channel (§3.3: it grows, it is still not a chat box) */
.composer {
  margin-top: 14px;
  display: flex; align-items: stretch;
  border: 1px solid var(--line); background: var(--matte);
  min-height: 52px;
}
.composer .c-mark { align-self: flex-start; padding: 17px 4px 0 14px; font-family: var(--fm); color: var(--gray); }
.composer:focus-within { outline: 1px solid var(--line); outline-offset: 2px; }
.composer .btn { border: none; border-left: 1px solid var(--line); height: auto; padding: 0 26px; }

.actions { margin-top: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.actions .sp { flex: 1; }

/* rail */
.rail { border-top: 1px solid var(--line); }
.rail .r-sec { padding: 14px 0; border-bottom: 1px solid var(--hairline); }
.rail label { display: block; font-family: var(--fm); font-size: 10px; letter-spacing: .18em; color: var(--gray); text-transform: uppercase; margin-bottom: 6px; }
.rail input, .rail select {
  width: 100%; border: none; border-bottom: 1px solid var(--hairline);
  padding: 7px 0; font-size: 13px; background: transparent;
}
.rail input:focus, .rail select:focus { outline: none; border-bottom-color: var(--line); }
.rail .hint { font-family: var(--fm); font-size: 10px; letter-spacing: .1em; color: var(--gray); margin-top: 6px; }

.lmini { padding: 14px 0; }
.lmini .l-row { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--hairline); }
.lmini .l-n { font-family: var(--fm); font-size: 11px; letter-spacing: .1em; width: 34px; }
.lmini .l-i { flex: 1; font-size: 12px; color: var(--gray); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lmini .l-i.cur { color: var(--ink); }
.lmini a { font-family: var(--fm); font-size: 10px; letter-spacing: .14em; text-decoration: none; }

/* ---------- Browse / Selected ---------- */
.b-head { display: flex; align-items: center; gap: 0; border-bottom: 1px solid var(--line); margin-bottom: 22px; flex-wrap: wrap; }
.b-head .tab {
  padding: 16px 20px; border-right: 1px solid var(--line);
  font-family: var(--fm); font-size: 11px; letter-spacing: .18em; text-transform: uppercase;
}
.b-head .tab.on { background: var(--ink); color: var(--paper); }
.b-head .sp { flex: 1; }
/* W6-A — the search field owns its own row at every width, so a filter tab
   growing, wrapping or changing count cannot move it. */
.b-filters { display: flex; align-items: center; flex-wrap: wrap; }
.b-search {
  flex: 1 0 100%; display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--hairline);
}
.search-lbl {
  flex: 0 0 auto; font-family: var(--fm); font-size: 10px; letter-spacing: .16em;
  color: var(--ink-2); text-transform: uppercase;
}
.b-head input.search {
  flex: 1 1 auto; min-width: 0; min-height: 44px; border: 1px solid var(--line);
  padding: 0 14px; background: var(--paper);
  font-family: var(--fm); font-size: 11px; letter-spacing: .1em;
}
.b-head input.search:focus { outline: none; background: var(--matte); }
/* W8.5 — the clear control is a sustained-use target, like the tabs beside it. */
.b-search .quiet { min-height: 44px; padding: 0 8px; }

.b-sub { display: flex; align-items: baseline; gap: 16px; margin-bottom: 18px; }
.b-sub .t { font-family: var(--fd); font-weight: 600; font-size: 17px; letter-spacing: .08em; text-transform: uppercase; }

.index-list { border-top: 1px solid var(--line); }
.index-list a {
  display: flex; align-items: baseline; gap: 18px;
  padding: 16px 6px; border-bottom: 1px solid var(--hairline);
  text-decoration: none;
}
.index-list a:hover { background: var(--ink); color: var(--paper); }
.index-list a:hover .dim { color: #9d9b94; }
.index-list .nm { font-family: var(--fd); font-weight: 600; font-size: 16px; letter-spacing: .06em; text-transform: uppercase; }
.index-list .ct { font-family: var(--fm); font-size: 11px; color: var(--gray); letter-spacing: .12em; }

.wall { column-count: 4; column-gap: 18px; }
.card { break-inside: avoid; margin-bottom: 18px; position: relative; border: 1px solid var(--hairline); background: var(--matte); }
.card:hover { border-color: var(--ink); }
.card img { width: 100%; }
.card figcaption { padding: 10px 12px; border-top: 1px solid var(--hairline); display: grid; gap: 3px; }
.card figcaption .b { font-family: var(--fm); font-size: 10px; letter-spacing: .12em; }
.card figcaption .m { font-family: var(--fm); font-size: 10px; letter-spacing: .1em; color: var(--gray); }
.card figcaption .i { font-size: 12px; color: var(--gray); font-style: italic; margin-top: 2px; }
.card .selmark { position: absolute; top: 0; left: 0; width: 12px; height: 12px; background: var(--ink); }
.empty-note { padding: 60px 0; text-align: center; color: var(--gray); }

/* ---------- Detail / lineage ---------- */
.d-head { display: flex; align-items: baseline; gap: 22px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.d-head .back { text-decoration: none; }
.d-head .back:hover { text-decoration: underline; }
.d-head .n { font-family: var(--fm); font-size: 12px; letter-spacing: .2em; }

.lineage {
  display: flex; align-items: flex-start; gap: 0;
  border: 1px solid var(--line); background: var(--matte);
  padding: 16px; margin: 18px 0 22px; overflow-x: auto;
}
/* a chain is a horizontal run; a fan is a vertical stack off a shared spine */
.ln-zone { display: flex; align-items: flex-start; }
.ln-fan { display: flex; flex-direction: column; border-left: 1px solid var(--ink); margin-left: 12px; }
.ln-branch { display: flex; align-items: flex-start; }
.ln-branch + .ln-branch { margin-top: 12px; }
.ln-node { text-align: center; min-width: 108px; }
.ln-node .th {
  width: 96px; height: 72px; margin: 0 auto; overflow: hidden;
  border: 1px solid var(--hairline); display: flex; align-items: center; justify-content: center; background: var(--paper);
}
.ln-node .th.empty { border: 1px solid var(--rule); }
.ln-node .th img { max-width: 100%; max-height: 100%; object-fit: contain; }
.ln-node.cur .th { border: 2px solid var(--ink); }
.ln-node .lb { font-family: var(--fm); font-size: 10px; letter-spacing: .12em; margin-top: 6px; color: var(--gray); }
.ln-node .lb2 { font-family: var(--fm); font-size: 10px; letter-spacing: .12em; margin-top: 2px; color: var(--gray); }
.ln-node.cur .lb, .ln-node.cur .lb2 { color: var(--ink); }
.ln-node a { text-decoration: none; color: inherit; }
.ln-link { display: flex; flex-direction: column; align-items: center; min-width: 110px; padding: 0 6px; align-self: flex-start; margin-top: 24px; }
.ln-link .il { font-family: var(--fm); font-size: 10px; letter-spacing: .08em; color: var(--gray); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px; }
.ln-link .rl { width: 100%; border-top: 1px solid var(--ink); position: relative; }
.ln-link .rl::after { content: ''; position: absolute; right: 0; top: -3px; border-left: 6px solid var(--ink); border-top: 3px solid transparent; border-bottom: 3px solid transparent; }

.d-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 26px; align-items: start; }
/* W4-A — one DOM order at both widths: head, stage, band, meta, rail. The band
   spans the grid beneath the comparison, so desktop reads comparison + meta
   then band, and the phone's single column reads comparison → band → meta.
   Flag 3: DOM order and desktop visual order differ here, deliberately. */
.d-grid > .d-stage { grid-column: 1; grid-row: 1; }
.d-grid > .d-meta { grid-column: 2; grid-row: 1; }
.d-grid > .d-band { grid-column: 1 / -1; grid-row: 2; margin-bottom: 0; }
/* W4-B — the rail is no longer adjacent to the head, so it gets a heading. */
.rail-head {
  font-family: var(--fm); font-size: 11px; letter-spacing: .16em;
  color: var(--ink-2); text-transform: uppercase; margin-bottom: 12px;
}
.d-stage { border: 1px solid var(--line); background: var(--matte); height: clamp(360px, 52vh, 600px); position: relative; overflow: hidden; }
.d-band { margin-bottom: 22px; }
.d-band .rule3 { margin-top: 0; }

.d-meta dl { display: grid; grid-template-columns: 130px 1fr; row-gap: 10px; column-gap: 14px; margin-bottom: 20px; }
.d-meta dt { font-family: var(--fm); font-size: 10px; letter-spacing: .16em; color: var(--gray); text-transform: uppercase; padding-top: 2px; }
.d-meta dd { font-size: 13px; }
.d-meta dd.mono-v { font-family: var(--fm); font-size: 11px; letter-spacing: .08em; }
.d-meta select, .d-meta input { border: none; border-bottom: 1px solid var(--hairline); padding: 10px 0; width: 100%; font-size: 13px; }
.d-meta select:focus, .d-meta input:focus { outline: none; border-bottom-color: var(--line); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .wall { column-count: 3; } }
@media (max-width: 920px) {
  main#view { padding: 18px 16px 90px; }
  header.top { padding: 14px 16px 10px; }
  .brand { font-size: 17px; }
  .top-meta .tagline { display: none; }
  .brand-block .statement { display: none; }
  footer.bot { padding: 12px 16px; }
  .gen { grid-template-columns: 1fr; }
  .stage { height: 52vh; }
  .composer { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; border-left: none; border-right: none; z-index: 5; }
  .d-grid { grid-template-columns: 1fr; }
  .d-grid > .d-stage, .d-grid > .d-meta, .d-grid > .d-band { grid-column: auto; grid-row: auto; }
  .wall { column-count: 2; }
}
/* W1-B — the phone budget. Worst-case intrinsic content is 444px at a
   360px viewport (a running flag plus 4-digit counts), so the three links
   buy the ~92px back by shrinking padding and tracking only at ≤560px.
   Type size (12px), the active ink fill and the counts are untouched, and
   nothing above 560px changes. W1-D: the overflow-x crutch is deleted, not
   narrowed — after this there is nothing left to scroll. */
@media (max-width: 560px) {
  nav.main .spacer { display: none; }
  nav.main a { flex: 1 1 0; justify-content: center; min-width: 0; padding: 13px 4px; letter-spacing: .04em; font-size: 10px; }
  .nav-new { min-width: 54px; padding: 0 8px; }
  .wall { column-count: 1; }
  .d-meta dl { grid-template-columns: 1fr; row-gap: 2px; }
  .d-meta dd { margin-bottom: 10px; }
  /* W6-A — on a phone the label sits above a full-width, ≥44px field that
     spans the whole content width, with CLEAR on the label's row. */
  .b-search { flex-wrap: wrap; gap: 6px 10px; }
  .b-search .search-lbl { order: 1; }
  .b-search .quiet { order: 2; margin-left: auto; }
  .b-head input.search { order: 3; flex: 1 0 100%; width: 100%; min-height: 44px; }
}

/* ============================================================
   T1 — THE CORE LOOP  (DESIGN_T1 §2–§9)
   A plate is a fixed-height media box above a fixed-height caption
   strip. Because the strip is anchored to the plate and not to the
   image, caption baselines line up across unequal aspect ratios.
   ============================================================ */

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.gen { display: block; }
.gen-main { max-width: 1600px; }

.plate-row { display: grid; gap: var(--plate-gap); align-items: start; }
.plate-row.one { grid-template-columns: 1fr; }
.plate-row.two { grid-template-columns: 1fr 1fr; }
.plate-row.dragover .plate { background: var(--hover); }

.plate-col { display: flex; flex-direction: column; min-width: 0; align-self: start; }

/* Above the plate, never inside it (§3). */
.plate-label {
  font-family: var(--fm); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-2); margin-bottom: 8px;
}

.plate { display: flex; flex-direction: column; border: 1px solid var(--ink); background: var(--field); }

.media {
  position: relative; height: var(--media-h); padding: 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--field); overflow: hidden;
}
.media img { max-width: 100%; max-height: 100%; object-fit: contain; }
.media img.dimmed { opacity: .5; }

/* registration marks, 2px, at the top-left and bottom-right corners */
.cm { position: absolute; width: 10px; height: 10px; pointer-events: none; }
.cm-tl { top: 0; left: 0; border-top: 2px solid var(--ink); border-left: 2px solid var(--ink); }
.cm-br { bottom: 0; right: 0; border-bottom: 2px solid var(--ink); border-right: 2px solid var(--ink); }

.cap {
  height: var(--cap-h); flex: 0 0 var(--cap-h);
  border-top: 1px solid var(--rule); background: var(--paper);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 12px; font-family: var(--fm); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink);
}
.cap-l, .cap-r {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cap-r { justify-content: flex-end; }
.cap-meta { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; }
.cap-status .cap-l { flex-direction: column; align-items: flex-start; gap: 1px; }
.cap-l1, .cap-l2 { display: block; line-height: 1.15; }
.cap-l2 { font-size: 10px; color: var(--ink-2); }
.cap .invalid, .cap .fail { color: var(--fail); }

/* quiet actions carry a 44px hit area inside a 34px strip (§9) */
.quiet {
  position: relative; display: inline-flex; align-items: center; min-height: var(--cap-h);
  font-family: var(--fm); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-2); padding: 0 2px;
}
.quiet::after { content: ''; position: absolute; inset: -5px -10px; }
.quiet:hover { color: var(--ink); }
.quiet:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* upload progress rides the bottom edge of the media box (§2) */
.uploadline { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--rule); }
.uploadline i { display: block; height: 1px; background: var(--ink); transition: width .15s linear; }

/* ---------- source preview: decode states, inspection tools (DESIGN_UX_P1) ---------- */
/* the <img> is always emitted so its own load/error events drive the state;
   while decoding or after a preview failure it is hidden behind a mono note */
.media img.awaiting { visibility: hidden; }
.media-note {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 11px; letter-spacing: .16em; color: var(--ink-2);
}
.media-note.fail { color: var(--fail); }
.media { touch-action: pan-y; }
.media.zoomed { touch-action: none; cursor: grab; }
.media.zoomed.panning { cursor: grabbing; }

/* the tool row sits outside the plate figure, so the caption divider is untouched */
.tools {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-top: 8px; font-size: 10px; letter-spacing: .14em;
}
.tools .t-left, .tools .t-right { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tools .t-right { color: var(--ink-2); }
.tools .t-pre { color: var(--ink-2); margin-right: 2px; }
.tools .quiet[aria-pressed="true"] { color: var(--ink); }
/* W8-C — rotation is a view change, and the note says so where the tool is used. */
.rot-note {
  margin-top: 8px; font-family: var(--fm); font-size: 10px;
  letter-spacing: .14em; color: var(--ink-2);
}
.markup-canvas { position: absolute; inset: 16px; width: calc(100% - 32px); height: calc(100% - 32px); z-index: 1; pointer-events: none; }
.markup-canvas.editing { pointer-events: auto; touch-action: none; cursor: crosshair; }
.markup-canvas.editing[data-tool="pen"], .markup-canvas.editing[data-tool="line"] { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M3 21 20 4l1 5L8 22z' fill='white' stroke='%23131311' stroke-width='1.5'/%3E%3C/svg%3E") 3 21, crosshair; }
.markup-status { font-family: var(--fm); font-size: 10px; letter-spacing: .14em; color: var(--ink-2); }
.markup-canvas [data-mark-index].selected { filter: drop-shadow(0 0 2px #111); }
.markup-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.markup-tool { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid transparent; }
.markup-tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.markup-tool:hover, .markup-tool[aria-pressed="true"] { background: var(--hover); border-color: var(--rule); }
.markup-tool[aria-pressed="true"] { box-shadow: inset 0 -2px var(--ink); }
.markup-tool:focus-visible, .markup-done:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.markup-done { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 1px solid var(--rule); }
.markup-done svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.markup-done:hover { background: var(--ink); color: var(--paper); }
.markup-toolbar .mark-note { margin-left: 8px; color: var(--ink-2); }
.markup-caption { color: var(--ink-2); }
.markup-entry { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin: 10px 0; }
.markup-entry .mono { color: var(--ink-2); }

/* ---------- owner provider settings ---------- */
.admin-page { max-width: 760px; }
.admin-head { display: flex; align-items: baseline; gap: 14px; border-bottom: 3px solid var(--ink); padding-bottom: 12px; margin-bottom: 18px; }
.admin-head h1 { margin: 0; font: 500 22px var(--fd); }
.admin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
.admin-field { display: flex; flex-direction: column; gap: 6px; }
.admin-field.full { grid-column: 1 / -1; }
.admin-field label, .admin-note { font: 11px var(--fm); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); }
.admin-field input, .admin-field select { min-height: 44px; padding: 8px 10px; border: 1px solid var(--rule); background: var(--paper); }
.admin-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.admin-status { min-height: 1.4em; color: var(--ink-2); }
.admin-key { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 10px 0; }
@media (max-width: 560px) { .admin-form { grid-template-columns: 1fr; } .admin-field.full,.admin-actions { grid-column: auto; } }

/* ---------- composer: label, head, history, auto-grow (DESIGN_UX_P1 §3) ---------- */
.c-ctx { display: flex; align-items: baseline; gap: 6px; }
.c-lbl { color: var(--ink); }
.c-state { color: var(--ink-2); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-right { margin-left: auto; display: inline-flex; align-items: baseline; gap: 14px; flex: 0 0 auto; }
.c-count { color: var(--ink-2); }
.hist { border-top: 1px solid var(--hairline); max-height: 220px; overflow-y: auto; }
.hist-row {
  display: flex; align-items: baseline; gap: 14px; width: 100%; padding: 16px 2px;
  border: none; border-bottom: 1px solid var(--hairline); background: transparent;
  text-align: left; cursor: pointer; font-family: var(--fd); font-size: 13px; color: var(--ink);
}
.hist-row:hover { background: var(--hover); }
.hist-row:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.hist-row .h-i { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-row .h-n { color: var(--ink-2); font-size: 10px; letter-spacing: .12em; }
.hist-empty { padding: 10px 2px; font-size: 12px; color: var(--ink-2); }
.composer textarea {
  flex: 1; border: none; padding: 15px 12px; font: inherit; font-size: 14px;
  min-width: 0; min-height: 52px; max-height: 122px; resize: none; overflow-y: auto;
  background: transparent; color: var(--ink); line-height: 22px;
}
.composer textarea:focus { outline: none; }
.composer textarea:disabled { color: var(--ink-2); }

.failoverlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.fo-box { background: var(--paper); border: 1px solid var(--ink); padding: 20px 24px; text-align: center; max-width: 420px; }
.fo-1 { font-size: 14px; }
.fo-2 { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.fo-box .btn { margin-top: 16px; }

.instr-line {
  margin-top: 12px; font-family: var(--fm); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rule3 { border-top: 3px solid var(--ink); margin-top: 12px; }

/* One action band on result and detail surfaces. */
.band { display: grid; grid-template-columns: repeat(3, 1fr); }
.band .cell {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  padding: 12px 14px; min-height: 52px; margin: 0; border: none;
  border-right: 1px solid var(--rule); border-radius: 0;
  background: transparent; text-align: left; cursor: pointer;
  font-family: var(--fm); text-transform: uppercase;
}
.band .cell:last-child { border-right: none; }
.band .cl { display: inline-flex; align-items: baseline; font-size: 11px; font-weight: 500; letter-spacing: .16em; color: var(--ink-2); }
.band .cs { font-size: 10px; font-weight: 400; letter-spacing: .14em; color: var(--ink-2); }
.band .mk { font-style: normal; margin-left: 4px; }
.band .cell.primary { background: var(--ink); }
.band .cell.primary .cl, .band .cell.primary .cs { color: var(--paper); }
.band .cell:hover { background: var(--hover); }
.band .cell:hover .cl, .band .cell:hover .cs { color: var(--ink); }
.band .cell.primary:hover { background: transparent; }
.band .cell.primary:hover .cl, .band .cell.primary:hover .cs { color: var(--ink); }
.band .cell:active { background: var(--ink); }
.band .cell:active .cl, .band .cell:active .cs { color: var(--paper); }
.band .cell.primary:active { background: transparent; }
.band .cell.primary:active .cl, .band .cell.primary:active .cs { color: var(--ink); }
.band .cell:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; position: relative; z-index: 2; }
/* must stay last: equal specificity, later wins */
.band .cell[aria-disabled="true"] { background: transparent; cursor: default; }
.band .cell[aria-disabled="true"]:hover, .band .cell[aria-disabled="true"]:active { background: transparent; }
.band .cell[aria-disabled="true"] .cl, .band .cell[aria-disabled="true"] .cs { color: var(--ink-2); }

.composer-bar { border-top: 3px solid var(--ink); margin-top: 12px; }
.c-ctx { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); padding: 8px 0 0; }
.composer input:disabled { color: var(--ink-2); }
main#view { padding-left: var(--gutter); padding-right: var(--gutter); }

.fade { animation: fadein 180ms linear; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.invalid-note { margin-top: 12px; font-family: var(--fm); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--fail); }

@media (max-width: 1199px) {
  :root { --media-h: clamp(320px, 44vh, 480px); --plate-gap: 16px; --gutter: 24px; }
}
/* W8.6 — on the wide desktop the comparison stops being the smaller half. */
@media (min-width: 1400px) {
  .d-grid { grid-template-columns: 2fr 1fr; }
}
/* the prototype floated the composer from 920px down; T1 only does that
   at mobile width, so the 3px rule stays attached to the plate */
@media (max-width: 920px) {
  .composer { position: static; left: auto; right: auto; bottom: auto; z-index: auto; }
}
@media (max-width: 899px) {
  .band { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .band .cell { padding: 10px 8px; border-right: 1px solid var(--rule); }
  .band .cell:last-child { border-right: none; }
  /* the rail turns vertical: indented rows off a 1px spine (§3.6) */
  .lineage { flex-direction: column; }
  .ln-zone { flex-direction: column; align-items: flex-start; }
  .ln-zone > .ln-node { min-width: 0; }
  .ln-zone .ln-link { margin-top: 0; padding-left: 14px; min-width: 0; }
  .ln-zone .ln-link .rl { display: none; }
  .ln-zone .ln-link .il { max-width: none; margin-bottom: 2px; }
}
@media (max-width: 759px) {
  :root { --media-h: clamp(280px, 44vh, 420px); --plate-gap: 16px; --gutter: 16px; --cap-h: 32px; }
  .plate-row.two { grid-template-columns: 1fr; }
  .cap { font-size: 10px; }
  .composer-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--paper); margin: 0;
  }
  .composer { margin-top: 0; border-left: none; border-right: none; }
  /* §3.6 — reserve the composer's MAXIMUM height, so growth never covers
     the plate, the tool row or the caption strip. */
  main#view { padding-bottom: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .scan { animation: none; top: 0; }
  .fade { animation: none; }
  .runflag { animation: none; }
  .status .dot { animation: none; }
  .uploadline i { transition: none; }
}
.gate-box .g-note.fail { color: var(--fail); }
