:root {
  --ink: #2e2926;
  --muted: #8d8179;
  --paper: #f7f3ee;
  --card: rgba(255, 253, 249, .92);
  --rose: #b86f72;
  --rose-dark: #98575c;
  --rose-pale: #ead4d1;
  --line: #e5dcd4;
  --shadow: 0 24px 70px rgba(74, 53, 45, .13);
  --app-height: 100dvh;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; }
body {
  color: var(--ink);
  background: var(--paper);
  font-family: "Alexandria", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
.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; }

.login-page {
  background:
    radial-gradient(circle at 16% 17%, rgba(207, 161, 157, .28), transparent 27%),
    radial-gradient(circle at 83% 78%, rgba(190, 157, 126, .17), transparent 32%),
    #f5f0ea;
  overflow-x: hidden;
  overflow-y: auto;
}
.login-page::before, .login-page::after {
  content: ""; position: fixed; border: 1px solid rgba(184,111,114,.17); border-radius: 50%; pointer-events: none;
}
.login-page::before { width: 420px; height: 420px; top: -240px; right: -100px; }
.login-page::after { width: 580px; height: 580px; bottom: -390px; left: -160px; }
.login-shell {
  min-height: 100vh; min-height: 100svh; min-height: var(--app-height); display: grid; place-items: center;
  padding: max(28px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) max(28px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left));
  position: relative;
}
.login-card {
  width: min(100%, 430px); padding: 48px 46px 38px; text-align: center; background: var(--card);
  border: 1px solid rgba(255,255,255,.85); box-shadow: var(--shadow); border-radius: 4px 42px 4px 42px; position: relative; z-index: 2;
}
.brand-mark {
  width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 22px; color: white;
  background: var(--rose); border-radius: 50% 50% 50% 12%; font-family: "Playfair Display", serif; font-size: 34px;
  box-shadow: 0 10px 24px rgba(184,111,114,.3); transform: rotate(-4deg);
}
.eyebrow { color: var(--rose); font-size: 11px; font-weight: 600; letter-spacing: .18em; margin: 0 0 8px; }
.login-card h1 { font-family: "Playfair Display", serif; font-size: clamp(42px, 10vw, 56px); margin: 0; font-weight: 600; line-height: 1.1; }
.login-copy { color: var(--muted); font-size: 13px; line-height: 1.9; max-width: 290px; margin: 17px auto 30px; }
.login-form { text-align: right; }
.login-form label { display: block; font-size: 11px; margin: 0 3px 9px; color: #675e58; }
.password-wrap { position: relative; }
.password-wrap input {
  width: 100%; height: 54px; border: 1px solid var(--line); border-radius: 14px; padding: 0 18px 0 48px; background: #fffdfa;
  outline: none; transition: .2s ease; font-size: 13px;
}
.password-wrap input:focus { border-color: var(--rose); box-shadow: 0 0 0 4px rgba(184,111,114,.09); }
.password-wrap input::placeholder { color: #b3a9a2; }
.reveal-button { position: absolute; left: 8px; top: 7px; width: 40px; height: 40px; border: 0; background: transparent; color: #aa9f98; }
.reveal-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.reveal-button.is-visible { color: var(--rose); }
.primary-button {
  width: 100%; height: 54px; border: 0; border-radius: 14px; margin-top: 16px; background: var(--rose); color: white; font-size: 13px;
  box-shadow: 0 10px 22px rgba(184,111,114,.25); transition: .2s ease;
}
.primary-button:hover { background: var(--rose-dark); transform: translateY(-1px); }
.primary-button span { margin-right: 8px; font-size: 18px; }
.form-error { color: #a84047; font-size: 11px; margin: 8px 4px -8px; }
.privacy-note { color: #aaa098; font-size: 9px; margin: 25px 0 0; }
.privacy-note span { color: var(--rose); }
.decorative-word { position: fixed; left: 4vw; bottom: -7vw; font: italic 600 30vw/.8 "Playfair Display", serif; color: rgba(184,111,114,.045); }

.chat-page { width: 100%; height: 100vh; height: var(--app-height); overflow: hidden; overscroll-behavior: none; background: #eee8e2; }
.chat-shell {
  width: min(100%, 880px); height: 100%; min-height: 0; margin: auto; background: #faf7f3;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto; box-shadow: 0 0 60px rgba(60,42,35,.12); overflow: hidden;
}
.chat-header {
  min-height: calc(78px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(26px, env(safe-area-inset-right)) 0 max(26px, env(safe-area-inset-left));
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; background: rgba(255,253,250,.94);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); z-index: 3;
}
.person { min-width: 0; display: flex; align-items: center; gap: 11px; }
.avatar { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50% 50% 50% 12px; display: grid; place-items: center; background: var(--rose-pale); color: var(--rose-dark); font-weight: 600; }
.person p { margin: 0; }
.person-name { font-size: 13px; font-weight: 600; }
.presence { color: var(--muted); font-size: 9px; margin-top: 4px !important; }
.presence span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #7eaa86; margin-left: 3px; }
.header-brand { font: italic 600 25px "Playfair Display", serif; }
.header-brand span { color: var(--rose); font-size: 13px; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 2px; }
.icon-button, .composer-action, .send-button { display: grid; place-items: center; border: 0; background: transparent; }
.icon-button { width: 40px; height: 40px; border-radius: 12px; color: #958a83; }
.icon-button:hover { background: #f4ece7; color: var(--rose); }
.owner-button { color: var(--rose); }
.delete-menu-wrap { position: relative; }
.delete-menu {
  position: absolute; z-index: 10; top: 47px; left: 0; width: 190px; padding: 8px; border: 1px solid var(--line);
  border-radius: 14px; background: #fffdfa; box-shadow: 0 16px 40px rgba(61,44,38,.16); text-align: right;
}
.delete-menu[hidden] { display: none; }
.delete-menu p { margin: 4px 8px 7px; color: var(--muted); font-size: 9px; }
.delete-menu button { width: 100%; border: 0; border-radius: 9px; padding: 10px; background: transparent; color: var(--ink); text-align: right; font-size: 10px; }
.delete-menu button:hover { background: #f5efea; }
.delete-menu button.danger { color: #a33f47; }
.icon-button svg, .composer-action svg, .send-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.messages {
  min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch;
  padding: 30px max(17px, env(safe-area-inset-right)) 30px max(17px, env(safe-area-inset-left));
  scroll-behavior: smooth; scroll-padding-block: 18px; background: radial-gradient(circle at 50% 10%, rgba(230,210,201,.26), transparent 42%);
}
.empty-state { height: 100%; min-height: 300px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.empty-state div { color: var(--rose); font-size: 18px; margin-bottom: 14px; opacity: .7; }
.empty-state p { font: italic 600 25px "Playfair Display", serif; margin: 0 0 6px; color: #5c514b; }
.empty-state span { font-size: 10px; }
.message { display: flex; margin: 8px 0; animation: message-in .28s ease both; }
.message.mine { justify-content: flex-start; }
.message.theirs { justify-content: flex-end; }
.bubble { position: relative; max-width: min(76%, 540px); padding: 11px 14px 8px; border-radius: 18px; box-shadow: 0 5px 16px rgba(61,44,38,.06); }
.mine .bubble { color: white; background: var(--rose); border-bottom-right-radius: 5px; }
.theirs .bubble { background: #fff; border: 1px solid #eee6df; border-bottom-left-radius: 5px; }
.bubble p { margin: 0; font-size: 13px; line-height: 1.75; overflow-wrap: anywhere; }
.bubble time { display: block; direction: ltr; text-align: left; font-size: 8px; margin-top: 4px; opacity: .7; }
.bubble time [data-receipt] { display: inline-block; letter-spacing: -2px; opacity: .72; transition: color .2s ease, opacity .2s ease; }
.bubble time [data-receipt].seen { color: #fff; opacity: 1; font-weight: 700; }
.message-delete {
  position: absolute; top: -7px; left: -7px; width: 21px; height: 21px; display: grid; place-items: center; padding: 0;
  border: 1px solid #eaded7; border-radius: 50%; background: #fffdfa; color: #a56a6d; box-shadow: 0 3px 9px rgba(61,44,38,.12);
  font: 16px/1 system-ui, sans-serif; opacity: 0; transition: opacity .15s ease, transform .15s ease;
}
.message:hover .message-delete, .message-delete:focus-visible { opacity: 1; }
.message-delete:hover { transform: scale(1.08); color: #a33f47; }
.message.image .bubble { padding: 5px; overflow: hidden; }
.message.image img { display: block; max-width: 100%; width: min(300px, calc(100vw - 92px)); max-height: min(360px, 52vh); object-fit: cover; border-radius: 14px; }
.message.image time { padding: 0 6px 3px; }
.audio-message { display: flex; align-items: center; gap: 10px; min-width: min(240px, calc(100vw - 104px)); direction: ltr; }
.audio-play { width: 34px; height: 34px; border: 0; border-radius: 50%; background: rgba(255,255,255,.22); color: inherit; }
.theirs .audio-play { background: var(--rose-pale); color: var(--rose-dark); }
.audio-track { height: 3px; background: rgba(255,255,255,.35); flex: 1; border-radius: 5px; overflow: hidden; }
.theirs .audio-track { background: #eadfd8; }
.audio-track span { display: block; width: 0; height: 100%; background: currentColor; }
@keyframes message-in { from { opacity: 0; transform: translateY(5px); } }

.composer-shell {
  background: rgba(255,253,250,.96); border-top: 1px solid var(--line);
  padding: 12px max(13px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(13px, env(safe-area-inset-left));
}
.composer { min-height: 52px; display: flex; align-items: flex-end; gap: 3px; background: #f5f0eb; border: 1px solid #ebe1da; border-radius: 18px; padding: 6px; }
.composer textarea { flex: 1; min-width: 0; height: 39px; max-height: 120px; resize: none; border: 0; outline: 0; background: transparent; padding: 10px 9px; font-size: 12px; line-height: 1.6; color: var(--ink); }
.composer textarea::placeholder { color: #aaa098; }
.composer-action { flex: 0 0 40px; height: 40px; border-radius: 12px; color: #968a82; }
.composer-action:hover { color: var(--rose); background: #eee5df; }
.composer-action.recording { color: #fff; background: var(--rose); }
.send-button { flex: 0 0 40px; height: 40px; border-radius: 12px; background: var(--rose); color: white; box-shadow: 0 5px 12px rgba(184,111,114,.25); }
.send-button:hover { background: var(--rose-dark); }
.send-button svg { transform: rotate(2deg); }
.recording-bar { align-items: center; gap: 8px; color: var(--rose-dark); font-size: 10px; padding: 1px 8px 10px; }
.recording-bar:not([hidden]) { display: flex; }
.record-dot { width: 7px; height: 7px; border-radius: 50%; background: #c84951; animation: blink 1s infinite; }
.recording-bar strong { direction: ltr; font-size: 10px; }
.recording-bar button { margin-right: auto; border: 0; color: #9a6265; background: transparent; font-size: 10px; }
.upload-status { min-height: 12px; margin: 4px 8px -6px; color: var(--rose-dark); font-size: 9px; line-height: 1.4; }
@keyframes blink { 50% { opacity: .28; } }

@media (max-width: 560px) {
  .login-shell { padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .login-card { padding: 38px 24px 30px; border-radius: 4px 34px 4px 34px; }
  .password-wrap input { font-size: 16px; }
  .chat-header {
    min-height: calc(66px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  }
  .header-brand { font-size: 21px; }
  .person-name { font-size: 12px; }
  .icon-button { width: 42px; height: 42px; }
  .bubble { max-width: 86%; }
  .bubble p { font-size: 13px; }
  .messages { padding-top: 18px; padding-bottom: 18px; }
  .composer-shell { padding-top: 9px; }
  .composer textarea { font-size: 16px; line-height: 1.35; padding-block: 9px; }
  .message-delete { width: 30px; height: 30px; top: -10px; left: -10px; opacity: .72; }
  .delete-menu button { min-height: 44px; font-size: 11px; }
}

@media (max-width: 390px) {
  .login-card { padding: 32px 20px 26px; }
  .brand-mark { width: 54px; height: 54px; margin-bottom: 17px; font-size: 30px; }
  .login-card h1 { font-size: 39px; }
  .login-copy { margin: 13px auto 22px; font-size: 12px; }
  .privacy-note { margin-top: 19px; line-height: 1.6; }
  .chat-header { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .avatar { flex-basis: 36px; width: 36px; height: 36px; }
  .person { gap: 7px; }
  .presence { font-size: 8px; }
  .header-brand { font-size: 19px; }
  .header-brand span { display: none; }
  .header-actions { gap: 0; }
  .icon-button { width: 38px; height: 40px; }
  .composer-shell {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }
  .composer { gap: 0; padding: 5px; }
  .composer-action, .send-button { flex-basis: 38px; width: 38px; height: 40px; }
  .composer textarea { padding-inline: 6px; }
  .bubble { max-width: 90%; }
  .audio-message { min-width: min(205px, calc(100vw - 86px)); }
  .empty-state p { font-size: 22px; }
}

@media (max-width: 340px) {
  .login-shell { padding-inline: 10px; }
  .login-card { padding-inline: 16px; }
  .presence { display: none; }
  .person-name { font-size: 11px; }
  .header-brand { font-size: 18px; }
  .icon-button { width: 35px; }
  .composer-action, .send-button { flex-basis: 35px; width: 35px; }
  .composer-action svg, .send-button svg { width: 19px; }
  .composer textarea::placeholder { font-size: 13px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .login-shell { align-items: start; padding-block: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom)); }
  .login-card { max-width: 520px; padding: 18px 28px; }
  .brand-mark { width: 42px; height: 42px; margin-bottom: 6px; font-size: 24px; }
  .eyebrow { margin-bottom: 2px; }
  .login-card h1 { font-size: 32px; }
  .login-copy { margin: 5px auto 10px; line-height: 1.5; }
  .password-wrap input, .primary-button { height: 46px; }
  .reveal-button { top: 3px; }
  .primary-button { margin-top: 8px; }
  .privacy-note { margin-top: 8px; }
  .chat-header { min-height: calc(54px + env(safe-area-inset-top)); }
  .avatar { flex-basis: 34px; width: 34px; height: 34px; }
  .messages { padding-block: 10px; }
  .composer-shell { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .composer { min-height: 46px; }
  .composer-action, .send-button { height: 36px; }
  .composer textarea { height: 36px; padding-block: 7px; }
}

@media (hover: none) and (pointer: coarse) {
  button { touch-action: manipulation; }
  .message-delete { opacity: .72; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
