/* Widow AI — "quiet correspondence"
 *
 * Warm linen paper, deep warm ink, letterpress serif headings.
 * Calm by design: generous type sizes, soft motion, high readability. */

:root {
  --paper: #f7f2ea;
  --paper-deep: #efe7da;
  --card: #fffdf9;
  --ink: #2e2a24;
  --ink-soft: #6b6258;
  --ink-faint: #9a9083;
  --line: #e3d9c9;
  --accent: #8e7cc3; /* overridden per persona via inline style */
  --notice: #3f6f54;
  --alert: #9c4a3c;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(46 42 36 / 0.05), 0 8px 28px rgb(46 42 36 / 0.07);
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Karla", "Gill Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgb(192 129 59 / 0.07), transparent 60%),
    radial-gradient(900px 420px at -10% 0%, rgb(74 157 143 / 0.06), transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 480;
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 0.5em;
}

a { color: inherit; }

/* ---------- Header & footer ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgb(255 253 249 / 0.65);
  backdrop-filter: blur(6px);
}

.wordmark {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 560;
  font-size: 1.45rem;
  text-decoration: none;
  color: var(--ink);
}

.wordmark-mark {
  display: inline-grid;
  place-items: center;
  width: 1.7em;
  height: 1.7em;
  margin-right: 0.3rem;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-style: normal;
  font-size: 0.85em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 2.5vw, 1.5rem);
  font-size: 0.95rem;
}

.site-nav a { text-decoration: none; color: var(--ink-soft); }
.site-nav a:hover { color: var(--ink); }

.site-nav .nav-cta {
  color: var(--card);
  background: var(--ink);
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
}

.nav-button {
  font: inherit;
  color: var(--ink-soft);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.nav-button:hover { color: var(--ink); }

.site-main { flex: 1; width: 100%; display: flex; flex-direction: column; }
.site-main > * { width: 100%; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--paper-deep);
  padding: 1.4rem clamp(1rem, 4vw, 2.5rem);
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-align: center;
}

.site-footer p { margin: 0.25rem 0; }

/* ---------- Flash ---------- */

.flash-wrap { padding: 0.75rem clamp(1rem, 4vw, 2.5rem) 0; max-width: 72rem; margin: 0 auto; width: 100%; }

.flash {
  padding: 0.7rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  border: 1px solid;
}

.flash-notice { color: var(--notice); border-color: rgb(63 111 84 / 0.3); background: rgb(63 111 84 / 0.07); }
.flash-alert { color: var(--alert); border-color: rgb(156 74 60 / 0.3); background: rgb(156 74 60 / 0.07); }

/* ---------- Hero ---------- */

.hero {
  max-width: 72rem;
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 5rem) clamp(1rem, 4vw, 2.5rem) clamp(1.5rem, 4vw, 3rem);
}

.hero-kicker {
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-faint);
  margin: 0 0 1rem;
}

.hero h1 {
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  max-width: 18ch;
}

.hero h1 em {
  font-style: italic;
  font-weight: 600;
  color: #a3563f;
}

.hero-lede {
  max-width: 56ch;
  font-size: 1.15rem;
  color: var(--ink-soft);
}

/* ---------- Persona gallery ---------- */

.persona-grid {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 2.5rem) clamp(3rem, 6vw, 5rem);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
  gap: 1.25rem;
}

.persona-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.4rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: rise 0.5s both;
  animation-delay: calc(var(--stagger, 0) * 60ms);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.persona-card-top { display: flex; align-items: center; gap: 0.9rem; }

.persona-card h2 { font-size: 1.45rem; margin: 0; }
.persona-card h2 a { text-decoration: none; }
.persona-card h2 a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

.persona-meta { margin: 0.1rem 0 0; color: var(--ink-faint); font-size: 0.9rem; }

.avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgb(255 255 255 / 0.55), transparent 55%),
    color-mix(in srgb, var(--accent) 28%, var(--card));
  color: color-mix(in srgb, var(--accent) 75%, var(--ink));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line));
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
}

.avatar-large { width: 4.6rem; height: 4.6rem; font-size: 1.5rem; }

.persona-tagline {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.08rem;
  color: var(--ink-soft);
  margin: 0;
  flex: 1;
}

.persona-card-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.button {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

.button:hover { transform: translateY(-1px); }
.button:active { transform: none; }

.button-solid {
  background: var(--ink);
  color: var(--card);
  border: 1px solid var(--ink);
}
.button-solid:hover { box-shadow: 0 4px 14px rgb(46 42 36 / 0.25); }

.button-quiet {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.button-quiet:hover { border-color: var(--ink-faint); color: var(--ink); }

.button-large { font-size: 1.05rem; padding: 0.75rem 1.5rem; }
.button-small { font-size: 0.85rem; padding: 0.35rem 0.8rem; }

/* ---------- Persona profile ---------- */

.persona-profile {
  max-width: 44rem;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2.5rem) 4rem;
}

.backlink {
  display: inline-block;
  margin-bottom: 1.6rem;
  color: var(--ink-faint);
  text-decoration: none;
  font-size: 0.95rem;
}
.backlink:hover { color: var(--ink); }

.persona-profile-header { display: flex; align-items: center; gap: 1.2rem; margin-bottom: 1.4rem; }
.persona-profile-header h1 { font-size: clamp(2rem, 5vw, 2.8rem); margin: 0; }

.persona-tagline-large { font-size: 1.35rem; margin-bottom: 1.2rem; }

.persona-bio { color: var(--ink-soft); font-size: 1.1rem; }

.persona-details {
  margin-top: 2rem;
  display: grid;
  gap: 1.25rem;
}

.persona-details h2 {
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
  margin-bottom: 0.35rem;
}

.persona-details p {
  margin: 0;
  color: var(--ink-soft);
}

.persona-profile-actions { margin-top: 2rem; }

.signin-nudge { color: var(--ink-soft); }

/* ---------- Conversations index ---------- */

.conversations-page {
  max-width: 44rem;
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2.5rem) 4rem;
}

