/* ==========================================================================
   QuickChat — design tokens
   ========================================================================== */

:root {
  --bg: #0b0d10;
  --bg-raised: #12151a;
  --bg-elevated: #171b22;
  --bg-input: #0e1116;
  --line: #232935;
  --line-soft: #1b202a;

  --text: #e8ecf3;
  --text-dim: #9aa4b5;
  --text-faint: #6b7488;

  --accent: #5b8cff;
  --accent-hot: #7aa2ff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --good: #3ecf8e;
  --warn: #f5b74e;
  --bad: #ff5f6d;

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 22px;

  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.3);

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-w: 340px;

  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

/* Many components below set an explicit `display`, which would otherwise beat
   the UA stylesheet's rule for [hidden]. Keep the attribute authoritative so
   toggling `el.hidden` always works. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Inter, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body.home { overflow: auto; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
p { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

button { font: inherit; color: inherit; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  display: block;
}

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #333c4d; background-clip: padding-box; }

/* ==========================================================================
   Primitives
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  font-weight: 550;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease), transform 0.1s var(--ease);
}
.btn:hover { background: #1e232c; border-color: #2c3444; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #08101f;
  font-weight: 650;
}
.btn-primary:hover { background: var(--accent-hot); border-color: transparent; }

.btn-ghost { background: transparent; }
.btn-lg { padding: 13px 22px; font-size: 16px; width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn.is-busy { opacity: 0.7; pointer-events: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-elevated); color: var(--text); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 550;
}
.field input,
.field select,
select, input[type='text'] {
  width: 100%;
  padding: 11px 13px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
input[type='text']:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa4b5' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--bg-input);
  font-family: inherit;
  font-size: 11.5px;
  color: var(--text-dim);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  font-size: 17px;
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent) 0%, #a06bff 100%);
  box-shadow: 0 0 18px rgba(91, 140, 255, 0.5);
  flex: none;
}
.brand.small { font-size: 15px; margin-bottom: 26px; opacity: 0.85; }
.brand.tiny .brand-mark { width: 18px; height: 18px; }

/* ==========================================================================
   Home
   ========================================================================== */

.aurora {
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 70vh;
  background:
    radial-gradient(45% 55% at 25% 30%, rgba(91, 140, 255, 0.28), transparent 70%),
    radial-gradient(40% 50% at 75% 20%, rgba(160, 107, 255, 0.22), transparent 70%),
    radial-gradient(35% 45% at 55% 60%, rgba(62, 207, 142, 0.12), transparent 70%);
  filter: blur(30px);
  pointer-events: none;
  z-index: 0;
}

.home-nav {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(20px, 5vw, 56px);
}
.nav-link { color: var(--text-dim); text-decoration: none; font-size: 14px; }
.nav-link:hover { color: var(--text); }

.home-main {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 clamp(20px, 5vw, 40px) 80px;
}

.hero { padding: clamp(40px, 8vh, 90px) 0 clamp(50px, 9vh, 100px); text-align: center; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 14px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(18, 21, 26, 0.7);
  font-size: 13px;
  color: var(--text-dim);
  backdrop-filter: blur(8px);
}
.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 10px var(--good);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.hero h1 {
  margin: 26px 0 18px;
  font-size: clamp(38px, 7vw, 68px);
  line-height: 1.05;
  letter-spacing: -0.035em;
}
.hero h1 em {
  font-style: normal;
  background: linear-gradient(100deg, var(--accent) 10%, #b07bff 60%, #3ecf8e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lede {
  max-width: 620px;
  margin: 0 auto;
  color: var(--text-dim);
  font-size: clamp(15px, 1.6vw, 17.5px);
}

.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: 38px auto 0;
  max-width: 420px;
}
.cta .btn-lg { box-shadow: 0 8px 30px rgba(91, 140, 255, 0.28); }

.join-form { display: flex; gap: 8px; width: 100%; }
.join-form input { flex: 1; }
.join-form .btn { flex: none; }

