/*
 * Stage 5 — the demo's face.
 *
 * Design intent, in one paragraph: the character stage is the hero and everything else
 * stays quiet — Peter's brief is "the chat should feel unremarkable". The one deliberate
 * device is typographic: roleplay has two registers, and the type encodes them. Narration
 * (the story's opening, the *asterisk* prose inside replies) is set in a serif italic —
 * book voice. Spoken dialogue and all UI chrome are the system sans — chat voice. Palette
 * is a deep aubergine-black with one soft violet accent: adjacent to the character-bot
 * world this demos into, without borrowing anyone's brand.
 */

:root {
  --ink: #16131c;        /* page */
  --panel: #201b2b;      /* raised surfaces */
  --panel-2: #282136;    /* interactive surfaces */
  --line: #352c48;       /* hairlines */
  --text: #ece9f2;
  --muted: #9d94b0;
  --accent: #b48eff;     /* violet — interaction + the user's own voice */
  --accent-ink: #1d1329; /* text on accent */
  --danger: #ff9b9b;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* `display: grid` on .chat-grid would defeat the hidden attribute without this. */
.view[hidden] { display: none !important; }

/* ── Picker ─────────────────────────────────────────────────────────────── */

#pick {
  max-width: 1060px;
  margin: 0 auto;
  padding: 48px 24px 64px;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 18px;
}

.pick-head h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(28px, 4.5vw, 40px);
  margin: 0 0 6px;
}

.sub {
  color: var(--muted);
  margin: 0 0 34px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

/* The clickable face of a card. A plain button so keyboards get it for free. */
.card-face {
  display: block;
  width: 100%;
  padding: 0;
  background: none;
  color: inherit;
  text-align: left;
  border-radius: 0;
}

.card-face img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: top;
  background: #0e0b14;
}

.card-body { padding: 12px 14px 14px; }

.card-body h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  margin: 0;
}

.card-body .tagline {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
}

/* ── Character builder card ─────────────────────────────────────────────────
   The grid's last card: a dropzone at rest; while a build runs it mirrors the
   build in one line (portrait thumbnail, name, N of M steps) and opens the
   builder modal on click. Same card chrome as the cast so it reads as "the
   next character", not as a form. */

.build-card { display: flex; flex-direction: column; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  flex: 1;
  min-height: 280px;
  padding: 24px 16px;
  background: none;
  color: var(--muted);
  border: 2px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
}

.dropzone:hover,
.dropzone.drag {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--panel-2);
}

.dropzone.busy {
  border-style: solid;
  color: var(--text);
}

.dz-plus {
  font-size: 44px;
  line-height: 1;
  font-weight: 200;
}

.dz-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  color: inherit;
}

.dz-hint { font-size: 13px; }

.dropzone.busy .dz-hint { color: var(--accent); }

.dz-thumb {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  background: #0e0b14;
  border: 2px solid var(--accent);
  margin-bottom: 8px;
}

@media (prefers-reduced-motion: no-preference) {
  .dropzone.busy .dz-thumb { animation: build-breathe 2.4s ease-in-out infinite; }
  @keyframes build-breathe {
    50% { box-shadow: 0 0 0 8px rgba(180, 142, 255, .12); }
  }
}

.build-error {
  color: var(--danger);
  font-size: 12.5px;
  margin: 10px 0 0;
  overflow-wrap: anywhere;
}

/* ── Character builder modal ─────────────────────────────────────────────────
   Two columns: the character as it becomes on the left, the build graph on the
   right. The left box takes the art's own aspect ratio (set by builder.js) so
   the face-box overlay is plain percentages of it. */

