/* Senpai home: the companion, immersive. Tokens and shared classes come from
   /ui/senpai.css; everything here is specific to this page. The scripts own the
   ids and classes listed at the top of index.html, so this file arranges them
   with positioning rather than moving them in the DOM. */

/* Fallbacks so the page still reads if /ui/senpai.css fails to load. */
:root {
  color-scheme: light;
  --home-plum: #2B1C33;
  --home-arch-top: #F3EEF9;
  --home-side-w: 0px;
  --home-dock-h: 132px;
}
body[data-page="home"] {
  margin: 0;
  background: var(--bg, #FBF6EE);
  color: var(--ink, #24152B);
  font-family: var(--font-ui, system-ui, sans-serif);
}
body[data-page="home"] [hidden] { display: none !important; }

/* ── the frame ─────────────────────────────────────────────────────────────── */
.home {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--home-side-w);
  overflow: hidden;
  isolation: isolate;
  transition: grid-template-columns var(--dur-3) var(--ease);
  /* A quiet warm field: one deeper ivory band low on the page, nothing else. */
  background:
    radial-gradient(60% 45% at 50% 108%, var(--bg-2), transparent 70%),
    var(--bg);
}
@media (min-width: 900px) {
  body[data-page="home"] { overflow: hidden; }
}
/* The whiteboard or the shared screen opens a column beside the avatar. */
.home:has(#screen-panel:not([hidden]), .board-panel:not([hidden])) {
  --home-side-w: clamp(340px, 34vw, 500px);
}

.home-top {
  position: absolute; z-index: 5; top: var(--s-5); left: var(--s-6); right: var(--s-6);
  display: flex; align-items: center; gap: var(--s-3);
  pointer-events: none;
}
.home-top > * { pointer-events: auto; }
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-size: 24px; font-weight: 500; letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--coral);
  box-shadow: 0 0 0 4px var(--coral-soft);
}

/* Status pill (app.js writes data-state and the text). */
.status {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 12px 5px 10px; border-radius: var(--r-pill);
  background: var(--surface); box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-2); font-size: 13px; font-weight: 600; line-height: 1.4; white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="ready"] .status-dot { background: var(--ok); }
.status[data-state="loading"] .status-dot,
.status[data-state="thinking"] .status-dot { background: var(--warn); animation: home-blink 1.1s ease-in-out infinite; }
.status[data-state="listening"] .status-dot { background: var(--ok); animation: home-blink 1.8s ease-in-out infinite; }
.status[data-state="user"] { color: var(--ink); }
.status[data-state="user"] .status-dot { background: var(--ink); }
.status[data-state="speaking"] { background: var(--coral-soft); color: var(--coral-ink); box-shadow: none; }
.status[data-state="speaking"] .status-dot { background: var(--coral); animation: home-blink 0.7s ease-in-out infinite; }
.status[data-state="error"] { background: #FBE1E1; color: #A12C2C; box-shadow: none; }
.status[data-state="error"] .status-dot { background: var(--err); }

.transcript-toggle {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 8px 0 16px; border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink); font: 600 14px/1 var(--font-ui); cursor: pointer;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-2) var(--ease), background-color var(--dur-2) var(--ease);
}
.transcript-toggle::after {
  content: ""; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-2);
  -webkit-mask: var(--icon-lines) center / 14px no-repeat, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask: var(--icon-lines) center / 14px no-repeat exclude, linear-gradient(#000 0 0);
}
.transcript-toggle:hover { box-shadow: var(--shadow-1); transform: translateY(-1px); }
.transcript-toggle:active { transform: scale(0.97); }
.transcript-toggle[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.transcript-toggle[aria-expanded="true"]::after { background: var(--lav-2); }
.transcript-count {
  min-width: 22px; padding: 2px 7px; border-radius: var(--r-pill);
  background: var(--lav); color: var(--ink); font-size: 12px; text-align: center;
}

/* ── the stage: avatar in a lavender arch ──────────────────────────────────── */
.stage-wrap {
  grid-column: 1; grid-row: 1;
  position: relative;
  min-width: 0; min-height: 0;
  container-type: size;
  display: grid; place-items: center;
  /* Room above for the name, below for the dock. */
  --arch-w: min(100cqw - 64px, (100cqh - 92px - var(--home-dock-h) - 24px) * 0.8, 620px);
  --arch-h: calc(var(--arch-w) / 0.8);
  --arch-r: calc(var(--arch-w) / 2);
  --arch-y: calc((92px - var(--home-dock-h) - 24px) / 2);
}
.stage-wrap > * { grid-area: 1 / 1; }

.stage {
  position: relative; z-index: 2;
  width: var(--arch-w); height: var(--arch-h);
  translate: 0 var(--arch-y);
  border-radius: var(--arch-r) var(--arch-r) var(--r-xl) var(--r-xl);
  overflow: hidden;
  background:
    radial-gradient(90% 55% at 50% 100%, var(--lav-2), transparent 72%),
    linear-gradient(180deg, var(--home-arch-top) 0%, var(--lav) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55), 0 30px 60px -30px rgba(36, 21, 43, 0.28);
  animation: home-stage-in 900ms var(--ease) both;
}
/* Ground shadow: the arch rests on the page. */
.stage-wrap::after {
  content: ""; z-index: 1; grid-area: 1 / 1; align-self: center;
  width: calc(var(--arch-w) * 0.9); height: 28px; border-radius: 50%;
  translate: 0 calc(var(--arch-y) + var(--arch-h) / 2 - 6px);
  background: radial-gradient(closest-side, rgba(36, 21, 43, 0.18), transparent);
  filter: blur(4px);
  animation: home-fade 900ms var(--ease) 200ms both;
}
sv-presenter {
  display: block; width: 100%; height: 100%;
  opacity: 0; transition: opacity 900ms var(--ease) 150ms;
}
.home[data-ready] sv-presenter { opacity: 1; }

.stage-overlay {
  position: absolute; inset: 0; z-index: 3;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-3); padding: var(--s-6); text-align: center;
  color: var(--ink-2); font-size: 15px;
}
.stage-overlay p { margin: 0; }
.stage-overlay--failure {
  background: linear-gradient(180deg, var(--home-arch-top), var(--lav));
}
.loader { display: flex; gap: 8px; }
.loader span {
  width: 9px; height: 9px; border-radius: 50%; background: var(--ink);
  opacity: 0.25; animation: home-loader 1.4s var(--ease) infinite;
}
.loader span:nth-child(2) { animation-delay: 0.18s; }
.loader span:nth-child(3) { animation-delay: 0.36s; }
#loading-text { font-variant-numeric: tabular-nums; }
.error-title { font-family: var(--font-display); font-size: 26px; color: var(--ink); line-height: 1.2; }
.error-detail { max-width: 34ch; font-size: 14px; color: var(--ink-2); }
.error-detail:empty { display: none; }
.stage-overlay--failure .btn { margin-top: var(--s-2); }

