:root {
  --bg: #FBF7FA;
  --surface: #F3EAF2;
  --ink: #2A1F2D;
  --muted: #8A7A8E;
  --line: #E7DCE6;
  --berry: #9B2E5E;
  --berry-ink: #FFFFFF;
  --tag: #3461AE;
  --cup: #EDE6F2;
  --focus: #9B2E5E;

  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --script: "Sacramento", cursive;
  --measure: 38rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1C1520;
    --surface: #2A2030;
    --ink: #F2E8F1;
    --muted: #A495A8;
    --line: #372B3D;
    --berry: #D9628F;
    --berry-ink: #1C1520;
    --tag: #8DB2F2;
    --cup: #3A3045;
    --focus: #E58AB0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1C1520;
  --surface: #2A2030;
  --ink: #F2E8F1;
  --muted: #A495A8;
  --line: #372B3D;
  --berry: #D9628F;
  --berry-ink: #1C1520;
  --tag: #8DB2F2;
  --cup: #3A3045;
  --focus: #E58AB0;
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

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

.script {
  font-family: var(--script);
  font-weight: 400;
  font-size: clamp(3.4rem, 13vw, 5.2rem);
  line-height: 1;
  letter-spacing: 0;
  margin: 0;
  color: var(--berry);
}

/* ---------- gate ---------- */

.gate {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  text-align: center;
}
.gate-avatar { margin-bottom: 1.25rem; }
.gate-copy { color: var(--muted); margin: .75rem 0 1.75rem; }
.gate-form {
  display: flex;
  gap: .5rem;
  width: 100%;
  max-width: 22rem;
}
.gate-form input {
  flex: 1;
  min-width: 0;
  padding: .8rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.gate-form input:focus { outline: none; border-color: var(--berry); }
.gate-form button {
  padding: .8rem 1.2rem;
  border: 0;
  border-radius: 999px;
  background: var(--berry);
  color: var(--berry-ink);
  font-weight: 600;
  cursor: pointer;
}
.gate-error { min-height: 1.5em; margin: 1rem 0 0; color: var(--berry); font-weight: 500; }

/* ---------- app shell ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.bar {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .7rem max(1rem, calc((100% - var(--measure)) / 2));
  padding-top: max(.7rem, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.bar img { border-radius: 50%; flex: none; object-fit: cover; }
.bar-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.handle { font-weight: 700; font-size: .95rem; }
.status {
  color: var(--muted);
  font-size: .8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ghost {
  margin-left: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .4rem .85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
}
.ghost:hover { background: var(--surface); }

.feed {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem max(1rem, calc((100% - var(--measure)) / 2)) 1rem;
  scroll-behavior: smooth;
}

/* ---------- intro (profile header at the top of the feed) ---------- */

.intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 1.5rem 0 2.25rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--line);
}
.intro-avatar {
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: .9rem;
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--berry);
  animation: settle .9s cubic-bezier(.2, .9, .3, 1.2) both;
}
.intro .script { animation: ink 1.1s .15s ease-out both; }
.intro-copy {
  max-width: 24rem;
  margin: .8rem 0 0;
  color: var(--muted);
}

@keyframes settle {
  from { transform: translateY(14px) rotate(-8deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes ink {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

/* ---------- messages ---------- */

.msg { margin: 0 0 1.75rem; scroll-margin-top: 1rem; }

.msg.me {
  display: flex;
  justify-content: flex-end;
}
.msg.me p {
  margin: 0;
  max-width: min(80%, 30rem);
  padding: .6rem 1rem;
  border-radius: 1.25rem 1.25rem .35rem 1.25rem;
  background: var(--berry);
  color: var(--berry-ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.her {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: .75rem;
  align-items: start;
}
.msg-avatar { border-radius: 50%; margin-top: .1rem; object-fit: cover; }

/* her unprompted post that opens every chat */
.msg.post .caption { font-size: 1.08rem; }
.msg.post { padding-bottom: 1.75rem; border-bottom: 1px solid var(--line); }
.msg-handle { font-weight: 700; font-size: .9rem; }
.caption {
  margin-top: .15rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1.02rem;
  line-height: 1.5;
}
.caption p { margin: 0 0 .7em; }
.caption p:last-child { margin-bottom: 0; }
.caption .tag { color: var(--tag); font-weight: 500; }
.caption.streaming p:last-child::after {
  content: "";
  display: inline-block;
  width: .45em;
  height: 1em;
  margin-left: .1em;
  vertical-align: -.15em;
  border-radius: 1px;
  background: var(--berry);
  animation: blink 1s steps(2) infinite;
}
.footnote {
  margin: .5rem 0 0;
  display: block;
  color: var(--muted);
  font-size: .8rem;
  font-style: italic;
}
.msg.error .caption { color: var(--muted); font-style: italic; }

@keyframes blink { 50% { opacity: 0; } }

.typing {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin: 0 0 1.75rem 2.6rem;
  color: var(--muted);
  font-size: .9rem;
  font-style: italic;
}
.sipping .level { animation: sip 1.6s ease-in-out infinite; }
@keyframes sip {
  0%, 100% { transform: translateY(14px); }
  50% { transform: translateY(0); }
}

/* ---------- composer ---------- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .75rem max(1rem, calc((100% - var(--measure)) / 2));
  padding-bottom: max(.9rem, env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 9rem;
  padding: .75rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  background: var(--surface);
  line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--berry); }
.composer textarea::placeholder { color: var(--muted); }
.composer button {
  flex: none;
  width: 2.9rem;
  height: 2.9rem;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--berry);
  color: var(--berry-ink);
  cursor: pointer;
  transition: opacity .15s, transform .15s;
}
.composer button:disabled { opacity: .35; cursor: default; }
.composer button:not(:disabled):active { transform: scale(.92); }

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

.msg:has(.caption.streaming) .footnote { visibility: hidden; }
