/* Structure and behaviour of the interface. Colours, fonts and sizes come from theme.css (see there for how to customise). */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: var(--font-size)/var(--line-height) var(--font-body); color: var(--text);
  background: radial-gradient(1200px 700px at 30% 20%, var(--stage-1), var(--stage-2));
}
main { --stage: 62%; display: grid; grid-template-columns: var(--stage) 8px minmax(0, 1fr); height: 100%; }
body.resizing { cursor: col-resize; user-select: none; }
.divider { cursor: col-resize; background: var(--fill-1); transition: background .15s; touch-action: none; }
.divider:hover, .divider:focus-visible, body.resizing .divider { background: var(--accent); outline: none; }

/* ---- companion side ---- */
.stage { position: relative; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; min-height: 0; }
.avatar { position: relative; width: 100%; height: min(96%, 840px); animation: bob 5s ease-in-out infinite; filter: drop-shadow(0 18px 36px rgba(0,0,0,.45)); }
.avatar.talking { animation-duration: 1.6s; }
.avatar svg { width: 100%; height: 100%; display: block; }
.avatar img.frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; user-select: none; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-5px) rotate(.4deg); } }
.tools { position: absolute; top: 12px; right: 14px; left: 150px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; z-index: 2; }
.status { position: absolute; top: 14px; left: 16px; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: var(--font-size-small); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.dot.on { background: var(--ok); }
.bubble {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(560px, 88%); max-height: 30%; overflow-y: auto; padding: 12px 18px;
  background: var(--bubble-bg); color: var(--bubble-text); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); white-space: pre-wrap;
}
/* Full body: she fills the height, so the bubble moves beside her instead of over her legs. */
.stage.full-body .bubble {
  left: auto; right: 16px; bottom: auto; top: 56px; transform: none;
  width: max(150px, min(280px, calc(50% - 130px))); max-height: 50%;
}
/* The credit a picture pack asks for (credit.txt): always readable, never hidden by the bubble. */
.pack-credit { position: absolute; left: 12px; bottom: 6px; z-index: 2; max-width: calc(100% - 24px); font-size: 12px; line-height: 1.3; color: rgba(255,255,255,.88); text-shadow: 0 0 3px rgba(0,0,0,.9), 0 1px 2px rgba(0,0,0,.9); pointer-events: none; }
.stage:has(.pack-credit:not([hidden])) .bubble { bottom: 40px; }
.save-form { position: absolute; top: 52px; right: 14px; z-index: 3; display: flex; gap: 8px; padding: 8px; background: var(--stage-tool-bg); border-radius: var(--radius-md); border: 1px solid var(--line); }

