:root {
  color-scheme: light;
  --app-height: 100dvh;
  --bg: #ffffff;
  --bg-soft: #f8fbff;
  --panel: rgba(255, 255, 255, 0.92);
  --panel-strong: #ffffff;
  --text: #132238;
  --muted: #66768d;
  --line: rgba(28, 52, 84, 0.12);
  --blue: #2d7ff9;
  --blue-strong: #1c5fd4;
  --pink: #ff5fa2;
  --sent-grad: linear-gradient(135deg, #2d7ff9, #ff5fa2);
  --shadow: 0 14px 32px rgba(39, 86, 153, 0.12);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 72px;
  --composer-h: 78px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgba(45, 127, 249, 0.13), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 95, 162, 0.14), transparent 24%),
    linear-gradient(180deg, #ffffff, #f6fbff 58%, #fdf7fb);
  color: var(--text);
  font-family: "Manrope", system-ui, sans-serif;
}

body {
  min-height: var(--app-height);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
}

#lock {
  min-height: var(--app-height);
  place-items: center;
  padding: 24px;
}

.lock-card {
  width: min(100%, 380px);
  padding: 28px 22px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(18px);
}

.lock-badge,
.role-chip,
.message-reply-label,
.unread-marker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.lock-badge,
.role-chip {
  background: rgba(45, 127, 249, 0.12);
  color: var(--blue-strong);
}

.lock-copy {
  margin: 10px 0 18px;
  color: var(--muted);
}

#pass,
.composer-input {
  width: 100%;
  border: 1px solid rgba(26, 70, 130, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

#pass {
  padding: 15px 16px;
  margin-bottom: 14px;
}

#pass:focus,
.composer-input:focus {
  border-color: rgba(45, 127, 249, 0.38);
  box-shadow: 0 0 0 4px rgba(45, 127, 249, 0.08);
}

.primary-btn,
.icon-btn {
  border: 0;
  transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

.primary-btn:active,
.icon-btn:active {
  transform: scale(0.96);
}

.primary-btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 16px;
  color: #fff;
  background: var(--sent-grad);
  box-shadow: 0 12px 24px rgba(45, 127, 249, 0.22);
}

#chatApp {
  min-height: var(--app-height);
  grid-template-rows: auto 1fr auto auto;
  background: transparent;
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  height: calc(var(--header-h) + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}

.header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(45, 127, 249, 0.16), rgba(255, 95, 162, 0.24));
  color: var(--blue-strong);
  display: grid;
  place-items: center;
  font-size: 22px;
}

.header-copy {
  min-width: 0;
}

.header-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-line {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: rgba(45, 127, 249, 0.08);
  color: var(--blue-strong);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
}

