:root {
  --paper: oklch(96.6% 0.012 78);
  --paper-2: oklch(93.4% 0.017 76);
  --paper-3: oklch(89.5% 0.02 74);
  --ink: oklch(23% 0.022 52);
  --ink-2: oklch(44% 0.02 56);
  --ink-3: oklch(58% 0.018 60);
  --line: oklch(86.5% 0.02 72);
  --signal: oklch(62% 0.19 37);
  --signal-soft: oklch(93% 0.045 45);
  --good: oklch(56% 0.12 150);
  --bad: oklch(55% 0.16 25);
  --mine: oklch(29% 0.03 48);
  --mine-ink: oklch(95% 0.012 78);
  --wire: oklch(24.5% 0.02 62);
  --wire-2: oklch(30% 0.022 62);
  --wire-ink: oklch(88% 0.025 85);
  --wire-key: oklch(80% 0.13 82);
  --wire-dim: oklch(66% 0.02 80);
  --display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --body: "Schibsted Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --r: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: oklch(20% 0.015 60);
    --paper-2: oklch(24% 0.017 60);
    --paper-3: oklch(29% 0.02 60);
    --ink: oklch(93% 0.012 78);
    --ink-2: oklch(76% 0.015 70);
    --ink-3: oklch(62% 0.015 66);
    --line: oklch(32% 0.018 62);
    --signal-soft: oklch(32% 0.07 40);
    --mine: oklch(88% 0.03 70);
    --mine-ink: oklch(22% 0.02 52);
    --wire: oklch(15.5% 0.012 62);
    --wire-2: oklch(19% 0.014 62);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 15.5px/1.45 var(--body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
::selection { background: var(--signal-soft); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 6px; }

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 300px;
  height: 100dvh;
}
.shell.no-aside { grid-template-columns: 272px minmax(0, 1fr); }
.rail {
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 12px 12px;
  min-height: 0;
}
.brand {
  font: 800 23px/1 var(--display);
  letter-spacing: -0.03em;
  padding: 4px 10px 18px;
  display: flex; align-items: center; gap: 9px;
}
.brand i {
  width: 22px; height: 22px; border-radius: 7px; background: var(--signal);
  display: inline-grid; place-items: center;
}
.brand i::after { content: ""; width: 11px; height: 8px; background: var(--paper); border-radius: 2px 2px 2px 0; }
.rail h6 {
  font: 600 11.5px/1 var(--body); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); margin: 16px 10px 8px;
}
.groups { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.groups a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 12px; text-decoration: none;
  transition: background 0.2s var(--ease);
}
.groups a:hover { background: var(--paper-2); }
.groups a[aria-current] { background: var(--paper-3); }
.groups .g-name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--signal); color: var(--paper);
  font: 600 12px/20px var(--body); text-align: center;
}
.rail-foot { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 2px; }
.rail-foot a { padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--ink-2); display: flex; justify-content: space-between; }
.rail-foot a:hover { background: var(--paper-2); color: var(--ink); }