.build-modal {
  width: min(1080px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  overflow: visible; /* the caption hangs below the box (.build-caption); the columns clip themselves */
}

.build-modal::backdrop {
  background: rgba(8, 6, 12, .7);
  backdrop-filter: blur(3px);
}

.build-split {
  display: grid;
  grid-template-columns: minmax(300px, 5fr) 6fr;
  grid-template-rows: minmax(0, 1fr);
  height: min(700px, 88vh);
  border-radius: 13px; /* the box's 14px, inside its 1px border */
  overflow: hidden;
}

.build-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
  padding: 18px;
  background: radial-gradient(120% 85% at 50% 30%, #2c2440 0%, #191423 62%, #120e1a 100%);
  border-right: 1px solid var(--line);
}

/* Sized by builder.js to fit the column at the art's ratio; the fallback square
   only shows until the first image reports its size. */
.build-stage-box {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: var(--ar, 1);
  border-radius: 12px;
  overflow: hidden;
  background: #0e0b14;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

.build-photo,
.build-live {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.build-photo {
  object-fit: contain;
  transition: opacity .5s ease;
}

.build-photo.fading { opacity: 0; }

.build-live[hidden] { display: none; }

/* Assess: a scan line sweeping the picture — "looking at it". */
.build-scan {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent 0%, rgba(180, 142, 255, .22) 48%, rgba(180, 142, 255, .55) 50%, rgba(180, 142, 255, .22) 52%, transparent 100%);
  background-size: 100% 24%;
  background-repeat: no-repeat;
  animation: build-scan 1.6s linear infinite;
}

@keyframes build-scan {
  from { background-position: 0 -24%; }
  to { background-position: 0 124%; }
}

/* The face box locks on: corner brackets that tighten from the whole frame. */
.build-facebox,
.build-cropbox {
  position: absolute;
  pointer-events: none;
  transition: left .55s cubic-bezier(.2, .8, .2, 1), top .55s cubic-bezier(.2, .8, .2, 1),
    width .55s cubic-bezier(.2, .8, .2, 1), height .55s cubic-bezier(.2, .8, .2, 1), opacity .3s;
}

.build-facebox {
  border: 1.5px solid rgba(180, 142, 255, .9);
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(0, 0, 0, .35);
}

.build-facebox::before,
.build-facebox::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2.5px solid var(--accent);
}

.build-facebox::before { top: -3px; left: -3px; border-right: none; border-bottom: none; }
.build-facebox::after { bottom: -3px; right: -3px; border-left: none; border-top: none; }

.build-facebox.locked { animation: build-lock .6s ease .5s 1; }

@keyframes build-lock {
  30% { box-shadow: 0 0 0 6px rgba(180, 142, 255, .25), inset 0 0 0 1px rgba(0, 0, 0, .35); }
}

.build-cropbox {
  border: 1px dashed rgba(236, 233, 242, .55);
  border-radius: 6px;
}

.build-stage-box .modal-intro-btn { z-index: 2; }

/* Never squeezed: the identity keeps its content height and the stage box above
   gives way (builder.js fits the box to what is left). */
.build-identity {
  flex: 0 0 auto;
  width: 100%;
  text-align: center;
}

.build-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 24px;
  margin: 0;
  line-height: 1.2;
}

.build-name.reveal { animation: build-reveal .6s ease both; }

@keyframes build-reveal {
  from { opacity: 0; transform: translateY(6px); }
}

.build-identity .tagline {
  color: var(--muted);
  font-size: 13px;
  margin: 3px 0 0;
}

.build-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}

.chip {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  animation: build-reveal .4s ease both;
}

/* The caption hangs BELOW the box, over the backdrop — a subtitle, not a panel: no
   background, no border, and no room taken inside the modal (it used to sit under the
   identity, and the stage box gave way to every line). A modal <dialog> is position:
   fixed, so it is the containing block and top: 100% is its bottom edge. The switch
   for the reading sits at the row's right edge; the text keeps clear of it. */
.build-caption {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none; /* the band is not a surface: a click beside the text is a backdrop click */
}

.build-caption-text,
.build-voice { pointer-events: auto; }

/* Shrink-wrapped and centred, so only the words themselves catch a click. */
.build-caption-text {
  display: inline-block;
  max-width: 100%;
  padding: 0 48px;
}

/* The intro, in the book voice — what the character will say once it can. */
.build-quote {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  max-width: 64ch;
  margin: 0 auto;
  animation: build-reveal .6s ease both;
}

.build-quote:empty { display: none; }

/* The live caption: the sentence being said, the word under the playhead lit. The
   quote keeps its book voice — this is still the character speaking — but loses the
   reveal animation, which would re-fire on every word. */
.build-quote.live { animation: none; }
.build-quote .w { transition: color .12s ease; }
.build-quote .w.on { color: var(--text); }
.build-quote .w.said { color: var(--text); opacity: .75; }

.build-speaker {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 4px;
  animation: build-reveal .4s ease both;
}

.build-speaker:empty { display: none; }

/* The reading, on or off: a speaker, crossed out when off. No chrome, like the caption. */
.build-voice {
  position: absolute;
  top: -4px;
  right: 0;
  display: inline-flex;
  padding: 4px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}

.build-voice:hover,
.build-voice:focus-visible { color: var(--text); }

.build-voice:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.build-voice .slash { display: none; }
.build-voice[aria-pressed="false"] .slash { display: inline; }