.chat-viewport {
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  left: 0;
  right: 0;
  bottom: calc(var(--composer-h) + var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 18px;
  scroll-behavior: smooth;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 100%;
  contain: layout paint;
}

.virtual-spacer {
  flex: none;
  width: 100%;
}

.load-older {
  width: 100%;
  max-width: 190px;
  margin: 2px auto 12px;
  min-height: 36px;
  border-radius: 999px;
  background: rgba(45, 127, 249, 0.08);
  color: var(--blue-strong);
}

.reply-bar,
.composer-meta,
.composer {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 25;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.reply-bar {
  bottom: calc(var(--composer-h) + var(--safe-bottom));
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.reply-copy {
  min-width: 0;
}

#replyTitle {
  display: block;
  color: var(--blue-strong);
  font-size: 12px;
  font-weight: 700;
}

#replyText {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-meta {
  bottom: calc(var(--composer-h) + var(--safe-bottom));
  padding: 8px 14px;
  color: var(--pink);
  font-size: 12px;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.composer {
  bottom: 0;
  min-height: calc(var(--composer-h) + var(--safe-bottom));
  padding: 10px 10px calc(10px + var(--safe-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px 44px 52px;
  gap: 8px;
  border-top: 1px solid var(--line);
}

.composer-input {
  min-height: 52px;
  padding: 0 16px;
}

.send-btn {
  min-height: 52px;
  padding: 0;
}

.chat-day {
  display: flex;
  justify-content: center;
  margin: 10px 0 12px;
}

.chat-day span,
.unread-marker {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 10px 18px rgba(45, 127, 249, 0.08);
  color: var(--muted);
}

.unread-marker {
  justify-content: center;
  margin: 10px auto;
  color: var(--pink);
  background: #fff6fb;
}

.message-row {
  display: flex;
  margin: 2px 0;
}

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

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

.message-cluster {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(84%, 440px);
}

.message-row.river .message-cluster {
  flex-direction: row-reverse;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(45, 127, 249, 0.12), rgba(255, 95, 162, 0.16));
  display: grid;
  place-items: center;
  font-size: 18px;
  flex: none;
}

.avatar.hidden {
  visibility: hidden;
}

.bubble-stack {
  min-width: 0;
}

.sender-name {
  margin: 0 0 4px 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.message-bubble {
  position: relative;
  padding: 10px 12px 8px;
  border-radius: 22px;
  box-shadow: 0 12px 18px rgba(30, 68, 120, 0.08);
  overflow: hidden;
}

.message-row.volcano .message-bubble {
  background: #ffffff;
  border: 1px solid rgba(25, 58, 95, 0.08);
  border-bottom-left-radius: 8px;
}

.message-row.river .message-bubble {
  color: #fff;
  background: var(--sent-grad);
  border-bottom-right-radius: 8px;
}

.message-reply {
  margin-bottom: 8px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.2);
}

.message-row.volcano .message-reply {
  background: rgba(45, 127, 249, 0.08);
}

.message-reply-label {
  padding: 0;
  background: transparent;
  color: inherit;
}

.message-text,
.deleted-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.45;
}

.deleted-text {
  font-style: italic;
  opacity: 0.78;
}

.media-thumb {
  display: block;
  margin-top: 6px;
  max-width: min(220px, 100%);
  width: 100%;
  border-radius: 16px;
  object-fit: cover;
  background: #eef5ff;
  min-height: 120px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
  min-height: 18px;
}

.meta-left,
.meta-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.meta-left {
  color: inherit;
  opacity: 0.78;
  font-size: 11px;
}

.message-row.volcano .meta-left,
.message-row.volcano .meta-right {
  color: var(--muted);
}

.status-check {
  font-size: 12px;
  letter-spacing: -1px;
}

.status-check.seen {
  color: #d8f0ff;
}

.reactions-bar,
.reaction-picker,
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.reaction-picker {
  display: none;
}

.message-row.expanded .reaction-picker {
  display: flex;
}

.action-chip,
.reaction-chip,
.reaction-picker button {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
  font-size: 12px;
}

.message-row.volcano .action-chip,
.message-row.volcano .reaction-chip,
.message-row.volcano .reaction-picker button {
  background: rgba(45, 127, 249, 0.06);
  color: var(--blue-strong);
  border-color: rgba(45, 127, 249, 0.12);
}

.reaction-chip.active {
  background: rgba(255, 255, 255, 0.3);
  font-weight: 700;
}

.message-row.volcano .reaction-chip.active {
  background: rgba(255, 95, 162, 0.12);
  border-color: rgba(255, 95, 162, 0.18);
  color: #b62e70;
}

.audio-player {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.audio-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: inherit;
}

.message-row.volcano .audio-toggle {
  background: rgba(45, 127, 249, 0.08);
}

.audio-progress {
  width: 100%;
}

.typing-indicator {
  padding: 8px 12px;
  margin: 6px 0 10px 44px;
  width: fit-content;
  border-radius: 16px;
  background: #ffffff;
  color: var(--muted);
  border: 1px solid rgba(25, 58, 95, 0.08);
  box-shadow: 0 10px 18px rgba(45, 127, 249, 0.07);
  font-size: 13px;
}

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

@media (max-width: 420px) {
  .message-cluster {
    max-width: 90%;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 42px 42px 48px;
  }
}
