/* ============================================================
   Tailcat Chat — visual shell
   Light + dark, single stylesheet, no external assets.
   ============================================================ */

:root {
  color-scheme: light dark;

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;

  --bg: #f5f0e7;
  --bg-deep: #eee6d9;
  --surface: #fffdf8;
  --surface-2: #faf5ec;
  --surface-3: #f1e9dc;
  --ink: #241f1a;
  --ink-soft: #494138;
  --muted: #63594e;
  --faint: #74685c;
  --line: #e1d6c6;
  --line-strong: #a08b76;

  --accent: #a94a22;
  --accent-hover: #8f3c18;
  --accent-ink: #fff8f1;
  --accent-soft: #f6e2d5;
  --accent-line: #e0b69e;

  --sage: #3f6752;
  --sage-soft: #e4eee6;
  --sage-line: #c4d9ca;

  --amber: #925b0d;
  --amber-soft: #f7ead4;
  --amber-line: #ead3a8;

  --danger: #9e382c;
  --danger-soft: #f8e4e0;
  --danger-line: #ebc4bd;

  --focus: #2c6b5e;

  --grid-line: rgba(66, 50, 34, 0.045);
  --glow-1: rgba(200, 122, 73, 0.17);
  --glow-2: rgba(86, 128, 102, 0.13);

  --shadow-1: 0 1px 2px rgba(45, 34, 22, 0.05), 0 10px 28px -16px rgba(45, 34, 22, 0.18);
  --shadow-2: 0 2px 4px rgba(45, 34, 22, 0.06), 0 30px 70px -28px rgba(45, 34, 22, 0.3);

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
  --r-xl: 28px;
  --ease: cubic-bezier(0.22, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --bg-deep: #0f0d0b;
    --surface: #1c1815;
    --surface-2: #221d19;
    --surface-3: #2a241f;
    --ink: #f2ebe2;
    --ink-soft: #d5cabd;
    --muted: #a79a8c;
    --faint: #96897d;
    --line: #332b24;
    --line-strong: #7f6d5b;

    --accent: #e18a5d;
    --accent-hover: #eea077;
    --accent-ink: #25140c;
    --accent-soft: #3a2419;
    --accent-line: #5b3624;

    --sage: #97c6a8;
    --sage-soft: #1e2f25;
    --sage-line: #34503d;

    --amber: #e0ae69;
    --amber-soft: #332818;
    --amber-line: #4e3c22;

    --danger: #f09286;
    --danger-soft: #3a211d;
    --danger-line: #5b322b;

    --focus: #8ad2c1;

    --grid-line: rgba(255, 244, 228, 0.035);
    --glow-1: rgba(201, 113, 65, 0.13);
    --glow-2: rgba(83, 132, 104, 0.1);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.24), 0 12px 30px -18px rgba(0, 0, 0, 0.7);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.28), 0 34px 80px -30px rgba(0, 0, 0, 0.8);
  }
}

/* ---------- reset ---------- */

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

html {
  min-height: 100%;
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

svg {
  display: block;
}

img,
svg {
  max-width: 100%;
}

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

.hidden {
  display: none !important;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 200;
  padding: 0.7rem 1rem;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 0.18s var(--ease);
}

.skip-link:focus {
  transform: none;
}

:where(a, button, input, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- shared bits ---------- */

.mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--ink), color-mix(in srgb, var(--ink) 82%, var(--accent)));
  color: var(--bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 6px 16px -10px rgba(0, 0, 0, 0.55);
}

.mark svg {
  width: 26px;
  height: 26px;
}

.mark-lg {
  width: 58px;
  height: 58px;
  border-radius: 18px;
}

.mark-lg svg {
  width: 37px;
  height: 37px;
}

.eyebrow,
.kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 650;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 0.95rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.16s var(--ease), color 0.16s var(--ease), border-color 0.16s var(--ease);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

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

.btn-soft {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-soft);
}

