/* ── Showcase — Gleam Real-Time Demo ──────────────────────────────────── */

:root {
  --bg: oklch(17% 0.022 276);
  --surface: oklch(22% 0.024 276);
  --surface-alt: oklch(27% 0.028 276);
  --surface-soft: oklch(19.5% 0.024 276);
  --border: oklch(34% 0.035 276);
  --border-strong: oklch(44% 0.04 276);
  --text: oklch(94% 0.018 285);
  --text-muted: oklch(76% 0.035 280);
  --accent: oklch(82% 0.105 310);
  --accent-strong: oklch(91% 0.07 310);
  --accent-dim: oklch(82% 0.105 310 / 14%);
  --on-accent: oklch(16% 0.025 276);
  --success: oklch(82% 0.09 165);
  --success-dim: oklch(82% 0.09 165 / 13%);
  --warning: oklch(84% 0.115 85);
  --warning-dim: oklch(84% 0.115 85 / 12%);
  --danger: oklch(78% 0.11 25);
  --danger-dim: oklch(78% 0.11 25 / 13%);
  --info: oklch(78% 0.1 245);
  --info-dim: oklch(78% 0.1 245 / 12%);
  --control-hover: oklch(30% 0.03 276);
  --placeholder: oklch(81% 0.025 280);
  --chat-bg: oklch(19.5% 0.024 276);
  --radius: 10px;
  --accent-hover: var(--accent-strong);
  --ok: var(--success);
  --warn: var(--warning);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --z-content: 10;
  --z-cursors: 20;
  --z-sticky: 30;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Visually hidden, but available to screen readers and form association. */
.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;
}

/* Keyboard focus ring — visible for keyboard users, quiet for mouse users. */
:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
summary {
  font: inherit;
}

button,
summary {
  cursor: pointer;
}

/* ── Landing Page ────────────────────────────────────────────────────── */

body.landing {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(2rem, 6vh, 5rem) 1rem;
}

.landing-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  width: 100%;
}

.landing-card {
  width: min(100%, 32rem);
  padding: clamp(1.5rem, 5vw, 3rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  text-align: center;
}

.landing-card h1 {
  margin-bottom: var(--space-2);
  font-size: 2rem;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.subtitle {
  max-width: 34rem;
  margin: 0 auto var(--space-5);
  color: var(--text);
  text-wrap: pretty;
}

/* ── Library Showcase (landing) ──────────────────────────────────────── */

.lib-showcase {
  width: 100%;
  max-width: 560px;
}

.lib-showcase-title {
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 0.35rem;
}

.lib-showcase-lead {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  max-width: 46ch;
  margin: 0 auto 1.75rem;
}

/* Feature-first showcase: the behavior leads, the library is a quiet tag. */
.feature-list { list-style: none; }

.feature-item {
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
}

.feature-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.feature-headline {
  font-weight: 600;
  color: var(--text);
}

.feature-lib {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
  text-decoration: none;
}
a.feature-lib:hover { background: var(--accent-hover); color: var(--on-accent); }

.feature-desc {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.foundation-note {
  margin-top: 1.25rem;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: center;
}

.foundation-link { color: var(--text-muted); text-decoration: underline; }
.foundation-link:hover { color: var(--accent); }

/* Stacked secondary auth controls own their spacing via gap, not per-button
   margins, so the disclosure body spaces evenly however many providers exist. */
.auth-section,
.indieauth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  text-align: left;
}

/* Secondary sign-in methods, collapsed so guest entry owns the first screen. */
.more-auth {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
}

.more-auth-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: color 0.15s ease-out;
}
.more-auth-summary:hover { color: var(--text); }
.more-auth-summary::-webkit-details-marker { display: none; }
.more-auth-summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease-out;
}
.more-auth[open] > .more-auth-summary::before { transform: rotate(90deg); }

.more-auth-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.85rem;
}

