/* ==========================================================================
   CIPHERROOM — Chat experience
   Minimal, warm and quiet. Warm white / charcoal / neutral grey with one
   restrained mint accent. All motion is 150–250 ms and disabled by the
   reduced-motion rule in security.css.
   Scope: #chat, its dialogs, the toast and the privacy cover.
   ========================================================================== */

:root {
  --c-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --c-page: #0e0f10;
  --c-surface: #17181a;
  --c-surface-2: #202124;
  --c-surface-3: #2a2b2f;
  --c-border: rgba(255, 255, 255, 0.09);
  --c-border-strong: rgba(255, 255, 255, 0.17);
  --c-text: #efeeea;
  --c-text-2: #b0afa9;
  --c-text-3: #8a8982;
  --c-accent: #52d1a7;
  --c-accent-text: #6fdcb9;
  --c-on-accent: #0b231b;
  --c-accent-soft: rgba(82, 209, 167, 0.12);
  --c-accent-border: rgba(82, 209, 167, 0.32);
  --c-mine-bg: #1f4d3f;
  --c-mine-text: #eefaf5;
  --c-theirs-bg: #26272b;
  --c-theirs-text: #efeeea;
  --c-warn: #e3b04b;
  --c-warn-soft: rgba(227, 176, 75, 0.13);
  --c-danger: #f08a80;
  --c-danger-soft: rgba(240, 138, 128, 0.12);
  --c-danger-border: rgba(240, 138, 128, 0.34);
  --c-focus: #7fe3c1;
  --c-backdrop: rgba(0, 0, 0, 0.6);
  --c-raise: 0 6px 20px rgba(0, 0, 0, 0.35);

  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 24px;
  --r-full: 999px;
  --t-fast: 150ms;
  --t-base: 200ms;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

html[data-theme="light"] {
  --c-page: #efece5;
  --c-surface: #fcfbf8;
  --c-surface-2: #f2f0ea;
  --c-surface-3: #e8e5dd;
  --c-border: rgba(40, 38, 30, 0.11);
  --c-border-strong: rgba(40, 38, 30, 0.2);
  --c-text: #1d1d1b;
  --c-text-2: #55544e;
  --c-text-3: #6c6b65;
  --c-accent: #38b28e;
  --c-accent-text: #1f7a5f;
  --c-on-accent: #072019;
  --c-accent-soft: rgba(56, 178, 142, 0.13);
  --c-accent-border: rgba(31, 122, 95, 0.32);
  --c-mine-bg: #cdeede;
  --c-mine-text: #10281f;
  --c-theirs-bg: #ebe8e0;
  --c-theirs-text: #1d1d1b;
  --c-warn: #8f6208;
  --c-warn-soft: rgba(190, 130, 20, 0.14);
  --c-danger: #b4372f;
  --c-danger-soft: rgba(180, 55, 47, 0.09);
  --c-danger-border: rgba(180, 55, 47, 0.32);
  --c-focus: #1f7a5f;
  --c-backdrop: rgba(30, 28, 20, 0.42);
  --c-raise: 0 6px 20px rgba(40, 38, 30, 0.12);
}

body.in-chat { background: var(--c-page); }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   Shared controls
   -------------------------------------------------------------------------- */
.chat, .sheet, .toast, .privacy-cover, .lightbox { font-family: var(--c-font); color: var(--c-text); }
.chat button, .sheet button, .privacy-cover button, .lightbox button {
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
    color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
}
.chat button:active:not(:disabled), .sheet button:active:not(:disabled),
.privacy-cover button:active:not(:disabled), .lightbox button:active:not(:disabled) { transform: scale(0.95); }
.chat :focus-visible, .sheet :focus-visible, .privacy-cover :focus-visible, .lightbox :focus-visible {
  outline: 2px solid var(--c-focus); outline-offset: 2px;
}

.icon-button {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center;
  border-radius: 50%; color: var(--c-text-2);
}
.icon-button:hover:not(:disabled) { background: var(--c-surface-2); color: var(--c-text); }

.btn {
  min-height: 44px; padding: 0 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--r-full); font-size: 14px; font-weight: 600; line-height: 1;
  border: 1px solid transparent;
}
.btn .icon { width: 18px; height: 18px; }
.btn-quiet { background: var(--c-surface-2); border-color: var(--c-border); color: var(--c-text); }
.btn-quiet:hover:not(:disabled) { background: var(--c-surface-3); }
.btn-accent { background: var(--c-accent); color: var(--c-on-accent); }
.btn-accent:hover:not(:disabled) { filter: brightness(1.06); }
.btn-danger { background: var(--c-danger-soft); border-color: var(--c-danger-border); color: var(--c-danger); }
.btn-danger:hover:not(:disabled) { background: var(--c-danger-border); }
.btn-block { width: 100%; }

