/* WeaverOS — Athena chat.
 *
 * Layers, lowest to highest precedence. Later layers win regardless of
 * selector specificity, so a component rule never has to fight a base rule.
 *   tokens      design decisions as custom properties (the only place hex lives)
 *   base        element defaults
 *   layout      app shell: conversations rail, thread, composer, drawers
 *   components  messages, prose, composer parts, vitals, cards
 *   states      streaming, voice, recording, open/closed, empty
 *   responsive  narrow-screen and input-mode adjustments
 *
 * A future light theme is a second `:root[data-theme="light"]` block in
 * `tokens`; nothing below reads a raw color.
 */
@layer tokens, base, layout, components, states, responsive;

/* ── Tokens ─────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    color-scheme: dark;

    /* Tokyo Night — shared with /architecture and the site chrome. */
    --night:    #1a1b26;
    --raised:   #1f2335;
    --raised-2: #24283b;
    --sunk:     #16161e;
    --line:     #2f3549;
    --line-2:   #3b4261;
    --ink:      #c0caf5;
    --ink-2:    #a9b1d6;
    --ink-3:    #7f88b0;   /* 5:1 on --night: the floor for any readable text */
    --cyan:     #7dcfff;
    --blue:     #7aa2f7;
    --violet:   #9d7cd8;
    --magenta:  #bb9af7;
    --teal:     #73daca;
    --green:    #9ece6a;
    --yellow:   #e0af68;
    --orange:   #ff9e64;
    --red:      #f7768e;

    --accent:   var(--cyan);
    --you:      color-mix(in oklab, var(--magenta) 11%, var(--raised));
    --you-edge: color-mix(in oklab, var(--magenta) 24%, var(--line));

    /* Legacy names read by the shared site chrome. */
    --base03: var(--night);
    --base02: var(--raised);
    --base01: #414868;
    --base0:  var(--ink-2);
    --base1:  var(--ink);
    --base2:  var(--ink);

    --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
    --mono:  'JetBrains Mono', ui-monospace, Menlo, monospace;

    /* Type scale: her prose sets the rhythm; everything else keys off it. */
    --fs-prose: 1.1875rem;   /* 19px */
    --lh-prose: 1.62;
    --fs-you:   1.0625rem;
    --fs-ui:    0.9375rem;
    --fs-small: 0.8125rem;
    --fs-code:  0.84em;

    --measure:  40rem;        /* ~68 characters of her prose */
    --column:   46rem;        /* thread + composer width */
    --rail:     17.5rem;
    --drawer:   24rem;

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-pill: 999px;

    --ease-out: cubic-bezier(0.2, 0.7, 0.1, 1);
    --t-fast: 140ms;
    --t-panel: 260ms;

    --shadow-panel: 0 24px 60px -24px rgb(0 0 0 / 0.7);

    /* Wing hues: which part of memory a reply drew on. */
    --wing-cyan: var(--cyan);   --wing-violet: var(--violet); --wing-magenta: var(--magenta);
    --wing-gold: var(--yellow); --wing-blue: var(--blue);     --wing-indigo: var(--violet);
    --wing-amber: var(--orange); --wing-rose: var(--red);     --wing-teal: var(--teal);
  }

  @media (prefers-contrast: more) {
    :root { --ink-2: var(--ink); --ink-3: #a9b1d6; --line: #414868; }
  }
}