/* The floating window's note on the stage (mini.js injects it with dark styles). */
#stage .mini-floating {
  z-index: 4; background: rgba(233, 226, 245, 0.92); color: var(--ink-2);
  backdrop-filter: blur(6px); font-size: 15px;
}
#stage .mini-floating strong {
  color: var(--ink); font-family: var(--font-display); font-weight: 500; font-size: 22px; margin-bottom: 6px;
}

/* ── presence: the state of the conversation, around the arch ─────────────── */
.presence {
  position: relative; z-index: 1;
  width: var(--arch-w); height: var(--arch-h);
  translate: 0 var(--arch-y);
  pointer-events: none;
}
.presence > span { position: absolute; display: block; }
.presence-halo {
  inset: -16% -34%;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, rgba(214, 201, 236, 0.9), rgba(214, 201, 236, 0.45) 55%, transparent);
  animation: home-breathe 7s ease-in-out infinite, home-fade 1.2s var(--ease) 300ms both;
  transition: background var(--dur-3) var(--ease), filter var(--dur-3) var(--ease);
}
.presence-ring, .presence-orbit {
  inset: -12px;
  border-radius: calc(var(--arch-r) + 12px) calc(var(--arch-r) + 12px) calc(var(--r-xl) + 12px) calc(var(--r-xl) + 12px);
}
.presence-ring {
  border: 1.5px solid var(--lav-2);
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease), border-color var(--dur-2) var(--ease), scale 120ms linear;
}
/* The thinking comet: a bright arc travelling around the arch's outline. */
.presence-orbit {
  padding: 2px;
  background: conic-gradient(from var(--orbit-a, 0deg), transparent 0 62%, var(--lav-2) 80%, var(--coral) 96%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  opacity: 0; transition: opacity var(--dur-3) var(--ease);
}
@property --orbit-a { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

/* listening: a soft ring breathing outward */
.stage-wrap[data-presence="listening"] .presence-ring { opacity: 1; animation: home-ring 2.4s ease-in-out infinite; }
/* user speaking: the ring follows the microphone level */
.stage-wrap[data-presence="user"] .presence-ring {
  opacity: calc(0.55 + var(--level, 0) * 0.45);
  border-color: var(--ink-2); border-width: 2px;
  scale: calc(1 + var(--level, 0) * 0.045);
}
.stage-wrap[data-presence="user"] .presence-halo { animation-duration: 3s, 1.2s; }
/* thinking: the comet orbits, the halo shimmers */
.stage-wrap[data-presence="thinking"] .presence-orbit { opacity: 1; animation: home-orbit 2.2s linear infinite; }
.stage-wrap[data-presence="thinking"] .presence-halo { animation: home-shimmer 2.2s ease-in-out infinite; }
/* speaking: coral-tinted, livelier waves */
.stage-wrap[data-presence="speaking"] .presence-halo {
  background: radial-gradient(closest-side, rgba(253, 227, 218, 0.95), rgba(242, 107, 78, 0.16) 62%, transparent);
  animation: home-breathe 1.6s ease-in-out infinite;
}
.stage-wrap[data-presence="speaking"] .presence-ring {
  opacity: 1; border-color: rgba(242, 107, 78, 0.55);
  animation: home-wave 1.3s ease-out infinite;
}
/* muted: still, so it is obvious nothing is being heard */
.stage-wrap[data-muted] .presence-ring { opacity: 0.6; animation: none; border-style: dashed; border-color: var(--muted); }
/* error: calm and clear, no motion */
.stage-wrap[data-presence="error"] .presence-halo { animation: none; background: radial-gradient(closest-side, rgba(207, 63, 63, 0.12), transparent); }
.stage-wrap[data-presence="error"] .presence-ring { opacity: 0.7; border-color: rgba(207, 63, 63, 0.45); animation: none; }
/* interrupted: a brief flash */
.stage-wrap[data-flash] .presence-ring { animation: home-flash 650ms var(--ease) both; border-color: var(--coral); }
.stage-wrap[data-flash] .stage { animation: home-nudge 450ms var(--ease) both; }

/* ── captions: the latest exchange beside the avatar ───────────────────────── */
.captions {
  position: relative; z-index: 4;
  align-self: start; justify-self: center;
  width: clamp(220px, 22vw, 320px);
  /* to the right of the avatar's head, overlapping the arch's edge a little */
  translate: calc(var(--arch-w) / 2 + min(10vw, 150px)) calc(50cqh + var(--arch-y) - var(--arch-h) * 0.32);
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-2);
  pointer-events: none;
}
.caption { margin: 0; overflow-wrap: anywhere; }
.caption--say {
  position: relative;
  padding: 16px 20px; border-radius: var(--r-l) var(--r-l) var(--r-l) 6px;
  background: var(--surface); box-shadow: var(--shadow-2);
  font-family: var(--font-display); font-size: 18px; line-height: 1.4; color: var(--ink);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; line-clamp: 6; overflow: hidden;
  transition: opacity var(--dur-2) var(--ease);
}
.caption--say[data-pending] { color: var(--muted); font-style: italic; }
.captions:has(.caption--heard:not([hidden])) .caption--say { opacity: 0.5; }
.caption--heard {
  align-self: flex-end; max-width: 92%;
  padding: 9px 14px; border-radius: var(--r-m) var(--r-m) 6px var(--r-m);
  background: var(--ink); color: var(--bg); font-size: 14px; line-height: 1.4;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.caption--error {
  order: -1;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-m);
  background: #FBE1E1; color: #8E2424; font-size: 14px; line-height: 1.45; font-weight: 500;
  box-shadow: var(--shadow-1);
}
.caption--error::before {
  content: "!"; flex: none; display: grid; place-items: center; width: 20px; height: 20px; margin-top: 1px;
  border-radius: 50%; background: var(--err); color: #fff; font-size: 12px; font-weight: 700;
}
.caption--in { animation: home-caption-in var(--dur-3) var(--ease) both; }

/* ── the side column (#chat-log's parent): shared screen and whiteboard ────── */
.conversation {
  grid-column: 2; grid-row: 1;
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; gap: var(--s-4);
  padding: 84px var(--s-6) calc(var(--home-dock-h) + 8px) 0;
  overflow-y: auto; overflow-x: hidden;
}
.side-card, .conversation > .board-panel {
  flex: none;
  animation: home-slide-in var(--dur-3) var(--ease) both;
}
.screen-error {
  /* A toast under the name, visible whatever is open. */
  position: absolute; z-index: 6; top: 76px; left: 50%; translate: -50% 0;
  max-width: min(520px, calc(100% - 32px));
  margin: 0; padding: 10px 16px; border-radius: var(--r-pill);
  background: #FBE1E1; color: #8E2424; font-size: 14px; font-weight: 500; box-shadow: var(--shadow-1);
}

.screen-panel {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-3); border-radius: var(--r-l);
  background: var(--surface); box-shadow: var(--shadow-2);
}
.screen-preview {
  position: relative; aspect-ratio: 16 / 10; max-height: 46vh;
  border-radius: var(--r-m); overflow: hidden; background: var(--home-plum);
}
.screen-preview video, .screen-preview img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block;
}
.screen-snapshot-tag {
  position: absolute; left: 8px; bottom: 8px; z-index: 2;
  padding: 4px 10px; border-radius: var(--r-pill); background: rgba(36, 21, 43, 0.78);
  font-size: 12px; color: var(--bg);
}
.screen-snapshot-tag button {
  border: 0; padding: 0; background: none; color: var(--coral-soft); font: inherit; cursor: pointer; text-decoration: underline;
}
.screen-panel[data-busy="true"] .screen-preview { outline: 3px solid var(--coral); outline-offset: -3px; }
.screen-bar { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-1) var(--s-1); }
.screen-hint { flex: 1; min-width: 0; font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.screen-placeholder {
  position: absolute; inset: 0; margin: 0; display: grid; place-items: center; padding: var(--s-4);
  text-align: center; font-size: 14px; color: var(--lav-2);
}
/* The pointer's origin is the arrow tip (top-left of the SVG); JS sets translate(left, top). */
.screen-pointer { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; width: 26px; height: 26px; }
.screen-pointer svg { display: block; fill: var(--coral); stroke: #fff; stroke-width: 1.4; filter: drop-shadow(0 2px 6px rgba(36, 21, 43, 0.45)); }
.screen-pointer-label {
  position: absolute; left: 22px; top: 18px; padding: 3px 9px; border-radius: var(--r-pill); white-space: nowrap;
  background: var(--coral); color: #2A0E06; font-size: 12px; font-weight: 700;
}
.screen-pointer--flip .screen-pointer-label { left: auto; right: 100%; }

/* ── transcript drawer (#chat-log with its head and empty hint) ────────────── */
.transcript-head, .chat-log, .empty-hint {
  position: fixed; right: 0; z-index: var(--z-panel, 30);
  width: min(420px, 100vw);
  visibility: hidden; translate: 100% 0;
  transition: translate var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
}
.home[data-transcript] :is(.transcript-head, .chat-log, .empty-hint) {
  visibility: visible; translate: 0 0;
  transition: translate var(--dur-3) var(--ease), visibility 0s;
}
ul.chat-log {
  top: 0; bottom: 0;
  list-style: none; margin: 0; padding: 92px var(--s-5) var(--s-5);
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--s-3);
  background: var(--surface);
  border-radius: var(--r-xl) 0 0 var(--r-xl);
  box-shadow: -20px 0 60px rgba(36, 21, 43, 0.14);
}
.transcript-head {
  top: 0; z-index: calc(var(--z-panel, 30) + 1);
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--s-4) var(--s-3) var(--s-5);
  background: linear-gradient(var(--surface) 75%, transparent);
  border-radius: var(--r-xl) 0 0 0;
}
.transcript-title { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 500; }
.empty-hint {
  top: 50%; z-index: calc(var(--z-panel, 30) + 1);
  margin: 0; padding: 0 var(--s-6); text-align: center; color: var(--muted); font-size: 15px;
}
.msg {
  max-width: 88%; padding: 11px 15px; border-radius: var(--r-m);
  white-space: pre-wrap; overflow-wrap: break-word; font-size: 15px; line-height: 1.5;
  animation: home-rise var(--dur-2) var(--ease) both;
}
.msg--user { align-self: flex-end; background: var(--ink); color: var(--bg); border-bottom-right-radius: 6px; }
.msg--assistant { align-self: flex-start; background: var(--bg-2); color: var(--ink); border-bottom-left-radius: 6px; }
.msg--pending { color: var(--muted); animation: home-blink 1.2s ease-in-out infinite; }
.msg--error { align-self: flex-start; background: #FBE1E1; color: #8E2424; font-size: 14px; }

/* ── the dock: talk, type, and the quieter tools ───────────────────────────── */
.dock {
  position: absolute; z-index: 6;
  bottom: var(--s-5);
  left: calc((100% - var(--home-side-w)) / 2);
  translate: -50% 0;
  width: max-content; max-width: calc(100% - var(--home-side-w) - 32px);
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2);
  transition: left var(--dur-3) var(--ease);
  animation: home-rise var(--dur-3) var(--ease) 450ms both;
}
.dock-main {
  display: flex; align-items: center; gap: var(--s-2);
  padding: 8px; border-radius: var(--r-pill);
  background: var(--surface); box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
}
.voice-bar { order: -1; display: flex; align-items: center; min-width: 0; }