.indieauth-hint {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-muted);
  margin-top: -0.4rem;
}

.badge,
.status-chip,
.count-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.status-connected,
.status-active {
  border-color: oklch(82% 0.09 165 / 38%);
  background: var(--success-dim);
  color: var(--success);
}

.status-connecting,
.status-idle {
  border-color: oklch(84% 0.115 85 / 34%);
  background: var(--warning-dim);
  color: var(--warning);
}

.status-error,
.status-closed {
  border-color: oklch(78% 0.11 25 / 42%);
  background: var(--danger-dim);
  color: var(--danger);
}

.auth-section { margin-bottom: var(--space-4); }

.btn,
#chat-form button,
#reconnect-button,
.btn-secondary,
.cursor-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.65rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 650;
  text-decoration: none;
  transition: background 0.2s ease-out, border-color 0.2s ease-out,
    color 0.2s ease-out,
    transform 0.12s cubic-bezier(0.25, 1, 0.5, 1),
    box-shadow 0.2s ease-out;
}
.btn:hover { transform: translateY(-1px); }

.btn-primary,
#chat-form button {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover,
#chat-form button:hover {
  background: var(--accent-hover);
}
.btn-primary:active { transform: translateY(1px); }

.btn-oauth {
  display: flex;
  width: 100%;
  margin-bottom: var(--space-2);
  border-color: var(--border);
  background: var(--surface-alt);
  color: var(--text);
  text-align: center;
}

.btn-oauth:hover,
#reconnect-button:hover,
.btn-secondary:hover,
.cursor-toggle:hover {
  border-color: var(--border-strong);
  background: var(--control-hover);
}
.btn-oauth:active { transform: translateY(1px); }

/* Ghost button for secondary actions (e.g. copy room link). */
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

#reconnect-button,
.btn-secondary,
.cursor-toggle {
  flex-shrink: 0;
  border-color: var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.btn-ghost:hover { background: var(--surface-alt); border-color: var(--text-muted); }
.btn-ghost:active { transform: translateY(1px); }

.guest-entry {
  margin-bottom: var(--space-5);
}

.guest-form {
  display: flex;
  gap: var(--space-2);
}

.guest-form input,
#chat-input {
  min-width: 0;
  min-height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1rem;
}

.login-form input {
  flex: 1;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
}
.login-form input:focus { border-color: var(--accent); }

/* Default placeholders render too faint to clear 4.5:1; pin them to the muted
   token at full opacity, which is contrast-checked against --surface-alt. */
.login-form input::placeholder,
#chat-input::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.landing-helper {
  max-width: 30rem;
  margin-inline: auto;
}

.guest-form input:hover,
#chat-input:hover {
  border-color: var(--border-strong);
}

.guest-form input:focus,
#chat-input:focus {
  border-color: var(--accent);
}

/* ── App Layout ──────────────────────────────────────────────────────── */

body.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#cursor-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--z-cursors);
}

.cursor-indicator {
  position: absolute;
  pointer-events: none;
  transform: translate3d(0, 0, 0);
  transition: transform 100ms ease-out;
  will-change: transform;
}

.cursor-arrow {
  width: 16px;
  height: 20px;
}

.cursor-label {
  position: absolute;
  inset-inline-start: 18px;
  top: 14px;
  max-width: 11rem;
  padding: 2px 6px;
  overflow: hidden;
  border: 1px solid var(--cursor-color, var(--accent));
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-sticky);
}

.brand {
  min-width: 0;
  margin-right: auto;
}

.logo {
  font-weight: 750;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.live-system {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
  max-width: min(56rem, 62vw);
}

.system-status {
  position: relative;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.system-status summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2rem;
  padding: 0.2rem 0.35rem 0.2rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  list-style: none;
}

.system-status summary::-webkit-details-marker {
  display: none;
}

.system-status[open] summary {
  border-color: var(--border-strong);
}

.system-status-title {
  font-size: 0.78rem;
  font-weight: 700;
}

.system-summary-status {
  display: inline-flex;
  align-items: center;
  min-height: 1.45rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--warning-dim);
  color: var(--warning);
  font-size: 0.7rem;
  font-weight: 700;
}