.hint { margin-top: 18px; font-size: 13px; color: var(--text-faint); }
.hint.is-error { color: var(--bad); }

.shake { animation: shake 0.4s; border-color: var(--bad) !important; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.feature {
  padding: 22px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(23, 27, 34, 0.9), rgba(18, 21, 26, 0.6));
  transition: border-color 0.2s, transform 0.2s var(--ease);
}
.feature:hover { border-color: var(--line); transform: translateY(-2px); }
.feature .icon { width: 22px; height: 22px; color: var(--accent); margin-bottom: 14px; }
.feature h3 { font-size: 15.5px; margin-bottom: 7px; }
.feature p { color: var(--text-dim); font-size: 14px; }

.home-footer {
  position: relative;
  z-index: 1;
  padding: 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  border-top: 1px solid var(--line-soft);
}
.home-footer .sep { margin: 0 8px; }

/* ==========================================================================
   Pre-join
   ========================================================================== */

.prejoin {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(60% 60% at 20% 10%, rgba(91, 140, 255, 0.14), transparent 70%),
    radial-gradient(50% 50% at 85% 90%, rgba(160, 107, 255, 0.12), transparent 70%),
    var(--bg);
  z-index: 50;
  overflow: auto;
}
.prejoin.is-hidden { display: none; }

.prejoin-card {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.85fr);
  gap: 34px;
  align-items: center;
  width: min(980px, 100%);
}

.prejoin-preview {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #05070a;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.prejoin-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.prejoin-preview.cam-off video { visibility: hidden; }

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-faint);
  font-size: 14px;
}
.prejoin-preview.cam-off .preview-placeholder { display: flex; }

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-weight: 650;
  color: #08101f;
  background: var(--accent);
  flex: none;
  text-transform: uppercase;
}
.avatar-lg { width: 84px; height: 84px; font-size: 32px; }

.level-bar {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 74px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.level-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--good), var(--accent));
  border-radius: 99px;
  transition: width 0.08s linear;
}

.preview-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  display: flex;
  justify-content: center;
  gap: 12px;
}

.prejoin-form h1 { font-size: 27px; margin-bottom: 12px; }
.room-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.room-line code {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bg-input);
  border: 1px solid var(--line);
  font-size: 13px;
  color: var(--accent-hot);
}
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.link-btn:hover { color: var(--text); background: var(--bg-elevated); }
.link-btn .icon { width: 15px; height: 15px; }

.occupants { color: var(--text-faint); font-size: 13.5px; margin-bottom: 22px; }
.occupants.is-live { color: var(--good); }

.device-details { margin: 4px 0 20px; }
.device-details summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13.5px;
  padding: 8px 0;
  list-style: none;
}
.device-details summary::-webkit-details-marker { display: none; }
.device-details summary:hover { color: var(--text); }
.device-details[open] summary { margin-bottom: 12px; }
.device-details .icon { width: 16px; height: 16px; }

.fineprint { margin-top: 12px; font-size: 13px; color: var(--bad); min-height: 18px; }

/* ==========================================================================
   App shell
   ========================================================================== */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--bg-raised);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 260px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--bg-elevated); color: var(--text); }
.chip .icon { width: 15px; height: 15px; }
.chip span { overflow: hidden; text-overflow: ellipsis; }
.chip.ghost { background: transparent; cursor: default; }
.chip.ghost:hover { background: transparent; color: var(--text-dim); }
.chip.icon-only { padding: 7px; cursor: pointer; }
.chip.icon-only:hover { color: var(--text); }
.chip.is-copied { color: var(--good); border-color: rgba(62, 207, 142, 0.4); }
.lock-chip { color: var(--warn); }

