:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --line: #e2e0d8;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --speaking: #e5f1ec;
  --system: #8a887f;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161715;
    --panel: #1f201d;
    --text: #ecebe6;
    --muted: #a3a29b;
    --line: #34352f;
    --accent: #5fb39a;
    --accent-text: #0f1a16;
    --speaking: #22362f;
    --system: #8d8c85;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Segoe UI", Arial, sans-serif;
}
h1 { font-size: 1.7rem; margin: 0 0 .5rem; }
h2 { font-size: 1rem; margin: 0 0 .75rem; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: .55rem 1.1rem;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .7rem;
  width: 100%;
}
.home { max-width: 640px; margin: 0 auto; padding: 3rem 16px; }
.lead { font-size: 1.1rem; color: var(--muted); }
.steps { padding-inline-start: 1.2rem; margin: 2rem 0 1rem; }
.hint { color: var(--muted); font-size: .9rem; }

.room { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.room header { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.status { color: var(--muted); font-size: .9rem; }
.layout { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.side { display: grid; gap: 1rem; }
#transcript { min-height: 50vh; max-height: 70vh; overflow-y: auto; display: grid; gap: .5rem; align-content: start; }
.msg { padding: .5rem .75rem; border-radius: 8px; }
.msg .who { font-weight: 700; margin-inline-end: .4rem; }
.msg .time { color: var(--muted); font-size: .75rem; margin-inline-start: .4rem; }
.msg.speaking { background: var(--speaking); }
.msg.system { color: var(--system); font-size: .85rem; padding: .1rem .75rem; }
.empty { color: var(--muted); }
.people { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.people .tag { color: var(--muted); font-size: .8rem; }
.copy-row { display: flex; gap: .5rem; }
.copy-row input { direction: ltr; font-size: .85rem; }
.field { display: grid; gap: .3rem; margin-bottom: .6rem; font-size: .9rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.small { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }
[hidden] { display: none !important; }
textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .7rem;
  width: 100%;
  resize: vertical;
}
.host-box { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); display: grid; gap: .5rem; }
.host-box > label { font-size: .9rem; }
.host-actions { justify-content: space-between; align-items: center; }
.check { display: flex; gap: .4rem; align-items: center; font-size: .9rem; }
.check input { width: auto; }
.msg.host { border-inline-start: 3px solid var(--accent); }
.msg.human { border-inline-start: 3px solid var(--line); }
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 0 .4rem;
  margin-inline-start: .3rem;
  border-radius: 999px;
  background: var(--speaking);
  color: var(--accent);
  vertical-align: middle;
}
.banner {
  background: var(--speaking);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .8rem;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.count { font-weight: 400; }
select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .5rem;
}
.grow { flex: 1 1 140px; width: auto; }
.people li { display: grid; gap: .25rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.people li:last-child { border-bottom: 0; padding-bottom: 0; }
.people li.empty { border: 0; }
.person { display: flex; justify-content: space-between; gap: .5rem; }
.voice-row { display: flex; gap: .3rem; }
.voice-select { font-size: .85rem; padding: .25rem .4rem; flex: 1 1 auto; min-width: 0; }
.pitch-select { font-size: .85rem; padding: .25rem .3rem; flex: 0 0 auto; }
.test-btn { padding: .2rem .55rem; font-size: .8rem; flex: 0 0 auto; }
.field .copy-row { margin-top: .2rem; }
.header-actions { align-items: center; }
.topic-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  align-items: baseline;
  background: var(--speaking);
  border-radius: 8px;
  padding: .5rem .75rem;
  margin-bottom: .9rem;
  font-size: .95rem;
}
.topic-label { font-weight: 700; }
.manage-row { display: flex; gap: .3rem; flex-wrap: wrap; }
.small-btn { font-size: .8rem; padding: .2rem .6rem; }
.btn.danger { color: #b3261e; border-color: #e7b9b5; }
.muted-tag { font-size: .72rem; padding: 0 .4rem; border-radius: 999px; background: #f3e2c4; color: #7a5410; }
.people li.is-muted > .person > span:first-child { opacity: .65; }
.topic-set { display: grid; gap: .4rem; margin-top: .5rem; padding-top: .75rem; border-top: 1px dashed var(--line); }
.topic-set label { font-size: .9rem; }
.title-row { display: flex; align-items: center; gap: .75rem; }
.menu-btn {
  display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
  width: 42px; height: 40px; padding: 0 10px;
}
.menu-btn span { display: block; height: 2px; border-radius: 2px; background: var(--text); }
.layout.side-closed { grid-template-columns: 1fr; }
.avatar {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 30px; height: 30px; border-radius: 50%; overflow: hidden;
  color: #fff; font-size: .85rem; font-weight: 700; background: var(--line);
  vertical-align: middle;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 22px; height: 22px; font-size: .7rem; margin-inline-end: .35rem; }
.person-name { display: inline-flex; align-items: center; gap: .45rem; }
.avatar-btn {
  position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%;
  line-height: 0;
}
.avatar-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-edit {
  position: absolute; bottom: -2px; inset-inline-start: -4px;
  width: 15px; height: 15px; border-radius: 50%; display: grid; place-items: center;
  font-size: 9px; line-height: 1; background: var(--panel); color: var(--text);
  border: 1px solid var(--line);
}
.crop-backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(0, 0, 0, .55); padding: 16px;
}
.crop-box {
  background: var(--panel); color: var(--text); border-radius: 14px; padding: 1.2rem;
  width: min(340px, 100%); display: grid; gap: .6rem; justify-items: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.crop-box h3 { margin: 0; font-size: 1.1rem; }
.crop-box .small { margin: 0; text-align: center; }
.crop-stage {
  position: relative; width: 280px; height: 280px; border-radius: 8px; overflow: hidden;
  cursor: grab; touch-action: none; user-select: none;
}
.crop-stage.dragging { cursor: grabbing; }
.crop-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.crop-stage canvas { display: block; }
/* Everything outside the circle is darkened: only the circle becomes the picture. */
.crop-mask {
  position: absolute; inset: 0; pointer-events: none; border-radius: 50%;
  box-shadow: 0 0 0 200px rgba(0, 0, 0, .6);
  outline: 2px solid rgba(255, 255, 255, .9); outline-offset: -2px;
}
.crop-zoom { display: flex; align-items: center; gap: .5rem; width: 100%; font-weight: 700; }
.crop-zoom input { flex: 1; }
.crop-actions { justify-content: flex-end; width: 100%; }
/* Stage: a dark video-call look, the same in light and dark mode. */
.stage {
  --stage-bg: #121417;
  --stage-tile: #1c1f24;
  --stage-text: #eef0f2;
  --stage-muted: #9aa1a9;
  --stage-live: #3ccf7a;
  background: var(--stage-bg);
  color: var(--stage-text);
  border-radius: 12px;
  padding: .8rem;
  margin-bottom: 1rem;
  display: grid;
  gap: .7rem;
}
.stage-strip { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; min-height: 0; }
.strip-tile {
  display: grid; justify-items: center; gap: .2rem; padding: .4rem .6rem;
  background: var(--stage-tile); border-radius: 8px; border: 2px solid transparent;
  min-width: 72px; transition: border-color .2s;
}
.strip-tile.talking { border-color: var(--stage-live); }
.strip-name { font-size: .72rem; color: var(--stage-muted); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-main {
  background: var(--stage-tile); border-radius: 10px; min-height: 240px;
  display: grid; place-items: center; align-content: center; gap: .6rem; padding: 1.2rem;
  position: relative;
}
.stage-name { font-size: .95rem; color: var(--stage-muted); }
.stage-avatar { display: grid; place-items: center; min-height: 150px; }
.avatar.big {
  width: clamp(110px, 22vw, 160px); height: clamp(110px, 22vw, 160px);
  font-size: clamp(2.6rem, 6vw, 4rem); font-weight: 800;
  transition: box-shadow .25s, transform .25s;
}
/* A soft pulsing ring while someone is speaking. */
.stage.talking .avatar.big { animation: talk-ring 1.4s ease-in-out infinite; }
@keyframes talk-ring {
  0%, 100% { box-shadow: 0 0 0 4px rgba(60, 207, 122, .55), 0 0 0 0 rgba(60, 207, 122, .25); }
  50% { box-shadow: 0 0 0 4px rgba(60, 207, 122, .9), 0 0 0 16px rgba(60, 207, 122, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .stage.talking .avatar.big { animation: none; box-shadow: 0 0 0 4px var(--stage-live); }
}
.stage-caption { display: flex; gap: .6rem; align-items: flex-start; min-height: 3.2rem; padding: 0 .4rem; }
.stage-caption .avatar.sm { margin-top: .25rem; }
.cap-name { font-size: .75rem; color: var(--stage-muted); }
.cap-text { font-size: 1.1rem; line-height: 1.5; }
/* Grid and flex children may shrink below their content, so long voice names never push the page wider. */
.layout > * { min-width: 0; }
.voice-row select { max-width: 100%; }
/* A select is as wide as its longest option unless told it may shrink. */
.side { grid-template-columns: minmax(0, 1fr); }
.voice-row .voice-select { flex: 1 1 0; width: 0; min-width: 0; }
/* The settings column carries its own fold button at the top. */
.side-col { display: grid; gap: .6rem; align-content: start; min-width: 0; }
.menu-btn {
  justify-self: end; /* the outer (left) edge in a right-to-left page */
  width: auto; height: 40px; padding: 0 .8rem; gap: .5rem;
  flex-direction: row; align-items: center;
}
.menu-btn .bars { display: inline-flex; flex-direction: column; gap: 4px; width: 18px; }
.menu-btn .bars span { display: block; height: 2px; border-radius: 2px; background: var(--text); }
.menu-label { font-size: .85rem; }
.layout.side-closed { grid-template-columns: 1fr auto; }
.layout.side-closed .side-col { align-self: start; }
.small-note { font-size: .75rem; font-weight: 400; color: var(--muted); }
/* The typing box now sits between the stage and the history. */
#joinForm, #sayForm { margin-top: 0; padding-top: 0; border-top: 0; margin-bottom: 1rem; }
.menu-btn .menu-label, .menu-btn .bars { height: auto; background: none; border-radius: 0; }
@media (max-width: 800px) {
  .layout.side-closed { grid-template-columns: 1fr; }
  .side-col { order: -1; } /* on a phone the fold button comes first, above the stage */
}
/* Recording: a red, pulsing indicator that stays on top while recording. */
.rec-btn.recording { background: #b3261e; border-color: #b3261e; color: #fff; }
.rec-banner {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  background: #fdecea; color: #7a1c15; border: 1px solid #f2b8b2;
  border-radius: 8px; padding: .5rem .8rem; margin-bottom: 1rem;
}
.rec-banner #recTime { font-variant-numeric: tabular-nums; }
.rec-note { font-size: .82rem; opacity: .85; flex: 1 1 200px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #d93025; animation: rec-blink 1s steps(2, start) infinite; }
@keyframes rec-blink { to { visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } }
@media (prefers-color-scheme: dark) {
  .rec-banner { background: #3a1714; color: #ffd9d4; border-color: #6b2a24; }
}
.kind-icon { font-size: .8rem; line-height: 1; opacity: .85; }
.strip-name .kind-icon { font-size: .7rem; }
.field .copy-row .grow { flex: 1 1 auto; }
/* Moving between rooms */
.room-nav { order: 3; flex-basis: 100%; gap: .4rem; }
.room-nav .btn { font-size: .88rem; padding: .35rem .8rem; }
.home-box { margin: 1rem 0; display: grid; gap: .6rem; }
.home-box h2 { margin: 0; }
.home-box .btn.primary { justify-self: start; }
.room-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.room-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.room-list li:last-child { border-bottom: 0; }
.room-link { font-weight: 700; }
/* Written methods and sources inside the transcript */
.protocol-card {
  margin: .4rem 0 .2rem; padding: .5rem .75rem; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--line);
}
.protocol-title { font-weight: 700; font-size: .92rem; }
.protocol-card ol { margin: .3rem 0 0; padding-inline-start: 1.3rem; font-size: .92rem; }
.msg-sources { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.msg-sources a { word-break: break-word; }
.title-line { display: flex; align-items: center; gap: .5rem; }
#newRoom { gap: .5rem; }
/* Room types */
.type-badge { font-size: .8rem; font-weight: 700; padding: .15rem .6rem; border-radius: 999px; background: var(--speaking); color: var(--accent); }
.new-room { display: grid; gap: .8rem; }
.type-pick { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .6rem; }
.type-pick legend { font-weight: 700; margin-bottom: .4rem; }
.type-card { display: grid; gap: .25rem; border: 2px solid var(--line); border-radius: 12px; padding: .7rem .8rem; cursor: pointer; background: var(--panel); }
.type-card:has(input:checked) { border-color: var(--accent); background: var(--speaking); }
.type-card input { position: absolute; opacity: 0; pointer-events: none; }
.type-card:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.type-icon { font-size: 1.5rem; }
/* Debate */
.debate-panel { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; margin-bottom: 1rem; display: grid; gap: .6rem; }
.debate-topic { font-weight: 700; font-size: 1.05rem; text-align: center; }
.debate-sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; align-items: start; }
.debate-side { border-radius: 10px; padding: .6rem .7rem; }
.side-a { background: #e3eefb; color: #173a63; }
.side-b { background: #fbe7e3; color: #63231a; }
@media (prefers-color-scheme: dark) {
  .side-a { background: #1c2c40; color: #d4e5fb; }
  .side-b { background: #3d221d; color: #fbdcd5; }
}
.side-name { font-weight: 700; margin-bottom: .3rem; }
.debate-side ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; font-size: .9rem; }
.debate-side li { display: flex; align-items: center; gap: .3rem; }
.debate-vs { align-self: center; font-weight: 800; color: var(--muted); }
.viewer-note { background: var(--speaking); border-radius: 8px; padding: .4rem .7rem; font-size: .9rem; margin: 0 0 1rem; }
/* Works in the transcript */
.work-link { display: inline-flex; align-items: center; gap: .5rem; margin-top: .3rem; font-size: .88rem; }
.work-link img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }
/* Info pack for the agents */
.brief-view { display: grid; gap: .5rem; font-size: .92rem; }
.brief-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14rem; overflow: auto; background: var(--bg); border-radius: 8px; padding: .5rem .7rem; }
.brief-files { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; }
.brief-files li { display: flex; gap: .5rem; align-items: center; justify-content: space-between; }
#briefEdit { display: grid; gap: .5rem; margin-top: .6rem; }
#briefEdit[hidden] { display: none; }
/* Stage / map switch and the neural map */
.view-toggle { display: flex; gap: .4rem; margin-bottom: .6rem; }
.view-toggle .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.map-wrap { background: #070a14; border-radius: 12px; padding: .6rem; margin-bottom: 1rem; display: grid; gap: .5rem; }
.map-wrap[hidden] { display: none; }
#mapCanvas { width: 100%; height: clamp(320px, 52vh, 560px); display: block; border-radius: 8px; }
.map-legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .78rem; color: #a9b6d6; padding: 0 .3rem; }
.lg-agent { color: #5ed6ff; }
.lg-human { color: #ffc45c; }
.flow-list { list-style: none; margin: 0; padding: 0 .3rem .2rem; display: grid; gap: .2rem; font-size: .85rem; color: #dfe8ff; }
.flow-list b { color: #7fe3ff; font-weight: 600; }
.flow-list span { color: #c9d3ee; }