/* --------------------------------------------------------------------------
   Chat shell
   -------------------------------------------------------------------------- */
.chat {
  position: relative;
  width: 100%; max-width: 880px; margin: 0 auto;
  height: calc(100vh - 48px); height: calc(100dvh - 48px); min-height: 480px;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-lg);
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--c-border);
  background: var(--c-surface); z-index: 5;
}
.peer { display: flex; align-items: center; gap: 12px; min-width: 0; }
.peer-avatar {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border-radius: 50%; background: var(--c-surface-2); border: 1px solid var(--c-border);
  font-size: 16px; font-weight: 600; color: var(--c-text-2);
  transition: background-color var(--t-base) var(--ease), color var(--t-base) var(--ease), border-color var(--t-base) var(--ease);
}
.chat[data-peer="here"] .peer-avatar { background: var(--c-accent-soft); border-color: var(--c-accent-border); color: var(--c-accent-text); }
.peer-text { min-width: 0; }
.peer-name {
  font-size: 16px; font-weight: 650; line-height: 1.25; letter-spacing: -0.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conn-status {
  display: flex; align-items: center; gap: 7px; min-width: 0;
  font-size: 13px; line-height: 1.3; color: var(--c-text-2);
}
.conn-status #status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .status-dot {
  width: 8px; height: 8px; flex: none; border-radius: 50%; box-shadow: none; animation: none;
  background: var(--c-text-3); transition: background-color var(--t-base) var(--ease);
}
.conn-status[data-state="connected"] .status-dot { background: var(--c-accent); }
.conn-status[data-state="checking"] .status-dot,
.conn-status[data-state="reconnecting"] .status-dot { background: var(--c-warn); }
.countdown { color: var(--c-text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.countdown::before { content: "·"; margin-right: 7px; }

.header-tools { display: flex; align-items: center; gap: 4px; flex: none; }

.verify-chip {
  height: 36px; padding: 0 12px 0 10px; display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-full); border: 1px solid var(--c-border); background: var(--c-surface-2);
  font-size: 13px; font-weight: 550; color: var(--c-text-2); white-space: nowrap;
}
.verify-chip .icon { width: 17px; height: 17px; color: var(--c-warn); }
.verify-chip:hover:not(:disabled) { background: var(--c-surface-3); color: var(--c-text); }
.verify-chip[data-state="verified"] { background: var(--c-accent-soft); border-color: var(--c-accent-border); color: var(--c-accent-text); }
.verify-chip[data-state="verified"] .icon { color: var(--c-accent-text); }
.verify-chip:disabled { opacity: 1; cursor: default; }

/* Menu & popovers */
.menu-wrap { position: relative; }
.menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  width: min(320px, calc(100vw - 24px)); padding: 6px;
  background: var(--c-surface); border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  box-shadow: var(--c-raise);
  opacity: 0; visibility: hidden; transform: translateY(-4px) scale(0.98); transform-origin: top right;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), visibility 0s linear var(--t-fast);
}
.menu[data-open="true"] {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), visibility 0s;
}
.menu-item {
  width: 100%; display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px;
  border-radius: 12px; text-align: left; color: var(--c-text);
}
.menu-item .icon { margin-top: 1px; color: var(--c-text-2); }
.menu-item span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.menu-item strong { font-size: 14px; font-weight: 600; line-height: 1.3; }
.menu-item small { font-size: 12px; line-height: 1.4; color: var(--c-text-3); }
.menu-item:hover, .menu-item:focus-visible { background: var(--c-surface-2); }
.menu-item.is-danger, .menu-item.is-danger .icon, .menu-item.is-danger small { color: var(--c-danger); }
.menu-item.is-danger small { opacity: 0.85; }
.menu-sep { height: 1px; margin: 6px 8px; background: var(--c-border); }