.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 13px; }
.bars i {
  width: 3px;
  border-radius: 1px;
  background: var(--line);
  transition: background 0.3s;
}
.bars i:nth-child(1) { height: 4px; }
.bars i:nth-child(2) { height: 7px; }
.bars i:nth-child(3) { height: 10px; }
.bars i:nth-child(4) { height: 13px; }
.bars[data-q='4'] i { background: var(--good); }
.bars[data-q='3'] i:nth-child(-n+3) { background: var(--good); }
.bars[data-q='2'] i:nth-child(-n+2) { background: var(--warn); }
.bars[data-q='1'] i:nth-child(1) { background: var(--bad); }
.bars[data-q='0'] i:nth-child(1) { background: var(--bad); }

/* ==========================================================================
   Stage & tiles
   ========================================================================== */

.layout {
  display: grid;
  grid-template-columns: 1fr 0;
  min-height: 0;
  transition: grid-template-columns 0.28s var(--ease);
}
.layout.sidebar-open { grid-template-columns: 1fr var(--sidebar-w); }

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: 10px;
  height: 100%;
  align-content: center;
}

/* Speaker layout: one big tile, the rest in a filmstrip. */
.tiles.speaker-view {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  align-content: stretch;
}
.tiles.speaker-view .tile { display: none; }
.tiles.speaker-view .tile.is-featured {
  display: block;
  grid-row: 1;
}
.tiles.speaker-view .filmstrip {
  grid-row: 2;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.tiles.speaker-view .filmstrip .tile {
  display: block;
  flex: none;
  width: 168px;
  aspect-ratio: 16 / 9;
}

.tile {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0e1116;
  border: 1.5px solid transparent;
  min-height: 0;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.tile.is-speaking {
  border-color: var(--good);
  box-shadow: 0 0 0 1px rgba(62, 207, 142, 0.3), 0 0 24px rgba(62, 207, 142, 0.15);
}
.tile.is-pinned { border-color: var(--accent); }

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0e1116;
}
.tile.is-mirrored video { transform: scaleX(-1); }
.tile.is-screen video { object-fit: contain; background: #05070a; }
.tile.cam-off video { visibility: hidden; }

.tile-placeholder {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(80% 80% at 50% 40%, #171b22, #0e1116);
}
.tile.cam-off .tile-placeholder { display: flex; }
.tile-placeholder .avatar { width: clamp(44px, 22%, 88px); height: clamp(44px, 22%, 88px); font-size: clamp(18px, 9%, 34px); }

.tile-top {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.18s, transform 0.18s;
  pointer-events: none;
}
.tile:hover .tile-top { opacity: 1; transform: none; pointer-events: auto; }

.tile-actions { display: flex; gap: 4px; }
.tile-actions button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.72);
  color: #fff;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.tile-actions button:hover { background: rgba(30, 35, 44, 0.9); }
.tile-actions button.is-active { background: var(--accent); color: #08101f; }
.tile-actions .icon { width: 15px; height: 15px; }

.tile-bottom {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.tile-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 8px;
  background: rgba(8, 10, 14, 0.66);
  backdrop-filter: blur(8px);
  font-size: 12.5px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-name .icon { width: 13px; height: 13px; flex: none; }
.tile-name .icon.muted-icon { color: var(--bad); }

.tile-badge {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: rgba(8, 10, 14, 0.66);
  backdrop-filter: blur(8px);
  font-size: 13px;
}
.tile-badge.hand { background: var(--warn); color: #1a1200; animation: raise 1.6s ease-in-out infinite; }
@keyframes raise { 50% { transform: translateY(-3px); } }

.tile-stats {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(8, 10, 14, 0.8);
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-dim);
  pointer-events: none;
  display: none;
}
.tile.show-stats .tile-stats { display: block; }

.tile-connecting {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(11, 13, 16, 0.7);
  font-size: 13px;
  color: var(--text-dim);
  backdrop-filter: blur(2px);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 9px;
  display: inline-block;
  vertical-align: -4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stage-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
  color: var(--text-faint);
}
.stage-hint .icon { width: 26px; height: 26px; }
.stage-hint .btn { pointer-events: auto; }

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line-soft);
  background: var(--bg-raised);
  overflow: hidden;
}
.sidebar[hidden] { display: none; }

.sidebar-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line-soft);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 550;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.sidebar-close { margin-left: auto; }

.badge, .count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 650;
}
.badge { background: var(--accent); color: #08101f; }
.count { background: var(--line); color: var(--text-dim); }

.panel { display: none; min-height: 0; }
.panel.is-active { display: grid; grid-template-rows: 1fr auto auto; }
#panelPeople.is-active, #panelStats.is-active { grid-template-rows: 1fr auto; }

/* -------------------------------------------------------------- messages */

.messages {
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg { display: flex; flex-direction: column; gap: 3px; max-width: 100%; }
.msg-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 12px;
  color: var(--text-faint);
}
.msg-head strong { color: var(--text-dim); font-weight: 600; font-size: 12.5px; }
.msg-body {
  padding: 8px 11px;
  border-radius: 12px;
  border-top-left-radius: 4px;
  background: var(--bg-elevated);
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.mine { align-items: flex-end; }
.msg.mine .msg-body {
  background: var(--accent);
  color: #08101f;
  border-top-left-radius: 12px;
  border-top-right-radius: 4px;
}
.msg.mine .msg-head { flex-direction: row-reverse; }
.msg-body a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.msg.system {
  align-items: center;
  font-size: 12px;
  color: var(--text-faint);
}
.msg.system .msg-body {
  background: transparent;
  padding: 2px 0;
  font-size: 12.5px;
}

.relay-tag {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--line);
  color: var(--text-faint);
}

.file-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elevated);
  min-width: 220px;
}
.msg.mine .file-card { background: var(--bg-elevated); color: var(--text); }
.file-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-input);
  flex: none;
  display: grid;
  place-items: center;
  color: var(--text-dim);
}
.file-meta { min-width: 0; flex: 1; }
.file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-sub { font-size: 11.5px; color: var(--text-faint); }
.file-progress {
  height: 3px;
  border-radius: 99px;
  background: var(--line);
  margin-top: 6px;
  overflow: hidden;
}
.file-progress i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.15s linear;
}