.btn-soft:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.btn-quiet {
  border-color: transparent;
  color: var(--muted);
  padding: 0 0.7rem;
}

.btn-quiet:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}

.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.icon-btn svg {
  width: 19px;
  height: 19px;
}

.hint {
  margin: 0.55rem 0 0;
  color: var(--faint);
  font-size: 0.71rem;
  line-height: 1.5;
}

/* ============================================================
   Join screen
   ============================================================ */

.join-screen {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: clamp(1.5rem, 5vw, 4rem) clamp(1rem, 5vw, 4rem) clamp(1.5rem, 4vw, 3rem);
  overflow: hidden;
  background:
    radial-gradient(1100px 720px at 82% -12%, var(--glow-1), transparent 62%),
    radial-gradient(880px 620px at -12% 112%, var(--glow-2), transparent 62%),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
}

.join-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.7;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 52px 52px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 46%, #000 10%, transparent 76%);
  mask-image: radial-gradient(ellipse at 50% 46%, #000 10%, transparent 76%);
}

.join-art {
  position: absolute;
  top: 50%;
  right: -16vw;
  z-index: 0;
  width: min(82vw, 980px);
  height: auto;
  color: var(--accent);
  opacity: 0.24;
  transform: translateY(-50%);
  pointer-events: none;
}

.join-inner {
  position: relative;
  z-index: 1;
  width: min(100%, 470px);
  padding: clamp(1.6rem, 4.6vw, 2.6rem);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-2);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.join-inner::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: linear-gradient(90deg, transparent 6%, var(--accent-line), transparent 94%);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.join-inner h1 {
  margin: 1.35rem 0 0.7rem;
  font-family: var(--font-display);
  font-size: clamp(2.65rem, 8vw, 3.65rem);
  font-weight: 600;
  line-height: 0.96;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

.join-inner h1 em {
  color: var(--accent);
  font-weight: 500;
}

.join-lede {
  max-width: 38ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.65;
  text-wrap: pretty;
}

.join-form {
  margin-top: 1.8rem;
}

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 650;
}

.input-shell {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.9rem;
  width: 18px;
  height: 18px;
  color: var(--faint);
  pointer-events: none;
}

#username-input {
  width: 100%;
  min-height: 52px;
  padding: 0 0.95rem 0 2.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 0.95rem;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease), background 0.16s var(--ease);
}

#username-input::placeholder {
  color: var(--faint);
}

#username-input:hover {
  border-color: var(--faint);
}

#username-input:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.field-hint {
  margin: 0.45rem 0 0;
  color: var(--faint);
  font-size: 0.72rem;
  line-height: 1.5;
}

.join-btn {
  width: 100%;
  min-height: 52px;
  margin-top: 1.1rem;
  padding: 0 1rem 0 1.25rem;
  justify-content: space-between;
  border-radius: var(--r-md);
  font-size: 0.92rem;
}

.btn-icon {
  width: 19px;
  height: 19px;
  transition: transform 0.2s var(--ease);
}

.join-btn:hover .btn-icon {
  transform: translateX(3px);
}

.join-note {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 1.4rem 0 0;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.6;
}

.join-note svg {
  flex: none;
  width: 15px;
  height: 15px;
  margin-top: 0.16rem;
  color: var(--sage);
}

