/* Dergbrain console.
 *
 * Visual language follows the Claude Code desktop app: warm neutral surfaces,
 * clay accent, a flowing transcript where tool calls are compact ⏺ / ⎿ rows,
 * and a docked composer.
 *
 * Type stays deliberately large and high contrast — this console is read on a
 * VR display without corrective lenses, so no step below ~15px and no low
 * contrast greys.
 */

:root {
  /* dark is the default surface, like the app */
  --bg: #262624;
  --surface: #30302e;
  --surface-2: #3a3a37;
  --line: #4a4a46;
  --line-soft: #3c3c39;
  --text: #faf9f5;
  --muted: #b4b2ab;
  --accent: #d97757;   /* clay */
  --accent-ink: #1f1e1d;
  --ok: #8fce9b;
  --warn: #e2b344;
  --err: #f08b7d;
  --tool: #c8a6e9;
  --radius: 12px;
  --radius-sm: 8px;
  --sans: system-ui, "Segoe UI", Verdana, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf9f5;
    --surface: #ffffff;
    --surface-2: #f0eee7;
    --line: #d6d3ca;
    --line-soft: #e4e1d9;
    --text: #1f1e1d;
    --muted: #5f5d57;
    --accent: #c15f3c;
    --accent-ink: #ffffff;
    --ok: #1f7a3f;
    --warn: #8a5a00;
    --err: #b3261e;
    --tool: #6b3fbb;
  }
}

* { box-sizing: border-box; }

/* The button/.chip rules below set display, which outranks the UA's
 * [hidden] { display: none } — without this, every hidden button still shows. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 18px;
  line-height: 1.7;
}

h1 { font-size: 1.15rem; margin: 0; font-weight: 650; letter-spacing: .01em; }
h2 { font-size: 1.1rem; margin: 0 0 1rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- app shell ---------- */