/* ── Base ───────────────────────────────────────────────────────────── */
@layer base {
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  html, body { height: 100%; }
  body {
    background: var(--night);
    color: var(--ink-2);
    font-family: var(--serif);
    font-optical-sizing: auto;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow: hidden;
  }
  button, input, textarea { font: inherit; color: inherit; }
  button { background: none; border: 0; cursor: pointer; }
  a { color: var(--cyan); text-underline-offset: 3px; text-decoration-color: color-mix(in oklab, var(--cyan) 45%, transparent); }
  a:hover { text-decoration-color: var(--cyan); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
  ::selection { background: color-mix(in oklab, var(--violet) 55%, transparent); color: var(--ink); }
  [hidden] { display: none !important; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
  }
}

/* ── Layout ─────────────────────────────────────────────────────────── */
@layer layout {
  /* Ambient flower-of-life field. Identity on the empty screen; once a
     conversation is open it recedes and a reading band covers the column. */
  .backdrop {
    position: fixed; inset: 0; z-index: 0;
    overflow: hidden; pointer-events: none;
    background: var(--night);
    transition: opacity 600ms ease;
  }
  .backdrop .lattice {
    position: absolute; inset: 0;
    -webkit-mask: var(--lattice) 0 0 / 66px 114.32px repeat;
            mask: var(--lattice) 0 0 / 66px 114.32px repeat;
    --lattice: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 66 114.32'%3E%3Cg fill='none' stroke='white' stroke-opacity='0.30' stroke-width='1'%3E%3Ccircle cx='-33' cy='-57.1577' r='66'/%3E%3Ccircle cx='33' cy='-57.1577' r='66'/%3E%3Ccircle cx='99' cy='-57.1577' r='66'/%3E%3Ccircle cx='-66' cy='0' r='66'/%3E%3Ccircle cx='0' cy='0' r='66'/%3E%3Ccircle cx='66' cy='0' r='66'/%3E%3Ccircle cx='132' cy='0' r='66'/%3E%3Ccircle cx='-33' cy='57.1577' r='66'/%3E%3Ccircle cx='33' cy='57.1577' r='66'/%3E%3Ccircle cx='99' cy='57.1577' r='66'/%3E%3Ccircle cx='-66' cy='114.315' r='66'/%3E%3Ccircle cx='0' cy='114.315' r='66'/%3E%3Ccircle cx='66' cy='114.315' r='66'/%3E%3Ccircle cx='132' cy='114.315' r='66'/%3E%3Ccircle cx='-33' cy='171.473' r='66'/%3E%3Ccircle cx='33' cy='171.473' r='66'/%3E%3Ccircle cx='99' cy='171.473' r='66'/%3E%3C/g%3E%3C/svg%3E");
  }
  .backdrop .ink {
    position: absolute; inset: -75%;
    background: conic-gradient(from 210deg,
      rgb(125 207 255 / 0.80), rgb(122 162 247 / 0.62), rgb(157 124 216 / 0.72),
      rgb(247 118 142 / 0.58), rgb(224 175 104 / 0.52), rgb(158 206 106 / 0.60), rgb(125 207 255 / 0.80));
    animation: lattice-turn 180s linear infinite;
    will-change: transform;
  }
  .backdrop .signal {
    position: absolute; inset: 0;
    transform: translate3d(-120%, 0, 0);
    background: linear-gradient(115deg, transparent 43%, rgb(192 202 245 / 0.1) 48%,
      rgb(192 202 245 / 0.34) 50%, rgb(192 202 245 / 0.1) 52%, transparent 57%);
    animation: signal-sweep 32s ease-in-out infinite;
    will-change: transform;
  }
  .backdrop::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(180deg, rgb(26 27 38 / 0.55), transparent 16%, transparent 78%, rgb(26 27 38 / 0.85));
  }
  @keyframes lattice-turn { to { transform: rotate(1turn); } }
  @keyframes signal-sweep { 0% { transform: translate3d(-120%,0,0); } 22%, 100% { transform: translate3d(120%,0,0); } }

  /* No z-index here: a stacking context on .app would trap the phone
     slide-over beneath the page-level scrim. DOM order already paints the
     app above the fixed backdrop. */
  .app {
    position: relative;
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
    height: 100dvh;
  }
  .app.rail-collapsed { grid-template-columns: 0 minmax(0, 1fr); }

  .chat {
    position: relative;
    display: flex; flex-direction: column;
    min-width: 0; min-height: 0;
  }
  /* Reading band: a quiet column behind the thread so linework never sits
     under text. Fades in with the first message. */
  .chat::before {
    content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none;
    background: linear-gradient(90deg, transparent,
      rgb(26 27 38 / 0.9) calc(50% - var(--column) / 2 - 3rem),
      rgb(26 27 38 / 0.9) calc(50% + var(--column) / 2 + 3rem), transparent);
    opacity: 0; transition: opacity 600ms ease;
  }
  .chat > * { position: relative; z-index: 1; }
  .chat > .weaver-site-header { z-index: 20; }

  .thread {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: var(--line-2) transparent;
  }
  .thread-inner {
    width: min(100%, var(--column));
    margin: 0 auto;
    min-height: 100%;
    display: flex; flex-direction: column;
    padding: clamp(24px, 4vh, 48px) 24px 24px;
  }

  .composer {
    flex: 0 0 auto;
    padding: 0 24px calc(14px + env(safe-area-inset-bottom));
  }
  .composer-inner { width: min(100%, var(--column)); margin: 0 auto; position: relative; }
  /* Soft fade so messages dissolve under the composer instead of cutting. */
  .composer::before {
    content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 28px;
    background: linear-gradient(transparent, var(--night)); pointer-events: none;
    opacity: 0.9;
  }
}