.join-foot {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 0.6rem;
  margin-top: 1.35rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

.foot-dot {
  color: var(--faint);
}

/* ============================================================
   Chat shell + header
   ============================================================ */

.chat-shell {
  display: flex;
  flex-direction: column;
  height: 100svh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.app-header {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 1rem clamp(1rem, 3vw, 2rem);
  padding: 0.7rem clamp(1rem, 3vw, 1.75rem);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0.04rem;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.13rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.brand-sub {
  color: var(--faint);
  font-size: 0.56rem;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}

.room-address {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-self: center;
  min-width: 0;
  max-width: 100%;
  padding: 0.24rem 0.28rem 0.24rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.addr-label {
  flex: none;
  color: var(--faint);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

#room-address {
  min-width: 0;
  max-width: min(34ch, 30vw);
  overflow: hidden;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-variant-ligatures: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.32rem;
  flex: none;
  min-width: 40px;
  min-height: 40px;
  padding: 0 0.55rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}

.copy-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.copy-btn svg {
  width: 15px;
  height: 15px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0 0.8rem;
  border: 1px solid var(--sage-line);
  border-radius: 999px;
  background: var(--sage-soft);
  color: var(--sage);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.role-badge::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent);
}

.role-badge[data-role="client"] {
  border-color: var(--amber-line);
  background: var(--amber-soft);
  color: var(--amber);
}

.role-badge[data-role="offline"] {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

/* The checkbox powers the mobile drawer without JavaScript. */
.sidebar-toggle {
  display: none;
}

.drawer-btn {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.16s var(--ease), color 0.16s var(--ease);
}

.drawer-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.drawer-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------- network shortcut ---------- */

.network-shortcut {
  min-height: 40px;
  border-radius: 999px;
}

.network-shortcut svg {
  width: 17px;
  height: 17px;
}

.network-shortcut-text {
  font-size: 0.75rem;
  font-weight: 650;
}

/* ---------- status + engine error ---------- */

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: none;
  padding: 0.52rem clamp(1rem, 3vw, 1.75rem);
  border-bottom: 1px solid var(--sage-line);
  background: var(--sage-soft);
  color: var(--sage);
  font-size: 0.77rem;
  line-height: 1.4;
}

.connection-status p {
  margin: 0;
  min-width: 0;
}

.connection-status strong {
  font-weight: 700;
}

.connection-status[data-state="connecting"] {
  border-color: var(--amber-line);
  background: var(--amber-soft);
  color: var(--amber);
}

.connection-status[data-state="offline"] {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.engine-error {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex: none;
  padding: 0.8rem clamp(1rem, 3vw, 1.75rem);
  border-bottom: 1px solid var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.engine-error-icon {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 0.1rem;
}

.engine-error h2 {
  margin: 0 0 0.2rem;
  font-size: 0.86rem;
  font-weight: 700;
}

.engine-error p {
  max-width: 90ch;
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.76rem;
  line-height: 1.55;
}

.engine-error code {
  padding: 0.08rem 0.28rem;
  border: 1px solid var(--danger-line);
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ---------- view tabs ---------- */

.view-tabs {
  display: inline-flex;
  align-self: flex-start;
  flex: none;
  gap: 2px;
  max-width: calc(100% - 2rem);
  margin: 0.65rem clamp(1rem, 3vw, 1.75rem) 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 1px 2px rgba(45, 34, 22, 0.045);
}

.view-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 1.15rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.16s var(--ease), border-color 0.16s var(--ease),
    color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.view-tab:hover {
  background: color-mix(in srgb, var(--surface) 65%, transparent);
  color: var(--ink);
}

.view-tab.is-active {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.view-tab.is-active:hover {
  background: var(--surface);
}

.view-tab:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- chat body ---------- */

.chat-body {
  position: relative;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.drawer-scrim {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface-2);
}

.sidebar-mobile-head {
  display: none;
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  padding: 1.05rem 0.95rem 1.5rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.side-section + .side-section {
  margin-top: 1.35rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.section-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.section-meta {
  color: var(--faint);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.room-list,
.user-list,
.sub-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.room-list {
  display: grid;
  gap: 0.12rem;
  margin-bottom: 0.6rem;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 41px;
  padding: 0.28rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.86rem;
  text-align: left;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.room-item:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.room-item.is-active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.hash {
  flex: none;
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.room-item.is-active .hash {
  color: inherit;
  opacity: 0.75;
}

.room-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-count {
  flex: none;
  min-width: 23px;
  padding: 0.05rem 0.38rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--faint);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.room-item.is-active .room-count {
  border-color: var(--accent-line);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent);
}

.new-room {
  display: flex;
  gap: 0.35rem;
}

#new-room-input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8rem;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

#new-room-input::placeholder {
  color: var(--faint);
}

#new-room-input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.new-room .btn {
  flex: none;
  min-height: 40px;
  padding: 0 0.65rem;
  font-size: 0.75rem;
}

.user-list {
  display: grid;
  gap: 0.05rem;
}

.user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.15rem 0.25rem;
  border-radius: var(--r-sm);
}

.user:hover {
  background: var(--surface-3);
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 29px;
  height: 29px;
  border: 1px solid var(--accent-line);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
}

.avatar[data-tone="b"] {
  border-color: var(--sage-line);
  background: var(--sage-soft);
  color: var(--sage);
}

.avatar[data-tone="c"] {
  border-color: var(--amber-line);
  background: var(--amber-soft);
  color: var(--amber);
}

.user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.you-tag {
  display: inline-block;
  margin-left: 0.28rem;
  padding: 0.03rem 0.28rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--faint);
  font-size: 0.52rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.role-mini {
  flex: none;
  color: var(--faint);
  font-size: 0.54rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.role-mini.host {
  color: var(--sage);
}

.side-copy {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.5;
}

.sub-list {
  display: grid;
  gap: 0.05rem;
  margin-bottom: 0.65rem;
}

.check-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 40px;
  padding: 0.1rem 0.3rem;
  border-radius: var(--r-sm);
  color: var(--ink-soft);
  font-size: 0.82rem;
  cursor: pointer;
}

.check-row:hover {
  background: var(--surface-3);
}

.check-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-box {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}

.check-box::after {
  content: "";
  width: 9px;
  height: 5px;
  border-bottom: 1.8px solid var(--accent-ink);
  border-left: 1.8px solid var(--accent-ink);
  opacity: 0;
  transform: rotate(-45deg) translate(0.5px, -1px);
}

.check-row input:checked + .check-box {
  border-color: var(--accent);
  background: var(--accent);
}

.check-row input:checked + .check-box::after {
  opacity: 1;
}

.check-row input:focus-visible + .check-box {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.5rem 0.3rem;
  border-radius: var(--r-sm);
  cursor: pointer;
}

.switch-row:hover {
  background: var(--surface-3);
}

.switch {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  margin-top: 0.05rem;
}

.switch input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  display: block;
  width: 40px;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-3);
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(30, 22, 15, 0.16);
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
}

.switch input:checked + .switch-track {
  border-color: var(--accent);
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  border-color: transparent;
  background: var(--accent-ink);
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.switch-copy {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  min-width: 0;
}

.switch-copy strong {
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 650;
}

.switch-copy small {
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.4;
}

/* ---------- main column ---------- */

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, color-mix(in srgb, var(--surface) 60%, transparent), transparent 72%),
    var(--bg);
}

.room-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex: none;
  padding: 1rem clamp(1rem, 3vw, 2rem) 0.85rem;
  border-bottom: 1px solid var(--line);
}

.room-title {
  min-width: 0;
}

#current-room {
  margin: 0.18rem 0 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 2.6vw, 2.05rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.025em;
}

#current-room::before {
  content: "#";
  margin-right: 0.08em;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.62em;
  font-weight: 500;
  vertical-align: 0.12em;
}

.room-head-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 28px;
  padding: 0.12rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.68rem;
  white-space: nowrap;
}

.pill svg {
  width: 13px;
  height: 13px;
  color: var(--muted);
}

.pill-quiet {
  background: transparent;
  color: var(--muted);
}

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

.messages {
  flex: 1;
  min-height: 0;
  padding: 1.4rem clamp(1rem, 3vw, 2rem) 1.2rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 2rem 1rem;
  text-align: center;
}

.empty-art {
  width: 156px;
  height: 94px;
  margin-bottom: 0.7rem;
  color: var(--accent);
  opacity: 0.55;
}

.empty-state h2 {
  margin: 0.15rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.empty-state p {
  max-width: 36ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
  text-wrap: pretty;
}

.empty-state .empty-note {
  margin-top: 0.85rem;
  color: var(--faint);
  font-size: 0.69rem;
}

/* Example message styling for app.js to reuse. */
.message {
  display: flex;
  gap: 0.65rem;
  max-width: 780px;
  margin: 0 auto 0.9rem;
}

.message-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.message-body {
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  row-gap: 0.1rem;
  margin-bottom: 0.1rem;
}

.message-author {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
}

.message-time {
  color: var(--faint);
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.message.is-system {
  justify-content: center;
  color: var(--faint);
  font-size: 0.7rem;
}

.message.is-system .message-text {
  color: var(--faint);
  font-size: 0.7rem;
  text-align: center;
}

/* ---------- composer ---------- */

.composer {
  flex: none;
  padding: 0.7rem clamp(1rem, 3vw, 2rem) max(0.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 55%, var(--bg));
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  max-width: 860px;
  margin: 0 auto;
  padding: 0.35rem 0.35rem 0.35rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

#message-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 132px;
  padding: 0.62rem 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.45;
  resize: none;
  field-sizing: content;
}

#message-input::placeholder {
  color: var(--faint);
}

.send-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  transition: background 0.16s var(--ease), transform 0.16s var(--ease);
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.96);
}