.system-summary-status.status-connected,
.system-summary-status.status-active {
  background: var(--success-dim);
  color: var(--success);
}

.system-summary-status.status-error,
.system-summary-status.status-closed {
  background: var(--danger-dim);
  color: var(--danger);
}

.count-badge {
  gap: var(--space-2);
  border-color: oklch(78% 0.1 245 / 36%);
  background: var(--info-dim);
  color: var(--info);
  font-size: 0.85rem;
  font-weight: 700;
}

.channel-library,
.try-library {
  color: var(--accent-strong);
  font-size: 0.68rem;
  font-weight: 700;
}

.count-label {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live-detail-list {
  position: absolute;
  inset-block-start: calc(100% + var(--space-2));
  inset-inline-end: 0;
  z-index: var(--z-sticky);
  display: grid;
  width: min(25rem, calc(100vw - 2rem));
  min-width: 18rem;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-width: 0;
}

.channel-copy {
  display: grid;
  gap: 0.05rem;
  min-width: 0;
}

.channel-library {
  overflow-wrap: anywhere;
}

.channel-name {
  color: var(--text);
  font-weight: 650;
}

.channel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.cursor-toggle[aria-pressed="false"] {
  border-color: oklch(84% 0.115 85 / 34%);
  background: var(--warning-dim);
  color: var(--warning);
}

/* The live count rising is the cross-tab CRDT moment: a quick pop + accent
   ring makes "someone just joined" feel like an event, not a digit swap. */
.count-badge { transform-origin: center; }
.count-badge.bump { animation: countBump 0.45s cubic-bezier(0.25, 1, 0.5, 1); }

@keyframes countBump {
  0% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-dim); }
  35% {
    transform: scale(1.14);
    box-shadow: 0 0 0 6px rgba(255, 175, 243, 0.22);
  }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 175, 243, 0); }
}

/* The first time every system reports healthy, the System status summary pill
   flips to "Live". A single soft ring radiates from the pill so the moment the
   demo becomes real-time reads as an event. JS adds .just-live once per session,
   then removes it on animationend. */
.system-summary-status.just-live {
  animation: liveGlow 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes liveGlow {
  0% { box-shadow: 0 0 0 0 oklch(82% 0.09 165 / 55%); }
  100% { box-shadow: 0 0 0 9px oklch(82% 0.09 165 / 0%); }
}

.user-info {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--space-2);
  font-size: 0.9rem;
  min-width: 0;
}

/* Keep long usernames (e.g. IndieAuth domains) from blowing out the bar. */
.user-name {
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}

.logout-form {
  margin: 0 0 0 0.5rem;
}

.btn-signout {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: inherit;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.8;
}

.btn-signout:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.6);
}
.btn-signout:active { transform: translateY(1px); }

#main {
  display: flex;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  position: relative;
  z-index: var(--z-content);
}

/* ── Chat Panel ──────────────────────────────────────────────────────── */

#chat-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--chat-bg);
  position: relative;
}

/* ── Chat Empty State ────────────────────────────────────────────────── */

.chat-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-align: center;
  padding: 2rem;
  pointer-events: none;
  color: var(--text-muted);
}

#chat-panel.has-messages .chat-empty { display: none; }

.chat-empty-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-dim);
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
  animation: emptyFloat 3.4s ease-in-out infinite;
}

@keyframes emptyFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.chat-empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.chat-empty-hint {
  max-width: 38ch;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* The empty layer ignores pointer events; its CTAs must opt back in. */
.chat-empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  pointer-events: auto;
}

.chat-empty-feedback {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--ok);
}
.chat-empty-feedback[hidden] { display: none; }