/* A reload mid-build has had no click, and the audio clock will not run without one. */
.build-listen {
  position: absolute;
  z-index: 3;
  right: 14px;
  bottom: 14px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  background: rgba(22, 19, 28, .82);
  color: var(--text);
  border: 1px solid rgba(180, 142, 255, .6);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
  animation: build-reveal .4s ease both;
}

.build-listen[hidden] { display: none; }

.build-sheet:focus { outline: none; }

.chip[data-chip="voice"],
.chip[data-chip="emotions"] { color: var(--accent); border-color: rgba(180, 142, 255, .4); }

/* The right column: bar, setup (pre-build) or the tree (during). */
.build-sheet {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px 22px;
}

.build-sheet .modal-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -24px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.build-setup { padding-top: 4px; }

.build-hint {
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  margin: 14px 0 18px;
}

/* A three-way segmented choice; the radio is the state, the label the control. */
.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.seg label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.seg label:hover { border-color: var(--accent); }

.seg input { position: absolute; opacity: 0; pointer-events: none; }

.seg label:has(input:checked) {
  border-color: var(--accent);
  background: rgba(180, 142, 255, .1);
}

.seg span { font-size: 14px; }

.seg small {
  font-size: 11.5px;
  color: var(--muted);
}

.build-cta {
  display: block;
  width: 100%;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 15px;
  border-radius: 10px;
}

.build-cta:hover:not([disabled]) { filter: brightness(1.08); }

.build-cta[disabled] { opacity: .55; cursor: default; }

/* The steps: one flat row each — glyph, label, what it is doing (mono, muted,
   one line), time. Nothing nests: the parallel branches are the runner's business. */
.build-tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.build-tree li { padding: 2px 0; }

.stage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--muted);
}

.stage-row .mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: 12px;
  background: var(--panel);
}

.stage-label {
  flex: none;
  font-size: 14px;
  white-space: nowrap;
}