/* Join request & reconnect banners */
.join-request {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 12px 16px 0; padding: 14px 16px;
  background: var(--c-accent-soft); border: 1px solid var(--c-accent-border); border-radius: var(--r-md);
  animation: slide-down var(--t-base) var(--ease);
}
.join-copy strong { display: block; font-size: 15px; font-weight: 650; }
.join-copy p { margin-top: 2px; font-size: 13px; line-height: 1.45; color: var(--c-text-2); }
.join-request-actions { display: flex; gap: 8px; flex: none; }
.join-request .btn { min-height: 40px; padding: 0 16px; }

.reconnect-banner {
  display: flex; align-items: center; gap: 10px; margin: 12px 16px 0; padding: 10px 14px;
  background: var(--c-warn-soft); color: var(--c-text); border-radius: 12px;
  font-size: 13px; line-height: 1.4;
  animation: slide-down var(--t-base) var(--ease);
}
.reconnect-banner .icon { width: 18px; height: 18px; color: var(--c-warn); }

/* --------------------------------------------------------------------------
   Conversation
   -------------------------------------------------------------------------- */
.conversation { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 2px;
  padding: 20px 16px 28px;
  scrollbar-width: thin; scrollbar-color: var(--c-border-strong) transparent;
}
.messages:focus-visible { outline-offset: -3px; }

.waiting-card {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 24px; text-align: center; pointer-events: none;
  opacity: 1; transition: opacity var(--t-base) var(--ease);
}
.waiting-card[hidden] { display: flex !important; opacity: 0; visibility: hidden; }
.delivery-failed { font-weight: 700; }
.delivery-detail { font-size: 10px; }
.waiting-card > * { pointer-events: auto; }
.waiting-mark {
  width: 56px; height: 56px; display: grid; place-items: center; margin-bottom: 4px;
  border-radius: 50%; background: var(--c-accent-soft); border: 1px solid var(--c-accent-border);
  color: var(--c-accent-text); font-size: 22px;
}
.waiting-card h2 { font-size: 18px; font-weight: 650; }
.waiting-card p { max-width: 300px; margin-bottom: 8px; font-size: 14px; line-height: 1.5; color: var(--c-text-2); }

.time-divider {
  align-self: center; margin: 14px 0 8px; font-size: 12px; line-height: 1; color: var(--c-text-3);
  font-variant-numeric: tabular-nums;
}
.system-message {
  align-self: center; max-width: 90%; margin: 12px 0; padding: 0 8px; text-align: center;
  font-size: 12.5px; line-height: 1.5; color: var(--c-text-3);
}

.message-row {
  position: relative; max-width: min(78%, 560px); display: flex; flex-direction: column;
  animation: message-in var(--t-base) var(--ease) both;
}
.message-row.mine { align-self: flex-end; align-items: flex-end; }
.message-row.theirs { align-self: flex-start; align-items: flex-start; }
.message-row.starts-group { margin-top: 10px; }
.message-row.is-expiring { opacity: 0; transform: scale(0.97); animation: none; transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease); }