.send-btn svg {
  width: 20px;
  height: 20px;
}

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 0.15rem;
}

.composer-foot .hint {
  margin: 0;
}

.hint-peers {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  white-space: nowrap;
}

.hint-peers svg {
  width: 13px;
  height: 13px;
  opacity: 0.8;
}

/* ============================================================
   Network view
   ============================================================ */

.network-view {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.75rem;
  min-height: 0;
  padding: 0.9rem clamp(1rem, 3vw, 1.75rem) max(0.8rem, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background:
    radial-gradient(ellipse 70% 42% at 88% -4%, var(--glow-2), transparent 68%),
    var(--bg);
}

.network-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex: none;
}

.network-head h2 {
  margin: 0.18rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 3vw, 2.1rem);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
}

.network-sub {
  max-width: 46ch;
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
  text-wrap: pretty;
}

.network-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.network-controls .btn {
  min-height: 38px;
  padding: 0 0.8rem;
  font-size: 0.76rem;
}

#network-zoom-out,
#network-zoom-in {
  width: 40px;
  padding: 0;
  font-size: 1.05rem;
  line-height: 1;
}

.network-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  flex: none;
  margin: 0;
}

.network-summary > div {
  min-width: 0;
  padding: 0.52rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.network-summary dt {
  color: var(--faint);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.network-summary dd {
  margin: 0.16rem 0 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.4;
}

#network-node-count,
#network-your-tier {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.1;
}

/* Graph viewport. JS sizes #network-stage and the SVG as peers join. */
.network-graph {
  position: relative;
  flex: 1 1 0;
  min-height: clamp(260px, 44vh, 560px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background-color: var(--surface-2);
  background-image: radial-gradient(circle at 1px 1px, var(--grid-line) 1px, transparent 0);
  background-size: 22px 22px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.network-stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  transform-origin: 0 0;
}

.network-edges {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  color: var(--line-strong);
  pointer-events: none;
}

.network-edges line,
.network-edges path,
.network-edges polyline {
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.network-edges .is-active,
.network-edges .network-edge.is-active {
  stroke: var(--accent);
  stroke-width: 1.8;
}

.network-nodes {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* JS places nodes by their centre using left/top. */
.network-node {
  position: absolute;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 118px;
  max-width: 190px;
  padding: 0.55rem 0.68rem 0.6rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  text-decoration: none;
  box-shadow: var(--shadow-1);
  cursor: pointer;
  pointer-events: auto;
  transform: translate(-50%, -50%);
  transition: transform 0.16s var(--ease), border-color 0.16s var(--ease),
    box-shadow 0.16s var(--ease), background 0.16s var(--ease);
}

.network-node:hover {
  z-index: 2;
  border-color: var(--accent-line);
  transform: translate(-50%, -50%) scale(1.035);
}

.network-node.is-you {
  border-color: var(--accent-line);
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface));
}

.network-node.is-root:not(.is-you) {
  border-color: var(--sage-line);
  background: color-mix(in srgb, var(--sage-soft) 45%, var(--surface));
}

.network-node[aria-selected="true"],
.network-node.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent), var(--shadow-1);
}

