/* /chat: one phone-shaped column with the thread and a composer pinned to the bottom. */

/* Self-hosted variable fonts (latin), SIL Open Font License 1.1. */
@font-face {
  font-family: "Playfair Display";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("../fonts/playfair.woff2") format("woff2");
}
@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/manrope.woff2") format("woff2");
}

:root {
  color-scheme: dark;

  --cocoa-950: #0c0807;
  --cocoa-900: #140d0a;
  --cocoa-800: #1f1510;
  --cream: #f3e9df;
  --cream-dim: rgba(243, 233, 223, 0.66);
  --cream-faint: rgba(243, 233, 223, 0.12);
  --wine: #6a1628;
  --wine-deep: #33080f;
  --blue: #2b2fe0;
  --blue-violet: #3b31cb;

  --serif: "Playfair Display", "Didot", "Bodoni 72", Georgia, serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --gutter: 16px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(106, 22, 40, 0.45), transparent 70%),
    var(--cocoa-950);
  color: var(--cream);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }

.app {
  display: flex;
  flex-direction: column;
  width: min(100%, 520px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
}

/* ---------- Header ---------- */

.head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) var(--gutter) 12px 8px;
  border-bottom: 1px solid var(--cream-faint);
}
.head-back {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--cream-dim);
  -webkit-tap-highlight-color: transparent;
}
.head-back:hover, .head-back:focus-visible { color: var(--cream); background: var(--cream-faint); outline: none; }
.head-back svg, .composer-send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.head-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 12%;
  box-shadow: 0 0 0 1px rgba(243, 233, 223, 0.2), 0 0 18px rgba(59, 49, 203, 0.5);
}
.head-text { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.head-link {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--cream-faint);
  border-radius: 50%;
  background: transparent;
  color: var(--cream-dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.head-link[hidden] { display: none; }
.head-link:hover, .head-link:focus-visible { color: var(--cream); border-color: rgba(59, 49, 203, 0.9); outline: none; }
.head-link svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Inside Instagram's own browser: a nudge to open the chat in a real one. */
.inapp {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--gutter);
  background: linear-gradient(120deg, rgba(43, 47, 224, 0.28), rgba(59, 49, 203, 0.12));
  border-bottom: 1px solid var(--cream-faint);
  font-size: 13px;
  line-height: 1.4;
}
.inapp[hidden] { display: none; }
.inapp-text { flex: 1; margin: 0; }
.inapp-open, .notice-btn {
  flex: none;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-violet) 100%);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.inapp-close {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: var(--cream-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.head-name { font: 400 18px/1.1 var(--serif); letter-spacing: 0.32em; }
.head-meta { font-size: 12px; color: var(--cream-dim); }

/* ---------- Thread ---------- */

.thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px var(--gutter);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.msg {
  max-width: 82%;
  padding: 9px 13px 7px;
  border-radius: 18px;
  animation: rise 0.35s var(--ease);
}
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { display: block; margin-top: 2px; font-size: 10.5px; color: var(--cream-dim); text-align: right; }

.msg--anna {
  position: relative;
  align-self: flex-start;
  margin-left: 36px;
  border-bottom-left-radius: 6px;
  background: var(--cocoa-800);
  border: 1px solid var(--cream-faint);
}
/* Her avatar beside the last bubble of each run of her messages, as in messengers. */
.msg--anna::before {
  content: "";
  position: absolute;
  left: -37px;
  bottom: -1px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--cocoa-800) url("../img/g1.webp?v=3") 50% 12% / cover no-repeat;
  box-shadow: 0 0 0 1px rgba(243, 233, 223, 0.2);
}
.msg--anna:has(+ .msg--anna)::before { display: none; }
.msg--user {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  background: linear-gradient(120deg, var(--wine) 0%, var(--wine-deep) 100%);
  box-shadow: 0 10px 30px -16px rgba(106, 22, 40, 0.95);
}
/* A bubble after one from the same side sits closer. */
.msg--anna + .msg--anna, .msg--user + .msg--user { margin-top: -3px; }
.msg.is-sending { opacity: 0.55; }

/* Photo from Anna: the image fills the bubble, caption and time below it. */
.msg--photo { padding: 4px 4px 6px; }
.photo {
  position: relative;
  width: min(240px, 60vw);
  aspect-ratio: 3 / 4;
  max-height: 360px;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(100deg, var(--cocoa-900) 30%, rgba(243, 233, 223, 0.08) 50%, var(--cocoa-900) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
.photo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.4s var(--ease);
  cursor: zoom-in;
}
.photo.is-loaded { animation: none; }
.photo.is-loaded img { opacity: 1; }
@keyframes shimmer {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}
.msg--photo p, .msg--photo time { padding: 0 9px; }
.msg--photo p { margin-top: 6px; }
.msg.is-broken .photo { display: none; }
.msg.is-broken::after { content: "Photo unavailable"; display: block; padding: 8px 9px 0; font-size: 13px; color: var(--cream-dim); }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(12, 8, 7, 0.94);
  cursor: zoom-out;
  animation: fade 0.2s ease;
}
.viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; }
@keyframes fade { from { opacity: 0; } }

/* Not a message: the private link, offered once after the first message. */
.notice {
  align-self: center;
  max-width: 92%;
  margin: 8px 0;
  padding: 12px 14px;
  border: 1px dashed rgba(243, 233, 223, 0.25);
  border-radius: 16px;
  text-align: center;
  font-size: 13px;
  line-height: 1.45;
  color: var(--cream-dim);
  animation: rise 0.35s var(--ease);
}
.notice p { margin: 0 0 10px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom));
  z-index: 15;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--cocoa-800);
  border: 1px solid var(--cream-faint);
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.9);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 0.25s, transform 0.25s var(--ease);
  pointer-events: none;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* ---------- Composer ---------- */

.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--cream-faint);
  background: rgba(12, 8, 7, 0.7);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

.composer-name, .composer textarea {
  width: 100%;
  border: 1px solid var(--cream-faint);
  border-radius: 20px;
  background: rgba(31, 21, 16, 0.8);
  /* 16px stops iOS zooming into the field. */
  font-size: 16px;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.composer-name { padding: 9px 16px; }
.composer-name:focus, .composer textarea:focus {
  border-color: rgba(59, 49, 203, 0.9);
  box-shadow: 0 0 0 1px rgba(43, 47, 224, 0.5);
}
.composer-name::placeholder, .composer textarea::placeholder { color: rgba(243, 233, 223, 0.4); }

.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  padding: 9px 16px;
  line-height: 1.4;
  resize: none;
}

.composer-send {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-violet) 100%);
  box-shadow: 0 8px 24px -10px rgba(43, 47, 224, 0.9);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s, transform 0.2s var(--ease);
}
.composer-send:active { transform: scale(0.94); }
.composer-send:disabled { opacity: 0.4; cursor: default; }

/* Turnstile shows itself here only when it needs the visitor to click; until then it takes no room. */
.composer-captcha { display: flex; justify-content: center; margin-bottom: -8px; }
.composer-captcha.is-visible { margin-bottom: 0; }
.composer-captcha:empty { display: none; }

.composer-error {
  margin: 0;
  font-size: 13px;
  color: #ff9aa8;
}
.composer-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  color: rgba(243, 233, 223, 0.45);
  text-align: center;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-reduced-motion: reduce) {
  .msg, .photo { animation: none; }
}
