:root {
  color-scheme: dark;
  --blue-950: #102c3d;
  --blue-800: #53ddf5;
  --blue-700: #77dced;
  --blue-600: #4ccfe8;
  --blue-500: #27b4e5;
  --blue-100: #122e3b;
  --ink: #e8f2fa;
  --muted: #a4b4c5;
  --subtle: #8295aa;
  --line: #223246;
  --line-strong: #3c526b;
  --surface: #101927;
  --surface-raised: #162233;
  --input-bg: #0b1420;
  --chat-bg: #0b121e;
  --own-bubble: #142f42;
  --danger: #ff9c9c;
  --success: #68ddb7;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 15% 12%, rgba(39, 180, 229, 0.12), transparent 46%),
    radial-gradient(ellipse at 88% 85%, rgba(59, 92, 173, 0.12), transparent 42%),
    linear-gradient(rgba(110, 160, 190, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(110, 160, 190, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    #080e18;
  font-family: var(--font);
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

button {
  border: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--blue-700);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.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;
}

.app-shell {
  width: min(100%, 520px);
  height: min(860px, calc(100dvh - 40px));
  min-height: min(520px, calc(100dvh - 40px));
}

.welcome-card,
.chat-card,
.fatal-card {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.welcome-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.welcome-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 82px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 100% 0, rgba(39, 180, 229, 0.12), transparent 70%),
    var(--surface);
}

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

.brand__mark {
  position: relative;
  display: grid;
  flex: 0 0 39px;
  width: 39px;
  height: 39px;
  place-items: center;
  border: 1px solid #36728a;
  border-radius: 11px;
  background: var(--blue-100);
  box-shadow: 0 0 22px rgba(39, 180, 229, 0.08);
}

.brand__mark::before,
.brand__mark::after,
.brand__mark span {
  position: absolute;
  content: "";
  border-radius: 999px;
  background: var(--blue-700);
}

.brand__mark::before {
  width: 18px;
  height: 6px;
  transform: rotate(-36deg) translate(1px, -3px);
}

.brand__mark::after {
  width: 11px;
  height: 6px;
  transform: rotate(45deg) translate(3px, 5px);
  opacity: 0.86;
}

.brand__mark span {
  width: 6px;
  height: 6px;
  transform: translate(-7px, 7px);
  opacity: 0.72;
}

.brand__copy {
  display: grid;
  min-width: 0;
  line-height: 1.16;
}

.brand__copy strong {
  font-size: 18px;
  letter-spacing: 0.06em;
}

.brand__copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.secure-pill {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  padding: 6px 9px;
  border: 1px solid #2c5a61;
  border-radius: 999px;
  color: var(--success);
  background: #102a2b;
  font-size: 11px;
  font-weight: 700;
}

.secure-pill > span:first-child {
  font-size: 7px;
}

.welcome-content {
  min-height: 0;
  padding: 32px 28px 24px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.welcome-copy {
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--blue-700);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.welcome-copy h1,
.fatal-card h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(27px, 7vw, 34px);
  font-weight: 800;
  letter-spacing: -0.045em;
  line-height: 1.16;
}

.welcome-copy > p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--input-bg);
}