.conversation-list { list-style: none; margin: 1.5rem 0 0; padding: 0; display: grid; gap: 0.75rem; }

.conversation-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}

.conversation-link {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex: 1;
  text-decoration: none;
  min-width: 0;
}

.conversation-row-text { display: grid; min-width: 0; }
.conversation-row-text strong { font-size: 1.05rem; }
.conversation-row-text small { color: var(--ink-faint); }

.empty-state { color: var(--ink-soft); margin-top: 1.5rem; }

/* ---------- Chat ---------- */

.chat-page .site-footer { display: none; }
.chat-page {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  --composer-clearance: 6.5rem;
}

.chat-page .site-main {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: hidden;
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 46rem;
  width: 100%;
  margin: 0 auto;
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.85rem clamp(1rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
}

.chat-back { margin: 0 0.2rem 0 0; font-size: 1.2rem; }

.chat-header-text { display: grid; line-height: 1.3; }
.chat-header-text strong { font-family: var(--font-display); font-size: 1.2rem; }
.chat-header-text small { color: var(--ink-faint); }

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 1.4rem clamp(1rem, 3vw, 1.5rem) var(--composer-clearance);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.chat-scroll::-webkit-scrollbar { display: none; }

.chat-welcome {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.97rem;
  max-width: 38rem;
  margin: 0 auto 1.6rem;
  padding: 1rem 1.2rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgb(255 253 249 / 0.6);
}

.chat-welcome p { margin: 0.3rem 0; }
.chat-welcome-note { font-size: 0.85rem; color: var(--ink-faint); }

.messages { display: flex; flex-direction: column; gap: 0.85rem; }

.message {
  max-width: 85%;
  padding: 0.8rem 1.05rem;
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(46 42 36 / 0.06);
  animation: rise 0.35s both;
}

.message p { margin: 0 0 0.6em; }
.message p:last-child { margin-bottom: 0; }

.message-user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
  border-bottom-right-radius: 4px;
}

.message-assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-bottom-left-radius: 4px;
}

.message-author {
  display: block;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.85rem;
  color: color-mix(in srgb, var(--accent) 70%, var(--ink));
  margin-bottom: 0.25rem;
}

.message-typing { display: inline-flex; gap: 0.3rem; padding: 0.95rem 1.1rem; margin-top: 0.85rem; }

.chat-bottom { height: 1px; }

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: pulse 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.18s; }
.typing-dot:nth-child(3) { animation-delay: 0.36s; }

@keyframes pulse {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.composer-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 5;
  width: 100%;
  border-top: 1px solid var(--line);
  padding: 0.9rem clamp(1rem, 3vw, 1.5rem) max(0.7rem, env(safe-area-inset-bottom));
  background: rgb(255 253 249 / 0.95);
}

.composer {
  display: flex;
  gap: 0.7rem;
  align-items: flex-end;
  max-width: 46rem;
  margin: 0 auto;
}

.composer textarea {
  flex: 1;
  font: inherit;
  resize: none;
  min-height: 3rem;
  max-height: 9rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}

.composer textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.composer-disabled textarea,
.composer-disabled .button {
  cursor: wait;
  opacity: 0.72;
}

/* ---------- Auth & forms ---------- */

.auth-card {
  max-width: 26.5rem;
  margin: clamp(2rem, 7vw, 5rem) auto 4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.5rem, 4vw, 2.4rem);
}

.auth-card h1 { font-size: 1.9rem; }

.auth-lede { color: var(--ink-soft); margin-top: -0.3rem; }

.field { margin: 1.1rem 0; display: grid; gap: 0.35rem; }

.field label { font-weight: 700; font-size: 0.92rem; }

.field input {
  width: 100%;
  min-width: 0;
  font: inherit;
  padding: 0.65rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
}

.field input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}

.field small { color: var(--ink-faint); }

.auth-card .button { margin-top: 0.5rem; width: 100%; }

.auth-switch { margin-top: 1.4rem; font-size: 0.95rem; color: var(--ink-soft); text-align: center; }

.form-errors {
  border: 1px solid rgb(156 74 60 / 0.35);
  background: rgb(156 74 60 / 0.07);
  color: var(--alert);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-size: 0.92rem;
}

.form-errors ul { margin: 0.2rem 0; padding-left: 1.1rem; }

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .chat-scroll { scroll-behavior: auto; }
}
