/* Lounge — felt-green walls, brass fittings, and every participant's own colour.
   People are circles, bots are rounded squares, everywhere. */

/* Fonts are bundled (SIL Open Font License, see fonts/OFL-*.txt) so the
   lounge works offline and makes no third-party requests. */
@font-face { font-family: "Bricolage Grotesque"; src: url("fonts/bricolage-grotesque.woff") format("woff"); font-weight: 500 700; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-bold.woff") format("woff"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Atkinson Hyperlegible"; src: url("fonts/atkinson-hyperlegible-italic.woff") format("woff"); font-weight: 400; font-style: italic; font-display: swap; }

:root {
  --felt: #1F3B36;
  --felt-2: #2A4C46;
  --felt-3: #355C55;
  --felt-ink: #E2EBE6;
  --felt-muted: #A3BAB2;
  --wall: #EBF0EC;
  --surface: #F8FAF8;
  --ink: #17211E;
  --moss: #4F6159;
  --line: #CFDAD4;
  --brass: #B9832B;
  --brass-soft: #F1E2C4;
  --rosewood: #A9483F;
  --focus: #B9832B;
  --shadow: 0 12px 40px rgba(16, 32, 28, .18);

  --font-ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;

  --step--1: .8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-4: 3.25rem;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --felt: #13241F;
    --felt-2: #1D332D;
    --felt-3: #28443D;
    --felt-ink: #DCE7E1;
    --felt-muted: #8FA79F;
    --wall: #18211E;
    --surface: #1F2A26;
    --ink: #E3EAE6;
    --moss: #9DB0A8;
    --line: #2E3D38;
    --brass: #D2A04A;
    --brass-soft: #3A3020;
    --rosewood: #E07F74;
    --focus: #D2A04A;
    --shadow: 0 16px 48px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--wall);
  color: var(--ink);
  font: var(--step-0)/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

.boot { display: grid; place-items: center; height: 100dvh; color: var(--moss); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 40px; padding: .45em 1em;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink);
  font-weight: 700;
}
.btn:hover { border-color: var(--moss); }
.btn-primary { background: var(--felt); border-color: var(--felt); color: var(--felt-ink); }
.btn-primary:hover { background: var(--felt-2); border-color: var(--felt-2); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--moss); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-danger-quiet { background: transparent; border-color: transparent; color: var(--rosewood); }
.btn-danger-quiet:hover { border-color: var(--rosewood); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 8px; background: transparent; color: inherit; font-size: 1.25rem; line-height: 1;
}
.icon-btn:hover { background: color-mix(in srgb, currentColor 12%, transparent); }

/* ---------------------------------------------------------------- avatars */

.avatar {
  --c: #6A7A72;
  flex: none; display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--c); color: var(--on-c, #fff);
  font: 700 .95rem/1 var(--font-display);
  user-select: none;
}
.avatar.is-bot { border-radius: 30%; }
.avatar.sm { width: 26px; height: 26px; font-size: .75rem; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.75rem; }
.avatar.emoji { font-size: 1.15rem; }
.avatar.sm.emoji { font-size: .85rem; }
.avatar.lg.emoji { font-size: 2.1rem; }
.avatar.xl { width: 104px; height: 104px; font-size: 2.6rem; }
.avatar.xl.emoji { font-size: 3.2rem; }
.avatar.has-pic { overflow: hidden; background: var(--c); }
.avatar.has-pic > img,
.avatar.has-pic > video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  pointer-events: none; /* clicks go to whatever the avatar sits in */
}

.field-title { font-weight: 700; font-size: var(--step--1); }
.pic-field { display: flex; align-items: center; gap: 16px; }
.pic-controls { display: grid; gap: 2px; min-width: 0; }
.pic-controls .row { margin-top: 4px; }
.pic-note { color: var(--moss); font-size: var(--step--1); }
@media (max-width: 420px) {
  .pic-field { flex-direction: column; align-items: flex-start; }
}

/* ---------------------------------------------------------------- auth */