/* ---- controls: one family of buttons and fields ---- */
button {
  border: 0; border-radius: var(--radius-md); padding: 0 16px; font: inherit; cursor: pointer;
  color: var(--accent-text); background: var(--accent);
}
button:disabled { opacity: .5; cursor: default; }
button.ghost, select.ghost { background: var(--fill-2); color: var(--text); padding: 6px 12px; font-size: var(--font-size-small); }
button.ghost:hover:not(:disabled) { background: var(--fill-3); }
select.ghost { border: 0; border-radius: var(--radius-md); cursor: pointer; padding: 6px 10px; }
/* The one control most people never find: Looks. It is tinted with the accent so it stands out from the plain row. */
select.looks-pop { background: color-mix(in srgb, var(--accent) 30%, var(--fill-2)); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
select.looks-pop:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 42%, var(--fill-2)); }
select.looks-pop:disabled { box-shadow: none; font-weight: inherit; }
/* Shown once, under the toolbar, until it is dismissed or Looks is used. */
.looks-hint { position: absolute; top: 56px; right: 14px; z-index: 3; display: flex; gap: 10px; align-items: center; max-width: min(340px, calc(100% - 28px)); padding: 8px 10px 8px 12px; background: var(--popover); color: var(--text); border: 1px solid var(--accent); border-radius: var(--radius-md); font-size: var(--font-size-small); box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.looks-hint[hidden] { display: none; }
.looks-hint button { flex: none; }
.pack-confirm { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--accent); border-radius: var(--radius-md); background: var(--fill-2); font-size: var(--font-size-small); }
.pack-confirm p { margin: 0 0 8px; }
.pack-confirm-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.stage > .pack-confirm { position: absolute; top: 56px; right: 14px; z-index: 5; width: min(360px, calc(100% - 28px)); margin: 0; background: var(--popover); box-shadow: 0 6px 20px rgba(0,0,0,.35); }
select.ghost option { color: var(--text); background: var(--popover); }
input[type="text"], input:not([type]), textarea {
  font: inherit; color: var(--text); background: var(--fill-1); border: 1px solid var(--line); border-radius: var(--radius-md);
}
input:focus-visible { outline: 2px solid var(--focus); }
button.icon { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: var(--radius-pill); background: none; color: var(--muted); }
button.icon:hover:not(:disabled) { background: var(--hover); color: var(--text); }
button.icon.mic.listening { color: var(--accent-text); background: var(--accent); animation: mic-pulse 1.4s infinite ease-in-out; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 0 5px var(--hover); } }
@media (prefers-reduced-motion: reduce) { button.icon.mic.listening { animation: none; } }
button.icon.send { background: var(--accent); color: var(--accent-text); }
button.icon.send:hover:not(:disabled) { background: var(--accent-hover); }
.icon-stop { display: none; }
button.icon.send.stop .icon-send { display: none; }
button.icon.send.stop .icon-stop { display: block; }
button.icon.send:disabled { background: var(--fill-2); color: var(--muted); opacity: 1; }
.seg-group { display: flex; background: var(--code-bg); border-radius: var(--radius-md); padding: 3px; gap: 2px; }
button.seg { background: transparent; color: var(--muted); padding: 5px 14px; font-size: var(--font-size-small); border-radius: var(--radius-md); }
button.seg.on { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
button:disabled.seg { opacity: .4; }

/* ---- chat panel ---- */
.panel { display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; }
.panel header { display: flex; justify-content: space-between; align-items: center; padding: 14px var(--panel-padding); border-bottom: 1px solid var(--line); }
.name-row { display: flex; align-items: center; min-width: 0; }
.panel h1.name { cursor: text; border-radius: var(--radius-sm); padding: 2px 6px; margin-left: -6px; }
button.name-reset { width: 28px; height: 28px; flex: none; }
.panel h1.name:hover, .panel h1.name:focus-visible { background: var(--hover); outline: none; }
input.name-edit { font: 500 22px/1 var(--font-heading); color: var(--text); background: var(--fill-1); border: 1px solid var(--focus); border-radius: var(--radius-sm); padding: 2px 6px; margin-left: -6px; outline: none; max-width: 14em; }
.panel h1 { margin: 0; font: 500 22px/1 var(--font-heading); color: var(--text); }
.workbar { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--fill-1); }
.workrow { display: flex; gap: 8px; align-items: center; }
button.icon.small { width: 26px; height: 26px; flex: none; font-size: 16px; line-height: 1; border: 1px solid var(--line); }
.worksummary { display: none; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--font-size-small); color: var(--muted); }
.worksummary-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workbar.collapsed { padding-top: 6px; padding-bottom: 6px; }
.workbar.collapsed .worksummary { display: flex; }
.workbar.collapsed .workbody { display: none; }
.workrow input { flex: 1; min-width: 0; padding: 7px 10px; font: var(--font-size-small) var(--font-mono); }
.setuprow { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 12px; color: var(--text); cursor: pointer; }
.setuprow .muted { color: var(--muted); }
.setuprow .computer-hint { display: none; color: var(--muted); font-style: italic; }
.setuprow.computer-only { cursor: default; opacity: 0.6; }
.setuprow.computer-only .computer-hint { display: inline; }
.workinfo { margin-top: 6px; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.workinfo code { font: 12px var(--font-mono); color: var(--text); }
.workinfo button { all: unset; cursor: pointer; text-decoration: underline; margin-left: 6px; }
.meter { padding: 6px 14px 8px; font: 12px var(--font-mono); color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.meter span { white-space: nowrap; }
.meter-toggle { all: unset; cursor: pointer; padding: 0 4px; border-radius: var(--radius-sm); }
.meter-toggle:hover, .meter-toggle:focus-visible { color: var(--text); }
.meter-toggle.warn { color: var(--warn-text); }
.meter-toggle.bad { color: var(--error-text); }
.meter.stale { opacity: .65; }
.meter .warn { color: var(--warn-text); }
.meter .bad { color: var(--error-text); }

/* ---- messages ---- */
.log { flex: 1; overflow-y: auto; padding: 16px var(--panel-padding); display: flex; flex-direction: column; gap: var(--gap); }
.msg { max-width: 88%; padding: 9px 13px; border-radius: var(--radius-lg); line-height: var(--line-height); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--surface); }
.msg.bot { align-self: flex-start; background: none; padding-left: 2px; max-width: 100%; white-space: normal; }
.msg.bot > :first-child { margin-top: 0; }
.msg.bot > :last-child { margin-bottom: 0; }
.msg.bot p, .msg.bot ul, .msg.bot ol, .msg.bot pre, .msg.bot blockquote { margin: 0 0 .7em; }
.msg.bot h3, .msg.bot h4, .msg.bot h5, .msg.bot h6 { margin: .9em 0 .4em; font-size: 1em; font-weight: 600; }
.msg.bot h3 { font-size: 1.1em; }
.msg.bot ul, .msg.bot ol { padding-left: 1.4em; }
.msg.bot li { margin: .15em 0; }
.msg.bot code { font: .9em var(--font-mono); background: var(--fill-2); padding: .1em .35em; border-radius: 6px; }
.msg.bot pre { padding: 10px 12px; overflow-x: auto; background: var(--code-bg); border-radius: var(--radius-sm); }
.msg.bot pre code { background: none; padding: 0; font-size: 12.5px; white-space: pre; }
.msg.bot blockquote { padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.msg.bot a { color: var(--accent); }
.msg.look { align-self: center; color: var(--accent); font-size: var(--font-size-small); }
.msg.sys { align-self: center; color: var(--muted); font-size: var(--font-size-small); }
.msg.sys a { color: inherit; }
/* An action, apart from what she says: its own small italic bubble. Chat only; work mode keeps the asterisks as emphasis. */
.msg.narration {
  align-self: center; width: fit-content; max-width: 86%;
  padding: 5px 14px; background: var(--fill-1); border: 1px solid var(--line); border-radius: var(--radius-pill);
  color: var(--muted); font-family: var(--font-heading); font-style: italic; font-size: var(--font-size-small);
  text-align: center; white-space: normal;
}
.msg.narration p { margin: 0; }
/* A problem in the page itself (errors.js): tap for the details. */
.msg.sys.problem { align-self: stretch; max-width: 100%; text-align: left; cursor: pointer; color: var(--warn-text); background: var(--warn-bg); border: 1px solid var(--warn-line); padding: 6px 10px; border-radius: var(--radius-md); overflow-wrap: anywhere; }
.msg.sys.problem pre { display: none; margin: 6px 0 0; font: 11px/1.4 var(--font-mono); white-space: pre-wrap; color: var(--text); }
.msg.sys.problem.open pre { display: block; }
.msg.tool { align-self: flex-start; max-width: 100%; font: 12px var(--font-mono); color: var(--muted); background: var(--fill-1); padding: 5px 9px; border-radius: var(--radius-sm); }
.msg.tool .st { margin-right: 6px; }
.msg.tool.error { color: var(--error-text); }
.msg .pics { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 6px; margin-bottom: 6px; }
.msg .pics img { max-height: 160px; max-width: 100%; border-radius: var(--radius-sm); }
.msg .pics:last-child { margin-bottom: 0; }
.msg .pics-note { font-size: 12px; opacity: .8; }
.msg.shell { align-self: stretch; max-width: 100%; padding: 8px 12px; border-radius: var(--radius-md); background: var(--code-bg); border: 1px solid var(--line); font: 12.5px/1.45 var(--font-mono); }
.msg.shell .shell-cmd { color: var(--accent); overflow-wrap: anywhere; }
.msg.shell pre { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; max-height: 320px; overflow: auto; }
.msg.shell .shell-wait, .msg.shell .shell-status { margin-top: 4px; color: var(--muted); }
.msg.shell .shell-status { color: var(--error-text); }
.shell-hint { padding: 0 6px; font-size: 12px; color: var(--warn-text); }
form.composer.shell { border-color: var(--warn-text); }
form.composer.shell textarea { font-family: var(--font-mono); }
.msg.pic-strip { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px; max-width: 100%; }
.thumb-btn { padding: 0; width: 96px; height: 96px; overflow: hidden; border-radius: var(--radius-md); border: 1px solid var(--line); background: var(--fill-1); cursor: zoom-in; }
.thumb-btn:hover, .thumb-btn:focus-visible { border-color: var(--accent); outline: none; }
.thumb-btn img { display: block; width: 100%; height: 100%; object-fit: cover; }
.msg .pics .thumb-btn { width: 72px; height: 72px; }
.viewer { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .82); }
.viewer > img { max-width: 92vw; max-height: 86vh; border-radius: var(--radius-sm); box-shadow: var(--shadow); background: var(--code-bg); }
.viewer-caption { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: 13px; color: #fff; text-shadow: 0 1px 4px #000; }
.viewer-btn { position: absolute; width: 44px; height: 44px; padding: 0; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .16); color: #fff; font-size: 22px; line-height: 44px; }
.viewer-btn:hover, .viewer-btn:focus-visible { background: rgba(255, 255, 255, .3); outline: none; }
.viewer-btn.close { top: 16px; right: 16px; font-size: 18px; }
.viewer-btn.prev { left: 16px; top: 50%; transform: translateY(-50%); }
.viewer-btn.next { right: 16px; top: 50%; transform: translateY(-50%); }
.msg.perm { align-self: stretch; max-width: 100%; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius-md); }
.perm-title { font-weight: 600; margin-bottom: 4px; }
.perm-desc { font-size: var(--font-size-small); color: var(--muted); margin-bottom: 6px; }
.perm-input { margin: 0 0 8px; padding: 8px 10px; max-height: 160px; overflow: auto; background: var(--code-bg); border-radius: var(--radius-sm); font: 12px/1.4 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.perm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.perm-actions button { padding: 6px 12px; font-size: var(--font-size-small); }
.perm-actions .deny { background: var(--fill-2); color: var(--text); }
.perm-more { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.perm-more button { padding: 5px 10px; font-size: 12px; }
.msg.perm.memory { background: var(--fill-1); border-color: var(--line); }
.memory-fact { margin-bottom: 8px; overflow-wrap: anywhere; }
.persona-text { white-space: pre-wrap; max-height: 40vh; overflow-y: auto; padding: 8px 10px; background: var(--fill-2, rgba(0, 0, 0, 0.18)); border-radius: 8px; }
.persona-note { margin-bottom: 8px; font-size: 12px; opacity: 0.8; }
.memory-undo { margin-left: 4px; padding: 2px 8px; font-size: 12px; }
.perm-done { font-size: var(--font-size-small); color: var(--muted); }
.perm-option { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0 0; font-size: var(--font-size-small); cursor: pointer; }
.perm-option input { margin-top: 3px; }
.perm-option-detail { color: var(--muted); }
.queue { display: flex; flex-direction: column; gap: 4px; padding: 0 4px 6px; font-size: 12px; color: var(--muted); }
.queue-item { display: flex; align-items: center; gap: 8px; }
.queue-item::before { content: "↳"; opacity: .6; }
.queue-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.working { display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px; font-size: 12px; color: var(--muted); }
.working .dots { display: inline-flex; gap: 4px; }
.working .dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: working-bounce 1.2s infinite ease-in-out; }
.working .dots i:nth-child(2) { animation-delay: .15s; }
.working .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes working-bounce { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .working .dots i { animation: none; opacity: .7; } }

/* ---- composer ---- */
form.composer { margin: 8px 14px 6px; padding: 10px 10px 8px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
form.composer:focus-within { border-color: var(--focus); }
.composer textarea { resize: none; max-height: 180px; padding: 4px 6px; border: 0; background: none; outline: none; }
.composer-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px; }
.composer-right { display: flex; align-items: center; gap: 4px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px; }
.attachments .thumb { position: relative; }
.attachments img { display: block; height: 56px; max-width: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.attachments .thumb button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0; border-radius: 50%; font-size: 12px; line-height: 20px; background: var(--popover); color: var(--text); border: 1px solid var(--line); }
.drop-target { outline: 2px dashed var(--accent); outline-offset: -6px; }

/* ---- popover menus (mirror the hidden <select>s) ---- */
.menus { display: flex; align-items: center; gap: 2px; }
.menu { position: relative; }
.menu > button { white-space: nowrap; display: flex; align-items: center; gap: 4px; padding: 5px 9px; border-radius: var(--radius-md); background: none; color: var(--muted); font-size: var(--font-size-small); }
.menu > button:hover:not(:disabled), .menu > button[aria-expanded="true"] { background: var(--hover); color: var(--text); }
.menu > button svg { opacity: .7; }
.menu-pop { position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 5; min-width: 260px; max-width: calc(100vw - 16px); max-height: min(60vh, 460px); overflow-y: auto; overscroll-behavior: contain; padding: 6px; border-radius: var(--radius-lg); background: var(--popover); border: 1px solid var(--line); box-shadow: var(--shadow); }
.menu-pop .menu-title { padding: 6px 10px 4px; font-size: 12px; color: var(--muted); }
.menu-pop button { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--radius-md); cursor: pointer; color: var(--text); }
.menu-pop button:hover, .menu-pop button:focus-visible { background: var(--hover); }
.menu-pop .item-label { display: block; }
.menu-pop .item-desc { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.menu-pop .check { color: var(--selected); }
.menu-backdrop { display: none; }

/* ---- preset gallery ---- */
.gallery { position: absolute; top: 52px; right: 14px; z-index: 4; width: min(520px, calc(100% - 28px)); max-height: calc(100% - 70px); overflow-y: auto; padding: 10px; border-radius: var(--radius-lg); background: var(--popover); border: 1px solid var(--line); box-shadow: var(--shadow); }
.gallery-title { padding: 2px 6px 8px; font-size: 12px; color: var(--muted); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.preset { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border-radius: var(--radius-md); background: var(--fill-1); color: var(--text); font-size: 12px; }
.preset:hover, .preset:focus-visible { background: var(--hover); outline: 2px solid var(--focus); }
.preset-pic { display: block; width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm); background: radial-gradient(circle at 50% 30%, var(--stage-1), var(--stage-2)); overflow: hidden; }
.preset-pic svg { display: block; width: 100%; height: 100%; }
.preset-pic img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; } /* a pack's head and shoulders */
.preset-pic.plain { display: grid; place-items: center; padding: 6px; box-sizing: border-box; text-align: center; font-size: 11px; color: var(--muted); }
.preset[aria-current="true"] { outline: 2px solid var(--focus); }
.preset:disabled { opacity: .75; }
.outfit-row { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; padding: 8px; border-radius: var(--radius-md); background: var(--fill-2); }
.preset-name { text-transform: capitalize; }
.preset-name.as-written { text-transform: none; }
.preset-state { font-size: 10px; color: var(--muted); }
.has-update .preset-state { color: var(--accent); }

/* A phone: the companion above, the chat below, and a bar between them to drag up or down (`#divider`,
   the same control as the vertical line on a wide screen). The column is `minmax(0, 1fr)`, not `1fr`:
   a plain `1fr` will not shrink under its widest content, so the page came out wider than the screen
   and she stood off to one side. */
@media (max-width: 800px) {
  main { --stage-h: 46%; grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--stage-h) 20px minmax(0, 1fr); height: 100dvh; }
  body.resizing { cursor: row-resize; }
  .bubble { display: none; }
  .divider { position: relative; cursor: row-resize; }
  .divider::after { content: ""; position: absolute; left: 50%; top: 50%; width: 48px; height: 4px; margin: -2px 0 0 -24px; border-radius: 2px; background: var(--muted); opacity: .8; }
  .panel { border-left: 0; overflow-y: auto; }
  .log { min-height: 96px; } /* never squeezed to nothing; if the rest does not fit, the panel scrolls */
  .status { top: 10px; left: 12px; }
  .tools { top: 38px; left: 10px; right: 10px; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; }
  .tools > * { flex: none; }
  /* The row scrolls sideways with no scrollbar, so its right edge fades out as the hint that there is more (the voice pickers make it wider than a
     phone). The spacer at the end keeps the last button clear of the fade once it is scrolled all the way, and when everything fits it is empty. */
  .tools { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
  .tools::after { content: ""; flex: none; width: 28px; }
  #voice-pick { max-width: 140px; } /* it is as wide as its longest voice name (300px and more), which pushes Speed, Full body and Reset look away */
  .avatar { height: max(calc(100% - 84px), 120px); }
  .save-form { top: 82px; left: 10px; right: 10px; }
  .looks-hint { top: 84px; left: 10px; right: 10px; max-width: none; }
  .save-form input { flex: 1; min-width: 0; }

  /* The composer's row: attach on the left, the menus (wrapping if they must) and send on the right. Send never
     leaves the screen. */
  .composer-bar { flex-wrap: nowrap; align-items: flex-end; }
  .composer-right { flex: 1; min-width: 0; align-items: flex-end; }
  .menus { flex: 1; min-width: 0; flex-wrap: wrap; justify-content: flex-end; }
  .menu { min-width: 0; }
  .menu > button { max-width: 100%; padding: 6px 8px; }
  .menu > button > span { overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
  button.icon.send { flex: none; }

  /* A menu opens as a sheet over the bottom of the screen, scrolling if it is long, behind a dimmed backdrop. */
  .menu-backdrop { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, .5); }
  .menu-pop {
    position: fixed; z-index: 30; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); min-width: 0; max-width: none;
    max-height: min(72dvh, 560px); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch;
  }
  .menu-pop .menu-title { padding: 6px 12px 8px; font-size: 13px; }
  .menu-pop button { padding: 12px; min-height: 48px; align-items: center; }
  .menu-pop .item-desc { font-size: 13px; }
}