/* Between the label and the time, taking whatever width is left. */
.stage-sub {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  opacity: .8;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-time {
  flex: none;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
  min-width: 42px;
  text-align: right;
}

li[data-status="done"] > .stage-row { color: var(--text); }
li[data-status="done"] > .stage-row .mark { color: var(--accent); border-color: rgba(180, 142, 255, .5); }

li[data-status="running"] > .stage-row { color: var(--text); }
li[data-status="running"] > .stage-row .stage-time { color: var(--accent); }
li[data-status="running"] > .stage-row .stage-sub { color: var(--accent); opacity: .85; }
li[data-status="running"] > .stage-row .mark {
  border-color: var(--accent);
  border-top-color: transparent;
  animation: build-spin .9s linear infinite;
}

@keyframes build-spin { to { transform: rotate(360deg); } }

li[data-status="failed"] > .stage-row { color: var(--danger); align-items: flex-start; }
li[data-status="failed"] > .stage-row .mark { color: var(--danger); border-color: var(--danger); margin-top: 5px; }
/* An error is worth its lines; everything else stays on one. */
li[data-status="failed"] > .stage-row .stage-sub { color: var(--danger); white-space: normal; text-align: left; padding-top: 8px; }
li[data-status="failed"] > .stage-row .stage-label { padding-top: 6px; }
li[data-status="failed"] > .stage-row .stage-time { padding-top: 8px; }

li[data-status="skipped"] > .stage-row { opacity: .6; }

.build-foot { margin-top: 14px; }

.build-foot:empty { display: none; }

.build-done {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.build-done-note {
  color: var(--muted);
  font-size: 13.5px;
  margin: 0 0 12px;
}

.build-done .story-btn { margin-top: 8px; text-align: center; }

@media (max-width: 720px) {
  .build-split {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    height: 92dvh;
  }

  .build-preview {
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .build-stage-box { max-height: 34dvh; }
}

/* ── Character sheet modal ──────────────────────────────────────────────────
   The extended card a picker card opens into: portrait left, sheet right,
   tabbed Scenes | About. <dialog> supplies ESC and the backdrop; padding
   stays 0 so a backdrop click is unambiguous (see app.js). */

.char-modal {
  width: min(880px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  overflow: hidden;
}

.char-modal::backdrop {
  background: rgba(8, 6, 12, .65);
  backdrop-filter: blur(3px);
}

.modal-split {
  display: grid;
  grid-template-columns: minmax(240px, 2fr) 3fr;
  /* A definite height is what lets the sheet column scroll instead of the row
     growing to its content and overflowing the dialog. */
  height: min(620px, 86vh);
  grid-template-rows: minmax(0, 1fr);
}

/* The live portrait's box. The LAYERS inside it are web/stage.css's business — the
   picker mounts the same CharacterStage the chat does (`char-stage fit-cover`), so
   the stacking, the blink easing and the breath arrive here without a second copy
   of any of them. This rule owns only the frame the component sits in. */
.modal-stage {
  position: relative;
  overflow: hidden;
  background: #0e0b14;
}

.modal-stage .char-stage {
  position: absolute;
  inset: 0;
}

/* The intro play button — .play-btn's family, sized up to a tap target and filled:
   it sits on artwork, where a hairline ghost button would disappear. A pill, not a
   circle: the glyph rides with a "preview" label so the play reads as a sample of
   the character, not the start of a scene. */
.modal-intro-btn {
  position: absolute;
  left: 14px;
  bottom: 14px;
  height: 40px;
  padding: 0 16px 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 14px rgba(8, 6, 12, .5);
}

.modal-intro-btn svg {
  width: 13px;
  height: auto;
}

.modal-intro-btn .intro-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.modal-intro-btn:hover:not([disabled]) { filter: brightness(1.08); }

/* inline-flex above would otherwise beat the hidden attribute. */
.modal-intro-btn[hidden] { display: none; }

.modal-intro-btn[disabled] {
  opacity: .55;
  cursor: default;
}

.modal-sheet {
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px 24px;
}

/* The sheet's floating top: name bar plus the tab toggle ride together on top
   of the scroll. Negative margins bleed the block to the column edges so
   content slides under it full-width. */
.modal-top {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -24px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.modal-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 14px 12px 24px;
}

/* Scenes | About. Scenes first — the scene buttons are the CTAs; the sheet
   prose is reference material. */
.modal-tabs {
  display: flex;
  gap: 6px;
  padding: 0 24px 12px;
}

.modal-tab {
  padding: 3px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.modal-tab[aria-selected="true"] {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.modal-bar-id { flex: 1; min-width: 0; }

.modal-bar h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 24px;
  margin: 0;
}

.modal-bar .tagline {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 0;
}

.modal-edit {
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.modal-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 6px;
}

.modal-about {
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0;
}

.modal-quirks {
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
  line-height: 1.5;
}

.modal-quirks li + li { margin-top: 4px; }

.modal-voice {
  font-size: 13.5px;
  margin: 0;
}

/* Stacked, and the FLEXIBLE row is the portrait, not the sheet: the sheet takes the
   height its open tab actually needs (capped so About still scrolls) and the character
   gets every pixel left over. With the fr on the sheet instead, a short Scenes tab
   pooled its spare height as dead space under the buttons while the portrait sat
   cropped at a fixed 240px strip. */
@media (max-width: 640px) {
  .modal-split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    height: 92vh; /* fallback */
    height: 92dvh; /* dynamic viewport: honest about mobile browser chrome */
  }

  .modal-sheet {
    max-height: 46vh;
    max-height: 46dvh;
  }
}

.story-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 12px;
  font-size: 13.5px;
}

.story-btn + .story-btn { margin-top: 6px; }

.story-btn:hover { border-color: var(--accent); }

/* Only the modal's scene list gets the chevron: those buttons NAVIGATE (close the
   sheet, enter the chat), while the editor reuses .story-btn for in-place controls
   where an arrow would promise a move that never happens. */
#modalStories .story-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#modalStories .story-btn::after {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  border-top: 1.5px solid var(--muted);
  border-right: 1.5px solid var(--muted);
  transform: rotate(45deg);
}

#modalStories .story-btn:hover::after { border-color: var(--accent); }

@media (prefers-reduced-motion: no-preference) {
  .card-face img { transition: opacity .15s ease; }
  .card-face:hover img { opacity: .88; }
}

/* ── Chat layout ────────────────────────────────────────────────────────── */

.chat-grid {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* iOS-style navigation bar: back on the left, title dead centre, pinned to the
   viewport top on both breakpoints. The empty third grid cell balances the back
   button so the title truly centres. */
.chat-head {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.chat-head .ghost { justify-self: start; }

/* The open book: two pages centered in the space under the bar, sharing top and
   bottom edges. The portrait sets the height; the chat page matches it. */
.book {
  display: flex;
  gap: 12px;
  height: min(86dvh, 768px);
  max-width: 100%;
  margin: auto; /* centers within the leftover viewport, both axes */
}

/* ── Stage (left page) — the hero ───────────────────────────────────────── */

/* Sized by the art itself: the aspect ratio is set per character from its manifest
   dimensions (see enterChat), so the page IS the portrait, edge to edge. */
.stage-col {
  position: relative;
  height: 100%;
  aspect-ratio: 1 / 1; /* placeholder — overwritten per character */
  max-width: 62vw;
}

.stage {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  overflow: hidden;
  /* The spotlight: if the box ever letterboxes (narrow screens), the art sits on
     this instead of a hard edge. */
  background: radial-gradient(120% 85% at 50% 30%, #2c2440 0%, #191423 62%, #120e1a 100%);
}

/* Layer mechanics (.stage img opacity/transition rules) moved to web/stage.css —
   the #stage element carries both classes: `stage char-stage`. */

/* ── Chat (right) ───────────────────────────────────────────────────────── */

/* Right page — pure chat: the log and the composer, nothing else. */
.chat-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  height: 100%;
  width: clamp(360px, 41vw, 504px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}

.chat-head h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 17px;
  margin: 0;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-head .story-title { color: var(--muted); }

.ghost {
  background: none;
  color: var(--muted);
  padding: 4px 8px;
  flex-shrink: 0;
}

.ghost:hover { color: var(--text); }

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 6px 8px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* The narrator opens the scene in the book voice — prose, not a bubble. */
.narration {
  font-family: var(--serif);
  font-style: italic;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 14px;
  max-width: 62ch;
}

.narration p { margin: 0 0 .7em; }
.narration p:last-child { margin-bottom: 0; }
.narration .bubble-foot { margin-top: 10px; }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  overflow-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 4px;
}

.bubble.char {
  align-self: flex-start;
  background: var(--panel-2); /* one step above the page it sits on */
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

/* Inside a reply the registers switch mid-sentence, and each one matches a voice:
   narration is the narrator's, dialogue is hers, thought is hers unspoken. */
.bubble.char em {
  font-family: var(--serif);
  color: var(--muted);
}

/* A thought is heard in her own voice but never said out loud, so it belongs to neither of
   the other two registers — not the narrator's serif, not her upright dialogue. Same sans
   as her speech, because it is her; italic and set back, because nobody else can hear it.
   The brackets are kept rather than styled away: they are how the convention reads. */
.bubble.char .thought {
  font-family: var(--sans);
  font-style: italic;
  color: var(--accent);
  opacity: 0.72;
}

/* The word being said, lit as it is spoken (web/word-lights.js) — in every register,
   since all three are voiced; the builder's caption does the same under the stage. A
   faint tint behind the word and a soft glow of its own colour, so it reads in the
   narrator's muted serif as well as her speech: nothing that moves the text (no weight,
   no size, the tint's bleed is a shadow), so the line never reflows under the reader.
   The words stay whatever colour their register gave them. */
.bubble.char .w,
.em-bubble.char .w,
.narration .w {
  border-radius: 3px;
  transition: background-color .08s ease, box-shadow .08s ease, text-shadow .08s ease;
}

.bubble.char .w.on,
.em-bubble.char .w.on,
.narration .w.on {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
  text-shadow: 0 0 8px color-mix(in srgb, currentColor 45%, transparent);
}

/* A word is also a place to start from: click it and the reply plays from there (the
   reply the player holds seeks on its clock; an older bubble replays from its stored
   audio). The hint is the same tint at half strength, only under the pointer — a bubble
   with no audio to seek into shows nothing. */
.bubble.char.seekable .w,
.em-bubble.char.seekable .w,
.narration.seekable .w { cursor: pointer; }

.bubble.char.seekable .w:hover,
.em-bubble.char.seekable .w:hover,
.narration.seekable .w:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 12%, transparent);
}

.bubble-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.play-btn {
  margin-left: auto; /* bottom-right corner of the bubble, meta or no meta */
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
}

.play-btn svg {
  width: 9px;
  height: auto;
  /* A play triangle centred by its box reads left-heavy; a hair of right shift
     optically centres it in the circle. */
  margin-left: 1px;
}

.play-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* The transport's state (web/app.js attachTransport): playing shows a pause glyph in the
   accent, paused keeps the accent ring around a play glyph, idle is the quiet circle. The
   pause glyph is symmetric, so it drops the play triangle's optical shift. */
.play-btn[data-state="playing"],
.play-btn[data-state="paused"] {
  color: var(--accent);
  border-color: var(--accent);
}

.play-btn[data-state="playing"] svg { margin-left: 0; }

.bubble.error {
  align-self: flex-start;
  background: none;
  border: 1px dashed var(--line);
  color: var(--danger);
  font-size: 13.5px;
}

/* ── Composer ───────────────────────────────────────────────────────────── */

.composer {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.composer input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--ink); /* recessed into the page */
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}

.composer input::placeholder { color: var(--muted); }

.composer input:focus {
  outline: none;
  border-color: var(--accent);
}

.composer button {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 10px;
}

.composer button:disabled,
.composer input:disabled {
  opacity: .55;
  cursor: default;
}

/* ── Small screens: full-bleed messenger, not a book ────────────────────── */
/* Portrait pinned to the top, composer pinned to the bottom, messages scrolling
   between them. No position: fixed needed — only .log scrolls, so the flex column
   pins both ends for free. dvh units track the keyboard/URL-bar resizes. */

@media (max-width: 760px) {
  .book {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: auto;
    width: 100%;
    gap: 0;
    margin: 0; /* fills the space under the bar instead of floating in it */
  }

  .stage-col {
    height: 32dvh;
    flex-shrink: 0;
    aspect-ratio: auto; /* full width; the art letterboxes on the spotlight */
    max-width: none;
  }

  .stage { border-radius: 0; } /* full-bleed against the screen edges */

  .chat-col {
    width: auto;
    flex: 1;
    min-height: 0;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0 12px;
  }

  .back-label { display: none; } /* just the arrow — the word is desktop-only */

  .log { padding: 12px 2px 8px 0; }

  /* Clears the iPhone home indicator (viewport-fit=cover exposes the inset). */
  .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }

  .bubble.char { background: var(--panel); } /* back on ink, one step is enough */

  .bubble { max-width: 88%; }
}

/* ── Character editor ───────────────────────────────────────────────────────
   /web/editor.html — same chrome as the chat (chat-head bar, ghost back), but
   the body is a full-viewport two-column form: identity left, stories right.
   Fields recess into the page like the composer input; labels are the modal's
   mono eyebrows. */

a.ghost { text-decoration: none; }

.edit-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.save-status {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-status.error { color: var(--danger); }

.save-btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  padding: 7px 18px;
}

.save-btn:disabled { opacity: .5; cursor: default; }

/* The top bar floats so Save (and the dirty status) never scroll away. */
.editor-head {
  position: sticky;
  top: 0;
  z-index: 2;
}

.edit-title-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

/* The character's face rides the bar — viseme_X is the resting frame, and
   object-position: top finds it in every framing from bust to full body. */
.edit-thumb {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: cover;
  object-position: top;
  background: #0e0b14;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.editor {
  display: grid;
  grid-template-columns: 190px minmax(0, 940px);
  gap: 34px;
  align-items: start;
  padding: 22px clamp(16px, 3vw, 44px) 70px;
}

.edit-nav {
  position: sticky;
  top: 72px; /* clears the floating bar */
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  background: none;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 9px 12px;
}

.nav-item:hover { color: var(--text); }

.nav-item.active {
  background: var(--panel-2);
  color: var(--text);
}

.nav-count {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

.nav-rule {
  border: none;
  border-top: 1px solid var(--line);
  margin: 8px 4px;
}

/* ── Asset preview panes (visemes, blink) ───────────────────────────────────
   The same layer mechanics as the chat stage: stacked frames swapped by
   opacity with NO easing — except the blink overlay, the one layer that fades. */

.preview-stage {
  position: relative;
  width: min(360px, 100%);
  aspect-ratio: 1 / 1; /* placeholder — overwritten from the manifest */
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(120% 85% at 50% 30%, #2c2440 0%, #191423 62%, #120e1a 100%);
}

.preview-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  transition: none;
}

.preview-stage img.on { opacity: 1; }

.preview-stage img.blink { transition: opacity 45ms linear; }

/* Emotion overlays ease like the chat stage's: an expression is a face moving. */
.preview-stage img.emotion { transition: opacity 140ms ease; }

.preview-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(360px, 100%);
  margin: 10px 0 4px;
}

.preview-controls .story-btn { width: auto; }

.preview-controls a { font-size: 13px; text-decoration: none; }

.asset-meta {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 6px 0 0;
}

/* One stage, three drivers: the shape list on the left parks the stage on a
   frame; play and babble animate the same stage. No per-shape thumbnails — at
   list size nothing reads anyway; the stage IS the preview. */
.visemes-split {
  display: grid;
  grid-template-columns: minmax(190px, 250px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

@media (max-width: 700px) {
  .visemes-split { grid-template-columns: 1fr; }
  .viseme-stage-col { order: -1; } /* stage first when stacked */
}

.viseme-stage-col { min-width: 0; }

.viseme-stage-col .preview-stage,
.viseme-stage-col .preview-controls {
  width: min(520px, 100%);
}

.viseme-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 11px;
  font-size: 12px;
}

.viseme-row + .viseme-row { margin-top: 6px; }

.viseme-row:hover { border-color: var(--accent); }

.viseme-row.active {
  border-color: var(--accent);
  color: var(--text);
}

.viseme-row strong {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  min-width: 14px;
}

.viseme-row .row-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.asset-meta.error { color: var(--danger); }

/* Regenerate: the same control under every generated asset's stage. */
.regen {
  width: min(520px, 100%);
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.regen .preview-controls { width: 100%; margin: 0 0 2px; flex-wrap: wrap; }
.regen .story-btn:disabled, .regen .ghost:disabled { opacity: .55; cursor: default; }
.regen .ghost { font-size: 13px; }
.emotions-split .regen { width: 100%; }

/* ── Voice pane + voices browser ──
   Two slot cards (speech voice / narrator) select which register the browser
   below is filling; rows follow the viseme-row idiom. The play cell is its own
   button so previewing never reads as picking. */
.voice-slots {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0 4px;
}

.voice-slot {
  flex: 0 1 240px;
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 10px 14px 12px;
  color: var(--muted);
}

.voice-slot:hover { border-color: var(--accent); }

.voice-slot.active {
  border-color: var(--accent);
  color: var(--text);
}

.voice-slot .modal-label { margin: 0 0 3px; }

.voice-slot strong {
  display: block;
  font-size: 14.5px;
  color: var(--text);
}

.voice-slot-detail {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .04em;
  margin-top: 2px;
}

.voice-reset {
  align-self: center;
  font-size: 12.5px;
}


/* The voices browser rules (.voice-browser, .voice-row, .voice-play, .voice-search,
   .voice-library …) moved to web/voices.css — link it on any page embedding
   web/voices.js. The slot cards above stay here: they are the editor's, not the
   component's. */
/* Header badge while background re-bakes run — visible whatever pane is open. */
.rebake-badge {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--accent);
  white-space: nowrap;
}

@media (prefers-reduced-motion: no-preference) {
  .rebake-badge { animation: rebake-pulse 1.6s ease-in-out infinite; }
  @keyframes rebake-pulse {
    50% { opacity: .5; }
  }
}

.tile-audit {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .03em;
}

.tile-audit.bad { color: var(--danger); }

.audit-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  max-width: 360px;
}

.audit-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.audit-list strong {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 12px;
  color: var(--text);
}

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; gap: 18px; }
  .edit-nav { position: static; flex-direction: row; }
}