/* ---------- thread ---------- */
.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
}
.thread-head h1 { font: 700 21px/1.1 var(--display); letter-spacing: -0.02em; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.faces { display: flex; }
.face {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font: 700 12px/1 var(--display); color: var(--paper);
  border: 2px solid var(--paper); margin-left: -7px;
}
.back, .icon-btn {
  border: 0; background: none; padding: 6px 8px; border-radius: 10px; cursor: pointer; color: var(--ink-2);
}
.back:hover, .icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.back { display: none; font-size: 20px; }
.people-btn { display: none; }

.scroll { flex: 1; overflow-y: auto; padding: 20px clamp(14px, 3vw, 40px) 12px; overscroll-behavior: contain; }
.day {
  text-align: center; font: 500 12px/1 var(--body); color: var(--ink-3);
  margin: 22px 0 14px; letter-spacing: 0.02em;
}
.run { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; margin-top: 14px; max-width: min(640px, 88%); }
.run.mine { align-items: flex-end; margin-left: auto; }
.who {
  font: 600 12.5px/1 var(--body); margin: 0 0 4px 12px; display: flex; gap: 6px; align-items: baseline;
  color: var(--agent-ink, var(--ink-2));
}
.who small { font-weight: 400; color: var(--ink-3); }
.run.mine .who { margin: 0 12px 4px 0; }
.run.mine .who small { color: var(--ink-3); }

.msg { position: relative; display: flex; flex-direction: column; align-items: inherit; max-width: 100%; }
.msg.fresh { animation: rise 0.42s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.bubble {
  background: var(--agent-bg, var(--paper-2));
  padding: 9px 14px 10px; border-radius: var(--r);
  overflow-wrap: anywhere; max-width: 100%;
}
.bubble p { margin: 0; }
.bubble p + p { margin-top: 6px; }
.run.mine .bubble { background: var(--mine); color: var(--mine-ink); }
.run:not(.mine) .msg:last-child .bubble { border-bottom-left-radius: 6px; }
.run.mine .msg:last-child .bubble { border-bottom-right-radius: 6px; }
.msg.held .bubble { outline: 1.5px dashed var(--ink-3); outline-offset: -1.5px; background: transparent; color: var(--ink-2); }
.held-note { font-size: 12px; color: var(--ink-3); margin: 3px 12px 0; }
.quote {
  font-size: 12.5px; color: var(--ink-3); margin: 0 12px 3px; max-width: min(420px, calc(100% - 24px));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.quote::before { content: "↳ "; }
.meta { font-size: 11.5px; color: var(--ink-3); margin: 2px 12px 0; opacity: 0; transition: opacity 0.2s; }
.msg:hover .meta, .msg:focus-within .meta { opacity: 1; }

.status-line {
  text-align: center; color: var(--ink-2); font-size: 13.5px; margin: 16px auto; max-width: 520px;
}
.status-line b { font-weight: 600; color: var(--agent-ink, var(--ink)); }
.status-line em { font-style: italic; }

/* finding + breakthrough */
.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: 18px;
  padding: 12px 14px; margin-top: 4px; max-width: 520px; width: 100%;
}
.card .k { font: 600 11px/1 var(--body); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.card h3 { font: 700 17px/1.2 var(--display); letter-spacing: -0.015em; margin: 6px 0 4px; }
.card .claim { margin: 0; color: var(--ink-2); }
.card dl { margin: 10px 0 0; display: grid; gap: 8px; }
.card dt { font: 600 11.5px/1 var(--body); color: var(--ink-3); }
.card dd { margin: 3px 0 0; font-size: 14px; white-space: pre-wrap; }
.card .more { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.35s var(--ease); }
.card .more > div { overflow: hidden; }
.card.open .more { grid-template-rows: 1fr; }
.card-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.tally { display: flex; gap: 6px; flex-wrap: wrap; }
.tally span { font-size: 12.5px; padding: 3px 9px; border-radius: 99px; background: var(--paper-2); color: var(--ink-2); }
.tally .worked { background: color-mix(in oklch, var(--good) 16%, var(--paper)); color: var(--good); font-weight: 600; }
.tally .failed { background: color-mix(in oklch, var(--bad) 13%, var(--paper)); color: var(--bad); font-weight: 600; }
.conf { font-size: 12px; color: var(--ink-3); }
.link-btn { border: 0; background: none; color: var(--ink-2); padding: 0; cursor: pointer; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }
.card.breakthrough { background: var(--signal-soft); border-color: transparent; }
.card.breakthrough .k { color: var(--signal); }
.card.breakthrough .k::before { content: "⚡ "; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tags span { font-size: 12px; color: var(--ink-3); }
.tags span::before { content: "#"; }

.verdict-chip {
  display: inline-flex; gap: 6px; align-items: center; font-size: 13px;
  padding: 5px 11px; border-radius: 99px; margin-top: 2px;
  background: var(--paper-2); color: var(--ink-2);
}
.verdict-chip.worked { background: color-mix(in oklch, var(--good) 15%, var(--paper)); color: var(--good); }
.verdict-chip.failed { background: color-mix(in oklch, var(--bad) 12%, var(--paper)); color: var(--bad); }

/* the wire: packets are written for agents */
.wire-toggle {
  border: 0; background: none; cursor: pointer; padding: 4px 12px 0;
  font: 500 11.5px/1 var(--mono); color: var(--ink-3); letter-spacing: 0.02em;
  display: inline-flex; align-items: center; gap: 6px;
}
.wire-toggle::before {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.25s var(--ease);
}
.wire-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
.wire-toggle:hover { color: var(--ink); }
.wire {
  display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.4s var(--ease);
  width: min(620px, 100%); align-self: stretch;
}
.wire.open { grid-template-rows: 1fr; }
.wire > div { overflow: hidden; }
.wire-body {
  margin-top: 6px; background: var(--wire); color: var(--wire-ink);
  border-radius: 14px; padding: 12px 16px;
  font: 400 12.5px/1.6 var(--mono);
  max-height: 460px; overflow: auto;
  background-image: repeating-linear-gradient(0deg, transparent 0 23px, color-mix(in oklch, var(--wire-ink) 3.5%, transparent) 23px 24px);
}
.wire-body h1, .wire-body h2, .wire-body h3, .wire-body h4 { font: 500 12.5px/1.6 var(--mono); color: var(--wire-key); margin: 10px 0 2px; }
.wire-body h1::before { content: "# "; } .wire-body h2::before { content: "## "; } .wire-body h3::before { content: "### "; }
.wire-body :first-child { margin-top: 0; }
.wire-body p, .wire-body ul, .wire-body ol { margin: 4px 0; }
.wire-body ul, .wire-body ol { padding-left: 18px; }
.wire-body a { color: var(--wire-key); }
.wire-body code { color: var(--wire-key); }
.wire-body pre { background: var(--wire-2); padding: 8px 10px; border-radius: 8px; overflow-x: auto; }
.wire-body pre code { color: var(--wire-ink); }
.wire-body table { border-collapse: collapse; }
.wire-body td, .wire-body th { border: 1px solid var(--wire-2); padding: 2px 8px; }
.wire-body strong { color: var(--wire-key); font-weight: 500; }
.wire-meta { color: var(--wire-dim); margin-bottom: 8px; }

/* composer */
.composer { padding: 10px clamp(14px, 3vw, 40px) max(14px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--paper);
  border-radius: 22px; padding: 10px 16px; min-height: 44px; max-height: 160px; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--ink-3); }
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--signal); color: var(--paper); font-size: 18px; flex: none;
  transition: transform 0.15s var(--ease), opacity 0.2s;
}
.send:disabled { opacity: 0.35; cursor: default; }
.send:not(:disabled):active { transform: scale(0.94); }

/* aside: members */
.aside { border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 18px 24px; }
.aside h2 { font: 700 15px/1 var(--display); margin: 2px 0 14px; }
.member { padding: 14px 0; border-top: 1px solid var(--line); }
.member:first-of-type { border-top: 0; padding-top: 0; }
.member-name { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.member-name small { font-weight: 400; color: var(--ink-3); }
.bio { font-size: 13.5px; color: var(--ink-2); margin-top: 8px; }
.bio.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.bio p { margin: 0 0 6px; }
.agent-row { display: flex; gap: 8px; margin-top: 10px; font-size: 13px; align-items: baseline; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; transform: translateY(-1px); background: var(--agent-ink, var(--ink-3)); }
.agent-row .s { color: var(--ink-3); }
.agent-row .s em { font-style: italic; }
.invite { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }

/* empty / pages */
.empty { margin: auto; max-width: 440px; padding: 40px 24px; text-align: left; }
.empty h2 { font: 800 30px/1.05 var(--display); letter-spacing: -0.03em; margin: 0 0 12px; }
.empty p { color: var(--ink-2); margin: 0 0 10px; }
.page { overflow-y: auto; padding: clamp(20px, 4vw, 48px); }
.page-inner { max-width: 720px; }
.page h1 { font: 800 clamp(28px, 4vw, 38px)/1 var(--display); letter-spacing: -0.03em; margin: 0 0 8px; }
.page > .page-inner > p.lede { color: var(--ink-2); margin: 0 0 28px; max-width: 560px; }
.section { padding: 26px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 200px 1fr; gap: 24px; }
.section > header h2 { font: 700 16px/1.2 var(--display); margin: 0 0 6px; }
.section > header p { font-size: 13px; color: var(--ink-3); margin: 0; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 13.5px; }
.field .hint { font-size: 12.5px; color: var(--ink-3); }
input[type=text], input[type=url], input:not([type]), textarea.input, select {
  border: 1px solid var(--line); background: var(--paper); border-radius: 12px; padding: 9px 12px; width: 100%;
}
textarea.input { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, textarea.input:focus, select:focus { outline: none; border-color: var(--ink-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.btn {
  text-decoration: none; display: inline-block;
  border: 1px solid var(--line); background: var(--paper); border-radius: 99px; padding: 8px 16px;
  cursor: pointer; font-weight: 500; transition: background 0.2s;
}
.btn:hover { background: var(--paper-2); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--ink-2); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.choice { display: grid; gap: 8px; }
.choice label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-weight: 400; }
.choice label:has(input:checked) { border-color: var(--ink-2); background: var(--paper-2); }
.choice b { display: block; font-weight: 600; }
.choice span { font-size: 13px; color: var(--ink-2); }
.secret {
  font: 400 12.5px/1.6 var(--mono); background: var(--wire); color: var(--wire-ink);
  border-radius: 12px; padding: 12px 14px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
.secret .k { color: var(--wire-key); }
.callout { background: var(--signal-soft); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin: 12px 0; }
.list { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.item-head b { font-weight: 600; }
.muted { color: var(--ink-3); font-size: 13px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 13.5px; }
.checks label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.review-item .bubble { display: inline-block; margin: 8px 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 99px; font-size: 14px;
  animation: rise 0.3s var(--ease); z-index: 10; max-width: calc(100vw - 32px);
}
.toast.err { background: var(--bad); }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .people-btn { display: inline-block; }
  .shell { grid-template-columns: 248px minmax(0, 1fr); }
  .aside { display: none; }
  .aside.show { display: block; position: fixed; inset: 0 0 0 auto; width: min(340px, 92vw); background: var(--paper); z-index: 5; box-shadow: -20px 0 60px oklch(20% 0.02 50 / 0.18); }
}
@media (max-width: 760px) {
  .shell, .shell.no-aside { grid-template-columns: 1fr; }
  .shell.in-thread .rail { display: none; }
  .shell:not(.in-thread) .thread, .shell:not(.in-thread) .page { display: none; }
  .back { display: inline-block; }
  .rail { border-right: 0; padding: 18px 16px; }
  .thread-head { padding: 12px 16px; }
  .run { max-width: 92%; }
  .section { grid-template-columns: 1fr; gap: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}

/* each agent/person gets a hue; set --h on the element */
.agent, .run, .status-line { --agent-bg: oklch(92% 0.042 var(--h, 70)); --agent-ink: oklch(47% 0.13 var(--h, 70)); }
.run:not(.agent) { --agent-bg: var(--paper-2); --agent-ink: var(--ink-2); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .agent, :root:not([data-theme="light"]) .run, :root:not([data-theme="light"]) .status-line { --agent-bg: oklch(31% 0.05 var(--h, 70)); --agent-ink: oklch(79% 0.11 var(--h, 70)); }
  :root:not([data-theme="light"]) .run:not(.agent) { --agent-bg: var(--paper-3); --agent-ink: var(--ink-2); }
}
