@font-face { font-family: Montserrat; font-weight: 400 700; font-display: swap; src: url(/fonts/montserrat-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: Montserrat; font-weight: 400 700; font-display: swap; src: url(/fonts/montserrat-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; }

:root {
  --bg: #121212;
  --bg-2: #1b1b1b;
  --field: #262626;
  --bubble: #3a3a3a;
  --chip: #3c3c3c;
  --line: #2a2a2a;
  --text: #ffffff;
  --muted: #a3a3a3;
  --accent: #e5485b;
  --accent-2: #ff8a8a;
  --toggle: #5ee6c2;
  --danger: #ff5d6c;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 Montserrat, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
svg { width: 24px; height: 24px; display: block; }
img { -webkit-user-drag: none; }

#app { height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; background: var(--bg); position: relative; }
#view { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#view.flush { overflow: hidden; display: flex; flex-direction: column; }

/* ---------- bottom tab bar ---------- */
#tabbar { display: flex; justify-content: space-around; align-items: center; height: 58px; padding-bottom: env(safe-area-inset-bottom); background: var(--bg-2); flex: none; }
#tabbar.hidden { display: none; }
#tabbar button { width: 56px; height: 48px; display: grid; place-items: center; color: #8e8e8e; position: relative; }
#tabbar button svg { width: 24px; height: 24px; }
#tabbar button.on { color: #fff; }
#tabbar button.on::after { content: ''; position: absolute; bottom: 4px; width: 22px; height: 2.5px; border-radius: 2px; background: #fff; }

/* ---------- headers ---------- */
.brand { height: 56px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; letter-spacing: .5px; font-size: 17px; flex: none; }
.brand svg { width: 30px; height: 22px; }
.page-title { height: 64px; display: grid; place-items: center; font-size: 22px; font-weight: 500; flex: none; position: relative; }
.page-title .circle { position: absolute; left: 12px; top: 10px; }
.circle { width: 44px; height: 44px; border-radius: 50%; background: #3a3a3a; display: grid; place-items: center; flex: none; }
.circle svg { width: 22px; height: 22px; }
.circle:active { background: #4a4a4a; }

/* ---------- character grid (Home / Search) ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.card { position: relative; aspect-ratio: 0.92; overflow: hidden; display: block; text-align: left; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.card .art { position: absolute; inset: 0; width: 100%; height: 100%; }
.card::after { content: ''; position: absolute; inset: 55% 0 0 0; background: linear-gradient(transparent, rgba(0,0,0,.55)); pointer-events: none; }
.card-name { position: absolute; left: 9px; right: 9px; bottom: 7px; font-size: 12px; font-weight: 500; z-index: 1; text-shadow: 0 1px 3px rgba(0,0,0,.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-bubble { position: absolute; right: 8px; top: 8px; z-index: 1; opacity: .95; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.card-bubble svg { width: 14px; height: 14px; }
.card:active { filter: brightness(.85); }

/* generated artwork when a character has no picture */
.art { object-fit: cover; display: block; }
.art.ph { display: grid; place-items: center; overflow: hidden; }
.art.ph span { font-size: 64px; line-height: 1; filter: drop-shadow(0 4px 12px rgba(0,0,0,.35)); }
.av30, .av34, .av44, .av28 { border-radius: 50%; flex: none; overflow: hidden; }
.av28 { width: 28px; height: 28px; } .av28.ph span { font-size: 14px; }
.av30 { width: 30px; height: 30px; } .av30.ph span { font-size: 15px; }
.av34 { width: 34px; height: 34px; } .av34.ph span { font-size: 17px; }
.av44 { width: 44px; height: 44px; } .av44.ph span { font-size: 22px; }
.pic110 { width: 108px; height: 108px; border-radius: 16px; overflow: hidden; } .pic110.ph span { font-size: 48px; }
.pic96 { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; } .pic96.ph span { font-size: 42px; }

/* ---------- search ---------- */
.search-row { display: flex; align-items: center; margin: 4px 16px 0; border-bottom: 1px solid #3a3a3a; }
.search-row input { flex: 1; background: none; border: 0; outline: 0; font-size: 22px; font-weight: 500; padding: 14px 4px; }
.search-row input::placeholder { color: #6f6f6f; }
.chips { display: flex; gap: 8px; padding: 18px 16px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { background: var(--chip); border-radius: 20px; padding: 6px 13px; font-size: 14px; white-space: nowrap; flex: none; }
.chip.on { background: #fff; color: #111; }
.chip.outline { background: #000; border: 1px solid #4a4a4a; font-weight: 500; }

/* ---------- lists (Chats / Profile) ---------- */
.rows { padding: 8px 0 16px; }
.row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 0 16px; text-align: left; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.row .row-body { flex: 1; min-width: 0; padding: 15px 0; border-bottom: 1px solid var(--line); }
.row:last-child .row-body { border-bottom: 0; }
.row .row-title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row:active { background: #1d1d1d; }
.row .badge { font-size: 11px; color: var(--toggle); border: 1px solid currentColor; border-radius: 10px; padding: 1px 7px; margin-left: 6px; vertical-align: 2px; }
.row .chev { color: #6f6f6f; }
.section-label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; padding: 18px 16px 2px; }
.empty { color: var(--muted); text-align: center; padding: 60px 30px; line-height: 1.6; }
.plus-ic { width: 44px; height: 44px; border-radius: 50%; border: 1.5px dashed #555; display: grid; place-items: center; color: var(--muted); flex: none; }

/* ---------- chat ---------- */
.chat-top { display: flex; justify-content: space-between; padding: 10px 12px 0; padding-top: max(10px, env(safe-area-inset-top)); flex: none; }
.chat-pill { display: flex; align-items: center; gap: 12px; margin: 10px 12px 4px; padding: 6px 16px 6px 6px; background: var(--bg-2); border-radius: 30px; text-align: left; flex: none; }
.chat-pill span { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 0 10px; display: flex; flex-direction: column; gap: 16px; overscroll-behavior: contain; }
.m { display: flex; gap: 10px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.m.user { justify-content: flex-end; }
.m.user .bubble { background: var(--bubble); padding: 9px 14px; border-radius: 6px 0 0 6px; max-width: 82%; white-space: pre-wrap; word-wrap: break-word; }
.m.user .bubble em { color: #cfcfcf; }
.m.bot { padding: 0 18px 0 12px; align-items: flex-start; transition: transform .2s; }
.m.bot .av30 { margin-top: 1px; }
.btext { flex: 1; min-width: 0; white-space: pre-wrap; word-wrap: break-word; }
.btext em { color: #b9b9b9; }
.btext b { font-weight: 600; }
.m.streaming .btext::after { content: '▍'; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: flex; align-items: center; gap: 4px; height: 30px; color: var(--muted); font-size: 13px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #8a8a8a; animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
.typing span { margin-left: 8px; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }
.swiper { display: flex; align-items: center; gap: 2px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.swiper button { width: 30px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: #cfcfcf; }
.swiper button svg { width: 16px; height: 16px; }
.swiper button:disabled { opacity: .25; }
.swiper button:active { background: #2a2a2a; }
.chat-error { color: var(--danger); font-size: 13px; text-align: center; padding: 0 24px; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); flex: none; }
.input-pill { flex: 1; display: flex; align-items: flex-end; gap: 10px; background: var(--field); border-radius: 26px; padding: 8px 14px 8px 8px; min-height: 50px; }
.input-pill .persona-btn { flex: none; margin-bottom: 3px; }
.input-pill textarea { flex: 1; background: none; border: 0; outline: 0; resize: none; max-height: 140px; padding: 5px 0; line-height: 1.4; }
.input-pill textarea::placeholder { color: #8e8e8e; }
.send { width: 50px; height: 50px; border-radius: 50%; background: var(--field); display: grid; place-items: center; flex: none; box-shadow: inset 0 0 0 3px #1b1b1b; }
.send.ready { background: #fff; color: #111; }
.send.stop { background: var(--danger); }

/* ---------- forms (setup / persona / settings) ---------- */
.form { padding: 4px 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.field label, .field .lbl { display: block; font-size: 15px; font-weight: 500; margin-bottom: 8px; }
.field .hint { color: var(--muted); font-size: 12px; font-weight: 400; }
.input, .textarea, select.input { width: 100%; background: var(--field); border: 1.5px solid transparent; border-radius: 12px; padding: 14px 16px; outline: 0; }
.textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
.input:focus, .textarea:focus { border-color: var(--accent); }
.counter { text-align: right; color: var(--muted); font-size: 11px; margin-top: -26px; margin-right: 12px; pointer-events: none; position: relative; }
.steps { display: flex; gap: 12px; padding: 4px 30px 10px; flex: none; }
.steps i { flex: 1; height: 6px; border-radius: 3px; background: #2e2e2e; }
.steps i.done { background: #7a2c35; }
.steps i.cur { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.pic-pick { position: relative; align-self: center; display: block; cursor: pointer; }
.pic-pick .cam { position: absolute; right: -4px; bottom: -4px; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; box-shadow: 0 0 0 3px var(--bg); }
.pic-pick .cam svg { width: 17px; height: 17px; }
.pic-name { text-align: center; font-size: 14px; font-weight: 500; margin-top: -6px; }
.fm-card { background: var(--field); border-radius: 14px; overflow: hidden; }
.fm-card .textarea { background: none; min-height: 150px; border: 0; font-size: 16px; padding: 16px 18px; }
.fm-actions { display: flex; justify-content: flex-end; gap: 20px; padding: 12px 18px; border-top: 1px solid #333; }
.fm-actions button { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.fm-actions svg { width: 19px; height: 19px; }
.link-btn { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 4px; float: right; font-weight: 500; }
.link-btn svg { width: 14px; height: 14px; }
.bottom-actions { padding: 10px 18px 18px; padding-bottom: max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.pill-btn { width: 100%; height: 52px; border-radius: 26px; background: #fff; color: #111; font-size: 17px; font-weight: 500; }
.pill-btn:disabled { opacity: .5; }
.text-btn { padding: 8px 20px; font-size: 16px; }
.text-btn.danger { color: var(--danger); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; font-weight: 500; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 13px; background: #444; transition: .2s; }
.switch span::after { content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%; top: 2px; left: 2px; background: #bbb; transition: .2s; }
.switch input:checked + span { background: #2f7f6b; }
.switch input:checked + span::after { left: 20px; background: var(--toggle); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bottom sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,0); z-index: 50; display: flex; align-items: flex-end; justify-content: center; transition: background .2s; }
.sheet-wrap.open { background: rgba(0,0,0,.55); }
.sheet { width: 100%; max-width: 560px; background: #1e1e1e; border-radius: 20px 20px 0 0; padding: 8px 0 max(14px, env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .22s ease-out; max-height: 88dvh; overflow-y: auto; }
.sheet-wrap.open .sheet { transform: none; }
.sheet::before { content: ''; display: block; width: 38px; height: 4px; border-radius: 2px; background: #4a4a4a; margin: 4px auto 8px; }
.sheet h3 { margin: 4px 20px 10px; font-size: 17px; font-weight: 600; }
.sheet .act { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 22px; text-align: left; font-size: 16px; }
.sheet .act:active { background: #2a2a2a; }
.sheet .act.danger { color: var(--danger); }
.sheet .act .sub { color: var(--muted); font-size: 13px; margin-left: auto; }
.sheet .form { padding-top: 0; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #333; padding: 10px 18px; border-radius: 22px; font-size: 14px; opacity: 0; transition: .2s; z-index: 60; pointer-events: none; max-width: 88vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
