/* Bundled fonts, served from this host. Google's CDN is blocked by the CSP
 * (default-src 'self'), so the files live in /app/fonts. All are SIL OFL 1.1
 * (licences alongside). The VOICE face — what the personality's own words are
 * set in — is chosen per personality (seed web.voice_font, see [data-voice]
 * below): a typeface that belongs to who is speaking. The voice faces are
 * bundled in one weight, so voice text is never bold. */
@font-face {
  font-family: 'IM Fell English';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/im-fell-english-italic-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IM Fell English';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/im-fell-english-normal-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'EB Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/eb-garamond-italic-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/eb-garamond-normal-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/ibm-plex-mono-italic-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/app/fonts/ibm-plex-mono-normal-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url(/app/fonts/source-sans-3-italic-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url(/app/fonts/source-sans-3-italic-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(/app/fonts/source-sans-3-normal-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Source Sans 3';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(/app/fonts/source-sans-3-normal-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Web chat PWA. --accent is set per personality from /api/web/card. */
:root {
  --accent: #4a3b2f;
  --bg: #f6f1e7;
  --surface: #fffdf8;
  --text: #2b2520;
  --muted: #7a6f63;
  --line: #e4dccd;
  --mine: #e9e1d2;
  --theirs: #fffdf8;
  --danger: #a33a2c;
  --radius: 18px;
  --font: 'IM Fell English', Georgia, 'Times New Roman', serif;
  --voice-size: 17px;
  --ui: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
/* The voice face per personality. "fell" (the default above) is an English
 * printer's type of the 1600s; "garamond" an old-style book face for the
 * ancient and scholarly; "sans" a present-day hand; "mono" a technician's. */
:root[data-voice="garamond"] { --font: 'EB Garamond', Georgia, 'Times New Roman', serif; --voice-size: 18.5px; }
:root[data-voice="sans"]     { --font: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --voice-size: 16px; }
:root[data-voice="mono"]     { --font: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace; --voice-size: 14.5px; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --surface: #25221e;
    --text: #efe8dc;
    --muted: #a39887;
    --line: #36312a;
    --mine: #3a342c;
    --theirs: #25221e;
    --danger: #e0806f;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--ui);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* loading */
#root.loading { display: grid; place-items: center; height: 100%; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* avatar / brand */
.avatar {
  flex: none; display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font: 400 24px/1 var(--font);
}
.avatar.sm { width: 38px; height: 38px; font-size: 17px; }
.avatar.lg { width: 76px; height: 76px; font-size: 32px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-name { font: 400 23px/1.2 var(--font); }
.brand-tag { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* auth */
.screen.auth { min-height: 100%; display: flex; }
.auth-wrap {
  width: 100%; max-width: 420px; margin: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 24px 20px; }
.card h1 { font: 400 26px/1.2 var(--font); margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 18px; }
.hint { font-size: 14px; color: var(--muted); margin: -8px 0 14px; }
.fine { font-size: 14px; color: var(--muted); margin: 16px 0 0; text-align: center; }
label { display: block; font-size: 14px; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=email] {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 340px) { .names { grid-template-columns: 1fr; } }
input.code { font-size: 26px; letter-spacing: 0.35em; text-align: center; font-variant-numeric: tabular-nums; }
.notice { min-height: 1.4em; color: var(--danger); font-size: 14px; margin: 12px 0 4px; }
.primary {
  width: 100%; margin-top: 8px; padding: 14px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: 0.55; cursor: default; }
.row { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer; font-size: 14px; }
.link:disabled { color: var(--muted); cursor: default; }
@media (prefers-color-scheme: dark) { .link { color: color-mix(in srgb, var(--accent) 45%, #fff); } }

/* chat layout */
.screen.chat { height: 100%; }
.app { display: flex; flex-direction: column; height: 100%; max-width: 760px; margin: 0 auto; }
.hd {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.hd-text { flex: 1; min-width: 0; }
.hd-name { font: 400 18px/1.2 var(--font); }
.hd-status { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: transparent; color: var(--muted); font-size: 20px; cursor: pointer;
}
.icon-btn:hover { background: var(--line); }
.hd-link { flex: none; border: 0; background: none; padding: 8px 4px; color: var(--muted); font-size: 14px; cursor: pointer; }

.thread { flex: 1; overflow-y: auto; padding: 16px 12px 8px; overscroll-behavior: contain; }
.intro { text-align: center; padding: 18px 16px 26px; }
.intro-name { font: 400 22px/1.2 var(--font); margin: 12px 0 4px; }
.intro-tag { color: var(--muted); margin: 0 auto; max-width: 30em; font-size: 15px; }
.day { text-align: center; color: var(--muted); font-size: 12px; margin: 14px 0 8px; text-transform: uppercase; letter-spacing: 0.06em; }

.msg { display: flex; margin: 3px 0; }
.msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 34em); padding: 9px 13px 6px; border-radius: var(--radius);
  border: 1px solid var(--line); overflow-wrap: anywhere;
}
.theirs .bubble { background: var(--theirs); border-bottom-left-radius: 6px; font-family: var(--font); font-size: var(--voice-size); }
.mine .bubble { background: var(--mine); border-bottom-right-radius: 6px; }
.text { white-space: pre-wrap; }
.text a { color: inherit; }
.meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; font-family: var(--ui); }
.pic { display: block; margin: 2px -6px 6px; }
.pic img { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; }
.pic-pending { padding: 18px; margin-bottom: 6px; border-radius: 12px; background: var(--line); color: var(--muted); font-size: 13px; text-align: center; }
.msg.sending .bubble { opacity: 0.6; }
.msg.failed .bubble { border-color: var(--danger); cursor: pointer; }
.msg.failed .meta::after { content: " · not sent, tap to retry"; color: var(--danger); }

.typing { padding: 2px 18px 8px; color: var(--muted); font-size: 13px; font-style: italic; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.field { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
textarea {
  width: 100%; resize: none; max-height: 160px; padding: 10px 14px;
  border-radius: 20px; border: 1px solid var(--line); background: var(--bg); outline: none;
}
.send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 17px; cursor: pointer;
}
.attach { font-size: 22px; }
.chip { display: inline-flex; align-self: flex-start; align-items: center; gap: 6px; padding: 4px 6px 4px 12px; border-radius: 999px; background: var(--mine); font-size: 13px; }
.chip-x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 6px; }

/* voice: read replies aloud, speak instead of typing */
.hd-voice { font-size: 18px; }
.hd-voice[aria-pressed="true"] { color: var(--accent); }
.hd-voice.speaking { animation: voice-pulse 1.2s ease-in-out infinite; }
.mic { font-size: 19px; }
.mic.talking { background: #2d7d46; color: #fff; }
.mic.listening { background: #c0392b; color: #fff; animation: voice-pulse 1.2s ease-in-out infinite; }
.say { border: 0; background: none; padding: 0 6px 0 0; color: var(--muted); font-size: 11px; cursor: pointer; }
.say:hover, .say:focus-visible { color: var(--accent); }
@keyframes voice-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .hd-voice.speaking, .mic.listening { animation: none; } }

/* offline + toast */
body.offline .hd-status::before { content: "Offline — "; color: var(--danger); }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; z-index: 10;
  transition: opacity 0.5s;
}
.toast.out { opacity: 0; }

/* notifications prompt */
.notify-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 14px; background: var(--mine); border-bottom: 1px solid var(--line); font-size: 14px; }
.notify-bar span { flex: 1; }
.notify-btn { border: 0; border-radius: 999px; padding: 6px 14px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.notify-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 6px; }