/* Demo cursor: a faint sample of the live-cursor feature, drifting across the
   empty room to foreshadow the payoff before the user opens a second tab. It
   sits behind the copy at low opacity so it reads as ambient preview, never a
   real participant; JS retires it the moment real presence arrives. */
.demo-cursor {
  position: absolute;
  top: 34%;
  left: 50%;
  z-index: 0;
  color: var(--accent);
  pointer-events: none;
  animation: demoDrift 9s ease-in-out infinite;
}

.demo-cursor .cursor-arrow {
  opacity: 0.6;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.demo-cursor-label {
  position: absolute;
  left: 18px;
  top: 14px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0.8;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px dashed var(--border);
}

@keyframes demoDrift {
  0%   { transform: translate(-44px, -8px); }
  25%  { transform: translate(56px, 22px); }
  50%  { transform: translate(8px, 58px); }
  75%  { transform: translate(-58px, 28px); }
  100% { transform: translate(-44px, -8px); }
}

/* Real presence has arrived (or a message landed): fade the preview out and
   stop drifting so the genuine cursors own the canvas. */
.chat-empty.demo-retired .demo-cursor {
  opacity: 0;
  animation: none;
  transition: opacity 0.4s ease-out;
}

.panel-heading {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.panel-heading h1 {
  margin-bottom: var(--space-1);
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}

.panel-heading p {
  max-width: 68ch;
  color: var(--text-muted);
  font-size: 0.92rem;
  text-wrap: pretty;
}

.try-guide {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}

.try-guide h3 {
  margin-bottom: var(--space-2);
  font-size: 0.82rem;
}

.try-guide ol {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--space-2);
  list-style: none;
  counter-reset: demo-step;
}

.try-step {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 0.1rem;
  padding-inline-start: 1.6rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  counter-increment: demo-step;
}

.try-step::before {
  content: counter(demo-step);
  position: absolute;
  inset-inline-start: 0;
  top: 0.1rem;
  display: inline-grid;
  place-items: center;
  width: 1rem;
  height: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
}

.try-step strong {
  display: block;
  color: var(--text);
  font-size: 0.8rem;
}

.try-library {
  overflow-wrap: anywhere;
}

.try-status {
  width: max-content;
  margin-top: 0.15rem;
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 700;
}

.try-step.is-complete::before {
  content: "✓";
  border-color: oklch(82% 0.09 165 / 55%);
  background: var(--success-dim);
  color: var(--success);
}

.try-step.is-complete .try-status {
  border-color: oklch(82% 0.09 165 / 38%);
  background: var(--success-dim);
  color: var(--success);
}

.try-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  margin-top: var(--space-3);
  padding-top: var(--space-2);
}

.try-note {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.demo-verified {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid oklch(82% 0.09 165 / 38%);
  border-radius: var(--radius);
  background: var(--success-dim);
  color: var(--text);
  animation: verifyPulse 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.demo-verified strong {
  color: var(--success);
}

.demo-verified span {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.connection-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-4) var(--space-5) 0;
  padding: var(--space-3);
  border: 1px solid oklch(78% 0.11 25 / 42%);
  border-radius: var(--radius);
  background: var(--danger-dim);
  color: var(--danger);
}

#chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5);
}

#chat-messages:focus-visible {
  outline-offset: -3px;
}

.chat-msg {
  margin-bottom: var(--space-3);
  max-width: 70ch;
  animation: fadeIn 180ms ease-out;
}

.chat-msg-restored {
  opacity: 0.95;
}