/* ── Components ─────────────────────────────────────────────────────── */
@layer components {

  /* Header slots inside the shared chrome. */
  .hdr-when { display: inline-flex; gap: 8px; color: var(--ink-3); font-size: 10.5px; letter-spacing: 0.12em; }
  .health {
    position: relative; width: 28px; height: 28px; margin: -10px -6px -10px -8px;
    border-radius: 50%; display: grid; place-items: center; flex: none;
  }
  .health::after {
    content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px color-mix(in oklab, var(--green) 55%, transparent);
    transition: background var(--t-fast), box-shadow var(--t-fast);
  }
  .health:hover { background: color-mix(in oklab, var(--ink) 8%, transparent); }
  .health[data-state="degraded"]::after { background: var(--yellow); box-shadow: 0 0 8px color-mix(in oklab, var(--yellow) 55%, transparent); }
  .health[data-state="error"]::after { background: var(--red); box-shadow: 0 0 8px color-mix(in oklab, var(--red) 55%, transparent); }
  .health[data-state="busy"]::after { background: var(--cyan); animation: breathe 1.1s ease-in-out infinite; }
  @keyframes breathe { 50% { opacity: 0.35; } }

  .hdr-actions { display: inline-flex; gap: 4px; }
  .icon-btn {
    width: 34px; height: 34px; border-radius: var(--r-sm);
    display: inline-grid; place-items: center;
    color: var(--ink-3);
    transition: color var(--t-fast), background var(--t-fast);
  }
  .icon-btn:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 8%, transparent); }
  .icon-btn svg { width: 18px; height: 18px; }
  .icon-btn[aria-expanded="true"] { color: var(--accent); }

  /* ── Conversations rail ── */
  .convs {
    grid-column: 1; grid-row: 1;
    display: flex; flex-direction: column;
    min-width: 0; overflow: hidden;
    background: color-mix(in oklab, var(--sunk) 88%, transparent);
    border-right: 1px solid var(--line);
    backdrop-filter: blur(6px);
  }
  .convs-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
  .btn-new {
    flex: 1;
    display: inline-flex; align-items: center; gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--line-2); border-radius: var(--r-md);
    color: var(--ink); font-size: var(--fs-ui);
    transition: border-color var(--t-fast), background var(--t-fast);
  }
  .btn-new:hover { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 8%, transparent); }
  .btn-new svg { width: 16px; height: 16px; color: var(--accent); }
  .convs-close { display: none; }
  .convs-find {
    margin: 0 14px 6px;
    display: flex; align-items: center; gap: 8px;
    padding: 0 10px;
    border-radius: var(--r-sm);
    background: color-mix(in oklab, var(--raised) 70%, transparent);
    color: var(--ink-3);
  }
  .convs-find:focus-within { box-shadow: 0 0 0 1px var(--line-2); }
  .convs-find svg { width: 14px; height: 14px; flex: none; }
  .convs-find input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 7px 0; font-size: var(--fs-small); color: var(--ink); }
  .convs-find input::placeholder { color: var(--ink-3); }
  .convs-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  .convs-group { padding: 16px 8px 6px; font-size: var(--fs-small); color: var(--ink-3); font-style: italic; }
  .conv {
    display: block; width: 100%; text-align: left;
    padding: 8px 10px 9px; border-radius: var(--r-sm);
    transition: background var(--t-fast);
  }
  .conv:hover { background: color-mix(in oklab, var(--raised) 85%, transparent); }
  .conv[aria-current="true"] { background: var(--raised-2); }
  .conv[aria-current="true"] .conv-title { color: var(--ink); }
  .conv-title { display: block; font-size: var(--fs-ui); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .conv-meta { display: block; font-size: var(--fs-small); color: var(--ink-3); margin-top: 1px; }
  .convs-note { padding: 18px 10px; font-size: var(--fs-small); color: var(--ink-3); }

  /* ── Empty state ── */
  .welcome {
    flex: 1; display: grid; place-items: center; align-content: center; gap: 18px;
    padding-bottom: 8vh; text-align: center; user-select: none;
  }
  .welcome pre {
    font-family: var(--mono);
    font-size: clamp(5px, 1.35vw, 10px);
    line-height: 1.05;
    background: linear-gradient(110deg, #f7768e, #bb9af7, #7dcfff, #73daca, #9ece6a, #ff9e64, #f7768e) 0 0 / 220% auto;
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
    animation: flow 7s linear infinite;
  }
  .welcome-sub { font-style: italic; font-size: 1.0625rem; color: var(--ink-3); }
  @keyframes flow { to { background-position: 220% center; } }

  .history-more {
    align-self: center;
    margin: 0 0 28px;
    padding: 6px 14px;
    border-radius: var(--r-pill);
    border: 1px solid var(--line);
    font-size: var(--fs-small); color: var(--ink-3);
    transition: color var(--t-fast), border-color var(--t-fast);
  }
  .history-more:hover:not(:disabled) { color: var(--ink); border-color: var(--line-2); }

  .day {
    display: flex; align-items: center; gap: 14px;
    margin: 12px 0 26px;
    font-size: var(--fs-small); color: var(--ink-3);
  }
  .day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }

  /* ── Messages ── */
  /* Rhythm reads as exchanges: your message sits close to her answer,
     and each new exchange gets more air. */
  .msg { margin-bottom: 36px; }
  .msg-user { margin-bottom: 16px; }
  .msg:last-child { margin-bottom: 8px; }

  .msg-user { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
  .msg-user .msg-body {
    max-width: min(85%, 34rem);
    padding: 10px 16px 11px;
    background: var(--you);
    border: 1px solid var(--you-edge);
    border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
    color: var(--ink);
    font-size: var(--fs-you);
    line-height: 1.5;
  }
  .msg-user time { font-size: var(--fs-small); color: var(--ink-3); padding-right: 4px; opacity: 0; transition: opacity var(--t-fast); }
  .msg-user:hover time, .msg-user:focus-within time { opacity: 1; }

  .msg-athena { --wing: var(--accent); }
  .msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: var(--fs-small); color: var(--ink-3); }
  .msg-mark { width: 14px; height: 14px; color: var(--wing); flex: none; transition: color 600ms ease; }
  .msg-who { color: var(--ink-2); font-size: var(--fs-ui); }
  .msg-status { font-style: italic; }
  .msg-athena .msg-body { max-width: var(--measure); color: var(--ink); }
  .badge {
    font-size: 0.75rem; padding: 1px 8px; border-radius: var(--r-pill);
    border: 1px solid color-mix(in oklab, var(--yellow) 40%, transparent);
    color: var(--yellow); cursor: help;
  }

  /* Always present, quiet until wanted: Listen and Copy are part of her voice. */
  .msg-actions { display: flex; gap: 2px; margin: 8px 0 0 -8px; opacity: 0.55; transition: opacity var(--t-fast); }
  .msg-athena:hover .msg-actions, .msg-athena:focus-within .msg-actions { opacity: 1; }
  .act {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 8px; border-radius: var(--r-sm);
    font-size: var(--fs-small); color: var(--ink-3);
    transition: color var(--t-fast), background var(--t-fast);
  }
  .act:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 7%, transparent); }
  .act svg { width: 14px; height: 14px; }
  .act[data-state="done"] { color: var(--green); }
  .act[data-state="busy"] { color: var(--accent); }
  .act[data-state="playing"] { color: var(--accent); }
  .act[data-state="failed"] { color: var(--red); }

  .msg-error {
    margin-top: 10px; padding: 10px 14px;
    border-left: 2px solid var(--red);
    background: color-mix(in oklab, var(--red) 8%, transparent);
    border-radius: 0 var(--r-sm) var(--r-sm) 0;
    font-size: var(--fs-ui); color: var(--ink);
  }
  .msg-error button { margin-left: 10px; color: var(--cyan); text-decoration: underline; text-underline-offset: 3px; }

  /* ── Prose (her replies; user bubbles reuse the inline parts) ── */
  .prose { font-size: var(--fs-prose); line-height: var(--lh-prose); overflow-wrap: anywhere; }
  .msg-user .prose { font-size: var(--fs-you); line-height: 1.5; }
  .prose > * + * { margin-top: 0.75em; }
  .prose strong { font-weight: 600; color: var(--ink); }
  .prose em { font-style: italic; }
  .prose del { color: var(--ink-3); }
  .prose h2, .prose h3, .prose h4, .prose h5 { font-weight: 500; color: var(--ink); line-height: 1.25; letter-spacing: -0.01em; }
  .prose h2 { font-size: 1.35em; margin-top: 1.2em; }
  .prose h3 { font-size: 1.18em; margin-top: 1.1em; }
  .prose h4, .prose h5 { font-size: 1em; margin-top: 1em; font-style: italic; }
  .prose > :first-child { margin-top: 0; }
  .prose ul, .prose ol { padding-left: 1.4em; }
  .prose li + li, .prose li > ul, .prose li > ol { margin-top: 0.3em; }
  .prose ul > li::marker { color: var(--wing, var(--accent)); }
  .prose ol > li::marker { color: var(--ink-3); font-variant-numeric: tabular-nums; }
  .prose blockquote { padding-left: 1em; border-left: 2px solid var(--violet); color: var(--ink-2); font-style: italic; }
  .prose hr { border: 0; height: 1px; background: var(--line); margin: 1.4em 0; }
  .prose code { font-family: var(--mono); font-size: var(--fs-code); padding: 0.1em 0.35em; border-radius: 4px; background: var(--raised-2); color: var(--teal); }
  .prose table { border-collapse: collapse; font-size: 0.9em; display: block; overflow-x: auto; max-width: 100%; }
  .prose th, .prose td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
  .prose th { color: var(--ink); font-weight: 500; }

  .code {
    border: 1px solid var(--line); border-radius: var(--r-md);
    background: var(--sunk); overflow: hidden;
  }
  .code-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 6px 4px 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--mono); font-size: 0.72rem; color: var(--ink-3);
  }
  .code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 0.8rem; line-height: 1.6; }
  .code pre code { background: none; padding: 0; color: var(--ink); font-size: inherit; white-space: pre; }

  .link-host { font-size: 0.8em; color: var(--ink-3); }
  a.chat-link::before {
    content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    margin-right: 5px; vertical-align: 0.12em; background: var(--line-2);
  }
  a.chat-link.verdict-safe-known-host::before, a.chat-link.verdict-safe-scanned::before { background: var(--green); }
  a.chat-link.verdict-safe-https::before { background: var(--cyan); }
  a.chat-link.verdict-unscanned::before { background: var(--yellow); }
  a.chat-link.verdict-blocked { color: var(--magenta); pointer-events: none; text-decoration: line-through; }
  a.chat-link.verdict-blocked::before { background: var(--magenta); }

  .contact { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 16px; background: var(--raised); }
  .contact-name { font-size: 1.1em; color: var(--ink); margin-bottom: 6px; }
  .contact dl { display: grid; grid-template-columns: max-content 1fr; gap: 3px 16px; font-size: 0.9em; }
  .contact dt { color: var(--ink-3); }
  .contact dd { color: var(--ink); overflow-wrap: anywhere; }

  .msg-image img { display: block; max-width: 100%; max-height: 320px; border-radius: var(--r-md); }
  .msg-image + .prose { margin-top: 8px; }

  /* Entities: tinted, underlined on hover; a click drafts a question. */
  .ent { color: var(--ent, var(--ink)); cursor: pointer; text-decoration: underline dotted transparent; text-underline-offset: 3px; transition: text-decoration-color var(--t-fast); }
  .ent:hover { text-decoration-color: currentColor; }
  .ent-person { --ent: var(--cyan); } .ent-org { --ent: var(--violet); } .ent-place { --ent: var(--green); }
  .ent-music { --ent: var(--magenta); } .ent-work { --ent: var(--blue); } .ent-product { --ent: var(--yellow); }
  .ent-event { --ent: var(--orange); } .ent-concept { --ent: var(--ink); font-style: italic; }

  .jump {
    position: absolute; left: 50%; bottom: calc(100% + 12px); z-index: 5;
    translate: -50% 0;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px 7px; border-radius: var(--r-pill);
    background: var(--raised-2); border: 1px solid var(--line-2);
    color: var(--ink); font-size: var(--fs-small);
    box-shadow: 0 8px 24px -10px rgb(0 0 0 / 0.6);
  }
  .jump svg { width: 14px; height: 14px; }

  /* ── Composer ── */
  .composer-box {
    background: var(--raised);
    border: 1px solid var(--line-2);
    border-radius: var(--r-lg);
    padding: 12px 12px 8px 16px;
    box-shadow: 0 12px 32px -18px rgb(0 0 0 / 0.8);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
  }
  .composer-box:focus-within {
    border-color: color-mix(in oklab, var(--accent) 50%, var(--line-2));
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 12%, transparent), 0 12px 32px -18px rgb(0 0 0 / 0.8);
  }
  .composer-box textarea {
    display: block; width: 100%;
    resize: none; border: 0; outline: 0; background: none;
    color: var(--ink); caret-color: var(--accent);
    font-size: 1.0625rem; line-height: 1.5;
    min-height: 1.5em; max-height: 40vh;
    overflow-y: auto;
  }
  .composer-box textarea::placeholder { color: var(--ink-3); }
  .composer-foot { display: flex; align-items: center; gap: 2px; margin: 8px 0 0 -8px; }
  .tool {
    height: 34px; min-width: 34px; padding: 0 8px;
    border-radius: var(--r-sm);
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    color: var(--ink-3); font-size: var(--fs-small);
    transition: color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  }
  .tool:hover { color: var(--ink); background: color-mix(in oklab, var(--ink) 7%, transparent); }
  .tool svg { width: 18px; height: 18px; flex: none; }
  #mic-btn { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
  .tool-voice[aria-pressed="true"] { color: var(--accent); background: color-mix(in oklab, var(--accent) 14%, transparent); }
  .spacer { flex: 1; }

  .ring { position: relative; width: 22px; height: 22px; margin-right: 6px; }
  .ring svg { width: 100%; height: 100%; rotate: -90deg; }
  .ring circle { fill: none; stroke-width: 2.2; }
  .ring .track { stroke: var(--line); }
  .ring .fill { stroke: var(--yellow); stroke-linecap: round; stroke-dasharray: 56.5; transition: stroke-dashoffset 120ms; }
  .ring.over .fill { stroke: var(--red); }

  .send {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--night);
    transition: opacity var(--t-fast), transform 100ms, background var(--t-fast);
  }
  .send svg { width: 16px; height: 16px; }
  .send:disabled { background: var(--line-2); color: var(--ink-3); cursor: default; }
  .send:not(:disabled):active { transform: scale(0.94); }

  .composer-hint {
    display: flex; flex-wrap: wrap; gap: 4px 16px;
    min-height: 1.4em; margin-top: 8px; padding: 0 4px;
    font-size: var(--fs-small); color: var(--ink-3);
    opacity: 0; transition: opacity var(--t-fast);
  }
  .composer-inner:focus-within .composer-hint { opacity: 1; }
  .composer-hint kbd { font-family: var(--mono); font-size: 0.72rem; padding: 0 5px; border: 1px solid var(--line-2); border-radius: 4px; color: var(--ink-2); }
  .composer-hint .voice-on { display: none; color: var(--accent); }

  .attachment { position: relative; display: inline-flex; gap: 10px; align-items: center; margin-bottom: 10px; padding: 6px 10px 6px 6px; border-radius: var(--r-md); background: var(--raised-2); max-width: 100%; }
  .attachment img { width: 48px; height: 48px; object-fit: cover; border-radius: var(--r-sm); }
  .attachment p { font-size: var(--fs-small); color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .attachment button { flex: none; }
  .composer.drag-over .composer-box { outline: 2px dashed var(--accent); outline-offset: 4px; }

  /* Slash commands */
  .slash {
    position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 10;
    max-height: min(320px, 50vh); overflow-y: auto;
    padding: 6px;
    background: var(--raised);
    border: 1px solid var(--line-2); border-radius: var(--r-md);
    box-shadow: var(--shadow-panel);
  }
  .slash-row { display: grid; grid-template-columns: minmax(7em, auto) 1fr auto; gap: 14px; align-items: baseline; padding: 7px 10px; border-radius: var(--r-sm); cursor: pointer; }
  .slash-row[aria-selected="true"], .slash-row:hover { background: color-mix(in oklab, var(--accent) 12%, transparent); }
  .slash-cmd { font-family: var(--mono); font-size: 0.82rem; color: var(--accent); }
  .slash-help { font-size: var(--fs-ui); color: var(--ink-2); }
  .slash-group { font-size: var(--fs-small); color: var(--ink-3); font-style: italic; }
  .slash-empty { padding: 8px 10px; color: var(--ink-3); font-style: italic; }

  /* Initiation: Athena reached out first. */
  .initiation {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    margin-bottom: 10px; padding: 12px 14px 12px 16px;
    border: 1px solid color-mix(in oklab, var(--accent) 35%, var(--line-2));
    border-radius: var(--r-lg);
    background: linear-gradient(100deg, color-mix(in oklab, var(--accent) 10%, var(--raised)), var(--raised));
    animation: arrive 480ms var(--ease-out);
  }
  .initiation .msg-mark { width: 18px; height: 18px; color: var(--accent); animation: breathe 2.4s ease-in-out infinite; }
  .init-copy { flex: 1 1 14rem; min-width: 0; }
  .init-lede { font-size: var(--fs-ui); color: var(--ink); }
  .init-topic { font-size: var(--fs-small); color: var(--ink-2); font-style: italic; }
  .init-actions { display: flex; gap: 6px; }
  .btn { padding: 7px 14px; border-radius: var(--r-pill); font-size: var(--fs-ui); transition: background var(--t-fast), color var(--t-fast); }
  .btn-primary { background: var(--accent); color: var(--night); font-weight: 500; }
  .btn-primary:hover { background: var(--teal); }
  .btn-quiet { color: var(--ink-2); }
  .btn-quiet:hover { background: color-mix(in oklab, var(--ink) 8%, transparent); color: var(--ink); }
  @keyframes arrive { from { opacity: 0; translate: 0 6px; } }

  /* ── Vitals drawer ── */
  .scrim {
    position: fixed; inset: 0; z-index: 140;
    background: rgb(0 0 0 / 0.45);
    opacity: 0; pointer-events: none;
    transition: opacity var(--t-panel);
  }
  .vitals {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 150;
    width: min(var(--drawer), 100vw);
    display: flex; flex-direction: column;
    background: var(--raised);
    border-left: 1px solid var(--line);
    box-shadow: var(--shadow-panel);
    translate: 102% 0; visibility: hidden;
    transition: translate var(--t-panel) var(--ease-out), visibility 0s linear var(--t-panel);
  }
  .vitals-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
  .vitals-head h2 { font-weight: 400; font-size: 1.35rem; color: var(--ink); }
  .vitals-body { flex: 1; overflow-y: auto; padding: 0 22px 28px; overscroll-behavior: contain; }
  .vitals-summary { font-size: var(--fs-ui); color: var(--ink-2); margin-bottom: 14px; }
  .bindings { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; font-size: var(--fs-small); color: var(--ink-3); }
  .binding { display: inline-flex; align-items: center; gap: 6px; }
  .binding i { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); }
  .binding[data-state="up"] i { background: var(--green); }
  .binding[data-state="live"] i { background: var(--green); animation: breathe 1.1s ease-in-out infinite; }
  .binding[data-state="down"] i { background: var(--red); }
  .vitals h3 { margin: 22px 0 4px; font-weight: 500; font-size: 1rem; color: var(--ink); }
  .stat { border-top: 1px solid var(--line); }
  .stat summary {
    display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
    padding: 8px 0; cursor: pointer; list-style: none;
    font-size: var(--fs-ui); color: var(--ink-2);
  }
  .stat summary::-webkit-details-marker { display: none; }
  .stat summary:hover { color: var(--ink); }
  .stat-val { font-family: var(--mono); font-size: 0.78rem; color: var(--ink); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
  .stat-val.flash { animation: flash 1.1s ease-out; }
  @keyframes flash { 0% { color: var(--accent); } }
  .stat p { padding: 0 0 10px; font-size: var(--fs-small); color: var(--ink-3); line-height: 1.5; }
  .pulse-row { display: grid; grid-template-columns: 4.5em 1fr auto; gap: 10px; align-items: center; padding: 5px 0; border-top: 1px solid var(--line); font-size: var(--fs-ui); color: var(--ink-2); }
  .spark { font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.04em; color: var(--spark, var(--green)); white-space: nowrap; overflow: hidden; }
  .spark.idle { color: var(--line-2); }
  .pulse-note { margin-top: 8px; font-size: var(--fs-small); color: var(--ink-3); }
  .vitals-foot { padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-size: var(--fs-small); color: var(--ink-3); }
}