/* ---- her behind the chat: `main[data-view="behind"]` (the button in the chat header) ----
   Both panels share one grid cell; the chat is on top and see-through, so she shows faintly behind it.
   Her buttons and speech bubble are hidden (the chat shows what she says), the connection dot stays,
   and so does a picture pack's credit line, which has to stay readable wherever she is: it runs across the
   top and the chat starts below it (`--credit-h`, measured in app.js). */
#view svg { display: block; }
#view .view-behind, main[data-view="behind"] #view .view-split { display: none; }
main[data-view="behind"] #view .view-behind { display: block; }
main[data-view="behind"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
main[data-view="behind"] > .stage, main[data-view="behind"] > .panel { grid-area: 1 / 1; }
main[data-view="behind"] > .divider, main[data-view="behind"] .tools, main[data-view="behind"] .save-form, main[data-view="behind"] .looks-hint,
main[data-view="behind"] .bubble, main[data-view="behind"] .status #status { display: none; }
main[data-view="behind"] .avatar { height: min(100%, 900px); }
main[data-view="behind"] .status { position: fixed; z-index: 5; top: calc(25px + var(--credit-h, 0px)); left: 6px; pointer-events: none; }
main[data-view="behind"] .pack-credit { position: fixed; z-index: 6; top: 0; left: 0; right: 0; bottom: auto; max-width: none; padding: 3px 10px; text-align: center; background: rgba(0, 0, 0, .6); }
main[data-view="behind"] .panel { position: relative; z-index: 1; padding-top: var(--credit-h, 0px); background: color-mix(in srgb, var(--panel) 55%, transparent); border-left: 0; }
main[data-view="behind"] .msg.bot { background: color-mix(in srgb, var(--panel) 72%, transparent); padding: 6px 10px; border-radius: var(--radius-md); }
main[data-view="behind"] .msg.narration { background: color-mix(in srgb, var(--panel) 72%, transparent); }
main[data-view="behind"] .msg.user { background: color-mix(in srgb, var(--surface) 72%, transparent); }
@media (min-width: 801px) {
  main[data-view="behind"] .panel { align-items: center; }
  main[data-view="behind"] .panel > * { width: min(100%, 780px); }
}

/* the pack studio panel (public/studio.js): not a .gallery, which the page's closeGallery() removes whenever a pack arrives or is picked */
.studio { position: absolute; top: 52px; right: 14px; z-index: 4; width: min(520px, calc(100% - 28px)); max-height: calc(100% - 70px); overflow-y: auto; padding: 10px; border-radius: var(--radius-lg); background: var(--popover); border: 1px solid var(--line); box-shadow: var(--shadow); }
.studio label { display: block; margin: 8px 6px 2px; font-size: 12px; color: var(--muted); }
.studio select, .studio input, .studio textarea { width: 100%; box-sizing: border-box; font: inherit; }
.studio .pack-confirm-buttons { margin: 10px 0 4px; }
.studio-status { margin: 8px 6px 0; font-size: var(--font-size-small); min-height: 1.2em; }
.studio-bad { color: var(--danger, #c0392b); }
.studio-candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 8px; }
.studio-candidates .preset img { width: 100%; display: block; border-radius: var(--radius-md); background: var(--fill-2); }
.studio-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.studio-tiles .preset img { width: 100%; display: block; border-radius: var(--radius-md); }
.studio-selected { outline: 2px solid var(--accent); }
.studio-spend { margin: 2px 6px 0; font-size: var(--font-size-small); font-weight: 600; }
.studio-spend:empty { display: none; }
.studio-paid { border: 1px solid #d9822b; }
.studio-flags { margin: 8px 6px 0; padding-left: 18px; font-size: var(--font-size-small); }
.studio-flags li { margin-bottom: 4px; }
.studio-review { display: block; }
.studio-confirm button { margin: 4px 6px 0 0; }
.studio-zoom { position: absolute; top: 52px; left: 14px; right: 14px; z-index: 5; height: calc(100% - 66px); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.studio-zoom img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius-lg); background: var(--popover); border: 1px solid var(--line); box-shadow: var(--shadow); }
.studio-zoom[hidden] { display: none; }
.studio-zoom.beside { right: auto; width: calc(100% - 576px); }

.studio-handover-text { width: 100%; font-family: var(--mono, monospace); font-size: 12px; box-sizing: border-box; }

.gallery-filter { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 10px 8px; }
.gallery-filter[hidden] { display: none; }
.gallery-empty { grid-column: 1 / -1; margin: 0; padding: 8px 12px; color: var(--muted, inherit); font-size: var(--font-size-small); }
.gallery-filter .chip { padding: 3px 10px; border-radius: 999px; font-size: var(--font-size-small); background: var(--panel-2, rgba(255,255,255,.08)); color: var(--text); border: 1px solid transparent; }
.gallery-filter .chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft, rgba(255,150,120,.18)); }