.network-node:focus-visible {
  z-index: 3;
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.network-node .node-tier {
  align-self: flex-start;
  padding: 0.05rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--faint);
  font-size: 0.53rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  line-height: 1.4;
  text-transform: uppercase;
}

.network-node.is-you .node-tier {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.network-node.is-root:not(.is-you) .node-tier {
  border-color: var(--sage-line);
  background: var(--sage-soft);
  color: var(--sage);
}

.network-node .node-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.83rem;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-node .node-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.22rem;
}

.network-node .node-tag {
  padding: 0.02rem 0.32rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--faint);
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.5;
  text-transform: uppercase;
}

.network-node .node-tag.you {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.network-node .node-tag.root {
  border-color: var(--sage-line);
  background: var(--sage-soft);
  color: var(--sage);
}

.network-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--surface) 70%, transparent), transparent 72%);
  text-align: center;
  pointer-events: none;
}

.network-empty svg {
  width: 42px;
  height: 42px;
  margin-bottom: 0.45rem;
  color: var(--accent);
  opacity: 0.6;
}

.network-empty h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.network-empty p {
  max-width: 40ch;
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
  text-wrap: pretty;
}

.network-detail {
  position: absolute;
  right: clamp(1rem, 3vw, 1.75rem);
  bottom: calc(max(0.85rem, env(safe-area-inset-bottom)) + 2.3rem);
  z-index: 8;
  width: min(300px, calc(100% - 2rem));
  max-height: min(360px, calc(100% - 12rem));
  padding: 0.95rem 1rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.network-detail .kicker {
  padding-right: 2.2rem;
}

.network-detail h3 {
  margin: 0.2rem 0 0;
  padding-right: 2rem;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

#node-detail-close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 34px;
  height: 34px;
}

#node-detail-close svg {
  width: 17px;
  height: 17px;
}