/* The one primary control. */
.voice-start {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 0 26px 0 20px; border: 0; border-radius: var(--r-pill);
  background: var(--ink); color: var(--bg); font: 600 16px/1 var(--font-ui); white-space: nowrap; cursor: pointer;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-2) var(--ease), background-color var(--dur-2) var(--ease);
}
.voice-start::before {
  content: ""; width: 20px; height: 20px; flex: none; background: var(--coral);
  -webkit-mask: var(--icon-mic) center / contain no-repeat; mask: var(--icon-mic) center / contain no-repeat;
}
.voice-start:hover:not(:disabled) { background: #3A2443; box-shadow: 0 10px 26px rgba(36, 21, 43, 0.26); transform: translateY(-1px); }
.voice-start:active:not(:disabled) { transform: scale(0.97); }
.voice-start:disabled { opacity: 0.45; cursor: not-allowed; }
.voice-start:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.voice-live { display: flex; align-items: center; gap: var(--s-2); padding-left: var(--s-3); min-width: 0; }
/* Microphone level: a dot that swells with the user's voice (--level is 0–1). */
.voice-meter {
  flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 calc(var(--level, 0) * 10px) rgba(46, 158, 107, 0.22);
  transition: box-shadow 0.1s linear;
}
.voice-live[data-state="loading"] .voice-meter, .voice-live[data-state="thinking"] .voice-meter { background: var(--warn); }
.voice-live[data-state="speaking"] .voice-meter { background: var(--coral); }
.voice-state { min-width: 7.5em; font-size: 14px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-live[data-state="user"] .voice-state, .voice-live[data-state="speaking"] .voice-state { color: var(--ink); }
.dock-pill {
  min-height: 44px; padding: 0 18px; border-radius: var(--r-pill);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: 600 14px/1 var(--font-ui); cursor: pointer; white-space: nowrap;
  transition: transform var(--dur-1) var(--ease), background-color var(--dur-2) var(--ease);
}
.dock-pill:hover { background: var(--bg-2); }
.dock-pill:active { transform: scale(0.96); }
.voice-mute[aria-pressed="true"] { background: var(--coral-soft); border-color: transparent; color: var(--coral-ink); }
.voice-end { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.voice-end:hover { background: #3A2443; }
.voice-note { max-width: 46ch; margin: 0; font-size: 13px; color: var(--ink-2); text-align: center; }

/* Typing: a quiet field that opens up while in use. */
.chat-form {
  display: flex; align-items: center; gap: 6px;
  margin: 0; padding: 0 6px 0 0; border-radius: var(--r-pill);
  background: var(--bg); box-shadow: inset 0 0 0 1px var(--line);
  transition: box-shadow var(--dur-2) var(--ease);
}
.chat-form[data-open]:focus-within { box-shadow: inset 0 0 0 1.5px var(--ink), 0 0 0 4px var(--lav); }
.chat-input {
  width: 150px; min-height: 44px; max-height: 120px; resize: none;
  padding: 12px 6px 12px 18px; border: 0; background: transparent; color: var(--ink);
  font: 15px/1.35 var(--font-ui); outline: none;
  transition: width var(--dur-3) var(--ease);
  field-sizing: content;
}
.chat-input::placeholder { color: var(--muted); }
.chat-form[data-open] .chat-input, .chat-form[data-filled] .chat-input { width: min(340px, 40vw); }
.chat-input:disabled { cursor: not-allowed; }
.send-btn {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border: 0; border-radius: 50%; background: var(--ink); color: var(--bg);
  font: 700 17px/1 var(--font-ui); cursor: pointer;
  scale: 0.6; opacity: 0; pointer-events: none;
  transition: scale var(--dur-2) var(--ease), opacity var(--dur-2) var(--ease);
}
.chat-form[data-open] .send-btn, .chat-form[data-filled] .send-btn { scale: 1; opacity: 1; pointer-events: auto; }
.send-btn:disabled { background: var(--muted); cursor: not-allowed; }
.send-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* The tools: text-light, under the dock. Labels come from the scripts, icons from here. */
.dock-tools { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px var(--s-1); }
.dock-tool {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 36px; padding: 0 12px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-2); font: 500 13.5px/1 var(--font-ui); white-space: nowrap; cursor: pointer;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.dock-tool::before {
  content: ""; width: 16px; height: 16px; flex: none; background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat;
}
.dock-tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.8); color: var(--ink); }
.dock-tool:active:not(:disabled) { transform: scale(0.96); }
.dock-tool:disabled { opacity: 0.4; cursor: not-allowed; }
.dock-tool[aria-pressed="true"] { background: var(--lav); color: var(--ink); }
.dock-tool--share { --icon: var(--icon-screen); }
.dock-tool--mini { --icon: var(--icon-pip); }
.dock-tool--new { --icon: var(--icon-new); }
.dock-tool--settings { --icon: var(--icon-sliders); }
.link-btn {
  border: 0; padding: 0; background: none; color: var(--coral-ink); font: inherit; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.screen-source-btn, .screen-ext-hint { font-size: 12.5px; color: var(--muted); white-space: nowrap; padding: 0 6px; }
.screen-source-btn:hover, .screen-ext-hint:hover { color: var(--coral-ink); }

/* Buttons the scripts create (board.js, settings.js, mini.js) use these names. */
.ghost-btn, .primary-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: var(--r-pill);
  font: 600 13.5px/1 var(--font-ui); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.ghost-btn { border: 1px solid rgba(36, 21, 43, 0.2); background: transparent; color: var(--ink); }
.ghost-btn:hover { background: var(--surface); border-color: var(--ink); }
.primary-btn { border: 1px solid var(--ink); background: var(--ink); color: var(--bg); }
.ghost-btn:active, .primary-btn:active { transform: scale(0.97); }
.ghost-btn:disabled, .primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── screen-share indicator and the extension popover ──────────────────────── */
.screen-indicator {
  position: fixed; z-index: var(--z-share, 70); top: var(--s-4); left: 50%; translate: -50% 0;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 14px; border-radius: var(--r-pill);
  background: var(--share); color: #fff; box-shadow: 0 10px 30px rgba(229, 72, 77, 0.35);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  animation: home-drop var(--dur-3) var(--ease) both;
}
@media (min-width: 900px) {
  body.has-rail .screen-indicator { left: calc(50% + var(--rail-w) / 2); }
}
.screen-rec-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #fff;
  animation: home-blink 1.4s ease-in-out infinite;
}
.screen-indicator button {
  min-height: 30px; padding: 0 14px; border: 0; border-radius: var(--r-pill); cursor: pointer;
  background: #fff; color: #A3161C; font: 700 13px/1 var(--font-ui);
}
.screen-indicator button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.screen-ext-info {
  /* A popover: closed it is display: none; open it sits in the top layer above the dock. */
  position: fixed; inset: auto auto calc(var(--home-dock-h) + 40px) 50%; translate: -50% 0; margin: 0;
  width: min(24rem, calc(100vw - 32px));
  padding: var(--s-5); border: 0; border-radius: var(--r-l);
  background: var(--surface); color: var(--ink); font-size: 14px; line-height: 1.5;
  box-shadow: var(--shadow-2);
}
.screen-ext-info p { margin: 0 0 10px; }
.screen-ext-info ol { margin: 0 0 10px; padding-left: 1.2rem; }
.screen-ext-info li { margin-bottom: 4px; }
.screen-ext-info a { color: var(--coral-ink); }
.screen-ext-info code { font-size: 13px; padding: 1px 5px; border-radius: 6px; background: var(--bg-2); }
.screen-ext-title { font-family: var(--font-display); font-size: 20px; }
.screen-ext-note { color: var(--muted); font-size: 13px; }
.screen-ext-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--s-4); }