.app {
  display: flex;
  height: 100dvh;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- sidebar ---------- */

.sidebar {
  flex: none;
  width: 17.5rem;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  border-right: 1px solid var(--line-soft);
}

/* The brand is the only thing in here now, so there is no gap below it to
   reserve — the old "+ New chat" button used to sit in that space. */
.side-head { padding: .4rem .85rem 0; }

/* The brand IS the new-chat button — there is no separate one. Styled as a
   button (hit target, hover, focus ring) while still reading as the wordmark. */
.brandbtn {
  width: 100%;
  margin: 0;
  /* Slim: the row is only as tall as the wordmark plus a little breathing room.
     Still ~2.1rem tall, which stays comfortably pointable in a headset. */
  padding: .3rem .4rem;
  justify-content: flex-start;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius, .5rem);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.brandbtn:hover {
  background: var(--surface);
  border-color: var(--line);
  filter: none;
}
.brandbtn:focus-visible {
  outline: 2px solid var(--accent, currentColor);
  outline-offset: 2px;
}
.brandbtn h1 { margin: 0; }

.threads {
  flex: 1;
  overflow-y: auto;
  padding: .25rem .6rem 1rem;
}
.threads .group {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  padding: .35rem .65rem;
}
/* The gap belongs BETWEEN groups, not above the first one — a top padding on
   every heading left a dead band under the brand. */
.threads .group:not(:first-child) { margin-top: .65rem; }
.thread {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  padding: .5rem .65rem;
  margin-bottom: .1rem;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}
.thread:hover { background: var(--surface); filter: none; }
.thread.active { background: var(--surface); border: 1px solid var(--line); }
.thread .t {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .95rem;
  line-height: 1.5;
}
.thread .s {
  display: block;
  font-size: .75rem;
  color: var(--muted);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* a thread still working shows the same pulsing dot as the status pill */
.thread .s.live::before {
  content: "";
  display: inline-block;
  width: .45rem;
  height: .45rem;
  margin-right: .35rem;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
.thread .s.bad { color: var(--err); }

/* the ⋯ handle: right-click works, but a menu you can only reach with a right
 * mouse button is a menu half the devices here cannot open */
.threadrow { position: relative; }
.threadrow .thread { padding-right: 2.1rem; }
.kebab {
  position: absolute;
  top: 50%;
  right: .3rem;
  transform: translateY(-50%);
  padding: .1rem .45rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.2;
  opacity: 0;
}
.threadrow:hover .kebab, .kebab:focus-visible { opacity: 1; }
.kebab:hover { background: var(--surface-2); color: var(--text); filter: none; }

/* Touch has no hover: leave the handle visible there, or the menu is
 * unreachable (long-press does not fire contextmenu everywhere). */
@media (hover: none) {
  .kebab { opacity: .8; }
}

.menu {
  position: fixed;
  z-index: 20;
  min-width: 10rem;
  padding: .3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
}
.menu button {
  justify-content: flex-start;
  background: transparent;
  color: var(--text);
  border: 0;
  font-weight: 500;
  font-size: .95rem;
  padding: .45rem .6rem;
  border-radius: 6px;
}
.menu button:hover { background: var(--surface-2); filter: none; }
.menu button.bad { color: var(--err); }
.menu button.bad:hover { background: color-mix(in srgb, var(--err) 14%, transparent); }
.threads .empty { color: var(--muted); font-size: .85rem; padding: .5rem .65rem; }

.side-foot {
  display: flex;
  gap: .5rem;
  padding: .75rem .85rem 1rem;
  border-top: 1px solid var(--line-soft);
}

/* Passkeys + sign out: icons, side by side. The label is carried by title and
   aria-label — an icon on its own is a guess, so keep both. */
.side-foot .footicon {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Generous hit target: this is also used in a VR headset browser, where
     pointing is far less precise than a mouse. */
  min-height: 2.75rem;
  padding: .5rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius, .5rem);
  cursor: pointer;
}
.side-foot .footicon:hover {
  color: var(--text);
  background: var(--surface-2);
  filter: none;
}
.side-foot .footicon:focus-visible {
  outline: 2px solid var(--accent, currentColor);
  outline-offset: 2px;
}
.side-foot .footicon svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 8;
  background: rgba(0, 0, 0, .5);
  border: 0;
  padding: 0;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.25rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
  flex: none;
}
.titlebox { flex: 1; min-width: 0; }
.threadtitle {
  font-weight: 650;
  font-size: 1rem;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon {
  display: none;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  padding: .3rem .6rem;
}

.brand { display: flex; align-items: center; gap: .6rem; }
.brand .spark {
  width: 1.1rem;
  height: 1.1rem;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  scrollbar-gutter: stable;
}
.wrap { max-width: 56rem; margin: 0 auto; padding: 1.5rem 1.25rem 2rem; }

/* ---------- narrow screens: sidebar becomes a drawer ---------- */

@media (max-width: 60rem) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 9;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: none; }
  .backdrop:not([hidden]) { display: block; }
  .icon { display: inline-flex; }
}

/* ---------- buttons ---------- */

