  /* Ledger: a private notebook that keeps its own accounts. Self-hosted type
     so a person's browser never talks to a font host. */
  @font-face { font-family: "Fraunces"; src: url(/fonts/fraunces-normal-400-700.woff2) format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
  @font-face { font-family: "Fraunces"; src: url(/fonts/fraunces-italic-400-700.woff2) format("woff2"); font-weight: 400 700; font-style: italic; font-display: swap; }
  @font-face { font-family: "Source Sans 3"; src: url(/fonts/source-sans-3-normal-400-700.woff2) format("woff2"); font-weight: 400 700; font-style: normal; font-display: swap; }
  @font-face { font-family: "Source Sans 3"; src: url(/fonts/source-sans-3-italic-400-700.woff2) format("woff2"); font-weight: 400 700; font-style: italic; font-display: swap; }
  @font-face { font-family: "IBM Plex Mono"; src: url(/fonts/ibm-plex-mono-normal-400.woff2) format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
  @font-face { font-family: "IBM Plex Mono"; src: url(/fonts/ibm-plex-mono-normal-500.woff2) format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }

  :root {
    --paper: #f5f4ef; --card: #fffefa; --ink: #24292e; --muted: #6b7078; --line: #dedbd2; --rule: #eceae2;
    --accent: #2b4c7e; --accent-soft: #e4eaf3; --done: #6b8f71; --done-soft: #e5eee7;
    --warn: #b7791f; --warn-soft: #f7efdf; --fail: #a54a3a; --fail-soft: #f3e3df;
    --code: #eeece4; --user: #ebe9e1; --shadow: 0 6px 16px rgba(36, 41, 46, 0.08);
    --display: "Fraunces", Georgia, "Times New Roman", serif;
    --body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --paper: #14171b; --card: #1b1f25; --ink: #e6e3da; --muted: #9a9e9b; --line: #2b3038; --rule: #22272e;
      --accent: #8eaad8; --accent-soft: #1f2a3c; --done: #8fb59a; --done-soft: #1e2a22;
      --warn: #d6a24a; --warn-soft: #332a18; --fail: #d6806b; --fail-soft: #35211d;
      --code: #232830; --user: #242930; --shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
    }
  }
  :root[data-theme="dark"] {
    --paper: #14171b; --card: #1b1f25; --ink: #e6e3da; --muted: #9a9e9b; --line: #2b3038; --rule: #22272e;
    --accent: #8eaad8; --accent-soft: #1f2a3c; --done: #8fb59a; --done-soft: #1e2a22;
    --warn: #d6a24a; --warn-soft: #332a18; --fail: #d6806b; --fail-soft: #35211d;
    --code: #232830; --user: #242930; --shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  }

  * { box-sizing: border-box; }
  form { margin: 0; }
  html, body { height: 100%; }
  /* 100dvh: on a phone the browser's own toolbars eat into 100vh, which would
     hide the composer behind them. */
  body { margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--body); display: flex; flex-direction: column; -webkit-text-size-adjust: 100%; }
  h1, h2, h3 { margin: 0; }
  h1 { font: 600 1.25rem/1 var(--display); letter-spacing: -0.01em; }
  h2 { font: 600 1.15rem/1.25 var(--display); }
  h3 { font: 600 0.72rem/1.4 var(--body); color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
  a { color: var(--accent); }
  .mono, code, pre { font-family: var(--mono); font-variant-numeric: tabular-nums; }
  code { background: var(--code); padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.85em; word-break: break-all; }
  pre { background: var(--code); padding: 0.7rem 0.9rem; border-radius: 6px; overflow-x: auto; font-size: 0.85em; margin: 0.4rem 0; }
  pre code { background: transparent; padding: 0; word-break: normal; }
  button { font: inherit; font-weight: 600; border: none; border-radius: 6px; cursor: pointer; padding: 0.5rem 0.9rem; background: var(--accent); color: #fff; margin-top: 0.8rem; }
  button:disabled { opacity: 0.5; cursor: default; }
  button.quiet { background: transparent; color: var(--muted); font-weight: 500; padding: 0.2rem 0.4rem; }
  button.outline { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
  button.danger { background: transparent; color: var(--fail); font-weight: 500; padding: 0.2rem 0.4rem; }
  button.solid-danger { background: var(--fail); color: #fff; }
  button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  label { display: block; font-size: 0.8rem; color: var(--muted); margin: 0.6rem 0 0.2rem; }
  input, select, textarea { width: 100%; padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--ink); font: inherit; }
  input[type="checkbox"], input[type="radio"] { width: auto; }
  textarea { resize: vertical; }
  .row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
  .row.spread { justify-content: space-between; }
  .row > h2 { margin: 0; }
  .spacer { flex: 1; }
  .muted { color: var(--muted); font-size: 0.85rem; }
  .error { color: var(--fail); font-size: 0.85rem; margin-top: 0.5rem; min-height: 1.2em; }
  .hidden { display: none !important; }
  .notice { border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; padding: 0.7rem 0.9rem; margin: 0.8rem 1rem; font-size: 0.9rem; }
  .notice button { margin-top: 0; }
  .banner { border: 1px solid var(--line); background: var(--accent-soft); border-radius: 6px; padding: 0.6rem 0.9rem; margin: 0.8rem 1.2rem 0; font-size: 0.9rem; }
  .banner.warn { background: var(--warn-soft); border-color: transparent; }
  .banner button { margin-top: 0; }
  .pill { display: inline-block; font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; padding: 0.1rem 0.5rem; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
  .pill.warn { background: var(--fail-soft); color: var(--fail); }
  table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
  th { text-align: left; color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.3rem 0.5rem 0.3rem 0; border-bottom: 1px solid var(--line); font-weight: 600; }
  td { padding: 0.45rem 0.5rem 0.45rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
  td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
  .wrap { overflow-x: auto; }

  /* header */
  .top { display: flex; align-items: center; gap: 1.2rem; padding: 0.6rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--card); flex: 0 0 auto; }
  .brand { display: flex; align-items: center; gap: 0.55rem; text-decoration: none; color: var(--ink); }
  .brand svg { width: 26px; height: 26px; }
  .top nav { display: flex; gap: 0.15rem; }
  .navlink { background: transparent; color: var(--muted); margin: 0; padding: 0.3rem 0.65rem; font-weight: 500; border-radius: 6px; }
  .navlink.active { background: var(--paper); color: var(--ink); }
  a.navlink { text-decoration: none; font-size: 15px; line-height: 1.55; }
  .who { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }

  /* cards and pages */
  main.narrow { max-width: 46rem; width: 100%; margin: 0 auto; padding: 1.5rem 1rem 5rem; overflow: auto; }
  .card { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
  .learning { border-top: 1px solid var(--rule); padding: 0.7rem 0; }
  .learning:first-child { border-top: 0; }
  #credentials-list .warn { color: var(--fail); font-size: 0.85rem; }
  #credentials-list .row { margin-top: 0.4rem; }
  .learning .lesson { margin-bottom: 0.2rem; }
  .learning .tag { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; border: 1px solid var(--line); border-radius: 999px; padding: 0.05rem 0.45rem; margin-right: 0.35rem; color: var(--muted); }
  .learning .tag.on { border-color: var(--accent); color: var(--accent); }
  .learning .tag.off { opacity: 0.7; text-decoration: line-through; }
  .learning textarea { width: 100%; min-height: 3.5rem; margin: 0.3rem 0; }
  .learning .row { gap: 0.4rem; flex-wrap: wrap; }
  .intro { margin: 0 0 0.6rem; }
  .legal { margin: 1rem 0 0; font-size: 0.82rem; }
  #packs button { margin-top: 0.4rem; }
  .credit-plus { color: var(--done); }
  .credit-minus { color: var(--muted); }
  .levels { display: grid; gap: 0.4rem; }
  .levels label { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem; align-items: start; margin: 0; padding: 0.6rem 0.7rem; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); font-size: 0.95rem; cursor: pointer; }
  .levels label input { margin-top: 0.3rem; }
  .levels label span { display: block; color: var(--muted); font-size: 0.85rem; }
  .levels label b { font-weight: 600; }

  /* workspace: rail | stage | inspector */
  main.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 236px minmax(0, 1fr) 320px; }
  /* Grid and flex items take their content's min-content width unless told
     otherwise. The rail's session titles are `white-space: nowrap`, so without
     this a long objective widened the whole layout — on a phone the page came
     out 2523px wide and the browser rendered it zoomed out. */
  .rail, .stage, .inspector, .session-list, .pane, .thread { min-width: 0; }
  /* Simple keeps the inspector — it is the tray results live in — but only
     its Results tab. Everything else in there is a Standard detail. It stays
     on screen even when empty: its own placeholder says what it is for, and a
     panel that appeared mid-run would shift the layout under the reader. */
  body[data-level="simple"] .needs-standard { display: none !important; }
  body:not([data-level="expert"]) .needs-expert { display: none !important; }
  .rail { border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; min-height: 0; }
  .rail > button { margin: 0.8rem; }
  .rail-actions { display: grid; gap: 0.4rem; margin: 0.8rem; }
  .rail-actions .row { gap: 0.3rem; }
  .rail-actions input { font-size: 0.9rem; }
  .rail > .rail-actions > button { margin: 0; }
  .session-list { overflow: auto; flex: 1; padding: 0 0.5rem 1rem; }
  .rail-group { display: block; padding: 0.7rem 0.65rem 0.25rem; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
  .session-item.project-item .title { font-weight: 600; }
  .session-item .live { color: var(--accent); }
  /* AP-222: a scheduled project says so where you scan (the rail) as well as
     where you act (the pane). Colour carries the state: due/refreshing reads
     as active, paused as a problem, the plain cadence as neither. */
  .sched { display: inline-flex; align-items: center; gap: 0.25rem; }
  .sched.soon { color: var(--accent); }
  .sched.now { color: var(--accent); font-weight: 600; }
  .sched.paused { color: var(--warn); }
  .check-found { margin: 0.3rem 0 0; padding-left: 1.2rem; }
  .check-found li { margin: 0.15rem 0; }
  .schedule-status { border-left: 3px solid var(--line); padding: 0.5rem 0 0.5rem 0.7rem; margin: 0.6rem 0; }
  .schedule-status .sched { font-size: 0.95rem; }
  .schedule-status .sched.now, .schedule-status .sched.soon { border-color: var(--accent); }
  .schedule-status .muted { display: block; margin-top: 0.15rem; }
  .session-item.in-project { margin-left: 0.7rem; }
  .session-item.new-in-project { margin-left: 0.7rem; color: var(--accent); font-weight: 500; font-size: 0.85rem; padding-top: 0.35rem; padding-bottom: 0.35rem; }
  .project-chip { background: var(--paper); border: 1px solid var(--line); }
  /* The project pane (inspector → Project): foldable sections, small
     controls, nothing wider than the 320px column. Its buttons drop the
     app's roomy default — a sidebar of full-size buttons, wrapping, was what
     made the pane hard to read. */
  #pane-project { gap: 0; }
  #pane-project button { margin: 0; padding: 0.3rem 0.65rem; font-size: 0.82rem; }
  #pane-project button.quiet, #pane-project button.danger { padding: 0.2rem 0.3rem; }
  #pane-project input, #pane-project select, #pane-project textarea { padding: 0.32rem 0.5rem; }
  .pj-head { display: grid; gap: 0.15rem; padding-bottom: 0.55rem; }
  #pane-project .pj-name { font: 600 1.1rem/1.3 var(--display); border-color: transparent; background: transparent; padding: 0.15rem 0.35rem; margin-left: -0.35rem; width: calc(100% + 0.35rem); }
  #pane-project .pj-name:hover, #pane-project .pj-name:focus { border-color: var(--line); background: var(--paper); }
  .pj-meta { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 1.75rem; color: var(--muted); font-size: 0.8rem; }
  .pj-working { display: grid; gap: 0.1rem; color: var(--muted); font-size: 0.8rem; }
  .pj-working .dot { margin-right: 0.35rem; }
  .pj-section { border-top: 1px solid var(--rule); padding: 0.45rem 0 0.75rem; }
  .pj-section > summary { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; list-style: none; padding: 0.2rem 0; }
  .pj-section > summary::-webkit-details-marker { display: none; }
  /* A chevron drawn with two borders: › folded, ⌄ open. */
  .pj-section > summary::before { content: ""; flex: none; width: 0.4rem; height: 0.4rem; margin: 0 0.15rem; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform 0.12s; }
  .pj-section[open] > summary::before { transform: translateY(-0.1rem) rotate(45deg); }
  .pj-section > summary h3 { flex: 1; }
  .pj-section > summary .sched { font-size: 0.75rem; }
  .pj-section[open] > summary { margin-bottom: 0.45rem; }
  .pj-section > :not(summary) + :not(summary) { margin-top: 0.55rem; }
  .pj-section textarea { display: block; min-height: 6rem; line-height: 1.45; }
  .pj-section .schedule-status { margin: 0; }
  .pj-note { color: var(--muted); font-size: 0.75rem; }
  .pj-note.warn { color: var(--fail); }
  #site-tags label { font-size: 0.8rem; }
  .pj-pill { font-size: 0.72rem; font-weight: 600; line-height: 1.5; padding: 0 0.5rem; border-radius: 999px; background: var(--rule); color: var(--muted); }
  .pj-pill.live { background: var(--done-soft); color: var(--done); }
  .pj-pill.fail { background: var(--fail-soft); color: var(--fail); }
  .pj-status { display: grid; gap: 0.2rem; }
  .pj-url { font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; }
  .pj-warn { color: var(--fail); font-size: 0.82rem; }
  .pj-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(6.5rem, 1fr)); gap: 0.35rem; }
  .pj-form { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.35rem 0.6rem; align-items: center; }
  .pj-form label { margin: 0; font-size: 0.8rem; }
  /* Settings → Site address: the name and the domain it sits under, on one line. */
  #site-address .row { flex-wrap: nowrap; gap: 0.3rem; }
  #site-address .row input { flex: 1 1 auto; min-width: 0; width: auto; }
  #site-address .row .muted { white-space: nowrap; }
  .pj-inline { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
  .pj-inline input { flex: 1 1 auto; min-width: 0; }
  #pane-project .pj-inline input[type="number"] { flex: 0 0 4.5rem; }
  .pj-inline .muted { font-size: 0.78rem; }
  .pj-row-end { display: flex; justify-content: flex-end; gap: 0.4rem; }
  .pj-links { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.3rem; color: var(--muted); font-size: 0.8rem; }
  .pj-files { display: grid; }
  #pane-project .pj-file { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; width: 100%; padding: 0.22rem 0.3rem; text-align: left; background: transparent; color: var(--ink); font-weight: 400; border-radius: 4px; }
  .pj-file:hover { background: var(--paper); }
  .pj-file .name { font-family: var(--mono); font-size: 0.78rem; overflow-wrap: anywhere; }
  .pj-file .pj-dl { color: var(--muted); }
  .pj-file:hover .pj-dl, .pj-file:focus-visible .pj-dl { color: var(--accent); }
  .pj-footer { border-top: 1px solid var(--rule); padding-top: 0.6rem; }
  .session-list > .muted { padding: 0.4rem 0.6rem; }
  .session-item { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); font-weight: 400; margin: 0 0 0.15rem; padding: 0.5rem 0.65rem; border-radius: 6px; }
  .session-item:hover { background: var(--paper); }
  .session-item.active { background: var(--paper); }
  .session-item .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.92rem; }
  .session-item .meta { display: flex; gap: 0.4rem; align-items: center; font-size: 0.75rem; color: var(--muted); }
  .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
  .dot.running { background: var(--accent); animation: pulse 1.4s infinite; }
  .dot.completed { background: var(--done); }
  .dot.failed { background: var(--fail); }
  .dot.stopped { background: var(--warn); }
  .dot.awaiting_user_input { background: var(--warn); }
  @keyframes pulse { 50% { opacity: 0.3; } }
  @media (prefers-reduced-motion: reduce) { .dot.running, .working i { animation: none; } }

  .stage { display: flex; flex-direction: column; min-height: 0; position: relative; }
  .thread { flex: 1; overflow: auto; padding: 1.2rem 1.4rem; }
  .empty { flex: 1; display: grid; place-content: center; gap: 0.5rem; text-align: center; padding: 2rem; color: var(--muted); }
  .empty h2 { font-size: 1.6rem; color: var(--ink); }
  .msg { max-width: 46rem; margin: 0 auto 1rem; }
  .msg-user { background: var(--user); border-radius: 10px 10px 2px 10px; padding: 0.6rem 0.9rem; margin-left: auto; margin-right: 0; width: fit-content; max-width: 46rem; }
  .msg-user .text { white-space: pre-wrap; }
  .msg-user .actions { display: flex; gap: 0.3rem; justify-content: flex-end; }
  .msg-user .actions button { margin-top: 0.2rem; font-size: 0.78rem; }
  .msg-user textarea { margin-top: 0.4rem; min-width: 22rem; }
  .msg-user > button { margin-top: 0.4rem; margin-right: 0.4rem; }
  .msg-answer { padding: 0.2rem 0.2rem 0.4rem; }
  .msg-answer p { margin: 0.35rem 0 0.7rem; }
  .msg-answer h1, .msg-answer h2, .msg-answer h3, .msg-answer h4 { font: 600 1.05rem/1.3 var(--display); margin: 0.9rem 0 0.35rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
  .msg-answer h1 { font-size: 1.25rem; } .msg-answer h4 { font-size: 0.98rem; }
  .msg-answer ul, .msg-answer ol { margin: 0.3rem 0 0.7rem 1.3rem; padding: 0; }
  .msg-answer li { margin: 0.15rem 0; }
  .msg-answer blockquote { margin: 0.5rem 0; padding: 0.2rem 0.9rem; border-left: 3px solid var(--line); color: var(--muted); }
  .msg-answer hr { border: none; border-top: 1px solid var(--line); margin: 0.9rem 0; }
  .msg-answer .table-wrap { overflow-x: auto; margin: 0.4rem 0 0.8rem; }
  .msg-answer table { width: auto; min-width: 50%; }
  .msg-answer th, .msg-answer td { padding: 0.3rem 0.8rem 0.3rem 0; }

  /* the turn: what Brenian did for one message */
  .turn { border: 1px solid var(--line); border-radius: 6px; background: var(--card); padding: 0.75rem 0.95rem; display: grid; gap: 0.6rem; }
  .turn-head { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
  .turn-head b { font: 600 1rem/1.3 var(--display); }
  .turn-head .state { color: var(--muted); font-size: 0.85rem; }
  .turn-head i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); margin-right: 0.45rem; vertical-align: 1px; }
  .working .turn-head i { animation: pulse 1.4s infinite; }
  .turn.done .turn-head i { background: var(--done); box-shadow: none; }
  .turn.stopped .turn-head i { background: var(--warn); box-shadow: none; }
  .turn.failed .turn-head i { background: var(--fail); box-shadow: none; }
  .plan { display: grid; gap: 0.35rem; }
  .plan .plan-line { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.88rem; }
  .plan .plan-line b { font-weight: 600; }
  .plan .plan-line span { color: var(--muted); }
  .plan .plan-line button { margin: 0 0 0 auto; font-size: 0.78rem; }
  .meter { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; }
  .meter > i { display: block; height: 100%; width: 0; background: var(--done); transition: width 0.3s ease; }
  .steps { list-style: none; margin: 0.15rem 0 0; padding: 0; display: grid; gap: 0.2rem; }
  .steps li { display: grid; grid-template-columns: 1.1em 1fr auto; gap: 0.5rem; align-items: baseline; font-size: 0.88rem; }
  .steps li i { font-style: normal; font-family: var(--mono); color: var(--muted); }
  .steps li.done i { color: var(--done); }
  .steps li.now { font-weight: 600; } .steps li.now i { color: var(--accent); }
  .steps li.failed i { color: var(--fail); }
  .steps li small { color: var(--muted); font-size: 0.78rem; }
  .steps li.failed small { color: var(--fail); }
  .steps .phase { display: block; font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-top: 0.3rem; }
  .activity { display: grid; gap: 0.3rem; }
  .activity .sum { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; font-size: 0.88rem; }
  .activity .sum button { margin: 0; font-size: 0.78rem; }
  .timeline { display: grid; gap: 0.15rem; font-size: 0.82rem; color: var(--muted); }
  .timeline .row-t { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr) auto; gap: 0.6rem; align-items: baseline; }
  .timeline .row-t .at { font-family: var(--mono); font-size: 0.74rem; }
  .timeline .row-t .what { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .timeline .row-t .what.thought { color: var(--muted); font-style: italic; white-space: normal; }
  .timeline .row-t .dur { font-family: var(--mono); font-size: 0.74rem; white-space: nowrap; }
  .timeline .row-t.error .what { color: var(--fail); white-space: normal; }
  .timeline details { margin: 0 0 0.3rem 3.8rem; }
  .timeline summary { cursor: pointer; font-size: 0.75rem; }
  .timeline pre { max-height: 14rem; overflow: auto; font-size: 0.75rem; white-space: pre-wrap; word-break: break-word; }
  .timeline .meta-row { display: flex; gap: 0.7rem; flex-wrap: wrap; font-family: var(--mono); font-size: 0.72rem; margin-left: 3.8rem; }
  .subagent { margin-left: 3.8rem; border-left: 2px solid var(--accent); padding: 0.1rem 0.6rem; color: var(--ink); }
  .subagent .summary { white-space: pre-wrap; }
  .results { display: grid; gap: 0.4rem; }
  .results .head { display: flex; gap: 0.6rem; align-items: baseline; }
  .results .head b { font: 600 0.95rem/1.3 var(--display); }
  .results .head span { color: var(--muted); font-size: 0.82rem; }
  .file { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.6rem; align-items: center; padding: 0.35rem 0; border-top: 1px solid var(--rule); font-size: 0.9rem; }
  .file .name { font-family: var(--mono); font-size: 0.82rem; overflow-wrap: anywhere; }
  .file small { display: block; color: var(--muted); font-size: 0.78rem; font-family: var(--body); }
  .file button { margin: 0; padding: 0.15rem 0.5rem; font-size: 0.78rem; }
  .file img { max-width: 100%; max-height: 16rem; border-radius: 4px; display: block; margin-top: 0.3rem; grid-column: 1 / -1; }
  .file .actions { display: flex; gap: 0.35rem; }
  /* The preview covers the screen and scales the picture to fit it, keeping
     its shape. A click anywhere closes it. */
  .image-preview { box-sizing: border-box; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 3rem 1rem 1rem; border: none; background: transparent; cursor: zoom-out; }
  .image-preview::backdrop { background: rgba(0, 0, 0, 0.85); }
  .image-preview img { display: block; width: 100%; height: 100%; object-fit: contain; }
  .image-preview button { position: absolute; top: 0.6rem; right: 0.8rem; margin: 0; }
  .working-files { color: var(--muted); font-size: 0.82rem; padding-top: 0.3rem; border-top: 1px solid var(--rule); }
  .working-files button { margin: 0; font-size: 0.78rem; }
  .working-files ul { list-style: none; margin: 0.3rem 0 0; padding: 0; font-family: var(--mono); font-size: 0.76rem; display: grid; gap: 0.1rem; overflow-wrap: anywhere; }
  .made { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: 0.5rem; }
  .made button { margin: 0; padding: 0; font-size: 0.85rem; color: var(--accent); font-weight: 600; }
  .stop-banner { border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 6px 6px 0; padding: 0.6rem 0.9rem; display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }
  .stop-banner.failed { border-left-color: var(--fail); background: var(--fail-soft); }
  .stop-banner b { font-weight: 600; }
  .stop-banner button { margin: 0 0 0 auto; }
  .draft { color: var(--muted); font-style: italic; white-space: pre-wrap; }
  .step-error { color: var(--fail); }
  .question { max-width: 46rem; margin: 0 auto 0.8rem; border: 1px solid var(--accent); border-radius: 6px; padding: 0.8rem 1rem; background: var(--card); }
  .question .row button { margin-top: 0.4rem; }
  .question .row button.pictured { display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem; padding: 0.4rem; width: 15rem; max-width: 100%; }
  .question .row button.pictured img { display: block; width: 100%; max-height: 13rem; object-fit: contain; border-radius: 4px; background: var(--rule); min-height: 4rem; }
  .jump { position: absolute; right: 1.4rem; background: var(--card); color: var(--accent); border: 1px solid var(--line); box-shadow: var(--shadow); padding: 0.3rem 0.7rem; font-size: 0.8rem; margin: 0; z-index: 2; }

  /* composer */
  .composer { flex: 0 0 auto; padding: 0.7rem 1.4rem 1rem; border-top: 1px solid var(--line); background: var(--card); }
  .composer .inner { max-width: 46rem; margin: 0 auto; display: grid; gap: 0.45rem; }
  .composer textarea { min-height: 3.2rem; }
  .composer-bar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; position: relative; }
  .composer-bar button { margin-top: 0; }
  .chip { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 0.15rem 0.7rem; font-size: 0.8rem; font-weight: 500; }
  .chip.on { border-color: var(--accent); color: var(--accent); }
  .popover { position: absolute; bottom: 2.4rem; left: 0; width: 22rem; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 0.4rem 0.9rem 0.9rem; box-shadow: var(--shadow); z-index: 3; }
  .popover.menu { left: auto; right: 0; width: 15rem; padding: 0.4rem; display: grid; }
  /* The composer bar wraps on a narrow pane; a popover anchored to its bottom
     edge then covered the chips of the first row. Anchor to its top edge. */
  .composer-bar > .popover { bottom: calc(100% + 0.4rem); }
  .limit-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.3rem 0; }
  .limit-row input { width: 5.5rem; margin: 0; }
  .turn .go-meter { font-size: 0.85rem; color: var(--muted); margin: 0.2rem 0 0.4rem; }
  .stop-banner .progress { display: block; color: var(--muted); font-size: 0.9rem; margin: 0.2rem 0; }
  .popover.menu button { margin: 0; text-align: left; background: transparent; color: var(--ink); font-weight: 500; padding: 0.4rem 0.6rem; border-radius: 4px; }
  .popover.menu button:hover { background: var(--paper); }
  .popover.menu button.danger { color: var(--fail); }
  .cost { display: flex; gap: 0.5rem; align-items: center; font-size: 0.8rem; color: var(--muted); }
  .cost a { color: var(--ink); font-weight: 600; font-family: var(--mono); font-size: 0.78rem; text-decoration: none; border-bottom: 1px dotted var(--muted); }
  .cost a:hover { color: var(--accent); border-bottom-color: currentColor; }
  .usage-session { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
  .usage-session:last-child { border-bottom: 0; }
  .usage-session.current { background: var(--accent-soft); margin: 0 -0.6rem; padding: 0.7rem 0.6rem; border-radius: 6px; }
  .usage-session .head { display: flex; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; }
  .usage-session .head a { font-weight: 600; color: var(--ink); text-decoration: none; }
  .usage-session .head a:hover { text-decoration: underline; }
  .usage-session .head .spend { margin-left: auto; font-family: var(--mono); font-size: 0.85rem; white-space: nowrap; }
  .usage-session table { margin-top: 0.4rem; }
  .cost .bar { flex: 0 0 4rem; height: 5px; border-radius: 3px; background: var(--rule); overflow: hidden; }
  .cost .bar i { display: block; height: 100%; width: 0; background: var(--done); }
  .chip.warn { border-color: var(--warn); color: var(--warn); }
  .chip.over { border-color: var(--fail); color: var(--fail); }
  .model-facts { font-size: 0.78rem; margin: 0.25rem 0 0.6rem; line-height: 1.4; }
  .space { min-width: 18rem; font-size: 0.85rem; }
  .space .space-bar { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin: 0.4rem 0; }
  .space .space-bar i { display: block; height: 100%; background: var(--done); }
  .space .space-bar i.warn { background: var(--warn); }
  .space .space-bar i.over { background: var(--fail); }
  .space .space-row { display: flex; gap: 0.5rem; align-items: center; padding: 0.2rem 0; }
  .space .space-row .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .space .muted { margin-top: 0.4rem; }
  .space .muted.warn { color: var(--warn); }
  .composer .send { padding: 0.45rem 1.1rem; }

  /* inspector */
  .inspector { border-left: 1px solid var(--line); background: var(--card); display: grid; grid-template-rows: auto 1fr; min-height: 0; }
  .tabs { display: flex; border-bottom: 1px solid var(--line); }
  .tabs button { margin: 0; background: transparent; color: var(--muted); font-weight: 500; border-radius: 0; padding: 0.6rem 0.75rem; font-size: 0.85rem; border-bottom: 2px solid transparent; }
  .tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
  .pane { padding: 0.8rem 0.9rem; overflow: auto; display: grid; gap: 0.7rem; align-content: start; font-size: 0.88rem; }
  .pane .steps li { font-size: 0.85rem; }
  .facts { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.8rem; font-size: 0.85rem; margin: 0; }
  .facts dt { color: var(--muted); }
  .facts dd { margin: 0; font-family: var(--mono); font-size: 0.8rem; }
  .stars { display: inline-flex; align-items: center; gap: 0.25rem; }
  .stars button { background: transparent; color: var(--line); font-size: 1.15rem; padding: 0 0.05rem; margin: 0; line-height: 1; }
  .stars button.on { color: var(--warn); }
  .timeline-all { display: grid; gap: 0.5rem; }
  .timeline-all .t { display: grid; gap: 0.15rem; cursor: pointer; }
  .timeline-all .t b { font-weight: 600; font-size: 0.85rem; }
  .timeline-all .t span { color: var(--muted); font-size: 0.82rem; }

  /* ── narrow screens ───────────────────────────────────────────────────
     The desktop layout is rail | stage | inspector. Three panes do not fit a
     phone, and stacking them makes the thread — the thing you came for —
     unreadable. So the stage keeps the screen and the other two become
     drawers over it, each with a scrim and a close button. */
  .scrim { position: fixed; inset: 0; background: rgba(20, 23, 27, 0.45); z-index: 15; border: none; padding: 0; margin: 0; }
  .mobile-only, .phone-only { display: none; }   /* mobile-only: ≤1024 (inspector is a drawer). phone-only: ≤760 (rail too). */
  #rail-close, #inspector-close { margin: 0; }

  @media (max-width: 1024px) {
    /* Tablet: two panes. The inspector slides in from the right. */
    main.workspace { grid-template-columns: 236px minmax(0, 1fr); }
    .inspector { position: fixed; top: 0; right: 0; bottom: 0; width: min(92vw, 380px); z-index: 20;
      transform: translateX(101%); transition: transform 0.18s ease-out; box-shadow: var(--shadow); border-left: 1px solid var(--line); }
    body.inspector-open .inspector { transform: none; }
    body:not(.inspector-open) .inspector { pointer-events: none; }
    .mobile-only { display: inline-flex; }
    .tabs { overflow-x: auto; }
    .tabs button { flex: 0 0 auto; }
  }

  @media (max-width: 760px) {
    /* A scrolled table keeps its natural column widths instead of squeezing
       them into slivers; a narrow one still fills the width. */
    .wrap table { min-width: max-content; }

    /* Phone: one pane. Both side panels are drawers; nothing is fixed-width. */
    main.workspace { grid-template-columns: minmax(0, 1fr); }
    .rail { position: fixed; top: 0; left: 0; bottom: 0; width: min(84vw, 320px); z-index: 20;
      transform: translateX(-101%); transition: transform 0.18s ease-out; box-shadow: var(--shadow); border-right: 1px solid var(--line); }
    body.rail-open .rail { transform: none; }
    body:not(.rail-open) .rail { pointer-events: none; }
    .inspector { width: min(94vw, 420px); }
    .phone-only { display: inline-flex; }

    /* Header: the address is the first thing to go; the toggles matter more. */
    .top { gap: 0.5rem; padding: 0.5rem 0.7rem; padding-left: calc(0.7rem + env(safe-area-inset-left)); padding-right: calc(0.7rem + env(safe-area-inset-right)); }
    .top h1 { font-size: 1.1rem; }
    .brand svg { width: 22px; height: 22px; }
    .top nav { gap: 0; }
    .navlink, a.navlink { padding: 0.3rem 0.45rem; font-size: 0.9rem; }
    #who { display: none; }
    .who { gap: 0.3rem; }

    /* Reading and typing */
    .thread { padding: 0.9rem 0.8rem calc(0.9rem + env(safe-area-inset-bottom)); }
    .msg { margin-bottom: 0.8rem; }
    .msg-user { max-width: 100%; }
    .msg-user textarea { min-width: 0; }
    .empty { padding: 1.5rem 1rem; }
    .empty h2 { font-size: 1.3rem; }
    .banner, .notice { margin-left: 0.7rem; margin-right: 0.7rem; }
    .composer { padding: 0.6rem 0.7rem calc(0.7rem + env(safe-area-inset-bottom)); }
    .composer textarea { min-height: 2.8rem; }
    /* 16px keeps iOS Safari from zooming the page when a field takes focus. */
    input, select, textarea { font-size: 16px; }
    .popover { width: min(92vw, 22rem); }
    .popover.menu { width: min(80vw, 15rem); }
    .jump { right: 0.8rem; }
    .question { margin-left: 0.2rem; margin-right: 0.2rem; }

    /* Thumbs, not cursors */
    .session-item { padding: 0.6rem 0.65rem; }
    .stop-banner button { margin-left: 0; }
    .results .head { flex-wrap: wrap; }
    .tabs button { padding: 0.7rem 0.8rem; }
    .stars button { font-size: 1.4rem; padding: 0 0.15rem; }
    .msg-user .actions button { padding: 0.3rem 0.5rem; }

    /* Wide content scrolls inside itself instead of widening the page */
    .facts { grid-template-columns: auto minmax(0, 1fr); }
    .timeline .row-t { grid-template-columns: 2.8rem minmax(0, 1fr) auto; gap: 0.4rem; }
    .timeline details, .timeline .meta-row, .subagent { margin-left: 1rem; }
    main.narrow { padding: 1.2rem 0.8rem 4rem; padding-left: calc(0.8rem + env(safe-area-inset-left)); padding-right: calc(0.8rem + env(safe-area-inset-right)); }
    .card { padding: 0.9rem 0.9rem; }
  }

  @media (max-width: 400px) {
    /* The narrowest phones: the brand word gives way to the mark. */
    .top h1 { display: none; }
    .brand { min-width: 24px; min-height: 24px; }   /* the mark alone is still a 24px target */
    .navlink, a.navlink { padding: 0.3rem 0.35rem; font-size: 0.86rem; }
  }