/* ── States ─────────────────────────────────────────────────────────── */
@layer states {
  body.has-thread .backdrop { opacity: 0.55; }
  body.has-thread .chat::before { opacity: 1; }

  /* Streaming: her words land in her normal ink, steady. (2026-10-09 — the
     flowing gradient read as "spaced out", Matt.) The quiet dot pulse after
     the text says she's still with you, including the silent stretch while
     a tool runs between sentences. */
  .msg-athena.thinking .msg-body::before,
  .msg-athena.streaming .msg-body::after {
    content: ""; display: block; width: 44px; height: 10px; margin-top: 6px;
    background:
      radial-gradient(circle, var(--accent) 3px, transparent 3.5px) 0 50% / 14px 10px repeat-x;
    -webkit-mask: linear-gradient(90deg, #000 30%, transparent 50%, #000 70%) 0 0 / 200% 100%;
            mask: linear-gradient(90deg, #000 30%, transparent 50%, #000 70%) 0 0 / 200% 100%;
    animation: think 1.4s linear infinite;
  }
  @keyframes think { to { -webkit-mask-position: -200% 0; mask-position: -200% 0; } }
  .msg-athena.streaming .msg-actions, .msg-athena.thinking .msg-actions { visibility: hidden; }
  .msg-athena.on-fallback .msg-body { color: var(--ink-2); }

  /* Voice mode: the mic is the primary control. */
  /* Spoken replies are short sentences; give them room to land. */
  body.voice-mode .msg-athena .prose { --lh-prose: 1.8; }
  body.voice-mode .msg-athena .prose > * + * { margin-top: 1em; }
  body.voice-mode .composer-hint .voice-on { display: inline; }
  body.voice-mode .composer-hint .typed { display: none; }
  body.voice-mode .composer-hint { opacity: 1; }
  body.voice-mode #mic-btn:not(.recording) { color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--accent) 45%, transparent); }
  #mic-btn.recording { color: var(--magenta); background: color-mix(in oklab, var(--magenta) 16%, transparent); animation: breathe 1.1s ease-in-out infinite; }
  #mic-btn.transcribing { color: var(--accent); animation: breathe 0.7s ease-in-out infinite; }

  body.vitals-open .vitals { translate: 0 0; visibility: visible; transition: translate var(--t-panel) var(--ease-out); }
  body.vitals-open .scrim, body.convs-open .scrim { opacity: 1; pointer-events: auto; }

  .app.rail-collapsed .convs { visibility: hidden; }
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@layer responsive {
  /* Below this the rail becomes a slide-over. */
  @media (max-width: 1023px) {
    .app, .app.rail-collapsed { grid-template-columns: minmax(0, 1fr); }
    .chat { grid-column: 1; grid-row: 1; }
    .convs {
      position: fixed; top: 0; bottom: 0; left: 0; z-index: 150;
      width: min(22rem, 88vw);
      background: var(--sunk);
      box-shadow: var(--shadow-panel);
      translate: -102% 0; visibility: hidden;
      transition: translate var(--t-panel) var(--ease-out), visibility 0s linear var(--t-panel);
    }
    body.convs-open .convs { translate: 0 0; visibility: visible; transition: translate var(--t-panel) var(--ease-out); }
    .convs-close { display: inline-grid; }
    .app.rail-collapsed .convs { visibility: hidden; }
  }

  @media (max-width: 640px) {
    :root { --fs-prose: 1.0625rem; --lh-prose: 1.6; --fs-you: 1rem; }
    .thread-inner { padding: 20px 16px 16px; }
    .composer { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
    .composer-box { padding: 10px 10px 6px 14px; border-radius: 14px; }
    .composer-box textarea { font-size: 16px; } /* 16px stops iOS zoom-on-focus */
    .composer-hint { display: none; }
    .hdr-when .hdr-date, .hdr-when .sep { display: none; }
    .msg { margin-bottom: 30px; }
    .msg-user { margin-bottom: 14px; }
    .msg-user .msg-body { max-width: 88%; }
    .vitals { width: 100vw; top: auto; height: min(82dvh, 720px); border-left: 0; border-top: 1px solid var(--line); border-radius: var(--r-lg) var(--r-lg) 0 0; translate: 0 102%; }
    body.vitals-open .vitals { translate: 0 0; } /* this layer outranks `states`, so restate the open position */
    .tool-voice span { display: none; }
  }

  /* Touch: no hover, so message actions and times stay visible, quietly. */
  @media (hover: none) {
    .msg-actions { opacity: 0.7; }
    .msg-user time { opacity: 1; }
    .act, .tool, .icon-btn { min-height: 40px; }
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    .backdrop .ink, .backdrop .signal { animation: none; }
  }
}