button, .ghost {
  font: inherit;
  font-weight: 600;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
button:hover { filter: brightness(1.08); }
button[disabled] { opacity: .5; cursor: not-allowed; filter: none; }

.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
.ghost:hover { background: var(--surface-2); filter: none; }

.danger { background: transparent; color: var(--err); border-color: var(--err); }
.danger:hover { background: color-mix(in srgb, var(--err) 14%, transparent); filter: none; }

/* ---------- login ---------- */

.login {
  max-width: 24rem;
  margin: 14vh auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login .brand { justify-content: center; margin-bottom: 1.5rem; }
.login button { width: 100%; justify-content: center; margin-top: 1rem; }
.login label { display: block; margin-bottom: .4rem; font-weight: 600; }

input[type=password], select, textarea {
  width: 100%;
  padding: .6rem .7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.error { color: var(--err); font-weight: 600; margin: .75rem 0 0; }
.muted { color: var(--muted); font-size: .92rem; }
.login .muted { margin: 0 0 1rem; }
.login code {
  font-family: var(--mono);
  font-size: .82rem;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: .15em .4em;
  overflow-wrap: anywhere;
}
.gate { font-size: 1.1rem; margin: 0 0 .5rem; }
.wide { width: 100%; justify-content: center; }
.login .wide { margin-top: .5rem; }
.login label { display: block; margin: 1rem 0 .4rem; font-weight: 600; }
input[type=text] {
  width: 100%;
  padding: .6rem .7rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

/* ---------- passkeys ---------- */

.keylist { list-style: none; padding: 0; margin: 1rem 0; }
.keylist li {
  display: flex;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: .8rem 1rem;
  margin-bottom: .5rem;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}
.keylist .t { font-weight: 600; }
.keylist .s { color: var(--muted); font-size: .8rem; font-family: var(--mono); }
.keyacts { display: flex; gap: .4rem; }
.keyacts .ghost { font-size: .85rem; padding: .3rem .7rem; }
.ghost.bad { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
.ghost.bad:hover { background: color-mix(in srgb, var(--err) 12%, transparent); }

.invitebox {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.invitebox input {
  font-family: var(--mono);
  font-size: .8rem;
  margin: .5rem 0;
}

/* A passkey you did not add is the alarm worth ringing. */
.alertbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: .9rem 1.1rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--warn);
  border-left: 4px solid var(--warn);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  font-size: .92rem;
}
.alertactions { display: flex; gap: .5rem; }

/* ---------- composer ---------- */

/* An empty new chat floats its composer, rather than pinning it to the top of
 * a blank page. */
#composer { margin-top: 10vh; }
.greeting {
  font-size: 1.5rem;
  font-weight: 500;
  text-align: center;
  color: var(--text);
  margin: 0 0 1.25rem;
}
.greeting::first-letter { color: var(--accent); }

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .5rem .5rem .5rem;
  transition: border-color .12s ease;
}
.composer:focus-within { border-color: var(--accent); }
.composer.over { border-color: var(--accent); border-style: dashed; }

.composer textarea {
  border: 0;
  background: transparent;
  padding: .6rem .65rem;
  resize: none;
  min-height: 3.4rem;
  max-height: 40vh;
  overflow-y: auto;
}
.composer textarea:focus-visible { outline: none; }
.composer textarea::placeholder { color: var(--muted); }

.composer-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  padding: .25rem .35rem 0;
}
.composer-bar .spacer { flex: 1; }

/* chip = the small pill controls along the composer footer */
.chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .3rem .7rem;
  cursor: pointer;
  max-width: 100%;
}
.chip:hover { background: var(--surface-2); color: var(--text); filter: none; }
select.chip {
  width: auto;
  appearance: none;
  padding-right: 1.6rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right .75rem center, right .55rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}
.send { border-radius: 999px; padding: .45rem 1.1rem; }

/* Attachment chips — in the composer, and echoed under the user's turn. */
.filelist { list-style: none; padding: 0; margin: 0 0 .35rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.filelist li {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-family: var(--mono);
  font-size: .8rem;
  padding: .25rem .6rem;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  color: var(--muted);
}
.turn .filelist { margin: .5rem 0 0; }
.turn .filelist li { background: var(--bg); }

input[type=file] { display: none; }

.notice {
  margin: .9rem .25rem 0;
  color: var(--muted);
  font-size: .85rem;
  display: flex;
  gap: .5rem;
  align-items: baseline;
}
.notice::before { content: "⚠"; color: var(--warn); }

/* dock = the follow-up composer pinned under the transcript */
.dock {
  flex: none;
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
  padding: .85rem 1.25rem 1.1rem;
}
.dock .inner { max-width: 56rem; margin: 0 auto; }
.dock textarea { min-height: 2.4rem; }

/* ---------- run view ---------- */

.runmeta, .dockmeta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dockmeta { padding-left: .35rem; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-weight: 650;
  font-size: .78rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .25rem .7rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge::before {
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: currentColor;
}
.badge.running, .badge.queued, .badge.starting, .badge.reconnecting {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
.badge.running::before { animation: pulse 1.1s ease-in-out infinite; }
.badge.done { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.badge.error, .badge.cancelled { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* ---------- transcript ---------- */

.timeline { display: flex; flex-direction: column; gap: 1.1rem; padding-bottom: 1rem; }

/* your turn: a quiet card, like the desktop app's echoed prompt */
.turn.user {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: .8rem 1rem;
}
.turn.user .who { color: var(--accent); }

/* Claude's turn: unboxed prose, the way the app renders it */
.turn.assistant { padding: 0 .1rem; }
.turn.live .body::after {
  content: "▍";
  color: var(--accent);
  animation: pulse 1s steps(2) infinite;
}
.turn.final {
  border-top: 1px solid var(--line-soft);
  padding-top: 1rem;
}
.turn.fail {
  border-left: 3px solid var(--err);
  padding: .8rem 1rem;
  background: color-mix(in srgb, var(--err) 8%, transparent);
  border-radius: var(--radius-sm);
}
.turn.fail .who { color: var(--err); }

.who {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: .3rem;
}

.body { overflow-wrap: anywhere; }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 .7rem; white-space: pre-wrap; }
.body .h { display: block; margin: 1rem 0 .3rem; font-weight: 700; }
.body ul { margin: 0 0 .7rem; padding-left: 1.3rem; }
.body li { margin-bottom: .2rem; }
.body code {
  font-family: var(--mono);
  font-size: .88em;
  background: var(--surface-2);
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  padding: .05em .35em;
}
.body pre {
  font-family: var(--mono);
  font-size: .84rem;
  line-height: 1.6;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: .8rem .9rem;
  margin: 0 0 .7rem;
  overflow-x: auto;
}
.body pre code { background: none; border: 0; padding: 0; font-size: 1em; }

/* thinking */
details.think { margin: .2rem 0 .7rem; }
details.think summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  font-style: italic;
  list-style: none;
}
details.think summary::before { content: "✧ "; color: var(--tool); }
details.think .think-body {
  margin: .5rem 0 0;
  padding-left: .9rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: .92rem;
  white-space: pre-wrap;
}

/* tool call: a dot-marked head with the result hanging off an elbow beneath —
 * the desktop transcript's shape. Both marks are drawn in CSS, not typed as
 * ⏺ / ⎿, because those code points are missing from a lot of font stacks and
 * fall back to tofu. */
.tool { font-size: .95rem; }

.tool-call summary {
  display: flex;
  gap: .55rem;
  align-items: baseline;
  overflow-wrap: anywhere;
  cursor: pointer;
  list-style: none;
}
.tool-call summary::-webkit-details-marker { display: none; }
.tool-call summary:hover .name { color: var(--tool); }

.dot {
  flex: none;
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: var(--tool);
  transform: translateY(-.1rem);
}
.tool-call .call { font-family: var(--mono); font-size: .86rem; }
.tool-call .name { color: var(--text); font-weight: 700; }
.tool-call .arg { color: var(--muted); }
.tool-call > pre {
  margin: .4rem 0 0 1.1rem;
  padding: .6rem .75rem;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: .8rem;
  max-height: 18rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--muted);
}

.tool-body { padding-left: 1.1rem; margin-top: .15rem; }
.tool-out {
  display: flex;
  gap: .55rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: .82rem;
}
.tool-out .elbow {
  flex: none;
  width: .55rem;
  height: .7rem;
  margin-top: .15rem;
  border-left: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  border-bottom-left-radius: 4px;
}
.tool-out > *:not(.elbow) { min-width: 0; }
.tool-out.fail { color: var(--err); }
.tool-out pre, details.tool-more pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
}
details.tool-more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .8rem;
  font-family: var(--mono);
}
details.tool-more pre {
  margin-top: .4rem;
  padding: .6rem .75rem;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  max-height: 24rem;
  overflow: auto;
  font-size: .82rem;
}
details.tool-more[open] summary { margin-bottom: .1rem; }

.usage {
  color: var(--muted);
  font-family: var(--mono);
  font-size: .78rem;
  padding-top: .25rem;
}

/* A turn boundary inside a reopened thread — the transcript can hold several
 * jobs, so give the eye a rule between them. */
.turn.user + .turn, .usage + .turn.user { margin-top: .2rem; }
.turn.user { margin-top: .4rem; }
