:root {
  --paper: #F5F2FB; --surface: #FFFFFF; --surface-2: #ECE7F7; --surface-3: #E2DAF3;
  --ink: #241A47; --ink-2: #4A4270; --muted: #7A7394;
  --rule: #E1DAF0; --rule-2: #CBC0E6;
  --primary: #5B3DF5; --primary-ink: #3D23C9; --primary-soft: #EAE4FF;
  --ax-opening: #F25C4B; --ax-compression: #E89A12; --ax-stance: #1FA870; --ax-distance: #3A86E8;
  --li: #0A66C2; --ig: #E1306C; --ss: #FF6719;
  --ok: #1F9D6A; --warn: #B7791F; --fail: #D6336C;
  --ok-soft: #DDF5EA; --warn-soft: #FBEED2; --fail-soft: #FBE0EA;
  --shadow: 0 10px 30px -18px rgba(36, 26, 71, 0.45);
  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --display: "Bricolage Grotesque", "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15112A; --surface: #1E1837; --surface-2: #271F46; --surface-3: #302755;
    --ink: #F0EBFB; --ink-2: #CBC3E7; --muted: #8F88B1;
    --rule: #352C5A; --rule-2: #473C72;
    --primary: #9B86FF; --primary-ink: #BDAEFF; --primary-soft: #2B2359;
    --ax-opening: #FF8A7A; --ax-compression: #FFB94A; --ax-stance: #3FD39A; --ax-distance: #6FADFF;
    --li: #5AA3F0; --ig: #F06292; --ss: #FF8A4C;
    --ok: #3FD39A; --warn: #FFB94A; --fail: #FF6B9A;
    --ok-soft: #173A2D; --warn-soft: #3B2E14; --fail-soft: #3E1A2B;
    --shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.8);
  }
}
:root[data-theme="dark"] {
  --paper: #15112A; --surface: #1E1837; --surface-2: #271F46; --surface-3: #302755;
  --ink: #F0EBFB; --ink-2: #CBC3E7; --muted: #8F88B1;
  --rule: #352C5A; --rule-2: #473C72;
  --primary: #9B86FF; --primary-ink: #BDAEFF; --primary-soft: #2B2359;
  --ax-opening: #FF8A7A; --ax-compression: #FFB94A; --ax-stance: #3FD39A; --ax-distance: #6FADFF;
  --li: #5AA3F0; --ig: #F06292; --ss: #FF8A4C;
  --ok: #3FD39A; --warn: #FFB94A; --fail: #FF6B9A;
  --ok-soft: #173A2D; --warn-soft: #3B2E14; --fail-soft: #3E1A2B;
  --shadow: 0 10px 30px -18px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.55 var(--sans); min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-family: var(--display); font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.tnum { font-variant-numeric: tabular-nums; }

/* top bar, with the hue legend as a band beneath it */
.bar {
  position: sticky; top: 0; z-index: 5; background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.65rem 1.25rem; border-bottom: 1px solid var(--rule);
}
.bar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px;
  background: linear-gradient(90deg, var(--ax-opening), var(--ax-compression), var(--ax-stance), var(--ax-distance));
}
.brand { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.wordmark { font-family: var(--display); font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; }
.engine { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.86rem; color: var(--muted); }
.model-pick {
  border: 1px solid var(--rule-2); background: var(--primary-soft); color: var(--primary-ink);
  border-radius: 999px; padding: 0.15rem 0.7rem; font-weight: 600; font-size: 0.86rem; cursor: pointer;
}
.bar-right { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.bar-sep { width: 1px; height: 1.4rem; background: var(--rule-2); margin: 0 0.3rem; }

/* three panes */
.cols { display: grid; grid-template-columns: minmax(0, 21rem) minmax(0, 1fr) minmax(0, 23.5rem); min-height: calc(100vh - 3.4rem); }
.cols.rail-closed { grid-template-columns: minmax(0, 21rem) minmax(0, 1fr) 2.9rem; }
.rail.closed { padding: 0.9rem 0.45rem; }
.rail-open {
  writing-mode: vertical-rl; transform: rotate(180deg); border: 1px solid var(--rule-2); background: var(--primary-soft);
  color: var(--primary-ink); border-radius: 999px; padding: 0.8rem 0.35rem; font-weight: 600; cursor: pointer; font-size: 0.86rem;
}
.title.editable { cursor: text; border-radius: 8px; }
.title.editable:hover { background: var(--primary-soft); }
.pane { padding: 1.25rem 1.25rem 3rem; min-width: 0; }
.pane.work { background: var(--surface); border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }
@media (max-width: 1180px) {
  .cols, .cols.rail-closed { grid-template-columns: minmax(0, 1fr); }
  .rail-open { writing-mode: horizontal-tb; transform: none; padding: 0.4rem 0.9rem; }
  .pane.work { border: none; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
}

/* controls */
.btn {
  border: 1px solid transparent; background: var(--primary); color: #fff;
  padding: 0.5rem 1.05rem; border-radius: 999px; cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.ghost { background: transparent; color: var(--primary-ink); border-color: var(--rule-2); }
.btn.quiet { background: var(--primary-soft); color: var(--primary-ink); }
.btn.tiny { padding: 0.25rem 0.75rem; font-size: 0.84rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.select, .input, textarea { border: 1px solid var(--rule-2); background: var(--surface); border-radius: 10px; padding: 0.5rem 0.7rem; width: 100%; }
.select { width: auto; border-radius: 999px; padding: 0.35rem 0.9rem; background: var(--surface); }
textarea { resize: vertical; line-height: 1.6; }
label.lbl { display: block; font-weight: 600; color: var(--ink-2); margin: 1.1rem 0 0.35rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 0.6rem; }
.card { border: 1px solid var(--rule); background: var(--surface); padding: 0.9rem 1rem; border-radius: 14px; }
.pane.work .card { background: var(--paper); }
details > summary { cursor: pointer; color: var(--ink-2); }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }
.hint { font-size: 0.86rem; color: var(--muted); margin-top: 0.45rem; }
.empty { color: var(--muted); border: 1px dashed var(--rule-2); padding: 1.1rem 1.2rem; border-radius: 14px; background: var(--surface); }
.pane.work .empty { background: var(--paper); }
.progress { color: var(--primary-ink); font-size: 0.9rem; font-weight: 600; }

/* chips: status by colour, tags by axis */
.chip {
  display: inline-flex; align-items: center; gap: 0.3em; padding: 0.12em 0.65em;
  border-radius: 999px; font-size: 0.78rem; font-weight: 500;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap; max-width: 100%;
}
.chip.pass { background: var(--ok-soft); color: var(--ok); }
.chip.fail { background: var(--fail-soft); color: var(--fail); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: var(--surface-2); color: var(--muted); }
.chip.accent { background: var(--primary-soft); color: var(--primary-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips.wrap .chip { white-space: normal; line-height: 1.35; padding: 0.22em 0.7em; }
.tags { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; }
.ax {
  display: inline-flex; padding: 0.1em 0.6em; border-radius: 999px; font-size: 0.76rem; font-weight: 600;
  color: color-mix(in srgb, var(--ax) 62%, var(--ink)); background: color-mix(in srgb, var(--ax) 16%, var(--surface));
}
.ax-opening { --ax: var(--ax-opening); } .ax-compression { --ax: var(--ax-compression); }
.ax-stance { --ax: var(--ax-stance); } .ax-distance { --ax: var(--ax-distance); }
.pill { font-size: 0.72rem; padding: 0.08em 0.55em; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.pill.creator { background: var(--primary-soft); color: var(--primary-ink); }
.pill.mined { background: var(--warn-soft); color: var(--warn); }
.pill.occasion { background: transparent; border: 1px dashed var(--rule-2); }

/* piece pane */
.pane h2.title { font-size: 1.35rem; }
.claims li { margin: 0.25rem 0; }
.claims .supported::marker { color: var(--ok); }
.claims .absent { color: var(--muted); }
.claims .contradicted { color: var(--fail); }
.x { border: none; background: none; color: var(--muted); cursor: pointer; padding: 0 0.25rem; border-radius: 6px; font-size: 1rem; line-height: 1; }
.x:hover { color: var(--fail); background: var(--fail-soft); }

/* work pane */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--rule); margin-bottom: 1.1rem; }
.tab {
  --pc: var(--muted); padding: 0.55rem 0.9rem; border: none; background: none; cursor: pointer; color: var(--muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px; display: flex; gap: 0.5rem; align-items: center; font-weight: 600;
}
.tab .mark { width: 0.7rem; height: 0.7rem; border-radius: 3px; background: var(--pc); opacity: 0.35; }
.tab.has .mark { opacity: 1; }
.tab.active { color: var(--ink); border-bottom-color: var(--pc); }
.tab .state { font-weight: 500; font-size: 0.78rem; color: var(--muted); }
.rules { margin: -0.5rem 0 1rem; font-size: 0.86rem; color: var(--muted); }
.rules summary { color: var(--muted); }
.rules summary:hover { color: var(--ink-2); }
.rules-body { margin-top: 0.6rem; padding: 0.9rem 1rem; border: 1px dashed var(--rule-2); border-radius: 14px; display: grid; gap: 0.7rem; color: var(--ink-2); }
.rules .rule b { display: block; font-weight: 600; margin-bottom: 0.15rem; color: var(--ink); }
.rules ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.rules a { color: var(--primary-ink); }
.rules .craft { border-top: 1px dashed var(--rule-2); padding-top: 0.7rem; }
.stage-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.axis-name { font-family: var(--display); font-size: 1.3rem; font-weight: 600; letter-spacing: -0.01em; }
.spread { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0.8rem; }
.cand { border: 1px solid var(--rule); background: var(--paper); border-radius: 14px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.cand.dropped { opacity: 0.55; }
.cand-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; flex-wrap: wrap; padding: 0.7rem 0.85rem; background: var(--surface-2); }
.cand .fields { padding: 0.7rem 0.85rem 0; }
.cand .fields .t { font-family: var(--display); font-weight: 600; font-size: 1.05rem; }
.cand .body { padding: 0.7rem 0.85rem; max-height: 22rem; overflow: auto; font-size: 0.93rem; }
.cand .body.streaming::after { content: "▍"; color: var(--primary); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cand-foot { padding: 0.6rem 0.85rem 0.8rem; border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: 0.5rem; margin-top: auto; }
.fold { font-size: 0.8rem; color: var(--muted); }
.fold b { color: var(--ink-2); font-weight: 600; }

.editor textarea { min-height: 20rem; font-size: 1rem; line-height: 1.65; padding: 1rem 1.1rem; border-radius: 14px; }
.editor .input { margin-bottom: 0.45rem; }
.toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin: 0.7rem 0; }
.toolbar .sep { flex: 1; }
.note-box { display: flex; gap: 0.5rem; align-items: center; margin: 0.4rem 0; }
.note-box[hidden] { display: none; }
.proposal { border-left: 4px solid var(--warn); }
.proposal .viol { margin: 0.4rem 0; font-size: 0.9rem; }
.proposal .viol b { color: var(--warn); }
.shipped-note { color: var(--ok); font-weight: 600; }

.gate { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: 0.8rem; margin-top: 1rem; }
.gate .card { border-top: 4px solid var(--rule-2); }
.gate .card.faith { border-top-color: var(--ok); }
.gate .card.faith.bad { border-top-color: var(--fail); }
.gate .card.voice { border-top-color: var(--primary); }
.gate h4 { font-size: 0.95rem; margin-bottom: 0.45rem; }
.gate .big { font-family: var(--display); font-size: 1.7rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.gate .locked { color: var(--muted); font-size: 0.88rem; }
.bar-scale { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; margin: 0.6rem 0 0.3rem; overflow: hidden; }
.bar-scale .fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(90deg, var(--ax-distance), var(--primary)); border-radius: 4px; }
.scale-labels { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--muted); }
.signals { margin-top: 1.1rem; }
.signals ul { padding-left: 0; list-style: none; margin: 0.4rem 0 0; }
.signals li { font-size: 0.88rem; margin: 0.35rem 0; display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.signals .k { font-size: 0.72rem; font-weight: 700; padding: 0.05em 0.55em; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.signals .k.picked { background: var(--primary-soft); color: var(--primary-ink); }
.signals .k.rewrote { background: color-mix(in srgb, var(--ax-opening) 16%, var(--surface)); color: color-mix(in srgb, var(--ax-opening) 62%, var(--ink)); }
.signals .k.annotated { background: var(--warn-soft); color: var(--warn); }
.signals .k.shipped { background: var(--ok-soft); color: var(--ok); }
.del { text-decoration: line-through; color: var(--fail); }
.ins { color: var(--ok); }

/* profile rail */
.rail h2 { font-size: 1.35rem; }
.rail-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.sec { margin-top: 1.2rem; }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--rule); padding-bottom: 0.3rem; }
.sec-h .x { color: var(--primary-ink); }
.line { display: grid; grid-template-columns: 0.65rem minmax(0, 1fr) auto; gap: 0.55rem; align-items: start; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); font-size: 0.9rem; }
.line .conf { width: 0.6rem; height: 0.6rem; border-radius: 50%; margin-top: 0.45rem; background: var(--primary); }
.line .conf.mid { opacity: 0.5; }
.line .conf.low { background: transparent; border: 2px solid var(--warn); }
.line .txt { cursor: text; border-radius: 6px; }
.line .txt:hover { background: var(--primary-soft); }
.line .txt input { width: 100%; }
.line .tags { align-items: center; }
.line .ev { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; }
.add-line { margin-top: 0.4rem; }
.mine .prop { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.5rem; align-items: start; margin: 0.45rem 0; font-size: 0.9rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.4rem; z-index: 20; }
.toast { background: var(--ink); color: var(--paper); padding: 0.6rem 0.9rem; border-radius: 12px; font-size: 0.88rem; max-width: 26rem; box-shadow: var(--shadow); }
.toast.err { background: var(--fail); color: #fff; }
@media (prefers-reduced-motion: reduce) { .cand .body.streaming::after { animation: none; } .btn:hover { filter: none; } }

/* sign-in page: the card is the only thing on the paper */
.login { display: grid; place-items: center; min-height: calc(100vh - 3.4rem); padding: 1.25rem; }
.login-card { width: min(100%, 22rem); box-shadow: var(--shadow); padding: 1.6rem 1.5rem 1.5rem; }
.login-card h1 { font-size: 1.7rem; }
.login-card .muted { margin: 0.5rem 0 0; }
.login-card .stack { margin-top: 1.3rem; }
.login-card .btn { display: block; text-align: center; text-decoration: none; }
.btn.li { background: var(--li); }
.login-error { color: var(--fail); margin: 0.8rem 0 0; }