.mode-tab {
  min-height: 42px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 750;
  transition: color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.mode-tab[aria-selected="true"] {
  color: var(--blue-700);
  background: #1a3040;
  box-shadow: inset 0 0 0 1px #2b5367;
}

.entry-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.conditional-fields {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field > label,
.manual-invite > label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.text-field,
.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--input-bg);
  transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.text-field:focus-within,
.select-wrap:focus-within {
  border-color: var(--blue-600);
  background: #101f2d;
  box-shadow: 0 0 0 3px rgba(76, 207, 232, 0.09);
}

.text-field input,
.select-wrap select {
  width: 100%;
  min-width: 0;
  height: 46px;
  border: 0;
  color: var(--ink);
  background: transparent;
  outline: none;
  font-size: 14px;
}

.text-field input {
  padding: 0 54px 0 42px;
}

.text-field--invite input {
  padding-right: 12px;
  font-size: 11px;
}

.field-icon {
  position: absolute;
  left: 14px;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  color: var(--blue-700);
  font-size: 15px;
  font-weight: 800;
  pointer-events: none;
}

.field-icon--person::before {
  width: 7px;
  height: 7px;
  border: 1.8px solid currentColor;
  border-radius: 50%;
  content: "";
  transform: translateY(-4px);
}

.field-icon--person::after {
  position: absolute;
  bottom: 0;
  width: 13px;
  height: 7px;
  border: 1.8px solid currentColor;
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
  content: "";
}

.field-count {
  position: absolute;
  right: 12px;
  color: var(--subtle);
  font-size: 11px;
  pointer-events: none;
}

.select-wrap select {
  appearance: none;
  padding: 0 38px 0 13px;
}

.select-wrap > span {
  position: absolute;
  right: 14px;
  color: var(--blue-700);
  pointer-events: none;
}

.field-help {
  margin: 0;
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.45;
}

.network-help {
  padding: 8px 10px;
  border-radius: 9px;
  background: var(--surface-raised);
}

.network-help[data-state="ready"] {
  color: var(--success);
  background: #102a26;
}

.network-help[data-state="error"] {
  color: var(--danger);
  background: #321d29;
}

.field-error {
  margin: -3px 0 0;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--danger);
  background: #321d29;
  font-size: 12px;
  line-height: 1.45;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 48px;
  padding: 0 17px;
  border-radius: 13px;
  color: #061923;
  background: linear-gradient(120deg, #7ce4ed, #46bfe9);
  box-shadow: 0 5px 22px rgba(39, 180, 229, 0.14);
  font-size: 14px;
  font-weight: 800;
  transition: transform 150ms ease, opacity 150ms ease, box-shadow 150ms ease;
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 11px 24px rgba(26, 126, 194, 0.29);
}

.primary-button:disabled,
.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  box-shadow: none;
}

.button-arrow {
  font-size: 20px;
  line-height: 1;
}

.trust-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.trust-note__icon {
  display: grid;
  flex: 0 0 27px;
  width: 27px;
  height: 27px;
  place-items: center;
  border-radius: 9px;
  color: var(--success);
  background: #102a26;
  font-size: 13px;
  font-weight: 900;
}

.trust-note p {
  display: grid;
  margin: 0;
  line-height: 1.28;
}

.trust-note strong {
  color: var(--muted);
  font-size: 12px;
}

.trust-note span:last-child {
  margin-top: 2px;
  color: var(--subtle);
  font-size: 11px;
}

.chat-card {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--chat-bg);
}

/* Keep the message pane flexible even when the invitation row is hidden. */
.chat-card > .chat-header { grid-row: 1; }
.chat-card > .manual-invite { grid-row: 2; }
.chat-card > .connection-banner { grid-row: 3; }
.chat-card > .messages-pane { grid-row: 4; }
.chat-card > .composer { grid-row: 5; }

.chat-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 84px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 100% 0, rgba(39, 180, 229, 0.1), transparent 70%),
    var(--surface);
}

.person__avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #326075;
  border-radius: 12px;
  color: var(--blue-700);
  background: var(--blue-100);
  box-shadow: inset 0 0 16px rgba(39, 180, 229, 0.05);
  font-size: 17px;
  font-weight: 800;
}

.person__copy {
  min-width: 0;
}

.person__copy h1 {
  margin: 0;
  overflow: hidden;
  font-size: 17px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.presence__dot,
.connection-banner__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--subtle);
}

.presence[data-online="true"] .presence__dot {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(104, 221, 183, 0.09);
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.leave-button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface-raised);
  font-size: 12px;
  white-space: nowrap;
}