.network-detail dl {
  display: grid;
  gap: 0.4rem;
  margin: 0.8rem 0 0;
}

.network-detail dl > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.38rem;
  border-bottom: 1px solid var(--line);
}

.network-detail dl > div:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.network-detail dt {
  flex: none;
  color: var(--faint);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.network-detail dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink-soft);
  font-size: 0.76rem;
  line-height: 1.4;
  text-align: right;
}

.network-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
  flex: none;
  padding: 0 0.15rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.network-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line-strong);
}

.legend-dot.you {
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.legend-dot.root {
  background: var(--sage);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sage) 14%, transparent);
}

.legend-line {
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--line-strong), var(--accent-line));
}

@media (min-width: 560px) and (max-width: 719px) {
  .network-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 720px) {
  .network-summary {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

/* ============================================================
   Motion
   ============================================================ */

@media (prefers-reduced-motion: no-preference) {
  .join-inner {
    animation: card-in 0.72s var(--ease) both;
  }

  .join-foot {
    animation: soft-in 0.7s 0.18s var(--ease) both;
  }

  .connection-status[data-state="connected"] .status-dot {
    animation: breathe 3.4s ease-in-out infinite;
  }

  .network-detail:not(.hidden) {
    animation: pop-in 0.18s var(--ease) both;
    transform-origin: bottom right;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.993);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes soft-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes breathe {
  0%,
  100% {
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 16%, transparent);
  }
  50% {
    box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 7%, transparent);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ============================================================
   Responsive: drawer below 860px
   ============================================================ */

@media (max-width: 860px) {
  .sidebar-toggle {
    position: fixed;
    top: 0;
    left: 0;
    display: block;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
  }

  .drawer-btn {
    display: grid;
  }

  .app-header {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand actions"
      "address address";
    gap: 0.55rem 0.7rem;
    padding: 0.62rem 1rem 0.7rem;
  }

  .brand {
    grid-area: brand;
  }

  .brand-sub {
    display: none;
  }

  .room-address {
    grid-area: address;
    justify-self: stretch;
    width: 100%;
    max-width: none;
    padding-left: 0.8rem;
  }

  #room-address {
    flex: 1;
    max-width: none;
  }

  .header-actions {
    grid-area: actions;
  }

  .network-shortcut-text {
    display: none;
  }

  .network-shortcut {
    width: 40px;
    padding: 0;
    justify-content: center;
  }

  .view-tabs {
    align-self: stretch;
    width: auto;
    max-width: none;
    margin: 0.55rem 1rem 0;
  }

  .view-tab {
    flex: 1;
    padding: 0 0.8rem;
  }

  .connection-status,
  .engine-error {
    padding-inline: 1rem;
  }

  .network-view {
    gap: 0.65rem;
    padding: 0.8rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  }

  .network-head {
    align-items: flex-start;
  }

  .network-controls {
    width: 100%;
  }

  .network-graph {
    min-height: clamp(240px, 42vh, 460px);
  }

  .chat-body {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 55;
    width: min(88vw, 340px);
    border-right: 1px solid var(--line-strong);
    box-shadow: 24px 0 60px -30px rgba(0, 0, 0, 0.45);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform 0.28s var(--ease), visibility 0.28s;
  }

  .sidebar-mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: none;
    padding: max(0.55rem, env(safe-area-inset-top)) 0.85rem 0.55rem 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink-soft);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .sidebar-toggle:checked ~ .chat-body .sidebar {
    transform: none;
    visibility: visible;
  }

  .drawer-scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: block;
    background: rgba(24, 18, 12, 0.4);
    opacity: 0;
    visibility: hidden;
    cursor: pointer;
    transition: opacity 0.28s var(--ease), visibility 0.28s;
  }

  .sidebar-toggle:checked ~ .chat-body .drawer-scrim {
    opacity: 1;
    visibility: visible;
  }

  .sidebar-toggle:focus-visible ~ .app-header .drawer-btn {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
  }

  .chat-main {
    height: 100%;
  }

  .room-head {
    padding: 0.9rem 1rem 0.75rem;
  }

  #current-room {
    font-size: 1.5rem;
  }

  .messages {
    padding: 1.1rem 1rem 1rem;
  }

  .empty-state {
    padding: 1.5rem 0.5rem;
  }

  .composer {
    padding: 0.6rem 0.85rem max(0.7rem, env(safe-area-inset-bottom));
  }

  .hint-peers {
    display: none;
  }
}