.edit-content { min-width: 0; }

.edit-head {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 20px;
  margin: 0 0 14px;
}

.field { margin: 0 0 14px; }

.field .modal-label { margin: 0 0 6px; }

.field input,
.field textarea,
.rule-row input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--ink); /* recessed, like the composer */
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus,
.rule-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.field .hint {
  font-size: 12px;
  color: var(--muted);
  margin: 5px 0 0;
}

.rule-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.rule-row input { flex: 1; }

.remove-btn {
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 8px;
  flex-shrink: 0;
}

.remove-btn:hover { color: var(--danger); }

/* Stories master–detail: pick on the left, edit on the right. */
.stories-split {
  display: grid;
  grid-template-columns: minmax(170px, 230px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.story-pick { color: var(--muted); }

.story-pick:hover { color: var(--text); }

.story-pick.active {
  color: var(--text);
  border-color: var(--accent);
}

.story-list .add-btn {
  margin-top: 10px;
  padding: 10px;
  font-size: 13px;
}

@media (max-width: 700px) {
  .stories-split { grid-template-columns: 1fr; }
}

.story-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 6px;
}

.story-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.story-head .remove-btn { margin-left: auto; }

.story-id {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  color: var(--muted);
}

.audio-badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.audio-badge.baked { color: var(--accent); }

.add-btn {
  width: 100%;
  padding: 12px;
  background: none;
  border: 2px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13.5px;
}

.add-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.editor-error {
  color: var(--danger);
  text-align: center;
  padding: 48px 16px;
}

/* Bottom-right corner (web/provider-badge.js): the deployed-commit label, faint —
   it answers "which build am I looking at" and is not part of the page — and the
   TTS provider pill beside it, which is NOT faint: it answers "is this costing
   money", and the answer has to be readable at a glance from across the room. The
   dot is the money: amber for a billed provider, green for the free mock. */
.corner {
  position: fixed;
  right: 10px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font: 12px var(--mono);
  user-select: none;
  z-index: 5;
}
.corner-version {
  color: var(--accent);
  opacity: 0.35;
  pointer-events: none;
}
.tts-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  color: var(--muted);
  letter-spacing: 0.01em;
  cursor: default;
}
.tts-badge:hover { color: var(--text); }
button.tts-badge { cursor: pointer; font: inherit; }
button.tts-badge:hover { border-color: var(--accent); }