.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: var(--felt);
  background-image: radial-gradient(circle at 20% 15%, var(--felt-3) 0, transparent 45%);
}
.auth-card {
  width: min(420px, 100%); padding: 40px 32px 32px;
  background: var(--wall); border-radius: 22px; box-shadow: var(--shadow);
}
.wordmark { font: 700 var(--step-4)/1 var(--font-display); letter-spacing: -.03em; }
.wordmark::after {
  content: ""; display: inline-block; width: .32em; height: .32em; margin-left: .08em;
  border-radius: 50%; background: var(--brass); vertical-align: baseline;
}
.wordmark-sm { font-size: 1.6rem; }
.auth-lede { margin: 12px 0 28px; color: var(--moss); }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 20px; padding: 4px; border-radius: 12px; background: color-mix(in srgb, var(--felt) 8%, transparent); }
.auth-tabs button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--moss); font-weight: 700; }
.auth-tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-weight: 700; font-size: var(--step--1); }
label .sub { font-weight: 400; color: var(--moss); }
input, textarea, select {
  width: 100%; min-height: 42px; padding: .55em .75em;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 400; font-size: var(--step-0);
}
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--rosewood); font-size: var(--step--1); min-height: 1.2em; }

/* ---------------------------------------------------------------- app layout */

.app {
  display: grid; height: 100dvh;
  grid-template-columns: 272px minmax(0, 1fr) auto;
}

/* sidebar */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--felt); color: var(--felt-ink); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 18px 14px 14px 20px; }
.me-chip {
  display: flex; align-items: center; gap: 8px; max-width: 150px; padding: 4px 10px 4px 4px;
  border: 1px solid var(--felt-3); border-radius: 999px; background: transparent; color: var(--felt-ink);
}
.me-chip:hover { background: var(--felt-2); }
.me-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--step--1); font-weight: 700; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 4px 10px 24px; }
.side-section + .side-section { margin-top: 22px; }
.side-title { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 0 10px; margin-bottom: 4px; }
.side-title h2 { font-size: var(--step--1); color: var(--felt-muted); font-weight: 500; letter-spacing: .01em; }
.side-title .icon-btn { color: var(--felt-muted); }
.side-title .icon-btn:hover { color: var(--felt-ink); }
.conv-list li + li { margin-top: 1px; }
.conv-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 6px 10px;
  border: 0; border-radius: 10px; background: transparent; color: var(--felt-ink); text-align: left;
}
.conv-item:hover { background: var(--felt-2); }
.conv-item[aria-current="true"] { background: var(--felt-3); }
.conv-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.unread .name { font-weight: 700; }
.conv-item.unread::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brass); flex: none; }
.room-glyph {
  flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px;
  background: var(--felt-2); color: var(--felt-muted); font: 700 .8rem var(--font-display);
}
.conv-item[aria-current="true"] .room-glyph { background: var(--felt); }
.side-link {
  display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--felt-muted); text-align: left; font-size: var(--step--1);
}
.side-link:hover { color: var(--felt-ink); background: var(--felt-2); }
.side-empty { padding: 6px 10px; color: var(--felt-muted); font-size: var(--step--1); }