@media (max-width: 600px) {
  .network-detail {
    position: fixed;
    top: auto;
    right: 0.6rem;
    bottom: max(0.6rem, env(safe-area-inset-bottom));
    left: 0.6rem;
    width: auto;
    max-height: min(58dvh, 340px);
  }
}

@media (max-width: 430px) {
  .join-inner {
    padding: 1.5rem;
  }

  .brand-lockup {
    gap: 0.75rem;
  }

  .mark-lg {
    width: 52px;
    height: 52px;
    border-radius: 16px;
  }

  .mark-lg svg {
    width: 33px;
    height: 33px;
  }

  .eyebrow {
    font-size: 0.6rem;
    letter-spacing: 0.13em;
  }

  .eyebrow-extra {
    display: none;
  }

  .app-header {
    padding-inline: 0.8rem;
  }

  .brand {
    gap: 0.55rem;
  }

  .brand .mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .brand .mark svg {
    width: 23px;
    height: 23px;
  }

  .brand-name {
    font-size: 1rem;
  }

  .header-actions {
    gap: 0.2rem;
  }

  .role-badge {
    gap: 0.35rem;
    min-height: 38px;
    padding: 0 0.52rem;
    font-size: 0.66rem;
  }

  .drawer-btn {
    width: 40px;
    height: 40px;
  }

  .view-tabs {
    margin-inline: 0.8rem;
  }

  .view-tab {
    min-height: 40px;
    font-size: 0.78rem;
  }

  .network-view {
    padding-inline: 0.8rem;
  }

  .network-head h2 {
    font-size: 1.55rem;
  }

  .network-controls .btn {
    min-height: 36px;
    padding: 0 0.62rem;
    font-size: 0.72rem;
  }

  #network-zoom-out,
  #network-zoom-in {
    flex: 0 0 36px;
    width: 36px;
  }

  .network-summary {
    gap: 0.35rem;
  }

  .network-summary > div {
    padding: 0.45rem 0.55rem;
  }

  .network-summary dt {
    font-size: 0.52rem;
    letter-spacing: 0.1em;
  }

  .network-summary dd {
    font-size: 0.72rem;
  }

  #network-node-count,
  #network-your-tier {
    font-size: 1.15rem;
  }

  .network-graph {
    min-height: 240px;
    border-radius: var(--r-md);
  }

  .network-empty {
    padding: 1rem;
  }

  .network-empty h3 {
    font-size: 1.1rem;
  }

  .network-empty p {
    font-size: 0.74rem;
  }

  .network-legend {
    gap: 0.3rem 0.7rem;
    font-size: 0.62rem;
  }

  .copy-btn {
    min-height: 40px;
    padding: 0 0.35rem;
  }

  .copy-text {
    display: none;
  }

  #room-address {
    font-size: 0.67rem;
  }

  .room-head-meta .pill-quiet {
    display: none;
  }

  .empty-art {
    width: 132px;
  }
}