.message-bubble {
  padding: 9px 14px; border: 1px solid transparent; border-radius: 19px;
  font-size: 15px; line-height: 1.42; overflow-wrap: anywhere; white-space: pre-wrap;
  user-select: text; -webkit-user-select: text; cursor: text;
}
.mine .message-bubble { background: var(--c-mine-bg); color: var(--c-mine-text); }
.theirs .message-bubble { background: var(--c-theirs-bg); color: var(--c-theirs-text); }
.mine[data-pos="first"] .message-bubble { border-bottom-right-radius: 6px; }
.mine[data-pos="middle"] .message-bubble { border-top-right-radius: 6px; border-bottom-right-radius: 6px; }
.mine[data-pos="last"] .message-bubble { border-top-right-radius: 6px; }
.theirs[data-pos="first"] .message-bubble { border-bottom-left-radius: 6px; }
.theirs[data-pos="middle"] .message-bubble { border-top-left-radius: 6px; border-bottom-left-radius: 6px; }
.theirs[data-pos="last"] .message-bubble { border-top-left-radius: 6px; }

.message-bubble.is-photo { padding: 3px; cursor: default; line-height: 0; }
.photo-button { display: block; padding: 0; border-radius: 16px; overflow: hidden; cursor: zoom-in; }
.shared-photo {
  display: block; width: auto; height: auto; min-width: 140px; min-height: 100px;
  max-width: min(320px, 62vw); max-height: 340px; object-fit: cover;
  background: var(--c-surface-3); border-radius: 16px;
}

.message-bubble.is-voice { padding: 8px 14px 8px 8px; cursor: default; }
.voice-player { display: flex; align-items: center; gap: 10px; min-width: min(230px, 58vw); }
.vp-toggle {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: color-mix(in srgb, currentColor 14%, transparent); color: inherit;
}
.vp-toggle:hover { background: color-mix(in srgb, currentColor 22%, transparent); }
.vp-toggle .icon { width: 18px; height: 18px; }
.vp-seek {
  flex: 1; min-width: 0; height: 24px; margin: 0; background: transparent; cursor: pointer;
  -webkit-appearance: none; appearance: none; color: inherit;
  --vp-fill: 0%;
}
.vp-seek::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, currentColor var(--vp-fill), color-mix(in srgb, currentColor 24%, transparent) var(--vp-fill));
}
.vp-seek::-moz-range-track { height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 24%, transparent); }
.vp-seek::-moz-range-progress { height: 4px; border-radius: 2px; background: currentColor; }
.vp-seek::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: currentColor; border: 0; }
.vp-seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: currentColor; border: 0; }
.vp-time { min-width: 34px; font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.85; text-align: right; }

.message-foot {
  display: flex; align-items: center; gap: 8px; min-height: 0; margin: 3px 6px 0;
  font-size: 11px; line-height: 1.3; color: var(--c-text-3);
}
.message-foot:empty { display: none; }
.reaction-count {
  padding: 1px 7px; border-radius: var(--r-full); background: var(--c-surface-2); border: 1px solid var(--c-border);
  font-size: 12px; line-height: 1.4;
}
.message-expiry { display: inline-flex; align-items: center; gap: 4px; }
.message-expiry .icon { width: 12px; height: 12px; }
.message-row.is-followed .message-expiry { display: none; }
.message-row.is-followed:hover .message-expiry, .message-row.actions-open .message-expiry { display: inline-flex; }

.delivery-status { display: none; align-items: center; gap: 4px; }
.delivery-status .icon { width: 13px; height: 13px; }
.mine.is-latest .delivery-status,
.mine .delivery-status[data-state="failed"],
.mine .delivery-status[data-state="unconfirmed"] { display: inline-flex; }
.delivery-status[data-state="delivered"] { color: var(--c-accent-text); }
.delivery-status[data-state="unconfirmed"] { color: var(--c-warn); }
.delivery-status[data-state="failed"] { color: var(--c-danger); font-weight: 600; }