.chat-msg-restored::before {
  content: "shelf";
  display: inline-block;
  margin-right: var(--space-2);
  padding: 0.05rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes verifyPulse {
  0% { opacity: 0; transform: translateY(6px) scale(0.98); }
  70% { opacity: 1; transform: translateY(0) scale(1.01); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-msg .sender {
  margin-right: var(--space-2);
  color: var(--sender-color, var(--accent-strong));
  font-weight: 650;
  font-size: 0.85rem;
}

.chat-msg .content {
  color: var(--text);
  overflow-wrap: anywhere;
}

.chat-msg .time {
  margin-left: var(--space-2);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.chat-system {
  margin: var(--space-3) 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.composer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Reconnection reassurance strip, sits directly above the composer. */
.composer-status {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  border-top: 1px solid var(--border);
}
.composer-status[hidden] { display: none; }

#chat-form {
  display: flex;
  gap: var(--space-2);
}

#chat-input {
  flex: 1;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
}
#chat-input:focus { border-color: var(--accent); }
#chat-input:disabled,
#chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chat-form button {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}
#chat-form button:hover { background: var(--accent-hover); }
#chat-form button:active { transform: translateY(1px); }

.form-helper {
  margin-top: var(--space-2);
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */

#sidebar {
  width: 17rem;
  min-width: 15rem;
  background: var(--surface);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#sidebar h3 {
  margin-bottom: var(--space-1);
  color: var(--text);
  font-size: 0.92rem;
}

/* Roster is a native <details> so it can collapse on mobile. */
.roster {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.roster-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  margin-bottom: 0.75rem;
  list-style: none;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.roster-summary::-webkit-details-marker { display: none; }
.roster-summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease-out;
}
.roster[open] > .roster-summary::before { transform: rotate(90deg); }

.roster-count {
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

#user-list {
  list-style: none;
  flex: 1;
}

#user-list li {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--space-2);
  padding: 0.45rem 0;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

#user-list .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.list-hint {
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-muted);
  padding: 0.5rem 0;
}

.empty-row {
  color: var(--text-muted);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

.tech-info {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.tech-info summary {
  min-height: 2.25rem;
  color: var(--text);
}

.tech-list {
  list-style: none;
  margin-top: var(--space-2);
}

.tech-list li {
  padding: 0.25rem 0;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.tech-list .tech-desc {
  margin-left: 0.4rem;
  color: var(--text-muted);
}

.tech-list strong {
  color: var(--accent-strong);
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive: tablet & mobile ─────────────────────────────────────── */

@media (max-width: 820px) {
  body.app {
    overflow: auto;
  }

  #top-bar {
    flex-wrap: wrap;
    align-items: flex-start;
    row-gap: 0.5rem;
    column-gap: 0.6rem;
    padding: var(--space-3) var(--space-4);
    padding-top: max(var(--space-3), env(safe-area-inset-top));
  }

  .brand {
    flex-basis: 100%;
  }

  .live-system {
    justify-content: flex-start;
    max-width: none;
  }

  .live-detail-list {
    inset-inline: 0 auto;
    width: min(calc(100vw - 2rem), 25rem);
  }

  #main {
    flex-direction: column;
    overflow: visible;
  }

  #chat-panel {
    min-height: 68vh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .composer {
    position: sticky;
    bottom: 0;
    z-index: var(--z-sticky);
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }

  #sidebar {
    width: 100%;
    min-width: 0;
    max-height: none;
    flex: 0 0 auto;
    border-top: 1px solid var(--border);
  }

  #sidebar:has(.roster[open]) { max-height: 50vh; }
  .roster[open] { overflow-y: auto; }
  .roster-summary { min-height: 44px; }
  .user-name { max-width: 32vw; }
}

@media (max-width: 560px) {
  body.landing {
    align-items: stretch;
    padding: 1rem;
  }

  .landing-card {
    align-self: center;
    padding: 1.75rem 1.25rem;
  }

  .guest-form,
  #chat-form,
  .connection-alert,
  .try-actions,
  .channel-row,
  .channel-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .guest-form input,
  .guest-form button,
  #chat-form button,
  #reconnect-button,
  .btn-secondary,
  .cursor-toggle {
    width: 100%;
  }

  .panel-heading,
  #chat-messages,
  .composer,
  #sidebar {
    padding-inline: var(--space-4);
  }
}

/* ── Touch Input ─────────────────────────────────────────────────────── */

@media (pointer: coarse) {
  .btn,
  #chat-form button,
  #reconnect-button,
  .btn-secondary,
  .cursor-toggle,
  .guest-form input,
  .login-form input,
  #chat-input,
  .more-auth-summary,
  .tech-info summary,
  .btn-signout {
    min-height: 44px;
  }

  .btn-signout {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
  }
}

/* ── Gallery ─────────────────────────────────────────────────────────── */

body.gallery-index,
body.gallery-dice {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.gallery-nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-link {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s ease-out;
}
.nav-link:hover { color: var(--text); }
.nav-link--current { color: var(--accent); }

.gallery-main {
  flex: 1;
  width: 100%;
  max-width: 56rem;
  margin-inline: auto;
  padding: var(--space-6) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.gallery-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.gallery-header h1 {
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.gallery-lead {
  color: var(--text-muted);
  max-width: 54ch;
  text-wrap: pretty;
}

/* Gallery index tile grid */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: var(--space-3);
}

.demo-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.15s ease-out, background 0.15s ease-out;
}

.demo-tile--active:hover {
  border-color: var(--accent);
  background: var(--surface-alt);
}

.demo-tile--soon {
  opacity: 0.55;
  cursor: default;
}

.demo-tile-name {
  font-weight: 650;
  color: var(--text);
}

.demo-tile-tag {
  font-size: 0.72rem;
  color: var(--accent);
}

.demo-tile-soon {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Dice demo sections */
.demo-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.demo-section h2 {
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.section-lead {
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 60ch;
  text-wrap: pretty;
}

/* Replica grid */
.replica-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: var(--space-4);
}

@media (max-width: 560px) {
  .replica-grid {
    grid-template-columns: 1fr;
  }
}

.replica-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s ease-out;
}

.replica-panel--partitioned {
  border-color: var(--warning);
  background: var(--warning-dim);
}

.replica-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.dice-value {
  font-size: 3.5rem;
  font-weight: 750;
  line-height: 1;
  color: var(--accent);
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dice-value--live {
  font-size: 4rem;
}

@keyframes dice-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.dice-value--bump {
  animation: dice-bump 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

/* Controls between replicas */
.replica-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding-top: var(--space-5);
}

.btn-partition {
  background: var(--surface-alt);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-partition:hover { border-color: var(--warning); color: var(--warning); }
.btn-partition--active {
  border-color: var(--warning);
  background: var(--warning-dim);
  color: var(--warning);
}

.btn-merge {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-strong);
}
.btn-merge:hover { background: var(--accent); color: var(--on-accent); }

/* Explain callout */
.explain-callout {
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  transition: border-color 0.2s ease-out, color 0.2s ease-out;
}

/* Live panel */
.live-panel {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.live-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.live-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* Generic gallery demo controls */
.demo-tile-emoji {
  font-size: 1.6rem;
  line-height: 1;
}

.replica-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--accent);
  min-height: 2.4rem;
  text-align: center;
  word-break: break-word;
}

.replica-ops {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
}

.btn-op {
  background: var(--surface-alt);
  border: 1px solid var(--border-strong);
  color: var(--text);
}
.btn-op:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.live-state {
  font-size: 2rem;
  font-weight: 750;
  line-height: 1;
  color: var(--accent);
  min-height: 2.4rem;
  display: flex;
  align-items: center;
  word-break: break-word;
}

.live-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

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

  .chat-msg,
  .chat-empty-icon,
  .count-badge.bump,
  .system-summary-status.just-live,
  .demo-cursor {
    animation: none;
  }

  .cursor-indicator,
  .roster-summary::before,
  .more-auth-summary::before,
  .chat-empty.demo-retired .demo-cursor {
    transition: none;
  }

  .btn:hover { transform: none; }
}