/* The picker above the pill: the providers this server offers, and "server default".
   Closed by the `hidden` attribute — which this display rule would otherwise beat, so
   it is restated with the attribute (measured: the menu sat open on every page). */
.corner { flex-wrap: wrap; justify-content: flex-end; }
.tts-menu[hidden] { display: none; }
.tts-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  min-width: 190px;
}
.tts-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 9px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--muted);
  font: 12px var(--mono);
  text-align: left;
  cursor: pointer;
}
.tts-option:hover { background: var(--panel-2); color: var(--text); }
.tts-option[aria-current="true"] { color: var(--text); background: var(--panel-2); }
.tts-option[data-billed="yes"] .tts-dot { background: #f0b05a; box-shadow: 0 0 0 3px color-mix(in srgb, #f0b05a 22%, transparent); }
.tts-option[data-billed="no"] .tts-dot { background: #6fd39a; box-shadow: 0 0 0 3px color-mix(in srgb, #6fd39a 22%, transparent); }
.tts-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f0b05a;
  box-shadow: 0 0 0 3px color-mix(in srgb, #f0b05a 22%, transparent);
}
.tts-badge[data-billed="no"] .tts-dot {
  background: #6fd39a;
  box-shadow: 0 0 0 3px color-mix(in srgb, #6fd39a 22%, transparent);
}
/* The lipsync engine pill and its rows: no money in the choice, so a grey dot. */
.tts-badge[data-kind="lipsync"] .tts-dot,
.tts-option:not([data-billed]) .tts-dot {
  background: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 22%, transparent);
}

/* ── Emotion lab (editor › emotions): the chat that drives the face ──────────
   Formerly its own page (web/emotions.html); the stage is the pane's preview
   stage, so only the conversation and controls live here. em- prefixed. */

/* The emotions pane is three columns: the character, the emotion list, the live
   talk. The stage fills its column; the lab keeps its own vertical rhythm. */
.emotions-split {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(170px, 220px) minmax(260px, 1fr);
  gap: 22px;
  align-items: start;
}

/* The pane is the one that needs room: the editor's content column widens for it
   alone, so the other panes' fields keep their measure. */
.editor.wide { grid-template-columns: 190px minmax(0, 1160px); }

.emotions-split .preview-stage,
.emotions-split .preview-controls {
  width: 100%;
}

@media (max-width: 1100px) {
  .emotions-split { grid-template-columns: minmax(200px, 1fr) minmax(170px, 1fr); }
  .emotions-split .em-lab { grid-column: 1 / -1; }
}

@media (max-width: 600px) {
  .emotions-split { grid-template-columns: 1fr; }
}

.em-lab {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.em-lab-head { font-family: var(--serif); font-weight: 600; font-size: 16px; margin: 0; }

.em-row { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 13px; }
.em-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.em-log {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 220px;
  max-height: 52vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.em-bubble { border-radius: 10px; padding: 8px 12px; max-width: 92%; }
.em-bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.em-bubble.char { align-self: flex-start; background: var(--panel-2); }
.em-bubble.char em { font-family: var(--serif); color: var(--muted); }
.em-bubble.char .thought { color: var(--muted); }
.em-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
  margin-right: 4px;
  vertical-align: 1px;
}
.em-bubble.error { align-self: center; color: var(--danger); font-size: 13px; }
.em-replay {
  display: block;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0 0;
}
.em-replay:hover { color: var(--text); }

.em-composer { display: flex; gap: 8px; }
.em-composer input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}
.em-composer button {
  padding: 10px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.em-composer button:disabled { opacity: .55; cursor: default; }

.em-hint { color: var(--muted); font-size: 12.5px; margin: 0; }

/* ── Sign-in widget (web/auth.js) — the header's right-hand slot on every page ──── */
.auth-widget { display: inline-flex; align-items: center; gap: 10px; justify-self: end; }
.auth-signin {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.auth-signin:hover { filter: brightness(1.08); }
.auth-console { color: var(--muted); text-decoration: none; font-size: 13px; }
.auth-console:hover { color: var(--text); }
.auth-pill { color: var(--muted); font-size: 12px; border: 1px dashed var(--line); border-radius: 999px; padding: 3px 9px; }
.auth-user { display: flex; align-items: center; min-width: 32px; min-height: 32px; }
.pick-head { position: relative; }
.pick-user { position: absolute; top: 0; right: 0; }
.card-face { position: relative; }
.card-yours {
  position: absolute;
  top: 10px;
  left: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 8px;
}