.typing {
  padding: 0 14px 6px;
  font-size: 12px;
  color: var(--text-faint);
  min-height: 18px;
  font-style: italic;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line-soft);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.icon-btn.send { color: var(--accent); }
.icon-btn.send:hover { background: var(--accent-soft); }

/* ---------------------------------------------------------------- people */

.people-list { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 2px; }

.person {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.person:hover { background: var(--bg-elevated); }
.person .avatar { width: 32px; height: 32px; font-size: 13px; }
.person-info { flex: 1; min-width: 0; }
.person-name {
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.person-sub { font-size: 11.5px; color: var(--text-faint); }
.person-icons { display: flex; align-items: center; gap: 4px; color: var(--text-faint); }
.person-icons .icon { width: 15px; height: 15px; }
.person-icons .icon.muted-icon { color: var(--bad); }
.person-icons .hand-icon { color: var(--warn); }
.tag {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--line);
  font-size: 10.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.people-actions { padding: 10px; border-top: 1px solid var(--line-soft); display: flex; gap: 8px; }

/* ----------------------------------------------------------------- stats */

.stats-body { overflow-y: auto; padding: 14px; font-size: 13px; }
.stat-group { margin-bottom: 18px; }
.stat-group h4 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 650;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line-soft);
}
.stat-row:last-child { border-bottom: 0; }
.stat-row span:first-child { color: var(--text-dim); }
.stat-row span:last-child { font-family: ui-monospace, monospace; }
.stat-good { color: var(--good); }
.stat-warn { color: var(--warn); }
.stat-bad { color: var(--bad); }

/* ==========================================================================
   Controls
   ========================================================================== */

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: var(--bg);
}
.controls-group { display: flex; align-items: center; gap: 8px; }