.reaction-actions {
  position: absolute; top: 100%; z-index: 4; margin-top: -4px; display: flex; gap: 2px; padding: 3px;
  background: var(--c-surface); border: 1px solid var(--c-border-strong); border-radius: var(--r-full);
  box-shadow: var(--c-raise);
  opacity: 0; visibility: hidden; transform: translateY(-3px);
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), visibility 0s linear var(--t-fast);
}
.mine .reaction-actions { right: 0; }
.theirs .reaction-actions { left: 0; }
.message-row:hover .reaction-actions, .message-row:focus-within .reaction-actions, .message-row.actions-open .reaction-actions {
  opacity: 1; visibility: visible; transform: none; transition-delay: 0s;
}
.reaction-actions button { width: 34px; height: 30px; border-radius: var(--r-full); font-size: 16px; line-height: 1; }
.reaction-actions button:hover { background: var(--c-surface-2); }

.new-pill {
  position: absolute; left: 50%; bottom: 12px; z-index: 6; transform: translateX(-50%);
  height: 36px; padding: 0 14px 0 12px; display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-full); background: var(--c-accent); color: var(--c-on-accent);
  font-size: 13px; font-weight: 600; box-shadow: var(--c-raise);
  animation: pill-in var(--t-base) var(--ease) both;
}
.new-pill .icon { width: 16px; height: 16px; }
.new-pill:active:not(:disabled) { transform: translateX(-50%) scale(0.95); }

/* --------------------------------------------------------------------------
   Composer
   -------------------------------------------------------------------------- */