@media (max-width: 360px) {
  .brand-name {
    font-size: 0.92rem;
  }

  .brand {
    gap: 0.45rem;
  }

  .app-header {
    padding-inline: 0.7rem;
  }
}

/* ============================================================
   App.js controls and states
   ============================================================ */

.field-hint.is-error {
  color: var(--danger);
  font-weight: 600;
}

.btn:disabled,
.join-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.copy-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.composer.is-disabled {
  opacity: 0.72;
}

.copy-btn.is-copied {
  color: var(--sage);
}

.copy-btn.is-copy-failed {
  color: var(--danger);
}

.connection-status[data-state="error"] {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
}

.engine-error .engine-error-detail {
  margin-top: 0.4rem;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

.inline-error {
  margin: 0.45rem 0 0;
  color: var(--danger);
  font-size: 0.7rem;
  line-height: 1.5;
}

.check-row > span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.check-row:has(input:disabled) {
  opacity: 0.55;
  cursor: default;
}

.check-row:has(input:disabled):hover {
  background: transparent;
}

.user-name.name-button {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: underline dotted var(--line-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}

.user-name.name-button:hover {
  color: var(--ink);
  text-decoration-style: solid;
}

.name-editor-wrap {
  margin-top: 0.45rem;
}

.name-editor {
  gap: 0.3rem;
}

.name-editor input {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.name-editor input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.name-editor .btn {
  flex: none;
  min-height: 40px;
  padding: 0 0.5rem;
  font-size: 0.7rem;
}

.follow-btn {
  position: relative;
  margin-left: 0.12rem;
  padding: 0.06rem 0.38rem;
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--faint);
  font-size: 0.57rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease);
}

.follow-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.follow-btn:hover {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--ink);
}

.follow-btn[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ============================================================
   Reduced motion
   ============================================================ */

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