.leave-button:hover:enabled { color: var(--ink); background: #203146; }
.leave-button:disabled { opacity: 0.55; cursor: wait; }

.room-members {
  grid-column: 1 / -1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.room-members summary { cursor: pointer; }

.room-members ul {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  max-height: 88px;
  margin: 10px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.room-members li { padding: 4px 8px; border-radius: 6px; background: var(--surface-raised); overflow-wrap: anywhere; }
.room-members li[data-online="false"] { color: var(--subtle); }

.room-code {
  max-width: 80px;
  overflow: hidden;
  color: var(--subtle);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 40px;
  place-items: center;
  border: 1px solid #31576b;
  border-radius: 10px;
  color: var(--blue-700);
  background: #142b3b;
  font-size: 17px;
  font-weight: 800;
  transition: background 150ms ease, transform 150ms ease;
}

.icon-button:hover:enabled {
  background: #1b3b4b;
  transform: translateY(-1px);
}

.copy-invite-button {
  width: 50px;
  font-size: 12px;
}

.manual-invite {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.manual-invite > div {
  display: flex;
  gap: 7px;
  margin-top: 5px;
}

.manual-invite input {
  min-width: 0;
  flex: 1;
  height: 40px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--input-bg);
  font-size: 12px;
}

.text-button {
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-size: 12px;
  font-weight: 750;
}

.text-button:hover:enabled,
.image-button:hover:enabled {
  background: #1b3b4b;
}

:is(.icon-button, .text-button, .image-button):disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.connection-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 28px;
  padding: 5px 12px;
  color: var(--muted);
  background: var(--input-bg);
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}

.connection-banner[data-state="connected"] {
  color: var(--success);
  background: #0e211f;
}

.connection-banner[data-state="connected"] .connection-banner__dot {
  background: var(--success);
}

.connection-banner[data-state="connecting"] .connection-banner__dot {
  background: var(--blue-500);
  animation: pulse 1.2s ease-in-out infinite;
}

.connection-banner[data-state="offline"] {
  color: #f2c481;
  background: #282219;
}

.connection-banner[data-state="offline"] .connection-banner__dot {
  background: #e5a24c;
}

@keyframes pulse {
  50% { opacity: 0.34; transform: scale(0.78); }
}

.messages-pane {
  position: relative;
  min-height: 0;
}

.messages-viewport {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  background:
    radial-gradient(circle at 1px 1px, rgba(118, 164, 192, 0.065) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--chat-bg);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
  margin: 0;
  padding: 20px 16px 28px;
  list-style: none;
}

.new-messages-button {
  position: absolute;
  z-index: 2;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 50%;
  min-height: 44px;
  max-width: calc(100% - 28px);
  padding: 10px 16px;
  border: 1px solid #31576b;
  border-radius: 999px;
  color: var(--blue-700);
  background: #152d3e;
  box-shadow: 0 7px 18px rgba(0, 0, 0, 0.28);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.2;
  transform: translateX(-50%);
}

.new-messages-button:hover {
  background: #1b3b4b;
}

.new-messages-button:focus-visible {
  outline: 2px solid var(--blue-700);
  outline-offset: 2px;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row--own {
  justify-content: flex-end;
}

.message-row--received {
  justify-content: flex-start;
}

.message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 0;
  max-width: 88%;
}

.message-row--own .message-content {
  align-items: flex-end;
}

.message-bubble {
  position: relative;
  min-width: 0;
  max-width: 100%;
  padding: 8px 10px;
  border: 1px solid #283b50;
  border-radius: 14px 14px 14px 5px;
  color: var(--ink);
  background: var(--surface-raised);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  outline: none;
}

.message-row--own .message-bubble {
  border-color: #28526b;
  border-radius: 14px 14px 5px 14px;
  background: var(--own-bubble);
}

.message-bubble--pending {
  border-style: dashed;
}

.message-bubble--error {
  border-color: #72404d;
  color: var(--danger);
  background: #2d1e2b;
}

.message-sender {
  margin: 0 0 4px;
  color: var(--blue-700);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.55;
}

.message-link {
  color: var(--blue-700);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.message-link:hover {
  color: var(--blue-800);
}

.message-link:focus-visible {
  border-radius: 2px;
  outline: 2px solid var(--blue-700);
  outline-offset: 2px;
}

.message-inline-emoji {
  display: inline-block;
  width: 26px;
  height: 26px;
  margin-inline: 1px;
  object-fit: contain;
  vertical-align: -0.4em;
}

.message-text--emoji-only {
  font-size: 28px;
  line-height: 1.35;
}

.message-text--emoji-only .message-inline-emoji {
  width: 36px;
  height: 36px;
  vertical-align: middle;
}

.message-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
}

.message-meta {
  display: flex;
  flex: 0 1 auto;
  min-width: 0;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.message-meta time {
  flex-shrink: 0;
  color: var(--subtle);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.message-status {
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-actions {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
}

.message-burn-button {
  min-width: 0;
  min-height: 28px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #f3b0ae;
  background: transparent;
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

.message-burn-button:hover:enabled {
  border-color: #a65d66;
  color: #ffd7d4;
  background: #3a2631;
}

.message-burn-button:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

.message-burn-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.message-reply-button {
  min-width: 0;
  min-height: 28px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--blue-700);
  background: transparent;
  font-size: 11px;
  white-space: nowrap;
}

.message-reply-button:hover:enabled {
  background: #1b3b4b;
}

.message-reply-button:focus-visible {
  outline: 2px solid var(--blue-700);
  outline-offset: 1px;
}

.message-reply-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.reply-preview {
  display: grid;
  gap: 3px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0 0 9px;
  padding: 7px 10px;
  border: 1px solid #315367;
  border-left: 3px solid var(--blue-600);
  border-radius: 6px;
  color: var(--muted);
  background: rgba(8, 20, 32, 0.55);
  text-align: left;
  font-size: 12px;
}

.reply-preview:hover:enabled {
  background: #183144;
}

.reply-preview:disabled {
  cursor: default;
}

.reply-preview__sender,
.reply-preview__text {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-preview__sender {
  color: var(--blue-700);
  font-weight: 700;
}

.message-sticker {
  display: block;
  width: 140px;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  object-fit: contain;
}

.message-row--highlight .message-bubble {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(76, 207, 232, 0.22);
}

.countdown-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 34px;
  height: 20px;
  padding: 0 4px;
  flex: 0 0 auto;
  border: 1px solid #2d5364;
  border-radius: 6px;
  color: var(--blue-700);
  background: #112e3d;
  font-variant-numeric: tabular-nums;
}

.countdown-ring svg {
  display: none;
}

.countdown-ring::after {
  content: "秒";
  font-size: 10px;
}

.countdown-ring__track,
.countdown-ring__progress {
  fill: none;
  stroke-width: 2.7;
}

.countdown-ring__track {
  stroke: rgba(91, 129, 151, 0.2);
}

.countdown-ring__progress {
  stroke: currentColor;
  stroke-linecap: round;
  transition: stroke 120ms ease;
}

.countdown-ring__text {
  position: relative;
  color: currentColor;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.countdown-ring--urgent {
  border-color: #72404d;
  color: var(--danger);
  background: #33212c;
}

.burned-notice {
  position: relative;
  isolation: isolate;
  padding: 6px 11px;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
}

.burned-notice::before,
.burned-notice::after {
  position: absolute;
  z-index: -1;
  border-radius: inherit;
  content: "";
  opacity: 0;
  pointer-events: none;
}

.burned-notice::before {
  inset: -5px -7px;
  background: radial-gradient(ellipse, rgba(255, 195, 104, 0.64), rgba(242, 123, 57, 0.18) 50%, transparent 74%);
}

.burned-notice::after {
  right: 5px;
  bottom: -2px;
  left: 5px;
  height: 15px;
  background:
    radial-gradient(ellipse at 26% 100%, rgba(255, 237, 164, 0.92), rgba(247, 155, 60, 0.48) 35%, transparent 66%),
    radial-gradient(ellipse at 74% 100%, rgba(255, 212, 116, 0.82), rgba(233, 113, 48, 0.28) 35%, transparent 66%);
  transform-origin: center bottom;
}

.burned-notice__label {
  position: relative;
  z-index: 1;
}

.burned-notice__embers {
  position: absolute;
  inset: 0 4px;
  pointer-events: none;
}

.burned-notice__embers i {
  position: absolute;
  bottom: 3px;
  left: var(--ember-left);
  width: 2px;
  height: 4px;
  border-radius: 50%;
  background: #ffd38a;
  box-shadow: 0 0 4px rgba(235, 130, 45, 0.7);
  opacity: 0;
}

.burned-notice__embers i:nth-child(1) { --ember-left: 12%; --ember-x: -8px; --ember-y: -20px; --ember-delay: 0ms; }
.burned-notice__embers i:nth-child(2) { --ember-left: 30%; --ember-x: -3px; --ember-y: -27px; --ember-delay: 35ms; }
.burned-notice__embers i:nth-child(3) { --ember-left: 47%; --ember-x: 5px; --ember-y: -23px; --ember-delay: 70ms; }
.burned-notice__embers i:nth-child(4) { --ember-left: 62%; --ember-x: -4px; --ember-y: -30px; --ember-delay: 95ms; }
.burned-notice__embers i:nth-child(5) { --ember-left: 77%; --ember-x: 8px; --ember-y: -22px; --ember-delay: 135ms; }
.burned-notice__embers i:nth-child(6) { --ember-left: 89%; --ember-x: 5px; --ember-y: -17px; --ember-delay: 170ms; }

/* Negative delays preserve the burn's progress when the message list is rebuilt. */
.burned-notice--animated::before {
  animation: burn-glow 640ms ease-out both;
  animation-delay: calc(0ms - var(--burn-elapsed, 0ms));
}

.burned-notice--animated::after {
  animation: burn-flame 580ms ease-out both;
  animation-delay: calc(0ms - var(--burn-elapsed, 0ms));
}

.burned-notice--animated .burned-notice__label {
  animation: burn-label 640ms ease-out both;
  animation-delay: calc(0ms - var(--burn-elapsed, 0ms));
}

.burned-notice--animated .burned-notice__embers i {
  animation: burn-ember 470ms cubic-bezier(0.16, 0.55, 0.4, 1) both;
  animation-delay: calc(var(--ember-delay) - var(--burn-elapsed, 0ms));
}

@keyframes burn-glow {
  0% { opacity: 0.7; transform: scale(0.92); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.15); }
}

@keyframes burn-flame {
  0% { opacity: 0.85; transform: translateY(0) scaleY(0.5); }
  28% { opacity: 0.75; transform: translateY(-4px) scaleY(1.1); }
  100% { opacity: 0; transform: translateY(-15px) scaleY(0.25); }
}

@keyframes burn-label {
  0% { color: #a56b38; }
  100% { color: var(--muted); }
}

@keyframes burn-ember {
  0% { opacity: 0; transform: translate3d(0, 3px, 0) rotate(-12deg) scale(0.6); }
  16% { opacity: 1; }
  55% { opacity: 0.7; }
  100% { opacity: 0; transform: translate3d(var(--ember-x), var(--ember-y), 0) rotate(45deg) scale(0.25); }
}

@media (prefers-reduced-motion: reduce) {
  .burned-notice--animated::before,
  .burned-notice--animated::after,
  .burned-notice--animated .burned-notice__label,
  .burned-notice--animated .burned-notice__embers i {
    animation: none !important;
  }

  .burned-notice__embers {
    display: none;
  }
}

.empty-chat {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-chat__mark {
  display: grid;
  width: 44px;
  height: 44px;
  margin-bottom: 11px;
  place-items: center;
  border: 1px solid #2e5268;
  border-radius: 15px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-size: 22px;
}

.empty-chat strong {
  color: var(--ink);
  font-size: 15px;
}

.empty-chat p {
  max-width: 280px;
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.7;
}

.composer {
  display: grid;
  grid-template-columns: 44px 44px minmax(0, 1fr) 44px;
  grid-template-areas:
    "picker picker picker picker"
    "reply reply reply reply"
    "image-draft image-draft image-draft image-draft"
    "image emoji input send";
  align-items: end;
  column-gap: 8px;
  min-width: 0;
  padding: 12px 14px 6px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.image-button {
  display: grid;
  grid-area: image;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid #31576b;
  border-radius: 11px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-size: 24px;
}

.emoji-button {
  display: grid;
  grid-area: emoji;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid #31576b;
  border-radius: 11px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-size: 26px;
  line-height: 1;
}

.emoji-button:hover:enabled,
.emoji-button[aria-expanded="true"] {
  border-color: var(--blue-600);
  background: #1b3b4b;
}

.emoji-button:disabled,
.emoji-item:disabled,
.emote-backspace-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.emote-picker {
  --emote-columns: 8;
  display: grid;
  grid-area: picker;
  grid-template-rows: 44px 76px minmax(0, 1fr) 44px;
  min-width: 0;
  height: 360px;
  max-height: min(360px, max(220px, calc(var(--app-viewport-height, 100dvh) - 310px)));
  margin-bottom: 10px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--input-bg);
}

.emote-picker button:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--blue-700);
  outline-offset: -3px;
}

.emote-picker__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding-left: 14px;
}

.emote-picker__heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.emote-picker__heading strong {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
}

.emote-hint {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--subtle);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emote-close-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
  touch-action: manipulation;
}

.emote-close-button:hover,
.emote-backspace-button:hover:enabled {
  color: var(--blue-700);
  background: #1b3b4b;
}

.emote-recent {
  min-width: 0;
  padding: 2px 8px 6px;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}

.emote-recent__label {
  display: block;
  height: 16px;
  padding-inline: 6px;
  color: var(--subtle);
  font-size: 10px;
  line-height: 16px;
}

.emote-picker__body {
  min-width: 0;
  min-height: 0;
  padding: 6px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.emote-backspace-button {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  touch-action: manipulation;
}

.emote-picker__footer {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding-inline: 14px 6px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.emote-scroll-hint {
  flex: 1;
  min-width: 0;
  color: var(--subtle);
  font-size: 10px;
}

.emote-empty,
.emote-empty-state {
  display: grid;
  grid-column: 1 / -1;
  min-height: 52px;
  padding: 8px;
  place-content: center;
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(var(--emote-columns), minmax(44px, 1fr));
  grid-auto-rows: 52px;
  gap: 2px 0;
  align-content: start;
}

.emoji-grid--recent {
  height: 52px;
  overflow: hidden;
}

.emote-recent-empty {
  grid-column: 1 / -1;
  align-self: center;
  margin: 0;
  padding-inline: 6px;
  color: var(--subtle);
  font-size: 11px;
}

.emoji-item {
  display: grid;
  min-width: 44px;
  min-height: 44px;
  padding: 6px 4px;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  font-size: 28px;
  line-height: 1;
  touch-action: manipulation;
}

.emoji-item img {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.emoji-item:hover:enabled {
  background: #1b3042;
}

.emoji-item:active:enabled {
  background: #244156;
}

.reply-draft {
  display: flex;
  grid-area: reply;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
  padding: 4px 6px 4px 10px;
  border-left: 3px solid var(--blue-600);
  border-radius: 6px;
  background: var(--blue-100);
}

.reply-draft__copy {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
  font-size: 12px;
}

.reply-draft__sender,
.reply-draft__text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-draft__sender {
  color: var(--blue-700);
  font-weight: 700;
}

.reply-draft__text {
  color: var(--muted);
}

.reply-draft button {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
}

.image-draft {
  grid-area: image-draft;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-bottom: 8px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  font-size: 12px;
}

.image-draft img { width: 48px; height: 48px; object-fit: contain; }
.image-draft span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.image-draft button { min-width: 44px; min-height: 44px; flex-shrink: 0; }

.message-image-button {
  display: block;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--input-bg);
}

.message-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(240px, 35dvh);
  object-fit: contain;
}

.image-viewer {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  border: 0;
  color: var(--ink);
  background: #080e18;
}

.image-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.image-viewer::backdrop { background: #080e18; }
.image-viewer__header { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.image-viewer__header h2 { flex: 1; min-width: 0; margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.image-viewer__header span { min-width: 0; color: var(--blue-700); font-size: 12px; overflow-wrap: anywhere; }
.image-viewer__header button { display: grid; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; place-items: center; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--ink); background: var(--surface-raised); }
.image-viewer__canvas {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  -webkit-overflow-scrolling: touch;
  outline: none;
}
.image-viewer__canvas:focus-visible {
  outline: 2px solid var(--blue-700);
  outline-offset: -2px;
}
.image-viewer__canvas[data-zoomed="true"] { cursor: grab; }
.image-viewer__canvas[data-dragging="true"] { cursor: grabbing; }
.image-viewer__stage {
  display: grid;
  min-width: 100%;
  min-height: 100%;
  place-items: center;
}
.image-viewer__canvas img {
  display: block;
  min-width: 0;
  min-height: 0;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}
.image-viewer__footer { padding: 8px 10px; border-top: 1px solid var(--line); background: var(--surface); text-align: center; }
.image-viewer__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.image-viewer__tools button {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #31576b;
  border-radius: 9px;
  color: var(--blue-700);
  background: var(--blue-100);
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  touch-action: manipulation;
}
.image-viewer__tools button:hover:enabled { background: #1b3b4b; }
.image-viewer__tools button[aria-pressed="true"] { border-color: var(--blue-600); background: #1b3b4b; }
.image-viewer__tools button:disabled { opacity: 0.5; cursor: not-allowed; }
.image-viewer__tools output {
  flex: 0 0 48px;
  min-width: 48px;
  color: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.image-viewer__footer p { margin: 6px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

html[data-mobile-viewport="true"] .image-viewer {
  top: var(--app-viewport-top, 0px);
  left: var(--app-viewport-left, 0px);
  right: auto;
  bottom: auto;
  width: var(--app-viewport-width, 100%);
  height: var(--app-viewport-height, 100dvh);
}

.composer textarea {
  grid-area: input;
  width: 100%;
  min-height: 44px;
  max-height: 112px;
  padding: 9px 12px;
  resize: none;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: var(--input-bg);
  outline: none;
  font-size: 16px;
  line-height: 1.5;
}

.composer textarea:focus {
  border-color: var(--blue-600);
  background: #101f2d;
  box-shadow: 0 0 0 3px rgba(76, 207, 232, 0.08);
}

.composer textarea::placeholder,
.text-field input::placeholder {
  color: var(--subtle);
  opacity: 1;
}

.send-button {
  display: grid;
  grid-area: send;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border-radius: 11px;
  color: #061923;
  background: linear-gradient(135deg, #7ce4ed, #46bfe9);
  box-shadow: 0 4px 16px rgba(39, 180, 229, 0.12);
  font-size: 22px;
  font-weight: 800;
  transition: transform 150ms ease, opacity 150ms ease;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

:is(.icon-button, .leave-button, .text-button, .image-button, .send-button, .primary-button):active:enabled {
  transform: translateY(1px);
}

.fatal-card {
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  padding: 34px 28px;
  overflow: auto;
  background:
    radial-gradient(circle at 100% 0, rgba(39, 180, 229, 0.1), transparent 38%),
    var(--surface);
}

.fatal-card__mark {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 22px;
  place-items: center;
  border-radius: 16px;
  color: var(--danger);
  background: #321d29;
  font-size: 22px;
  font-weight: 850;
}

.fatal-card > p:not(.eyebrow) {
  margin: 13px 0 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.fatal-card .primary-button {
  margin-top: 15px;
}

.toast-region {
  position: fixed;
  z-index: 20;
  left: calc(var(--app-viewport-left, 0px) + var(--app-viewport-width, 100vw) / 2);
  top: calc(var(--app-viewport-top, 0px) + max(12px, env(safe-area-inset-top)));
  max-width: min(330px, calc(var(--app-viewport-width, 100vw) - 28px));
  max-height: min(120px, max(44px, calc(var(--app-viewport-height, 100dvh) - 160px)));
  overflow: hidden;
  overflow-wrap: anywhere;
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 11px;
  color: var(--ink);
  background: #1c3345;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  font-size: 13px;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast-region[data-visible="true"] {
  opacity: 1;
  transform: translate(-50%, 0);
}

html[data-desktop="true"] body {
  padding: 0;
  background: var(--surface);
}

html[data-desktop="true"] .app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 0;
}

html[data-desktop="true"] .welcome-card,
html[data-desktop="true"] .chat-card,
html[data-desktop="true"] .fatal-card {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Follow the visible viewport when a mobile browser raises its keyboard. */
html[data-mobile-viewport="true"] body {
  padding: 0;
}

html[data-mobile-viewport="true"] .app-shell {
  position: fixed;
  top: var(--app-viewport-top, 0px);
  left: var(--app-viewport-left, 0px);
  width: var(--app-viewport-width, 100%);
  height: var(--app-viewport-height, 100dvh);
  min-height: 0;
}

html[data-mobile-viewport="true"] :is(.welcome-card, .chat-card, .fatal-card) {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

html[data-mobile-viewport="true"] .composer {
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
}

html[data-mobile-viewport="true"] :is(.copy-invite-button, .leave-button) {
  min-width: 44px;
  min-height: 44px;
}

html[data-mobile-viewport="true"] .emote-picker {
  height: 360px;
  max-height: min(360px, max(176px, calc(var(--app-viewport-height, 100dvh) - 240px)));
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .chat-header {
  min-height: 68px;
  padding: 8px 10px 6px;
  gap: 6px;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .person__avatar {
  width: 36px;
  height: 36px;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .composer {
  padding-bottom: max(4px, env(safe-area-inset-bottom));
}

html[data-mobile-viewport="true"][data-keyboard-open="true"] .composer {
  padding-bottom: 4px;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .composer textarea {
  max-height: 68px;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .emote-picker {
  grid-template-rows: 46px minmax(0, 1fr) 44px;
  height: 220px;
  max-height: min(220px, max(110px, calc(var(--app-viewport-height, 100dvh) - 230px)));
  margin-bottom: 6px;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) :is(.emote-picker__header, .emote-recent__label) {
  display: none;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .emote-recent {
  padding-block: 0;
}

html[data-mobile-viewport="true"]:is([data-keyboard-open="true"], [data-compact-viewport="true"]) .emoji-grid--recent {
  height: 44px;
  grid-auto-rows: 44px;
}

@media (max-width: 520px) {
  body {
    padding: 0;
  }

  .app-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
  }

  .welcome-card,
  .chat-card,
  .fatal-card {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chat-header {
    padding-top: max(14px, env(safe-area-inset-top));
    padding-inline: 14px;
    gap: 10px;
  }

  .room-code {
    display: none;
  }

  .messages-viewport .message-list {
    padding: 16px 12px 24px;
  }

  .message-content {
    max-width: 90%;
  }

  .composer {
    padding-inline: 10px;
  }

}

@media (max-width: 520px), (max-height: 680px) {
  .welcome-content {
    padding: 24px 22px 20px;
  }

  .welcome-copy {
    margin-bottom: 16px;
  }

  .entry-form {
    margin-top: 14px;
    gap: 12px;
  }
}

@media (max-width: 520px), (pointer: coarse) {
  .message-reply-button,
  .message-burn-button {
    min-width: 44px;
    min-height: 44px;
    padding-inline: 6px;
  }

  /* Small form text triggers focus zoom on mobile browsers, including iOS. */
  html:not([data-desktop="true"]) .text-field input,
  html:not([data-desktop="true"]) .select-wrap select,
  html:not([data-desktop="true"]) .manual-invite input,
  html:not([data-desktop="true"]) .composer textarea {
    font-size: 16px;
  }
}

@media (max-width: 360px) {
  .welcome-header {
    padding-inline: 15px;
  }

  .welcome-content {
    padding-inline: 16px;
  }

  .secure-pill {
    padding-inline: 7px;
    font-size: 10px;
  }

  .room-code {
    display: none;
  }

}

@media (max-height: 480px) {
  .chat-header {
    padding-block: 8px;
    min-height: 68px;
    row-gap: 6px;
  }

  .composer {
    padding-top: 6px;
  }

}

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