.composer-zone {
  padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--c-surface);
  border-top: 1px solid var(--c-border);
}
.composer-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 30px; padding: 0 4px; }
.burn-chip {
  position: relative; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 6px 0 8px;
  border-radius: var(--r-full); border: 1px solid var(--c-border); color: var(--c-text-2); font-size: 12px; cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.burn-chip:hover { background: var(--c-surface-2); }
.burn-chip:focus-within { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.burn-chip .icon { width: 14px; height: 14px; }
.burn-chip::after { content: ""; width: 0; height: 0; margin: 2px 2px 0 0; border: 4px solid transparent; border-top-color: currentColor; border-bottom-width: 0; opacity: 0.7; }
.burn-chip select {
  -webkit-appearance: none; appearance: none; background: transparent; border: 0; outline: none;
  color: var(--c-text); font: inherit; font-weight: 600; padding: 0 2px; cursor: pointer;
}
.burn-chip select option { background: var(--c-surface); color: var(--c-text); }
.composer-aside { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 10px; font-size: 12px; color: var(--c-text-3); }
.typing-status { display: inline-flex; align-items: center; gap: 8px; min-width: 0; animation: fade-in var(--t-base) var(--ease); }
.typing-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots span {
  width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.35;
  animation: typing 1s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
.photo-transfer { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.photo-transfer > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-transfer progress {
  width: 56px; height: 4px; -webkit-appearance: none; appearance: none; border: 0; border-radius: 2px;
  background: var(--c-surface-3); overflow: hidden;
}
.photo-transfer progress::-webkit-progress-bar { background: var(--c-surface-3); }
.photo-transfer progress::-webkit-progress-value { background: var(--c-accent); border-radius: 2px; transition: width var(--t-fast) linear; }
.photo-transfer progress::-moz-progress-bar { background: var(--c-accent); border-radius: 2px; }
.voice-status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-status:empty { display: none; }

.composer { position: relative; }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer-field {
  flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; padding: 0 16px;
  background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 22px;
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease);
}
.composer-field:focus-within { border-color: var(--c-accent-border); background: var(--c-surface); box-shadow: 0 0 0 3px var(--c-accent-soft); }
.composer-field textarea {
  display: block; width: 100%; height: 22px; max-height: 132px; padding: 0; margin: 10px 0;
  resize: none; overflow-y: auto; background: transparent; color: var(--c-text);
  font-size: 15px; line-height: 22px; scrollbar-width: thin;
}
.composer-field textarea::placeholder { color: var(--c-text-3); }
.composer-field textarea:disabled { cursor: not-allowed; }

.send-button {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%;
  background: var(--c-accent); color: var(--c-on-accent);
}
.send-button:hover:not(:disabled) { filter: brightness(1.06); }
.send-button:disabled { opacity: 0.4; }
.composer:not(.has-text) #send { display: none; }
.composer.has-text .mic-button { display: none; }
.composer.has-text #send, .composer:not(.has-text) .mic-button { animation: pop-in var(--t-fast) var(--ease); }
.icon-button#composer-plus[aria-expanded="true"] { background: var(--c-surface-2); color: var(--c-text); }
.icon-button#composer-plus .icon { transition: transform var(--t-base) var(--ease); }
.icon-button#composer-plus[aria-expanded="true"] .icon { transform: rotate(45deg); }

.attach-panel {
  position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 20; display: flex; gap: 4px; padding: 6px;
  background: var(--c-surface); border: 1px solid var(--c-border-strong); border-radius: var(--r-md); box-shadow: var(--c-raise);
  opacity: 0; visibility: hidden; transform: translateY(6px) scale(0.98); transform-origin: bottom left;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), visibility 0s linear var(--t-fast);
}
.attach-panel[data-open="true"] {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), visibility 0s;
}
.attach-item { min-width: 84px; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px 12px; border-radius: 12px; font-size: 13px; font-weight: 550; }
.attach-item:hover:not(:disabled) { background: var(--c-surface-2); }

.recording-bar {
  display: flex; align-items: center; gap: 6px; min-height: 52px; padding: 4px;
  background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 26px;
  animation: fade-in var(--t-base) var(--ease);
}
.recording-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.rec-dot { width: 10px; height: 10px; flex: none; border-radius: 50%; background: var(--c-danger); }
.rec-time { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rec-hint { font-size: 12px; color: var(--c-text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --------------------------------------------------------------------------
   Toast, cover, dialogs
   -------------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 1000;
  max-width: min(420px, calc(100vw - 32px)); padding: 11px 18px;
  background: var(--c-text); color: var(--c-surface); border-radius: var(--r-full);
  font-size: 13px; font-weight: 550; line-height: 1.4; text-align: center;
  transform: translate(-50%, 8px); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--t-base) var(--ease), transform var(--t-base) var(--ease), visibility 0s linear var(--t-base);
}
.toast[data-open="true"] { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }

.privacy-cover {
  position: fixed; inset: 0; z-index: 99999; display: grid; place-items: center; padding: 24px;
  background: var(--c-page); text-align: center;
}
.privacy-cover > div { max-width: 360px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.privacy-cover h2 { font-size: 20px; font-weight: 650; }
.privacy-cover p { margin-bottom: 12px; font-size: 14px; line-height: 1.55; color: var(--c-text-2); }
.empty-symbol {
  width: 56px; height: 56px; display: grid; place-items: center; border-radius: 50%;
  background: var(--c-accent-soft); border: 1px solid var(--c-accent-border); color: var(--c-accent-text); font-size: 22px;
}

.sheet {
  width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 48px); margin: auto; padding: 20px 20px 22px;
  background: var(--c-surface); color: var(--c-text); border: 1px solid var(--c-border-strong); border-radius: var(--r-lg);
  box-shadow: var(--c-raise); overflow-y: auto; overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-in var(--t-base) var(--ease); }
.sheet.is-closing, .lightbox.is-closing { animation: sheet-out var(--t-fast) var(--ease) forwards; }
.sheet::backdrop, .lightbox::backdrop { background: var(--c-backdrop); }
.sheet[open]::backdrop, .lightbox[open]::backdrop { animation: fade-in var(--t-base) var(--ease); }
.sheet.is-closing::backdrop, .lightbox.is-closing::backdrop { animation: fade-out var(--t-fast) var(--ease) forwards; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -6px -8px 8px 0; }
.sheet h2 { font-size: 18px; font-weight: 650; line-height: 1.3; }
.sheet-block { padding: 14px 0; border-top: 1px solid var(--c-border); }
.sheet-block:first-of-type { border-top: 0; }
.field-label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--c-text-3); }
.sheet-note { margin-top: 10px; font-size: 13px; line-height: 1.55; color: var(--c-text-2); }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.sheet-actions.is-split { margin-top: 18px; }
.sheet-actions.is-split .btn { flex: 1; }

