:root {
  color-scheme: dark;
  --bg: #0a0f1c;        /* night indigo */
  --surface: #151d33;
  --raised: #1d2744;
  --line: #273250;
  --rim: rgba(159, 227, 255, .09);   /* the hairline round surfaces: light, not a border */
  --glass: rgba(22, 30, 52, .78);    /* sheets and chips over the chat, blurred */
  --fg: #e9eef8;
  --mut: #8e98b4;
  --you: #6e8bff;       /* the user's voice, primary actions */
  --you-bg: #263a73;
  --agent: #7fc8f8;     /* name colour of the main voice; the Reactor's cyan */
  --flux: #b48cff;      /* the Reactor's violet */
  --ok: #4cd38a;
  --warn: #f2b441;
  --bad: #f0566a;
  --ui: "Geologica", -apple-system, system-ui, sans-serif;   /* pwa/fonts: the same face as the laptop's panel */
  --text: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  --gut: 16px;
  --safe-l: max(var(--gut), env(safe-area-inset-left));
  --safe-r: max(var(--gut), env(safe-area-inset-right));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* the reactor's light: a glow from under the dock, a cold one from the top corner */
html, body { margin: 0; height: 100%; color: var(--fg);
  background: radial-gradient(130% 55% at 50% 108%, rgba(110, 139, 255, .17), transparent 62%),
    radial-gradient(90% 40% at -10% -5%, rgba(127, 200, 248, .07), transparent 70%), var(--bg);
  font: 17px/1.45 var(--text); -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; }
button { font: 500 16px/1.2 var(--ui); color: var(--fg); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 16px; min-height: 48px; cursor: pointer; }
button:active { transform: scale(.97); }
button:disabled { opacity: .55; }
:focus-visible { outline: 2px solid var(--you); outline-offset: 2px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell: header / chat / dock ---------- */
/* Fill the window itself, not 100dvh: on the iPhone home screen (black-translucent status bar) 100dvh came
   out shorter than the screen, and the app ended well above its bottom edge, under the mic button. */
/* minmax(0, 1fr): an implicit auto column grows with a long unbreakable line (the book's title) and the page scrolls sideways */
.app { position: fixed; inset: 0; max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; }
/* iPhone home screen (translucent status bar): 100%, dvh and the fixed viewport are the status bar
   shorter than the screen, and nothing is drawn in the strip left below. Only lvh is the screen;
   standalone has no browser bars for lvh to reach under. */
@media (display-mode: standalone) {
  html { height: 100lvh; }
  body { position: relative; height: 100%; }
  .app { position: absolute; }
}

.top { display: flex; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top)) var(--safe-r) 6px var(--safe-l); }
.top .mark { --mascot-size: 40px; flex: none; margin: 0 8px 0 -4px; }
.top .mark[data-state="sleep"] .ch { filter: brightness(.9) saturate(.85); }   /* idle on the phone: resting, not dark */
.brand-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; margin-right: auto; }
.brand { margin: 0; font: 600 19px/1.1 var(--ui); font-variation-settings: "SHRP" 70; color: var(--fg); letter-spacing: -.01em; }
/* under the name: what the conversation does now, or, only when it is broken, the link */
.conv { font: 500 13px/1.2 var(--ui); color: var(--mut); }
.conv.speaking { color: var(--agent); }
.link-warn { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 500 13px/1.2 var(--ui); color: var(--bad); }
.icon-btn, .events-btn { position: relative; min-height: 40px; min-width: 40px; padding: 8px; border-radius: 12px; background: transparent; border: 0; color: var(--fg); }
.badge { position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--warn); color: #1b1404; font: 700 12px/18px var(--ui); text-align: center; }

