:root {
  color-scheme: dark;
  --bg: #15120f;
  --bg-soft: #1c1814;
  --panel: #211c18;
  --panel-strong: #2a231e;
  --line: rgba(255, 255, 255, .085);
  --text: #f7f2ea;
  --muted: #aba198;
  --accent: #e7a66d;
  --accent-strong: #f2b77f;
  --accent-ink: #2e1a0c;
  --mine: #5d3b26;
  --other: #28221d;
  --read: #efad72;
  --danger: #ef8c86;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background:
    radial-gradient(circle at 50% -10%, rgba(154, 101, 61, .22), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.hidden { display: none !important; }
.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.login {
  height: 100dvh;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, var(--safe-bottom));
}
.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(145deg, rgba(45, 37, 31, .96), rgba(26, 22, 18, .98));
  box-shadow: 0 30px 90px rgba(0, 0, 0, .4);
}
.brand-mark {
  position: relative;
  width: 58px;
  height: 58px;
  margin-bottom: 24px;
  border-radius: 19px;
  background: linear-gradient(145deg, var(--accent-strong), #be7441);
  box-shadow: 0 12px 30px rgba(189, 116, 65, .24);
}
.brand-mark span {
  position: absolute;
  top: 19px;
  width: 20px;
  height: 20px;
  border: 3px solid var(--accent-ink);
  border-radius: 50%;
}
.brand-mark span:first-child { left: 12px; }
.brand-mark span:last-child { right: 12px; }
.login h1 { margin: 0; font-size: clamp(30px, 8vw, 40px); letter-spacing: -.04em; }
.login-copy { max-width: 320px; margin: 10px 0 28px; color: var(--muted); line-height: 1.5; }
.login label { display: block; margin: 15px 0 7px; color: #c8beb4; font-size: 13px; font-weight: 650; }
.login input, .caption-input {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(10, 8, 7, .54);
  color: var(--text);
  padding: 0 15px;
}
.login input:focus, .caption-input:focus { border-color: rgba(231, 166, 109, .75); outline: 0; }
.form-error { min-height: 20px; margin-top: 13px; color: var(--danger); font-size: 13px; text-align: center; }

.primary, .secondary, .danger-btn {
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 750;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { background: var(--accent-strong); }
.primary:disabled { opacity: .45; cursor: default; }
.secondary { border: 1px solid var(--line); background: var(--panel-strong); color: var(--text); }
.wide { width: 100%; margin-top: 22px; }

.app {
  position: relative;
  width: min(100%, 860px);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 80% 2%, rgba(126, 78, 48, .16), transparent 36%),
    var(--bg);
  border-inline: 1px solid rgba(255, 255, 255, .035);
}
.topbar {
  z-index: 5;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(21, 18, 15, .84);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
}
.peer { min-width: 0; display: flex; align-items: center; gap: 11px; }
.avatar {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 50%;
  background: linear-gradient(145deg, #785038, #422d21);
  color: #fff5e9;
  font-weight: 800;
}
.avatar.large { width: 50px; height: 50px; font-size: 18px; }
.peer-copy { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.peer-copy strong { overflow: hidden; text-overflow: ellipsis; font-size: 16px; }
.peer-copy span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.peer-copy span.online { color: #a9caa8; }
.unread-badge {
  display: inline-grid;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 10px;
}
.icon-btn, .close-btn {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  cursor: pointer;
}
.icon-btn span { position: relative; top: -4px; font-size: 22px; letter-spacing: 1px; }

.connection {
  flex: 0 0 auto;
  padding: 7px 14px;
  background: #6f3a31;
  color: #fff0e9;
  font-size: 12px;
  text-align: center;
}
.messages {
  flex: 1 1 auto;
  overflow: hidden auto;
  padding: 16px 12px 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .13) transparent;
  overscroll-behavior-y: contain;
}
.day {
  width: max-content;
  margin: 14px auto 18px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, .055);
  border-radius: 999px;
  background: rgba(17, 14, 12, .72);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.unread-separator {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 18px 0;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
}
.unread-separator::before, .unread-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(231, 166, 109, .35);
}
.message-row { display: flex; margin: 4px 0; animation: message-in .18s ease-out; }
.message-row.highlight .bubble { animation: highlight-message 1.2s ease; }
.message-row.mine { justify-content: flex-end; }
.bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 9px 11px 7px;
  border: 1px solid rgba(255, 255, 255, .045);
  border-radius: 18px 18px 18px 6px;
  background: var(--other);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .11);
  overflow: hidden;
}
.mine .bubble { border-radius: 18px 18px 6px 18px; background: var(--mine); }
.bubble.selected { border-color: rgba(231, 166, 109, .38); }
.reply-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: -2px 0 7px;
  padding: 6px 8px;
  overflow: hidden;
  border: 0;
  border-left: 2px solid var(--accent);
  border-radius: 5px;
  background: rgba(0, 0, 0, .16);
  color: var(--text);
  text-align: left;
}
.reply-preview strong { color: var(--accent-strong); font-size: 11px; }
.reply-preview span { overflow: hidden; color: rgba(255, 255, 255, .68); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.deleted-message { padding: 3px 5px; color: rgba(255, 255, 255, .48); font-size: 13px; font-style: italic; }
.message-text { min-width: 42px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.message-photo {
  display: block;
  width: min(360px, 65vw);
  max-height: 430px;
  margin: -5px -7px 6px;
  border: 0;
  border-radius: 14px;
  object-fit: cover;
  cursor: zoom-in;
  background: rgba(0, 0, 0, .18);
}
.message-meta {
  min-height: 15px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 5px;
  margin: 3px 0 -1px 8px;
  color: rgba(255, 255, 255, .57);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
}
.message-status { min-width: 15px; font-size: 12px; letter-spacing: -3px; }
.message-status.read { color: var(--read); }
.message-status.failed { color: var(--danger); letter-spacing: 0; }
.retry-btn {
  margin-left: 4px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: #ffc1bc;
  font-size: 11px;
  text-decoration: underline;
  cursor: pointer;
}
.message-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.message-reactions button {
  min-width: 37px;
  min-height: 25px;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, .16);
  color: var(--text);
  font-size: 11px;
}
.message-reactions button.mine { border-color: rgba(231, 166, 109, .52); background: rgba(231, 166, 109, .14); }
.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px -3px -2px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.message-action {
  min-width: 32px;
  height: 30px;
  padding: 0 7px;
  border: 0;
  border-radius: 9px;
  background: rgba(0, 0, 0, .18);
  color: var(--text);
  font-size: 14px;
}
.message-action.danger { color: #ffaaa4; }
.typing {
  flex: 0 0 auto;
  min-height: 23px;
  padding: 4px 18px 2px;
  color: var(--accent);
  font-size: 12px;
}
.composer-context {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: rgba(33, 28, 24, .97);
}
.composer-context > div { min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-left: 9px; border-left: 2px solid var(--accent); }
.composer-context strong { color: var(--accent); font-size: 11px; }
.composer-context span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.composer-context button { flex: 0 0 auto; width: 36px; height: 36px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 22px; }
.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 9px 11px calc(9px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(21, 18, 15, .94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.composer textarea {
  flex: 1 1 auto;
  width: 0;
  min-height: 44px;
  max-height: 132px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  color: var(--text);
  padding: 11px 15px;
  line-height: 20px;
}
.composer textarea::placeholder { color: #847b73; }
.composer textarea:focus { border-color: rgba(231, 166, 109, .5); outline: 0; }
.composer-btn, .send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.composer-btn { background: var(--panel-strong); color: var(--text); font-size: 25px; }
.send-btn { background: var(--accent); color: var(--accent-ink); font-size: 25px; font-weight: 800; }
.new-messages {
  position: absolute;
  z-index: 4;
  right: 16px;
  bottom: calc(76px + var(--safe-bottom));
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  background: #33281f;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .32);
  font-size: 12px;
  font-weight: 750;
}

.modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: end center;
}
.modal-backdrop, .lightbox-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(3, 2, 2, .68);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.sheet {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  max-height: min(86dvh, 720px);
  overflow-y: auto;
  padding: 14px 20px calc(22px + var(--safe-bottom));
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 28px 28px 0 0;
  background: #201b17;
  box-shadow: 0 -20px 70px rgba(0, 0, 0, .38);
  animation: sheet-in .22s ease-out;
}
.sheet-handle { width: 38px; height: 4px; margin: 0 auto 17px; border-radius: 4px; background: rgba(255, 255, 255, .15); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 20px; }
.sheet-head h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.close-btn { flex: 0 0 auto; font-size: 25px; }
.settings-user { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 18px; background: var(--panel-strong); }
.settings-user div:last-child { display: flex; flex-direction: column; gap: 3px; }
.settings-user span, .setting-row span { color: var(--muted); font-size: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 2px; border-bottom: 1px solid var(--line); }
.setting-row > div { display: flex; flex-direction: column; gap: 4px; }
.hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.settings-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.settings-actions button { height: 62px; padding: 7px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; }
.settings-actions button span { color: var(--accent); font-size: 20px; }
.danger-btn { width: 100%; margin-top: 28px; border: 1px solid rgba(239, 140, 134, .19); background: rgba(134, 52, 48, .18); color: #f3a29d; }
.version { margin-top: 15px; color: #7d756e; font-size: 11px; text-align: center; }
.preview-sheet { padding-top: 22px; }
.preview-loader { min-height: 220px; display: grid; place-items: center; border-radius: 18px; background: #17130f; color: var(--muted); }
.preview-image { display: block; width: 100%; max-height: 52dvh; border-radius: 18px; object-fit: contain; background: #100d0b; }
.caption-input { margin-top: 12px; background: #17130f; }
.preview-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 15px; }
.gallery-sheet { width: min(100%, 680px); }
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #110e0c;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item span {
  position: absolute;
  inset: auto 0 0;
  padding: 18px 6px 6px;
  overflow: hidden;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72));
  color: #fff;
  font-size: 9px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.empty-state { margin: 28px 0; color: var(--muted); line-height: 1.45; text-align: center; }
.sessions-list { display: grid; gap: 9px; }
.session-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel-strong); }
.session-card > div { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.session-card strong { font-size: 13px; }
.session-card span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.danger-small { min-height: 36px; padding: 0 11px; border: 1px solid rgba(239, 140, 134, .18); border-radius: 11px; background: rgba(134, 52, 48, .18); color: #f3a29d; font-size: 11px; }

.lightbox {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(54px, env(safe-area-inset-top)) 12px max(20px, var(--safe-bottom));
}
.lightbox-backdrop { background: rgba(0, 0, 0, .92); backdrop-filter: blur(12px); }
.lightbox img { position: relative; z-index: 1; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lightbox-close {
  position: absolute;
  z-index: 2;
  top: max(10px, env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 50%;
  background: rgba(20, 20, 20, .68);
  color: #fff;
  font-size: 28px;
}
.lightbox-nav {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: 46px;
  height: 54px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 15px;
  background: rgba(20, 20, 20, .55);
  color: #fff;
  font-size: 34px;
}
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }
.lightbox-counter {
  position: absolute;
  z-index: 2;
  bottom: max(12px, var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(10, 10, 10, .6);
  color: #fff;
  font-size: 11px;
}
.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  bottom: calc(92px + var(--safe-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: 11px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #332821;
  color: var(--text);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .35);
  font-size: 13px;
}

@keyframes message-in { from { opacity: 0; transform: translateY(5px); } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: .5; } }
@keyframes highlight-message { 0%, 100% { box-shadow: 0 4px 16px rgba(0, 0, 0, .11); } 35% { box-shadow: 0 0 0 3px rgba(231, 166, 109, .45); } }

@media (min-width: 700px) {
  .app { box-shadow: 0 0 80px rgba(0, 0, 0, .24); }
  .sheet { align-self: center; border-bottom: 1px solid var(--line); border-radius: 28px; padding-bottom: 24px; }
  .modal { place-items: center; padding: 20px; }
  .bubble { max-width: min(70%, 560px); }
}
@media (max-width: 420px) {
  .login-card { padding: 28px 22px; }
  .bubble { max-width: 84%; }
  .messages { padding-inline: 9px; }
  .lightbox-nav { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; }
}