.secret {
  display: block; padding: 12px 14px; border: 1px solid var(--c-border); border-radius: 12px; background: var(--c-surface-2);
  font-family: var(--font-mono, ui-monospace, Menlo, monospace); font-size: 15px; letter-spacing: 0.05em; line-height: 1.5;
  overflow-wrap: anywhere; user-select: all; -webkit-user-select: all;
}
.secret[data-revealed="false"] { user-select: none; -webkit-user-select: none; color: var(--c-text-3); letter-spacing: 0.12em; }
.check-code { display: block; font-family: var(--font-mono, ui-monospace, Menlo, monospace); font-size: 24px; letter-spacing: 0.14em; font-weight: 600; color: var(--c-text); }
.safety-code {
  display: block; margin: 14px 0; padding: 14px; border: 1px solid var(--c-border); border-radius: 12px; background: var(--c-surface-2);
  font-family: var(--font-mono, ui-monospace, Menlo, monospace); font-size: 16px; line-height: 1.9; letter-spacing: 0.05em;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums; user-select: text;
}
.safety-check { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 14px; font-size: 14px; line-height: 1.45; cursor: pointer; }
.safety-check input { width: 20px; height: 20px; flex: none; margin-top: 1px; accent-color: var(--c-accent); cursor: pointer; }
.safety-dialog .btn-block { margin-bottom: 4px; }
.qr-dialog #qr-code svg { display: block; width: min(240px, 70%); height: auto; margin: 16px auto 14px; padding: 10px; border-radius: 14px; background: #fff; }
.qr-dialog .check-code { font-size: 18px; text-align: center; }
.confirm-dialog { width: min(400px, calc(100vw - 24px)); }

.lightbox {
  width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; padding: 0; margin: 0; border: 0; background: transparent;
  overflow: hidden;
}
.lightbox[open] { display: grid; place-items: center; animation: fade-in var(--t-base) var(--ease); }
.lightbox::backdrop { background: rgba(0, 0, 0, 0.88); }
.lightbox img { max-width: min(94vw, 1100px); max-height: 86dvh; border-radius: 14px; background: var(--c-surface-3); }
.lightbox-close { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; background: rgba(0, 0, 0, 0.5); color: #fff; }
.lightbox-close:hover:not(:disabled) { background: rgba(0, 0, 0, 0.7); color: #fff; }

/* --------------------------------------------------------------------------
   Motion
   -------------------------------------------------------------------------- */
@keyframes message-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }
@keyframes pill-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes typing { 0%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 600px) {
  body.in-chat .shell { padding: 0; }
  .chat {
    position: fixed; top: var(--vv-top, 0px); left: 0; right: 0; max-width: none;
    height: var(--vv-h, 100dvh); min-height: 0; border: 0; border-radius: 0;
  }
  .chat-header { padding: max(10px, env(safe-area-inset-top)) 8px 10px 14px; }
  .peer-avatar { width: 36px; height: 36px; font-size: 15px; }
  .verify-chip { padding: 0 10px 0 8px; }
  .messages { padding: 16px 12px 28px; }
  .message-row { max-width: 86%; }
  .join-request { flex-direction: column; align-items: stretch; gap: 12px; margin: 10px 12px 0; }
  .join-request-actions .btn { flex: 1; }
  .reconnect-banner { margin: 10px 12px 0; }
  .composer-zone { padding-left: 8px; padding-right: 8px; }
  .rec-hint { display: none; }
  .sheet {
    width: 100%; max-width: none; margin: auto 0 0; max-height: 88dvh; border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: 0; padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
  .confirm-dialog { width: 100%; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@media (max-width: 360px) {
  .burn-text { display: none; }
  .verify-chip span { max-width: 78px; overflow: hidden; text-overflow: ellipsis; }
}
@media (hover: none) {
  .reaction-actions { transition-delay: 0s; }
}