/* room */
.room { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.room-head {
  display: flex; align-items: center; gap: 16px; min-height: 72px; padding: 12px 20px 12px 28px;
  border-bottom: 1px solid var(--line);
}
.menu-btn { display: none; }
.room-ident { flex: 1; min-width: 0; }
.room-title { font-size: var(--step-2); line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-desc { color: var(--moss); font-size: var(--step--1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-actions { display: flex; gap: 4px; }

/* The seat strip: who's in the room, at a glance. */
.seats { display: flex; align-items: center; padding-left: 8px; }
.seats .avatar { margin-left: -8px; box-shadow: 0 0 0 3px var(--wall); }
.seats .more { margin-left: 6px; color: var(--moss); font-size: var(--step--1); font-weight: 700; }

.empty { flex: 1; display: grid; align-content: center; justify-items: start; gap: 12px; padding: 40px clamp(24px, 8vw, 96px); max-width: 720px; }
.empty h2 { font-size: var(--step-2); }
.empty p { color: var(--moss); max-width: 52ch; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* timeline */
.timeline { flex: 1; overflow-y: auto; padding: 12px 0 8px; overscroll-behavior: contain; }
.load-older { display: block; margin: 8px auto 4px; border: 0; background: none; color: var(--moss); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.messages { max-width: 860px; }
.day {
  display: flex; align-items: center; gap: 12px; margin: 18px 28px 6px;
  color: var(--moss); font-size: var(--step--1); font-weight: 700;
}
.day::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.msg { display: grid; grid-template-columns: var(--msg-avatar, 36px) minmax(0, 1fr); column-gap: 14px; padding: 1px 28px; }
.msg.first { margin-top: 14px; }
.msg:hover { background: color-mix(in srgb, var(--felt) 4%, transparent); }
.msg .avatar, .msg .avatar-btn { grid-row: span 2; margin-top: 2px; }
.msg .avatar-btn .avatar { margin-top: 0; grid-row: auto; }
.msg:not(.first) .gutter { grid-column: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.msg-name { padding: 0; border: 0; background: none; color: var(--ink); font: 700 var(--step-0)/1.3 var(--font-display); }
.msg-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.bot-tag {
  padding: 0 6px; border: 1px solid var(--line); border-radius: 6px;
  color: var(--moss); font-size: .72rem; font-weight: 700; line-height: 1.5;
}
.msg-time { color: var(--moss); font-size: .75rem; }
.msg-body { grid-column: 2; min-width: 0; overflow-wrap: anywhere; max-width: 72ch; }
.msg-body p + p, .msg-body p + ul, .msg-body ul + p, .msg-body pre + p, .msg-body p + pre { margin-top: .55em; }
.msg-body ul { padding-left: 1.25em; list-style: disc; }
.msg-body ol { padding-left: 1.4em; list-style: decimal; }
.msg-body blockquote { margin: .4em 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--moss); }
.msg-body code { padding: .05em .35em; border-radius: 5px; background: color-mix(in srgb, var(--felt) 9%, transparent); font-size: .9em; }
.msg-body pre { margin: .5em 0; padding: 12px 14px; overflow-x: auto; border-radius: 10px; background: color-mix(in srgb, var(--felt) 9%, transparent); }
.msg-body pre code { padding: 0; background: none; }
.msg-body a { color: inherit; text-decoration-color: var(--brass); text-underline-offset: 3px; }
.mention { font-weight: 700; box-shadow: inset 0 -.35em 0 var(--brass-soft); }
.mention.me { background: var(--brass-soft); border-radius: 4px; padding: 0 2px; }
.msg.pending .msg-body { color: var(--moss); }

.tool {
  grid-column: 2; margin: 4px 0 2px; max-width: 72ch;
  font-size: var(--step--1); color: var(--moss);
}
.tool summary { cursor: pointer; width: fit-content; padding: 2px 8px; border: 1px dashed var(--line); border-radius: 8px; list-style: none; }
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; }
.tool[open] summary::before { content: "▾ "; }
.tool pre { margin: 6px 0 0; padding: 10px 12px; overflow-x: auto; border-radius: 8px; background: color-mix(in srgb, var(--felt) 7%, transparent); white-space: pre-wrap; }
.tool.error summary { border-color: var(--rosewood); color: var(--rosewood); }

.event { margin: 10px 28px; color: var(--moss); font-size: var(--step--1); text-align: center; }
.event.error { color: var(--rosewood); }

/* composer */
.composer-wrap { padding: 0 20px 14px 28px; }
.typing { min-height: 1.5em; color: var(--moss); font-size: var(--step--1); }
.typing .dots span { display: inline-block; animation: bob 1.2s infinite ease-in-out; }
.typing .dots span:nth-child(2) { animation-delay: .15s; }
.typing .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 60%, 100% { transform: none; opacity: .4; } 30% { transform: translateY(-3px); opacity: 1; } }
.join-bar {
  max-width: 860px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
}
.composer {
  position: relative; display: flex; align-items: flex-end; gap: 8px; max-width: 860px;
  padding: 8px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
}
.composer:focus-within { border-color: var(--moss); }
.composer textarea { flex: 1; min-height: 40px; max-height: 40vh; padding: 8px 8px; border: 0; background: transparent; resize: none; }
.composer textarea:focus { outline: none; }
.send { background: var(--brass); border-color: var(--brass); color: #1C1407; }
.send:hover { background: color-mix(in srgb, var(--brass) 88%, #000); border-color: transparent; }
.hint { margin-top: 6px; color: var(--moss); font-size: .75rem; }

.mention-pop {
  position: absolute; bottom: calc(100% + 6px); left: 8px; z-index: 5;
  min-width: 240px; max-height: 260px; overflow-y: auto; padding: 6px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow);
}
.mention-opt { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 8px; background: none; text-align: left; }
.mention-opt[aria-selected="true"], .mention-opt:hover { background: color-mix(in srgb, var(--felt) 9%, transparent); }
.mention-opt .handle { color: var(--moss); font-size: var(--step--1); }

/* members */
.members { display: flex; flex-direction: column; width: 288px; min-height: 0; border-left: 1px solid var(--line); background: var(--surface); }
.members-head { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 0 12px 0 20px; border-bottom: 1px solid var(--line); }
.members-head h2 { font-size: var(--step-1); }
.member-list { flex: 1; overflow-y: auto; padding: 12px 10px; }
.member-list h3 { margin: 14px 10px 6px; color: var(--moss); font: 500 var(--step--1) var(--font-ui); }
.member-list h3:first-child { margin-top: 0; }
.member {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 10px;
  border: 0; border-radius: 10px; background: none; text-align: left;
}
.member:hover { background: color-mix(in srgb, var(--felt) 7%, transparent); }
.member .who { min-width: 0; }
.member .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .who small { display: block; color: var(--moss); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members-foot { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; border-top: 1px solid var(--line); }

/* ---------------------------------------------------------------- dialog */

.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: min(86dvh, 820px); padding: 0;
  border: 0; border-radius: 18px; background: var(--wall); color: var(--ink); box-shadow: var(--shadow);
}
.dialog::backdrop { background: color-mix(in srgb, var(--felt) 55%, transparent); }
.dialog-inner { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 16px 8px 24px; }
.dialog-head h2 { font-size: var(--step-2); }
.dialog-body { overflow-y: auto; padding: 8px 24px 4px; }
.dialog .form-error { padding: 0 24px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 24px 22px; }
.dialog-actions .spacer { flex: 1; }

.pick-list { display: grid; gap: 2px; }
.pick {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 12px; background: none; text-align: left;
}
.pick:hover, .pick:focus-visible { background: color-mix(in srgb, var(--felt) 8%, transparent); }
.pick .who { flex: 1; min-width: 0; }
.pick .who strong { display: flex; align-items: center; gap: 6px; }
.pick .who small { display: block; color: var(--moss); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-check { display: flex; align-items: center; gap: 12px; padding: 6px 4px; font-weight: 400; font-size: var(--step-0); }
.pick-check input { width: 18px; min-height: 18px; height: 18px; accent-color: var(--felt); }
.fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 4px; }
.fieldset legend { padding: 0; margin-bottom: 4px; font-weight: 700; font-size: var(--step--1); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.subtle { color: var(--moss); font-size: var(--step--1); font-weight: 400; }
.section-label { margin-top: 6px; font: 700 var(--step-1) var(--font-display); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 30px; height: 30px; padding: 0; border: 2px solid transparent; border-radius: 50%; background: var(--c); }
.swatch[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 2px var(--wall); }
.swatches input[type="color"] { width: 38px; min-height: 30px; height: 30px; padding: 0 2px; }

.profile-card { display: grid; gap: 14px; }
.profile-top { display: flex; align-items: center; gap: 16px; }
.profile-top h3 { font-size: var(--step-2); }
.profile-top small { color: var(--moss); }
.traits { display: flex; flex-wrap: wrap; gap: 6px; }
.trait { padding: 2px 10px; border-radius: 999px; background: color-mix(in srgb, var(--c, var(--felt)) 16%, transparent); font-size: var(--step--1); font-weight: 700; }
.persona { white-space: pre-wrap; padding: 12px 14px; border-radius: 12px; background: var(--surface); }

.result { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 12px; background: none; text-align: left; }
.result:hover { background: color-mix(in srgb, var(--felt) 8%, transparent); }
.result small { color: var(--moss); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--wall); box-shadow: var(--shadow); font-weight: 700;
}
.toast.error { background: var(--rosewood); color: #fff; }

/* ---------------------------------------------------------------- small screens */

@media (max-width: 1100px) {
  .members { position: fixed; inset: 0 0 0 auto; z-index: 20; box-shadow: var(--shadow); }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-grid; }
  .room-head { padding: 10px 12px; gap: 8px; min-height: 60px; }
  .room-title { font-size: var(--step-1); }
  .seats { display: none; }
  .msg { padding: 1px 16px; column-gap: 10px; }
  .day, .event { margin-left: 16px; margin-right: 16px; }
  .composer-wrap { padding: 0 12px 10px; }
  .hint { display: none; }
  .room-actions .btn { min-height: 40px; padding: .4em .55em; }
  .room-actions .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .room-desc { display: none; }
  .members { width: min(320px, 92vw); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------------------------------------------------------- pictures */

.pics { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; margin: 6px 0 2px; }
.pic {
  display: block; padding: 0; border: 0; border-radius: 12px; overflow: hidden;
  background: color-mix(in srgb, var(--felt) 10%, transparent); cursor: zoom-in;
}
.pic img {
  display: block; width: auto; height: auto;
  max-width: min(100%, 380px); max-height: 380px;
}
.pic:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.clip-wrap { position: relative; display: block; max-width: 75vw; }
.pic video { display: block; width: 100%; height: auto; background: #11181A; pointer-events: none; }
.clip-badge {
  position: absolute; left: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px 2px 6px; border-radius: 999px; background: rgb(12 18 16 / .66); color: #F4EFE4;
  font-size: var(--step--1); font-variant-numeric: tabular-nums; backdrop-filter: blur(4px);
}
.pics.many .clip-wrap { width: 168px !important; }
.pics.many .pic video { height: 168px; object-fit: cover; }
@media (max-width: 640px) { .pics.many .clip-wrap { width: 30vw !important; } .pics.many .pic video { height: 30vw; } }
.animate-from img { display: block; max-width: 100%; max-height: 220px; margin: 0 auto; border-radius: 10px; }
.link-btn {
  padding: 0; border: 0; background: none; color: var(--rosewood); font: inherit; font-size: var(--step--1);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.link-btn:hover { color: var(--ink); }
.stop-video, .stop-reply, .stop-picture { margin-left: 10px; }
.probe p { margin: 2px 0; }
.probe .warn { color: var(--rosewood); }
textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }
.pic-caption { margin-top: 4px; color: var(--moss); font-size: var(--step--1); font-style: italic; max-width: 380px; }
.pic-btn { color: var(--moss); width: 40px; height: 40px; }
.pic-btn:hover { color: var(--ink); }

.dialog.wide { width: min(980px, calc(100vw - 32px)); }
.viewer { display: grid; gap: 16px; }
.viewer img, .viewer video { display: block; width: auto; height: auto; max-width: 100%; max-height: 64dvh; margin: 0 auto; border-radius: 12px; }
.viewer video { background: #11181A; }
@media (min-width: 821px) {
  .viewer { grid-template-columns: minmax(0, 1fr) 260px; align-items: start; }
  .viewer .meta { grid-template-columns: 1fr; gap: 2px; }
  .viewer .meta dd + dt { margin-top: 10px; }
}
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: var(--step--1); }
.meta dt { color: var(--moss); font-weight: 700; }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.dialog-actions a.btn { text-decoration: none; }

.field-label { font-weight: 700; font-size: var(--step--1); }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: color-mix(in srgb, var(--felt) 8%, transparent); }
.seg label { flex: 1; display: block; font-size: var(--step-0); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; padding: 7px 10px; border-radius: 9px; text-align: center; color: var(--moss); font-weight: 700; cursor: pointer; }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
details.more summary { cursor: pointer; color: var(--moss); font-weight: 700; font-size: var(--step--1); width: fit-content; }

/* ---------------------------------------------------------------- reading aloud */

.msg { grid-template-columns: var(--msg-avatar, 36px) minmax(0, 1fr) auto; }
.msg > .msg-tools { grid-column: 3; grid-row: 1 / span 2; align-self: start; display: flex; gap: 2px; }
.msg-del {
  display: inline-grid; place-items: center; min-width: 32px; height: 32px; margin-top: 2px; padding: 0 6px;
  border: 0; border-radius: 8px; background: transparent; color: var(--moss); font: inherit; font-size: var(--step--1); font-weight: 700;
  opacity: 0; transition: opacity .12s;
}
.msg:hover .msg-del, .msg-del:focus-visible, .msg-del[data-armed] { opacity: 1; }
.msg-del:hover { color: var(--rosewood); background: color-mix(in srgb, var(--rosewood) 10%, transparent); }
.msg-del[data-armed] { color: #fff; background: var(--rosewood); }
@media (hover: none) { .msg-del { opacity: .7; } }
.listen {
  display: inline-grid; place-items: center; width: 32px; height: 32px; margin-top: 2px;
  border: 0; border-radius: 8px; background: transparent; color: var(--moss);
  opacity: 0; transition: opacity .12s;
}
.msg:hover .listen, .listen:focus-visible, .listen.loading, .listen.playing { opacity: 1; }
.listen:hover { color: var(--ink); background: color-mix(in srgb, var(--felt) 9%, transparent); }
.listen.playing { color: var(--brass); }
.listen.loading svg { animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 50% { opacity: .35; } }
@media (hover: none) { .listen { opacity: .7; } }

.read-aloud {
  display: flex; align-items: flex-start; gap: 10px; margin: 0 12px 4px; padding: 12px;
  border-radius: 12px; background: color-mix(in srgb, var(--felt) 6%, transparent);
  font-weight: 700; font-size: var(--step-0); cursor: pointer;
}
.read-aloud input { width: 18px; height: 18px; min-height: 18px; margin-top: 2px; accent-color: var(--felt); }
.read-aloud small { display: block; margin-top: 2px; color: var(--moss); font-weight: 400; font-size: var(--step--1); }
.voice-row { align-items: center; margin-top: 0; }

/* ---------------------------------------------------------------- slideshow */

dialog.slideshow {
  --ss-ink: #EEF2EF;
  --ss-dim: #A9B5AF;
  --ss-glass: rgb(20 26 24 / .72);
  position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; border-radius: 0;
  background: #0B0F0E; color: var(--ss-ink);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
dialog.slideshow:not([open]) { display: none; }
dialog.slideshow::backdrop { background: #0B0F0E; }
dialog.slideshow:focus { outline: none; }

.ss-progress { position: absolute; inset: 0 0 auto 0; height: 3px; background: rgb(255 255 255 / .08); z-index: 3; }
.ss-progress > span { display: block; height: 100%; width: 0; background: #E2B455; }
@keyframes ss-fill { from { width: 0; } to { width: 100%; } }

.ss-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px 8px; z-index: 2;
}
.ss-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.ss-title strong { font-family: var(--font-display); font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-count { color: var(--ss-dim); font-size: var(--step--1); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ss-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.ss-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--ss-ink); cursor: pointer;
}
.ss-btn:hover { background: rgb(255 255 255 / .1); }
.ss-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.ss-btn:focus-visible, .ss-nav:focus-visible, .ss-thumb:focus-visible, .ss-speed:focus-visible { outline: 2px solid #E2B455; outline-offset: 2px; }
.ss-speed {
  height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid rgb(255 255 255 / .18);
  background: transparent; color: var(--ss-ink); font: inherit; font-size: var(--step--1);
}
.ss-speed option { color: #17211E; }

.ss-stage { position: relative; min-height: 0; }
.ss-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  padding: 4px 64px; opacity: 0; transition: opacity .45s ease;
}
.ss-img.on { opacity: 1; }
.ss-nav {
  position: absolute; top: 50%; translate: 0 -50%; z-index: 2;
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: var(--ss-glass); color: var(--ss-ink); cursor: pointer;
}
.ss-nav:hover { background: rgb(40 50 46 / .9); }
.ss-nav.prev { left: 12px; }
.ss-nav.next { right: 12px; }

.ss-bottom { display: grid; gap: 10px; padding: 8px 16px 14px; z-index: 2; }
.ss-meta { display: grid; gap: 2px; text-align: center; max-width: 900px; margin: 0 auto; }
.ss-who { color: var(--ss-dim); font-size: var(--step--1); }
.ss-caption {
  margin: 0; font-size: .95rem; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ss-thumbs {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px; justify-content: safe center;
  scrollbar-width: thin; scrollbar-color: rgb(255 255 255 / .2) transparent;
}
.ss-thumb {
  flex: none; width: 64px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: 8px;
  overflow: hidden; background: #1A2220; cursor: pointer; opacity: .55; transition: opacity .2s;
}
.ss-thumb:hover { opacity: .85; }
.ss-thumb[aria-current] { opacity: 1; border-color: #E2B455; }
.ss-thumb img, .ss-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.ss-vid { pointer-events: none; }
.ss-vid.on { pointer-events: auto; z-index: 1; }

@media (max-width: 640px) {
  .ss-img { padding: 0; }
  .ss-nav { width: 40px; height: 40px; background: rgb(20 26 24 / .55); }
  .ss-nav.prev { left: 6px; }
  .ss-nav.next { right: 6px; }
  .ss-tools .ss-speed { display: none; }
  .ss-title strong { display: none; }
  .ss-thumb { width: 52px; height: 40px; }
  .ss-top { padding: 10px 8px 6px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .ss-img, .ss-thumb { transition: none; }
}

.pics-wrap { display: grid; justify-items: start; }
.pics-show {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; padding: 2px 8px 2px 6px;
  border: 0; border-radius: 999px; background: transparent; color: var(--moss);
  font: inherit; font-size: var(--step--1); font-weight: 600; cursor: pointer;
}
.pics-show:hover { background: color-mix(in srgb, currentColor 12%, transparent); color: inherit; }

/* ---------------------------------------------------------------- sharing pictures */

.pics.many .pic img { width: 168px; height: 168px; max-width: none; object-fit: cover; }
@media (max-width: 640px) { .pics.many .pic img { width: 30vw; height: 30vw; } }

.attach-tray {
  max-width: 860px; margin-bottom: 8px; padding: 10px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  display: grid; gap: 8px;
}
.attach-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px; }
.attach-item { position: relative; flex: none; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--felt) 10%, transparent); }
.attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-remove {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; padding: 0; border: 0; cursor: pointer;
  background: rgb(15 20 18 / .72); color: #fff; font-size: 16px; line-height: 1;
}
.attach-remove:hover { background: rgb(15 20 18 / .9); }
.attach-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: var(--moss); font-size: var(--step--1); }
.attach-status > span:first-child { flex: 1; min-width: 12ch; }
.attach-bar { flex: 1 1 120px; height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--moss) 25%, transparent); overflow: hidden; }
.attach-bar > span { display: block; height: 100%; background: var(--brass); transition: width .2s; }

.room { position: relative; }
.room.dropping::after {
  content: "Drop pictures to share them here";
  position: absolute; inset: 10px; z-index: 20; display: grid; place-items: center;
  border: 3px dashed var(--brass); border-radius: 18px;
  background: color-mix(in srgb, var(--wall) 85%, transparent);
  font: 700 1.2rem var(--font-display); color: var(--ink); pointer-events: none;
}

.viewer .seen { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--felt) 7%, transparent); }
.viewer .seen p { margin: 0; }
.viewer .seen .section-label { margin-bottom: 4px; font-size: var(--step--1); }

/* ---------------------------------------------------------------- dictation */

.mic-btn.recording { color: #fff; background: #C2453A; border-radius: 50%; }
.mic-btn.recording:hover { background: #A8382F; color: #fff; }
.rec-bar {
  max-width: 860px; margin-bottom: 8px; padding: 8px 10px 8px 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid color-mix(in srgb, #C2453A 45%, var(--line)); border-radius: 16px; background: var(--surface);
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #C2453A; flex: none; animation: rec-pulse 1.2s ease-in-out infinite; }
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.rec-text { font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-level { flex: 1 1 80px; min-width: 60px; height: 6px; border-radius: 3px; background: color-mix(in srgb, var(--moss) 22%, transparent); overflow: hidden; }
.rec-level > span { display: block; height: 100%; width: 0; background: #C2453A; transition: width .08s linear; }
.rec-spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--moss) 30%, transparent); border-top-color: var(--brass); animation: rec-spin .8s linear infinite; }
@keyframes rec-spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- picture size (each person's or bot's own) */

.msg { --msg-avatar: 36px; }
.msg.av-medium { --msg-avatar: 56px; }
.msg.av-large { --msg-avatar: 88px; }
.profile-top { --profile-avatar: 104px; }
.profile-top.av-medium { --profile-avatar: 136px; }
.profile-top.av-large { --profile-avatar: 176px; }
@media (max-width: 640px) {
  .msg.av-medium { --msg-avatar: 48px; }
  .msg.av-large { --msg-avatar: 64px; }
  .profile-top.av-medium { --profile-avatar: 120px; }
  .profile-top.av-large { --profile-avatar: 144px; }
}
.msg .avatar { width: var(--msg-avatar); height: var(--msg-avatar); font-size: calc(var(--msg-avatar) * .4); }
.msg .avatar.emoji { font-size: calc(var(--msg-avatar) * .5); }
.msg.av-medium .avatar.is-bot, .msg.av-large .avatar.is-bot { border-radius: 24%; }
/* A tall picture shouldn't push the text away from the name: the last row takes the extra height. */
.msg.first { grid-template-rows: auto 1fr; align-items: start; }
.profile-top .avatar.xl { width: var(--profile-avatar); height: var(--profile-avatar); font-size: calc(var(--profile-avatar) * .4); }
.profile-top .avatar.xl.emoji { font-size: calc(var(--profile-avatar) * .5); }

.size-choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.size-choice label {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.size-choice label:has(input:checked) { border-color: var(--brass); box-shadow: 0 0 0 1px var(--brass); }
.size-choice input { position: absolute; opacity: 0; pointer-events: none; }
.size-choice label:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.size-choice .avatar { flex: none; }
.size-choice strong { display: block; font-size: var(--step--1); }
.size-choice small { color: var(--moss); font-size: .75rem; }

/* ---------------------------------------------------------------- profile picture viewer */

.avatar-btn {
  display: inline-grid; padding: 0; border: 0; background: none; color: inherit; cursor: pointer;
  border-radius: 50%; align-self: start; justify-self: start;
}
.avatar-btn.is-bot { border-radius: 30%; }
.avatar-btn.has-pic { cursor: zoom-in; }
.avatar-btn:hover .avatar { filter: brightness(1.06); box-shadow: 0 0 0 2px var(--brass); }
.avatar-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

dialog.avatar-viewer {
  padding: 0; border: 0; background: transparent; color: #EEF2EF; max-width: none; max-height: none; overflow: visible;
  display: grid; gap: 12px; justify-items: center;
}
dialog.avatar-viewer:not([open]) { display: none; }
dialog.avatar-viewer::backdrop { background: rgb(8 12 11 / .86); }
.av-frame {
  --av-box: min(92vw, 76vh, 720px);
  width: var(--av-box); height: var(--av-box);
  display: grid; place-items: center; overflow: hidden;
  border-radius: 24px; background: #0B0F0E; box-shadow: 0 20px 60px rgb(0 0 0 / .5);
}
.av-frame img, .av-frame video { width: 100%; height: 100%; object-fit: contain; display: block; }
.av-caption { width: min(92vw, 720px); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.av-caption strong { font-family: var(--font-display); font-size: 1.1rem; }
.av-caption .spacer { flex: 1; }
.av-caption .btn { color: #EEF2EF; border-color: rgb(255 255 255 / .25); }
.av-caption .btn:hover { background: rgb(255 255 255 / .1); }
.av-hint { color: #A9B5AF; font-size: var(--step--1); }
@media (max-width: 640px) { .av-hint { display: none; } }

/* ---------------------------------------------------------------- archiving */

.archived-box > summary { cursor: pointer; list-style: none; }
.archived-box > summary::-webkit-details-marker { display: none; }
.archived-box > summary h2::before { content: "▸"; display: inline-block; width: 1em; }
.archived-box[open] > summary h2::before { content: "▾"; }
.side-count { font-weight: 400; opacity: .7; text-transform: none; letter-spacing: 0; }
.archived-bar { margin-bottom: 8px; border-style: dashed; }
.archived-bar > span { flex: 1; min-width: 16ch; }

/* ---------------------------------------------------------------- auto replies, suggestions */

.auto-tag {
  padding: 0 6px; border-radius: 6px; background: var(--brass-soft); color: #6B4A12;
  font-size: .72rem; font-weight: 700; line-height: 1.5;
}
#btn-auto { position: relative; }
#btn-auto .auto-dot { display: none; }
#btn-auto.on { color: var(--ink); }
#btn-auto.on .auto-dot {
  display: block; position: absolute; top: 6px; left: 20px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--brass); box-shadow: 0 0 0 2px var(--wall);
}
.auto-row { display: grid; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; }
.auto-row.locked { opacity: .7; }
.auto-head { align-items: center; }
.auto-head .avatar { flex: none; }
.auto-details { padding-left: 2px; }
.draft { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--felt) 7%, transparent); }
.draft.loading { color: var(--moss); animation: pulse 1.2s infinite ease-in-out; }
.draft-text { margin: 0 0 6px; white-space: pre-wrap; font-size: var(--step-0); }
@media (prefers-color-scheme: dark) { .auto-tag { color: #F1D9A8; } }

/* ---------------------------------------------------------------- admin: users, settings */

.user-list { display: grid; gap: 2px; }
.user-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  padding: 10px 8px; border-bottom: 1px solid var(--line);
}
.user-row:last-child { border-bottom: 0; }
.user-row .who { display: grid; min-width: 0; }
.user-row .who strong { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.user-row .who small { color: var(--moss); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-acts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.btn-sm { min-height: 32px; padding: .3em .7em; font-size: var(--step--1); }
.badge {
  padding: 0 6px; border: 1px solid var(--line); border-radius: 6px;
  color: var(--moss); font-size: .72rem; font-weight: 700; line-height: 1.5;
}
.badge.admin { border-color: transparent; background: var(--brass-soft); color: var(--ink); }
@media (max-width: 640px) {
  .user-row { grid-template-columns: auto minmax(0, 1fr); }
  .user-acts { grid-column: 1 / -1; justify-content: flex-start; }
}
.pw-row { display: flex; gap: 8px; align-items: center; }
.pw-row input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pw-row code { flex: 1; padding: 8px 10px; border-radius: 8px; background: var(--surface); font-size: 1rem; user-select: all; overflow-wrap: anywhere; }
.pw-note { padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--brass) 14%, transparent); }
.pw-note p { margin: 0 0 6px; }
.pw-note .subtle { margin: 6px 0 0; }
.settings-group { display: grid; gap: 4px; }
.setting { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; padding: 8px 2px; cursor: pointer; }
.setting > span { display: grid; gap: 2px; }
.setting input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--felt); }