.ctl {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 62px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s var(--ease);
}
.ctl:hover { background: var(--bg-elevated); border-color: #2c3444; }
.ctl:active { transform: translateY(1px); }
.ctl-label { font-size: 10.5px; color: var(--text-dim); letter-spacing: 0.01em; }

.ctl[data-on='false'] {
  background: rgba(255, 95, 109, 0.14);
  border-color: rgba(255, 95, 109, 0.35);
  color: var(--bad);
}
.ctl[data-on='false'] .ctl-label { color: var(--bad); }

.ctl.is-active {
  background: var(--accent-soft);
  border-color: rgba(91, 140, 255, 0.45);
  color: var(--accent-hot);
}
.ctl.is-active .ctl-label { color: var(--accent-hot); }

.ctl.is-recording {
  background: rgba(255, 95, 109, 0.16);
  border-color: rgba(255, 95, 109, 0.4);
  color: var(--bad);
  animation: rec 1.8s ease-in-out infinite;
}
@keyframes rec { 50% { opacity: 0.68; } }

.ctl.danger {
  background: var(--bad);
  border-color: transparent;
  color: #240309;
}
.ctl.danger .ctl-label { color: rgba(36, 3, 9, 0.75); }
.ctl.danger:hover { background: #ff7079; }

.ctl-level {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 3px;
  height: 2px;
  border-radius: 99px;
  background: var(--good);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.08s linear;
}
.ctl-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.reaction-wrap { position: relative; }
.reaction-tray {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  z-index: 20;
}
.reaction-tray button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 21px;
  cursor: pointer;
  transition: background 0.12s, transform 0.12s var(--ease);
}
.reaction-tray button:hover { background: var(--bg-input); transform: scale(1.14); }

/* ==========================================================================
   Overlays
   ========================================================================== */

.reactions-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.floating-reaction {
  position: absolute;
  bottom: 90px;
  font-size: 34px;
  animation: float-up 3.2s ease-out forwards;
  will-change: transform, opacity;
}
.floating-reaction small {
  display: block;
  font-size: 11px;
  text-align: center;
  color: var(--text-dim);
  margin-top: 2px;
}
@keyframes float-up {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  12% { transform: translateY(-20px) scale(1.1); opacity: 1; }
  100% { transform: translateY(-58vh) scale(0.9); opacity: 0; }
}

.toasts {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 70;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in 0.28s var(--ease);
}
.toast.is-out { animation: toast-out 0.24s var(--ease) forwards; }
.toast .icon { width: 16px; height: 16px; }
.toast.good .icon { color: var(--good); }
.toast.warn .icon { color: var(--warn); }
.toast.bad .icon { color: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(0.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(0.97); } }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 7, 10, 0.72);
  backdrop-filter: blur(6px);
  z-index: 80;
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(480px, 100%);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  box-shadow: var(--shadow);
  animation: modal-in 0.24s var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}
.toggle-row strong { font-size: 14px; font-weight: 600; display: block; }
.toggle-row p { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

.switch { position: relative; flex: none; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s;
}
.switch span::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s var(--ease), background 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

.shortcut-list { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.shortcut-list h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: 10px; }
.shortcut-list ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.shortcut-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.shortcut-list li span { border-bottom: 1px dashed var(--line-soft); }

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .prejoin-card { grid-template-columns: 1fr; gap: 20px; }
  .prejoin-preview { aspect-ratio: 16 / 11; }
}

@media (max-width: 760px) {
  :root { --sidebar-w: 100%; }

  .layout { grid-template-columns: 1fr; position: relative; }
  .layout.sidebar-open { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 30;
    border-left: 0;
  }
  .layout.sidebar-open .stage { visibility: hidden; }

  .ctl { min-width: 0; padding: 9px 11px; }
  .ctl-label { display: none; }
  .ctl.overflow { display: none; }
  .controls { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); gap: 6px; }
  .controls-group { gap: 6px; }

  .topbar { padding: 8px 10px; }
  .chip { font-size: 12px; padding: 5px 9px; max-width: 150px; }

  .tiles.speaker-view .filmstrip .tile { width: 116px; }
  .toasts { top: 54px; }
}

@media (max-width: 420px) {
  #clock { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