.chat { overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: 16px var(--safe-r) 24px var(--safe-l); display: flex; flex-direction: column;
  -webkit-mask-image: linear-gradient(transparent, #000 20px, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(transparent, #000 20px, #000 calc(100% - 24px), transparent); }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; margin-top: auto; }
.feed li { max-width: 84%; padding: 9px 14px; border-radius: 20px; overflow-wrap: anywhere; white-space: pre-wrap; }
.feed li.agent { align-self: flex-start; background: linear-gradient(180deg, #172039, #131b30); box-shadow: inset 0 0 0 1px var(--rim);
  border-bottom-left-radius: 6px; padding-left: 12px; }
/* every agent bubble is signed with the voice that speaks it */
.feed .who { display: block; margin-bottom: 3px; font: 600 12.5px/1.2 var(--ui); color: var(--name, var(--agent)); }
.feed li.user { align-self: flex-end; background: linear-gradient(160deg, #3350b4, #263e8e); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .09);
  border-bottom-right-radius: 6px; }
/* a story picture: a wide card on the agent's side, tap to see it full screen */
.feed li.picture { align-self: flex-start; max-width: min(92%, 420px); padding: 6px; background: var(--surface); box-shadow: inset 0 0 0 1px var(--rim);
  border-bottom-left-radius: 6px; cursor: zoom-in; white-space: normal; }
.feed li.picture img { display: block; width: 100%; height: auto; min-height: 120px; border-radius: 15px; background: var(--raised); }
.feed li.picture p { margin: 6px 8px 2px; font: 14px/1.3 var(--ui); color: var(--mut); }
/* a report: a card on the agent's side with its title and gist, tap to read it full screen */
.feed li.report { align-self: flex-start; width: min(92%, 420px); max-width: none; padding: 12px 14px; background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--rim); border-bottom-left-radius: 6px; white-space: normal; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.feed li.report .who { display: flex; align-items: center; gap: 6px; margin: 0; }
.feed li.report .who svg { width: 16px; height: 16px; }
.feed li.report .title { font: 600 17px/1.3 var(--ui); }
.feed li.report .gist { margin: 0; color: var(--mut); font-size: 15px; line-height: 1.4;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.feed li.report .open { align-self: flex-end; font: 600 14px var(--ui); color: var(--agent); }
/* a tale: a card with its cover and title, tap to open the book; the tale itself is in the catalog */
.feed li.tale { align-self: flex-start; width: min(92%, 420px); max-width: none; padding: 8px; background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--rim); border-bottom-left-radius: 6px; white-space: normal; cursor: pointer; display: flex; gap: 12px; align-items: center; }
.feed li.tale img { flex: none; width: 88px; height: 66px; border-radius: 12px; object-fit: cover; background: var(--raised); }
.feed li.tale div { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.feed li.tale .who { margin: 0; }
.feed li.tale .title { font: 600 17px/1.3 var(--ui); }
.feed li.tale .open { font: 600 14px var(--ui); color: var(--agent); }
/* where the restored history ends and this visit begins */
.feed li.sep { align-self: center; max-width: none; padding: 2px 10px; font: 12px/1.3 var(--ui); color: var(--mut); }
/* events: a quiet line in the timeline, not a bubble */
.feed li.ev { align-self: stretch; max-width: none; padding: 4px 2px; border-radius: 0; display: flex; gap: 8px; align-items: baseline;
  font: 14px/1.35 var(--ui); color: var(--mut); cursor: pointer; }
.feed li.ev b { color: var(--fg); font-weight: 600; }
.feed li.ev time { margin-left: auto; font-size: 12px; flex: none; }
.ev-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--mut); transform: translateY(-1px); }
.t-task_done .ev-dot { background: var(--ok); }
.t-task_failed .ev-dot { background: var(--bad); }
.t-needs_approval .ev-dot { background: var(--warn); }
.t-session_idle .ev-dot { background: var(--you); }
.t-sent .ev-dot { background: transparent; box-shadow: inset 0 0 0 2px var(--you); }
/* a message the agent sent on the user's behalf: under the user's side, quieter than their own bubble */
.feed li.sent { align-self: flex-end; background: transparent; border: 1px dashed #2f3b5e; color: var(--mut); font-size: 15px;
  border-bottom-right-radius: 6px; cursor: pointer; }
.feed li.sent .who { color: var(--mut); font-weight: 500; }
.feed li.sent .who b { color: var(--you); font-weight: 600; }
.feed li.sent:not(.open) .sent-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }

.empty { margin: auto 0; text-align: center; color: var(--mut); padding: 0 12px; }
.empty p { margin: 0 0 6px; }
.empty .hint { font: 600 23px/1.3 var(--ui); font-variation-settings: "SHRP" 70; color: var(--fg); }

/* floating bits above the dock */
.overlay { position: absolute; left: 0; right: 0; bottom: var(--dock-h, 120px); display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 0 var(--safe-r) 10px var(--safe-l); pointer-events: none; }
.overlay > * { pointer-events: auto; }
.new-pill { min-height: 36px; padding: 6px 14px; border: 0; border-radius: 18px; background: var(--glass); font-size: 14px;
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  box-shadow: inset 0 0 0 1px var(--rim), 0 6px 20px #0008; }
.toast { margin: 0; width: 100%; padding: 12px 14px; border-radius: 14px; background: #3b1e2a; border: 1px solid #6b2a3c; color: #ffd0d6;
  font: 15px/1.35 var(--ui); box-shadow: 0 8px 24px #0009; }
.toast.info { background: var(--glass); border-color: var(--rim); color: var(--fg);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4); }
/* work in progress (pictures, reports): one chip each, always in view until the result is in the chat */
.jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.job { display: flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px 12px 6px 9px; border-radius: 16px;
  background: var(--glass); box-shadow: inset 0 0 0 1px var(--rim), 0 6px 20px #0008; font: 14px/1.3 var(--ui); color: var(--fg);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4); }
.job span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job svg { flex: none; width: 16px; height: 16px; stroke: var(--agent); stroke-width: 2.4; animation: spin 1s linear infinite; }
@media (prefers-reduced-motion: reduce) { .job svg { animation: none; } }
/* the composer: a rounded field that grows with the text, the send button inside it at the bottom right */
.composer { --send: 36px; display: flex; align-items: flex-end; gap: 4px; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 5px 5px 5px 0; border-radius: 24px; cursor: text;
  background: linear-gradient(180deg, #19223d, #141c32);
  box-shadow: inset 0 0 0 1px var(--rim), 0 10px 30px -14px #000c;
  transition: box-shadow .2s ease, background-color .2s ease; }
.composer:focus-within { box-shadow: inset 0 0 0 1px rgba(110, 139, 255, .55), 0 0 0 4px rgba(110, 139, 255, .13), 0 10px 30px -14px #000c; }
/* 17px: iOS zooms into a field with text under 16px */
.composer textarea { flex: 1; min-width: 0; display: block; margin: 0; border: 0; outline: 0; resize: none; background: transparent;
  color: var(--fg); font: 17px/1.4 var(--text); padding: 6px 6px 6px 16px; min-height: var(--send);
  max-height: min(9.6em, 32dvh); overflow-y: hidden; overscroll-behavior: contain; scrollbar-width: thin;
  caret-color: var(--you); -webkit-appearance: none; appearance: none; }
.composer textarea.scrolls { overflow-y: auto; }
.composer textarea::placeholder { color: var(--mut); opacity: .85; }
.composer textarea:focus-visible { outline: 0; }
.send { flex: none; width: var(--send); height: var(--send); min-height: 0; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 28%, #93a8ff, #6e8bff 55%, #5269e6); color: #0b1330;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 6px 16px -6px rgba(110, 139, 255, .8);
  transition: transform .18s cubic-bezier(.3, 1.5, .5, 1), opacity .18s ease, box-shadow .18s ease, color .18s ease; }
.send svg { width: 20px; height: 20px; stroke-width: 2.4; transition: transform .18s ease; }
.send:active:not(:disabled) { transform: scale(.9); }
/* empty: a quiet ghost of the button, not a dead grey block */
.send:disabled { opacity: 1; cursor: default; background: var(--raised); color: #5d6889; box-shadow: inset 0 0 0 1px var(--line); transform: scale(.9); }
.send:disabled svg { transform: translateY(1px); }
@media (prefers-reduced-motion: reduce) { .composer, .send, .send svg { transition: none; } }

.dock { position: relative; padding: 12px var(--safe-r) max(14px, env(safe-area-inset-bottom)) var(--safe-l); }
.dock::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(159, 227, 255, .16) 14%, rgba(159, 227, 255, .16) calc(50% - 66px),
    transparent calc(50% - 58px), transparent calc(50% + 58px), rgba(159, 227, 255, .16) calc(50% + 66px), rgba(159, 227, 255, .16) 86%, transparent); }
/* a low bar; the round button (play, or the mic in a conversation) sticks out above its top edge */
/* the home indicator needs ~20px, not the whole 34px inset: the side buttons have their own padding */
.dock { padding-top: 4px; padding-bottom: max(6px, calc(env(safe-area-inset-bottom) - 20px)); }
.chat { padding-bottom: 60px; }
.app:has(.jobs:not([hidden])) .chat { padding-bottom: 104px; }   /* the job strip floats over the end of the chat */
.overlay { bottom: calc(var(--dock-h, 60px) + 52px); }
.dock .composer:not([hidden]) ~ div { margin-top: 8px; }   /* the debug text-only call: the composer over pause | end */
/* text mode: the dock holds only the composer; nothing sticks out above it, so the chat ends right on it */
.app.typing .dock { padding: 6px var(--safe-r) max(10px, calc(env(safe-area-inset-bottom) - 12px)) var(--safe-l); }
.app.typing .dock::before { display: none; }
.app.typing .chat { padding-bottom: 16px; }
.app.typing:has(.jobs:not([hidden])) .chat { padding-bottom: 56px; }
.app.typing .overlay { bottom: calc(var(--dock-h, 60px) + 4px); }
/* the iPhone keyboard is up: the app fits the part of the screen above it (app.js), and the
   home-indicator inset is under the keyboard, so the composer sits right on the keyboard */
.app.kb { position: fixed; top: var(--vv-top, 0px); bottom: auto; height: var(--vv-h, 100%); }
.app.kb .dock { padding-bottom: 8px; }
.primary { width: 100%; min-height: 64px; border: 0; border-radius: 20px; background: var(--you); color: #0b1330; font: 700 21px/1.2 var(--ui); }
.quiet { background: transparent; border: 0; color: var(--mut); min-height: 40px; font-size: 15px; }

/* idle: · | play | stop (paused only); live: pause | mic | end */
/* one fixed row, so the bar keeps its height whatever buttons a state shows */
.dock-idle, .dock-live { display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: 52px; align-items: center; column-gap: 12px; }
.side { display: flex; flex-direction: column; align-items: center; gap: 2px; background: transparent; border: 0; color: var(--mut);
  font-size: 13px; padding: 4px; min-height: 48px; }
.side.end { color: var(--bad); }
.orb { position: relative; align-self: end; width: 88px; height: 88px; margin: -46px 0 2px; border-radius: 50%; padding: 0; border: 0;
  background: radial-gradient(circle at 50% 28%, #93a8ff, #6e8bff 50%, #5269e6); color: #0b1330;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), inset 0 -8px 16px rgba(18, 28, 90, .35), 0 14px 34px -10px rgba(110, 139, 255, .75);
  display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.orb svg { width: 34px; height: 34px; stroke-width: 2; position: relative; }
/* the Reactor's ring of ticks round the button: still when idle, turning while it connects, lit by the voice */
.orb::before { content: ""; position: absolute; inset: -12px; border-radius: 50%; pointer-events: none;
  background: repeating-conic-gradient(rgba(159, 227, 255, .9) 0 1.4deg, transparent 1.4deg 10deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4.5px));
  opacity: calc(.28 + var(--lvl, 0) * .72); transition: opacity 80ms linear; }
.orb.start.busy::before { animation: spin 4s linear infinite; opacity: .6; }
.orb.start.alert::before { background: repeating-conic-gradient(rgba(242, 180, 65, .95) 0 1.4deg, transparent 1.4deg 10deg); opacity: .8; }
/* the triangle box is centred, plus half a pixel so it looks centred */
.orb.start .i-play { fill: currentColor; stroke: none; transform: translateX(.5px); }
.orb.start .i-wait, .orb.start.busy .i-play { display: none; }
.orb.start.busy .i-wait { display: block; animation: spin 1s linear infinite; }
.orb.start:disabled { opacity: 1; background: var(--raised); color: var(--mut); box-shadow: inset 0 0 0 1px var(--line); }
.orb.start.alert { background: var(--warn); color: #1b1404; animation: nudge 1.4s ease-in-out infinite; }
#off-btn { justify-self: center; width: 52px; height: 52px; min-height: 0; padding: 0; display: grid; place-items: center; }
.side .i-stop { width: 36px; height: 36px; fill: currentColor; stroke: none; }
@keyframes spin { to { transform: rotate(360deg); } }
/* mic mode in the header: mic = open mic, hand = push-to-talk */
.icon-btn .m-ptt, .icon-btn.ptt .m-open { display: none; }
.icon-btn.ptt .m-ptt { display: block; }
.icon-btn.ptt, .icon-btn.on { color: var(--ok); }
.story-btn .s-chat, .story-btn[aria-pressed="true"] .s-book { display: none; }
.story-btn[aria-pressed="true"] .s-chat { display: block; }
.orb .mic-off, .orb.muted .mic-on { display: none; }
.orb.muted .mic-off { display: block; }
.orb.muted { background: var(--raised); color: var(--mut); box-shadow: inset 0 0 0 1px var(--line); }
.orb.muted::before { opacity: .12; }
.orb.ptt { background: var(--raised); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.orb.ptt .mic-off { display: none; } .orb.ptt .mic-on { display: block; }
.orb.ptt.talking { background: var(--ok); color: #06210f; box-shadow: 0 14px 34px -10px rgba(76, 211, 138, .7); }
.orb:active { transform: none; }
/* volume halo: --lvl 0..1 set from JS, colour follows who is speaking */
.halo { --hc: var(--you); position: absolute; inset: -18px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--hc) 62%, transparent); opacity: calc(.18 + var(--lvl, 0) * .5);
  transform: scale(calc(.9 + var(--lvl, 0) * .3)); transition: transform 80ms linear, opacity 80ms linear; }
.orb.agent .halo { --hc: var(--agent); }
.orb.muted .halo, .orb.ptt:not(.talking) .halo { opacity: 0; }

@keyframes nudge { 50% { transform: scale(1.02); box-shadow: 0 0 0 8px #f2b44133; } }
@media (prefers-reduced-motion: reduce) {
  .orb.start.alert, .orb.start.busy .i-wait, .orb.start.busy::before { animation: none; }
  .halo { transform: none; transition: none; }
}

/* ---------- stage: a widget in the chat's place (ADR-0024) ---------- */
.stage { grid-row: 2; min-height: 0; display: flex; flex-direction: column; }
.stage > * { flex: 1; min-height: 0; }

/* the story book: the picture stays put, the words of its scene run below */
.story { display: flex; flex-direction: column; gap: 10px; padding: 10px var(--safe-r) 0 var(--safe-l); }
.story-bar { display: flex; align-items: center; gap: 4px; min-height: 40px; }
.story-title { flex: 1; min-width: 0; margin: 0; font: 600 18px/1.2 var(--ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.story-bar .quiet { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; color: var(--fg); }
.story-bar .quiet svg { width: 20px; height: 20px; }
.story-listen svg { fill: currentColor; stroke: none; }
@media (max-width: 480px) { .story-shelf-btn span { display: none; } }
.story-book { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.story-pic { position: relative; flex: none; margin: 0; border-radius: 22px; overflow: hidden; background: var(--raised);
  aspect-ratio: 4 / 3; max-height: 52dvh; display: grid; cursor: zoom-in; }
.story-pic > * { grid-area: 1 / 1; }
.story-pic img { width: 100%; height: 100%; object-fit: contain; }
.story-pic img.turn { animation: turn .45s ease-out; }
@keyframes turn { from { opacity: 0; } }
.story-pic .pic-wait { display: grid; place-items: center; }
.story-pic .pic-wait svg { width: 44px; height: 44px; stroke: var(--agent); stroke-width: 2.2; animation: spin 1s linear infinite; }
.story-pic.empty { aspect-ratio: auto; min-height: 96px; cursor: default; }
.story-pic figcaption { align-self: end; justify-self: start; margin: 10px; padding: 4px 10px; border-radius: 10px;
  background: #0d1220b8; font: 14px/1.3 var(--ui); color: var(--fg); }
.story-pic figcaption:empty { display: none; }
.story-nav { align-self: center; width: 44px; height: 44px; min-height: 0; padding: 0; border-radius: 50%; display: grid; place-items: center;
  background: #0d1220a6; border: 0; }
.story-nav.prev { justify-self: start; margin-left: 8px; }
.story-nav.next { justify-self: end; margin-right: 8px; }
.story-count { align-self: start; justify-self: end; margin: 10px; padding: 2px 9px; border-radius: 10px; background: #0d1220b8;
  font: 13px/1.4 var(--ui); color: var(--mut); }
.story-count:empty { display: none; }
.story-text { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 64px; }
.story-text .line { margin: 0 0 12px; font: 19px/1.5 var(--text); color: var(--mut); white-space: pre-wrap; transition: color .3s; }
.story-text .line.now { color: var(--fg); }
.story-text .line.ask { font-style: italic; color: var(--fg); }
.story-text .line.ask::before { content: "? "; font-style: normal; font-weight: 600; color: var(--agent); }
.story-empty { padding: 16px; color: var(--mut); background: none !important; cursor: default !important; }
.story-text .who { display: block; font: 600 13px/1.2 var(--ui); color: var(--name, var(--agent)); }
.story-shelf { flex: 1; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0 0 64px; display: flex; flex-direction: column; gap: 10px; }
.story-shelf li { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 18px; background: var(--surface); cursor: pointer; }
.story-shelf img { flex: none; width: 88px; height: 66px; border-radius: 12px; object-fit: cover; background: var(--raised); }
.story-shelf div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.story-shelf b { font: 600 16px/1.3 var(--ui); }
.story-shelf span { font: 13px/1.3 var(--ui); color: var(--mut); }
@media (prefers-reduced-motion: reduce) {
  .story-pic img.turn, .story-pic .pic-wait svg { animation: none; }
}

/* ---------- events drawer (bottom sheet) ---------- */
.drawer { width: 100%; max-width: 640px; max-height: 82dvh; margin: auto auto 0; padding: 0 var(--safe-r) max(16px, env(safe-area-inset-bottom)) var(--safe-l);
  border: 0; border-radius: 24px 24px 0 0; background: rgba(20, 28, 49, .86); color: var(--fg); overflow-y: auto; overscroll-behavior: contain;
  -webkit-backdrop-filter: blur(26px) saturate(1.5); backdrop-filter: blur(26px) saturate(1.5); box-shadow: inset 0 1px 0 rgba(159, 227, 255, .16); }
.drawer::backdrop { background: #04060daa; }
.drawer[open] { animation: sheet .22s ease-out; }
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .drawer[open] { animation: none; } }
.drawer-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 20px 0 10px;
  background: linear-gradient(rgb(20, 28, 49) 75%, rgba(20, 28, 49, 0)); }
.drawer-head::before { content: ""; position: absolute; left: 50%; top: 7px; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px;
  background: rgba(233, 238, 248, .2); }
.drawer h2 { margin: 0; font: 600 21px/1.2 var(--ui); font-variation-settings: "SHRP" 70; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.events li { padding: 10px 12px; border-radius: 14px; background: rgba(10, 15, 28, .55); box-shadow: inset 0 0 0 1px var(--rim); }
.events li.pending { box-shadow: inset 0 0 0 1px rgba(242, 180, 65, .45); }
.events .ev-top { display: flex; align-items: center; gap: 8px; font: 600 15px/1.3 var(--ui); }
.events .ev-top time { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--mut); }
.events .ev-text { margin: 4px 0 0 16px; font-size: 14px; color: var(--mut); overflow-wrap: anywhere; }
.events li:not(.open) .ev-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4; overflow: hidden; }
.events .ev-note { margin: 4px 0 0 16px; font: 12px var(--ui); color: var(--warn); }
.events-empty { color: var(--mut); font-size: 15px; }
.quiet.danger { color: var(--bad); margin-top: 16px; }
.version { color: var(--mut); font-size: 13px; margin-top: 20px; font-variant-numeric: tabular-nums; }

/* full-screen picture */
.viewer { max-width: 100vw; max-height: none; width: 100%; height: 100%; margin: 0; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  border: 0; background: #04060df2; color: var(--fg); cursor: zoom-out; }
.viewer[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.viewer::backdrop { background: #04060df2; }
.viewer img { max-width: 100%; max-height: 85dvh; object-fit: contain; }
.viewer p { margin: 0 var(--gut); font: 16px/1.35 var(--ui); color: var(--mut); text-align: center; }

/* a report, full screen: the title bar stays, the text scrolls */
.reader { max-width: 100vw; max-height: none; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--fg); }
.reader[open] { display: flex; flex-direction: column; }
.reader::backdrop { background: var(--bg); }
.reader-head { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--rim);
  padding: calc(6px + env(safe-area-inset-top)) var(--safe-r) 6px var(--safe-l); }
.reader-head h2 { flex: 1; min-width: 0; margin: 0; font: 600 17px/1.3 var(--ui); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; width: 100%; max-width: 720px; margin: 0 auto;
  padding: 8px var(--safe-r) calc(24px + env(safe-area-inset-bottom)) var(--safe-l); overflow-wrap: anywhere; }
.md h1 { font: 700 24px/1.25 var(--ui); margin: 12px 0 8px; }
.md h2 { font: 700 20px/1.3 var(--ui); margin: 22px 0 6px; }
.md h3 { font: 600 17px/1.3 var(--ui); margin: 18px 0 4px; }
.md p, .md ul, .md ol { margin: 8px 0; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 3px 0; }
.md a { color: var(--agent); }
.md blockquote { margin: 10px 0; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--mut); }
.md code { font: 14px ui-monospace, monospace; background: var(--surface); padding: 1px 5px; border-radius: 6px; }
.md pre { background: var(--surface); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 15px; margin: 10px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; overflow-wrap: normal; }
.md th { background: var(--surface); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.md img { max-width: 100%; }
.md .md-wait { color: var(--mut); text-align: center; margin-top: 40px; }
.md .md-raw { white-space: pre-wrap; font: 14px/1.45 ui-monospace, monospace; background: none; padding: 0; }

.debug { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 8px; }
.debug h2 { font-size: 16px; }
.debug h3 { font: 600 14px var(--ui); color: var(--mut); }
.debug select, .debug textarea { width: 100%; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.debug textarea, .debug pre { font: 13px ui-monospace, monospace; }
.debug pre { white-space: pre-wrap; word-break: break-all; background: var(--bg); padding: 8px; border-radius: 10px; max-height: 240px; overflow: auto; }
.row { display: flex; gap: 8px; margin: 8px 0; align-items: center; }

/* ---------- pairing ---------- */
.pairing .app { display: none; }
.pair { max-width: 420px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px;
  padding: calc(24px + env(safe-area-inset-top)) var(--safe-r) calc(24px + env(safe-area-inset-bottom)) var(--safe-l); }
.pair h1 { margin: 0; font: 700 28px/1.2 var(--ui); }
.pair p { margin: 0; color: var(--mut); }
.pair code { color: var(--fg); background: var(--surface); padding: 2px 6px; border-radius: 6px; }
.pair input { width: 100%; font: 600 26px var(--ui); letter-spacing: .15em; text-align: center; padding: 14px; color: var(--fg);
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.pair-msg { padding: 10px 12px; border-radius: 12px; background: #3b1e2a; color: #ffd0d6 !important; }

/* ---------- phone on its side: ~375px of height, so the dock becomes a rail on the right ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  /* iOS insets both sides on its side, but the camera cut-out is only on one; app.js tells which
     (html[data-notch]), and the other side (the charging port) keeps just the gutter */
  :root { --ins-l: env(safe-area-inset-left); --ins-r: env(safe-area-inset-right);
    --safe-l: max(var(--gut), var(--ins-l)); --safe-r: max(var(--gut), var(--ins-r));
    --rail: calc(100px + var(--ins-r)); }
  html[data-notch="left"] { --ins-r: 0px; }
  html[data-notch="right"] { --ins-l: 0px; }
  .app { max-width: none; grid-template-columns: 1fr var(--rail); grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "chat dock"; }
  /* the header reaches the rounded screen corners: it keeps the full inset on both sides */
  .top { grid-area: top; padding: max(4px, env(safe-area-inset-top)) max(var(--gut), env(safe-area-inset-right)) 4px max(var(--gut), env(safe-area-inset-left)); }
  .chat { grid-area: chat; padding: 10px var(--gut) 16px var(--safe-l); }
  .feed { width: 100%; max-width: 760px; margin-inline: auto; }
  .feed li { max-width: 78%; }
  .feed li.picture { max-width: min(60%, 420px); }
  .feed li.picture img { width: auto; max-width: 100%; max-height: 58dvh; margin: 0 auto; }

  .dock::before { display: none; }
  .dock { grid-area: dock; display: flex; flex-direction: column; justify-content: center; border-top: 0; border-left: 1px solid var(--rim);
    padding: 8px max(12px, var(--ins-r)) max(8px, env(safe-area-inset-bottom)) 12px; }
  .chat { padding-bottom: 16px; }
  .app:has(.jobs:not([hidden])) .chat { padding-bottom: 56px; }
  .dock-idle, .dock-live { grid-template-columns: 1fr; grid-template-rows: none; justify-items: center; row-gap: 8px; }
  .dock-idle > span { display: none; }
  .orb { width: 76px; height: 76px; margin: 0; }
  .orb svg { width: 30px; height: 30px; }

  /* the book on its side: the picture on the left, the words on the right */
  .stage { grid-area: chat; }
  .story { padding: 6px var(--gut) 0 var(--safe-l); gap: 6px; }
  .story-book { flex-direction: row; gap: 16px; }
  .story-pic { flex: 1.3; aspect-ratio: auto; max-height: none; height: 100%; margin-bottom: 10px; }
  .story-text { flex: 1; padding-bottom: 16px; }
  .story-text .line { font-size: 18px; }
  .story-shelf { padding-bottom: 16px; }

  .overlay { right: var(--rail); bottom: 10px; }
  /* text mode on its side: no rail, the composer runs along the bottom under the chat */
  .app.typing { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; grid-template-areas: "top" "chat" "dock"; }
  .app.typing .dock { display: block; border-left: 0; padding: 4px var(--safe-r) max(6px, env(safe-area-inset-bottom)) var(--safe-l); }
  .app.typing .chat { padding-right: var(--safe-r); padding-bottom: 12px; }
  .app.typing .overlay { right: 0; bottom: calc(var(--dock-h, 60px) + 4px); }
  .overlay > * { max-width: 560px; }
  .drawer { max-height: 94dvh; }
  .viewer[open] { gap: 6px; }
  .viewer img { max-height: calc(100dvh - 56px); }
}
/* the part of a reply the voice did not get to (the user cut in): kept, greyed */
.feed li.agent .unsaid { color: var(--mut); opacity: .6; }