/* ── settings dialog (settings.js) ─────────────────────────────────────────── */
.settings {
  width: min(880px, calc(100vw - 32px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 0; border-radius: var(--r-xl);
  background: var(--bg); color: var(--ink);
  box-shadow: 0 30px 80px rgba(36, 21, 43, 0.25);
}
.settings[open] { animation: home-pop var(--dur-3) var(--ease) both; }
.settings::backdrop { background: rgba(36, 21, 43, 0.38); backdrop-filter: blur(3px); }
.settings-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); margin: 0; }
.settings-head, .settings-foot { flex: none; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-5) var(--s-6); }
.settings-head { justify-content: space-between; padding-bottom: var(--s-3); }
.settings-eyebrow { margin: 0 0 4px; }
.settings-head h2 { margin: 0; font-family: var(--font-display); font-size: 30px; font-weight: 500; line-height: 1.1; }
.settings-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-2) var(--s-6) var(--s-5); }
.settings-section + .settings-section { margin-top: var(--s-5); }
.settings-section h3 { margin: 0 0 var(--s-2); font-size: 16px; font-weight: 600; }
.settings-name { width: 100%; max-width: 360px; }
.settings-label { margin: var(--s-5) 0 var(--s-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.settings-hint { margin: 6px 0; color: var(--ink-2); font-size: 14px; }
.settings-error { margin: 6px 0; color: var(--err); font-size: 14px; }
.settings-more { margin: var(--s-6) 0 0; font-size: 14px; color: var(--ink-2); }
.settings-more a { color: var(--ink); font-weight: 600; }
.settings-foot { border-top: 1px solid var(--line); flex-wrap: wrap; justify-content: flex-end; padding-top: var(--s-4); padding-bottom: var(--s-4); }
.settings-message { flex: 1 1 14rem; margin: 0; font-size: 14px; color: var(--ink-2); }
.settings-message:empty { display: none; }
.settings-message[data-kind="ok"] { color: var(--ok); }
.settings-message[data-kind="warn"] { color: var(--warn); }
.settings-message[data-kind="error"] { color: var(--err); }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: var(--s-3); }
.avatar-option {
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 6px 6px 10px;
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), transform var(--dur-1) var(--ease);
}
.avatar-option:hover { border-color: rgba(36, 21, 43, 0.3); transform: translateY(-2px); }
.avatar-option[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.avatar-option:focus-visible, .voice-option:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.avatar-thumb {
  display: grid; place-items: center; aspect-ratio: 1; margin: 0; border-radius: 12px; overflow: hidden;
  background: linear-gradient(180deg, var(--home-arch-top), var(--lav));
}
.avatar-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-thumb-missing { font-size: 12px; color: var(--muted); }
.avatar-name { padding: 0 4px; font-size: 13px; font-weight: 500; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-current {
  align-self: flex-start; padding: 2px 8px; border-radius: var(--r-pill);
  background: var(--coral-soft); color: var(--coral-ink); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.avatar-option .badge-current { position: absolute; top: 12px; left: 12px; }

.voice-list { display: flex; flex-direction: column; gap: var(--s-2); }
.voice-row {
  display: flex; align-items: center; gap: var(--s-3); padding: 4px 12px 4px 4px;
  border: 1px solid var(--line); border-radius: var(--r-m); background: var(--surface);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}
.voice-row.is-selected { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.voice-option {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding: 10px 12px;
  border: 0; border-radius: 12px; background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.voice-option:disabled { cursor: not-allowed; opacity: 0.5; }
.voice-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-weight: 600; }
.voice-tagline { font-size: 13px; font-weight: 400; color: var(--ink-2); }
.voice-meta { font-size: 12px; color: var(--coral-ink); text-transform: capitalize; }
.voice-desc { font-size: 13px; color: var(--ink-2); }
.voice-preview { flex: none; }
.voice-preview[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* ── responsive ────────────────────────────────────────────────────────────── */
/* Narrow stage (tablet, or the side column open on a laptop): captions sit over the arch's foot. */
@container (max-width: 900px) {
  .captions {
    align-self: end; width: min(calc(var(--arch-w) + 40px), calc(100cqw - 32px));
    translate: 0 calc(-1 * (var(--home-dock-h) + 36px));
    align-items: center;
  }
  .caption--say { font-size: 16px; padding: 12px 16px; border-radius: var(--r-l); -webkit-line-clamp: 3; line-clamp: 3; text-align: center; }
  .caption--heard { align-self: center; }
}

@media (max-width: 899.98px) {
  :root { --home-dock-h: 124px; }
  .home {
    height: calc(100dvh - var(--bar-h, 0px) - env(safe-area-inset-bottom));
    grid-template-columns: minmax(0, 1fr);
  }
  body:not(.has-rail) .home { height: 100dvh; }
  .home:has(#screen-panel:not([hidden]), .board-panel:not([hidden])) { --home-side-w: 0px; }
  .home-top { top: var(--s-4); left: var(--s-4); right: var(--s-4); gap: var(--s-2); }
  .brand { font-size: 21px; }
  .stage-wrap { --arch-w: min(100cqw - 40px, (100cqh - 76px - var(--home-dock-h) - 20px) * 0.8, 520px); --arch-y: calc((76px - var(--home-dock-h) - 20px) / 2); }

  /* Panels stack over the lower stage, above the dock, as a sheet. */
  /* Same grid cell as the stage, not positioned, so the dock and the drawer keep .home as their box. */
  .conversation {
    grid-column: 1; grid-row: 1; z-index: 5;
    align-self: end;
    max-height: calc(100% - 64px - var(--home-dock-h));
    margin-bottom: var(--home-dock-h);
    padding: var(--s-3) var(--s-4);
    justify-content: flex-end;
    pointer-events: none;
  }
  .conversation:not(:has(> .side-card:not([hidden]), > .board-panel:not([hidden]))) { padding: 0; }
  /* With a panel up, the captions move to the top so neither hides the other. */
  .home:has(#screen-panel:not([hidden]), .board-panel:not([hidden])) .captions { align-self: start; translate: 0 64px; }
  .home:has(#screen-panel:not([hidden]), .board-panel:not([hidden])) .caption--say { -webkit-line-clamp: 2; line-clamp: 2; font-size: 15px; }
  .conversation > * { pointer-events: auto; }
  .conversation > .board-panel { max-width: 560px; width: 100%; align-self: center; }
  .side-card { max-width: 560px; width: 100%; align-self: center; }
  .screen-preview { max-height: 30vh; }

  .dock { bottom: var(--s-3); left: 50%; width: calc(100% - 24px); max-width: 560px; }
  .dock-main { width: 100%; }
  .voice-bar { flex: 1; }
  .voice-start { flex: 1; justify-content: center; padding: 0 18px; }
  .voice-live { flex: 1; padding-left: var(--s-2); }
  .voice-state { min-width: 0; flex: 1; }
  .chat-input { width: 150px; }
  .chat-form[data-open] .chat-input, .chat-form[data-filled] .chat-input { width: 100%; }
  .chat-form[data-open], .chat-form[data-filled] { flex: 1; }
  /* While typing, the field takes the room and the main button folds to its microphone. */
  .dock-main:has(.chat-form[data-open], .chat-form[data-filled]) .voice-bar { flex: none; }
  .dock-main:has(.chat-form[data-open], .chat-form[data-filled]) .voice-start { flex: none; width: 52px; padding: 0; gap: 0; font-size: 0; }
  .dock-main:has(.chat-form[data-open], .chat-form[data-filled]) .voice-state { display: none; }

  .transcript-head, .chat-log, .empty-hint { width: 100vw; translate: 0 100%; }
  ul.chat-log { top: 12dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: 0 -20px 60px rgba(36, 21, 43, 0.18); padding-top: 80px; padding-bottom: calc(var(--s-5) + var(--bar-h, 0px) + env(safe-area-inset-bottom)); }
  .transcript-head { top: 12dvh; border-radius: var(--r-xl) var(--r-xl) 0 0; z-index: calc(var(--z-panel, 30) + 1); }
  .home[data-transcript] :is(.transcript-head, .chat-log, .empty-hint) { translate: 0 0; }
  .empty-hint { top: 50%; }

  .screen-ext-info { bottom: calc(var(--bar-h, 0px) + var(--home-dock-h) + 24px); }
  .screen-indicator { top: var(--s-3); }
}

@media (max-width: 560px) {
  /* Tools become icon buttons; their names stay readable to assistive tech. */
  .dock-tool { font-size: 0; gap: 0; width: 40px; height: 40px; padding: 0; justify-content: center; }
  .dock-tool::before { width: 18px; height: 18px; }
  .transcript-toggle-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .transcript-toggle { padding: 0 6px 0 10px; gap: 6px; }
  .status { font-size: 12px; padding: 4px 10px 4px 8px; }
  .voice-start { font-size: 15px; }
  .voice-mute, .voice-end { padding: 0 14px; }
  /* Typing collapses to a keyboard key beside the main button and opens to the full dock. */
  .chat-form { position: relative; padding: 0; }
  .chat-input { width: 48px; height: 48px; min-height: 48px; padding: 13px 0 0 48px; overflow: hidden; field-sizing: fixed; }
  .chat-input::placeholder { color: transparent; }
  .chat-form::before {
    content: ""; position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 20px; height: 20px;
    background: var(--ink-2); pointer-events: none;
    -webkit-mask: var(--icon-keyboard) center / contain no-repeat; mask: var(--icon-keyboard) center / contain no-repeat;
    transition: opacity var(--dur-2) var(--ease);
  }
  .chat-form[data-open]::before, .chat-form[data-filled]::before { opacity: 0; }
  .chat-form[data-open] .chat-input, .chat-form[data-filled] .chat-input { padding: 13px 6px 0 18px; overflow: auto; }
  .chat-form[data-open] .chat-input::placeholder { color: var(--muted); }
  .chat-form[data-open] .send-btn, .chat-form[data-filled] .send-btn { margin-right: 6px; }
  .chat-form:not([data-open]):not([data-filled]) .send-btn { display: none; }

  .settings { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: 0; border-radius: 0; }
  .settings-inner { max-height: 100dvh; height: 100dvh; }
  .settings-head, .settings-foot { padding-left: var(--s-4); padding-right: var(--s-4); }
  .settings-body { padding-left: var(--s-4); padding-right: var(--s-4); }
  .avatar-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .voice-row { flex-direction: column; align-items: stretch; padding: 4px 4px 10px; }
  .voice-preview { align-self: flex-start; margin-left: 12px; }
}
@media (max-width: 380px) {
  .voice-live .voice-state { display: none; }
  .brand { font-size: 19px; }
}

/* ── icons (masks; decorative, the buttons carry their own text) ───────────── */
:root {
  --icon-mic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Crect x='9' y='3' width='6' height='11' rx='3'/%3E%3Cpath d='M5 11a7 7 0 0 0 14 0M12 18v3'/%3E%3C/svg%3E");
  --icon-screen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='12' rx='2'/%3E%3Cpath d='M8 20h8M12 16v4'/%3E%3C/svg%3E");
  --icon-pip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Crect x='12' y='12' width='6' height='4' rx='1' fill='%23000'/%3E%3C/svg%3E");
  --icon-new: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 1 0 3-6.7L3 8'/%3E%3Cpath d='M3 3v5h5'/%3E%3C/svg%3E");
  --icon-sliders: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 7h10M18 7h2M4 17h4M12 17h8'/%3E%3Ccircle cx='16' cy='7' r='2'/%3E%3Ccircle cx='10' cy='17' r='2'/%3E%3C/svg%3E");
  --icon-keyboard: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='6' width='20' height='12' rx='2'/%3E%3Cpath d='M6 10h.01M10 10h.01M14 10h.01M18 10h.01M8 14h8'/%3E%3C/svg%3E");
  --icon-lines: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M5 7h14M5 12h14M5 17h9'/%3E%3C/svg%3E");
}

/* ── motion ────────────────────────────────────────────────────────────────── */
@keyframes home-stage-in { from { opacity: 0; transform: translateY(14px) scale(0.965); } to { opacity: 1; transform: none; } }
@keyframes home-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes home-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes home-drop { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes home-pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes home-slide-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes home-caption-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes home-blink { 50% { opacity: 0.35; } }
@keyframes home-loader { 0%, 100% { opacity: 0.2; transform: translateY(0); } 50% { opacity: 0.9; transform: translateY(-4px); } }
@keyframes home-breathe { 0%, 100% { transform: scale(0.97); opacity: 0.85; } 50% { transform: scale(1.03); opacity: 1; } }
@keyframes home-shimmer { 0%, 100% { transform: scale(0.98); filter: hue-rotate(0deg); opacity: 0.8; } 50% { transform: scale(1.02); filter: hue-rotate(-25deg); opacity: 1; } }
@keyframes home-ring { 0%, 100% { transform: scale(1); opacity: 0.45; } 50% { transform: scale(1.025); opacity: 1; } }
@keyframes home-wave { 0% { transform: scale(1); opacity: 0.9; } 100% { transform: scale(1.07); opacity: 0; } }
@keyframes home-orbit { to { --orbit-a: 360deg; } }
@keyframes home-flash { 0% { opacity: 1; transform: scale(1); border-width: 4px; } 100% { opacity: 0; transform: scale(1.06); } }
@keyframes home-nudge { 30% { transform: scale(0.985); } 100% { transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .home *, .home *::before, .home *::after, .home::after,
  .screen-indicator, .screen-rec-dot, .settings, .settings * {
    animation: none !important;
    transition: none !important;
  }
  /* Without motion the states still read: ring visible, colours change. */
  .stage-wrap[data-presence="speaking"] .presence-ring,
  .stage-wrap[data-presence="listening"] .presence-ring { opacity: 1; }
  .stage-wrap[data-presence="thinking"] .presence-orbit { opacity: 1; }
}
