:root {
  --bg: #1a1020;
  --bg-2: #241629;
  --surface: rgba(255, 255, 255, 0.05);
  --surface-2: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f6ecef;
  --muted: #b9a4b3;
  --rose: #ff7a9a;
  --rose-2: #ffb38a;
  --me: linear-gradient(135deg, #ff7a9a, #ff9e8a);
  --error: #ff9b9b;
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.glow {
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background:
    radial-gradient(60vmax 50vmax at 85% -10%, rgba(255, 122, 154, 0.22), transparent 60%),
    radial-gradient(50vmax 40vmax at -10% 110%, rgba(255, 179, 138, 0.14), transparent 60%);
}

/* ---------- onboarding ---------- */
.screen { min-height: 100%; }
#onboarding { display: grid; place-items: center; padding: 32px 16px; }

.card {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 28px;
  backdrop-filter: blur(12px);
}
.eyebrow { margin: 0 0 8px; font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--rose); font-weight: 600; }
h1 { font: 600 30px/1.15 Fraunces, Georgia, serif; margin: 0 0 12px; }
h1 em { font-weight: 400; color: var(--rose-2); }
.lede { color: var(--muted); margin: 0 0 24px; }

form { display: grid; gap: 16px; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.hint { font-weight: 400; opacity: .7; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .15s, background .15s;
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(-45deg, transparent 50%, var(--muted) 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select option { background: var(--bg-2); }
input:focus, select:focus, textarea:focus { border-color: var(--rose); background: var(--surface-2); }
input::placeholder, textarea::placeholder { color: #8a7486; }

fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
legend { font-size: 13px; font-weight: 500; color: var(--muted); padding: 0; margin-bottom: 6px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice label { position: relative; }
.choice input { position: absolute; opacity: 0; }
.choice span {
  display: block; text-align: center; padding: 12px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  transition: all .15s;
}
.choice input:checked + span { border-color: var(--rose); background: rgba(255, 122, 154, 0.15); }
.choice input:focus-visible + span { outline: 2px solid var(--rose); outline-offset: 2px; }

.check { grid-template-columns: auto 1fr; align-items: start; gap: 10px; font-weight: 400; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--rose); padding: 0; }

.error { color: var(--error); margin: 0; min-height: 1em; font-size: 13px; }

button { font: inherit; cursor: pointer; }
.primary {
  border: 0; border-radius: 14px; padding: 14px;
  background: var(--me); color: #2a0f1a; font-weight: 600;
  transition: transform .1s, opacity .15s;
}
.primary:active { transform: scale(.98); }
.primary:disabled { opacity: .6; cursor: progress; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }

.chat-head {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: rgba(26, 16, 32, 0.8); backdrop-filter: blur(12px);
}
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--me); color: #2a0f1a; font: 600 18px Fraunces, serif;
  box-shadow: 0 0 0 3px rgba(255, 122, 154, 0.2);
}
.who { display: grid; flex: 1; line-height: 1.25; }
.who strong { font: 600 17px Fraunces, serif; }
.who span { font-size: 12px; color: var(--muted); }
.who span::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #6fe3a0; margin-right: 6px; vertical-align: 1px; }

.ghost { background: none; border: 0; color: var(--muted); font-size: 22px; padding: 4px 10px; border-radius: 10px; }
.ghost:hover { background: var(--surface); }
.menu {
  position: absolute; right: 12px; top: 60px; z-index: 5;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 6px;
  display: grid; min-width: 180px; box-shadow: 0 12px 30px rgba(0,0,0,.4);
}
.menu button { background: none; border: 0; color: var(--text); text-align: left; padding: 10px 12px; border-radius: 8px; }
.menu button:hover { background: var(--surface-2); }

.messages {
  list-style: none; margin: 0; padding: 20px 16px;
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 80%; padding: 10px 14px; border-radius: var(--radius);
  white-space: pre-wrap; word-wrap: break-word;
  animation: rise .25s ease-out;
}
.msg.model { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 6px; }
.msg.user { align-self: flex-end; background: var(--me); color: #2a0f1a; border-bottom-right-radius: 6px; }
.msg.error-msg { align-self: center; background: none; color: var(--error); font-size: 13px; }

.typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }

.composer {
  display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 22px; padding: 11px 16px; }
.send {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%;
  background: var(--me); color: #2a0f1a; display: grid; place-items: center;
}
.send:disabled { opacity: .5; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

@media (max-width: 420px) {
  .card { padding: 24px 18px; }
  h1 { font-size: 26px; }
  .msg { max-width: 88%; }
}

.msg.note { align-self: center; background: none; color: var(--muted); font-size: 12px; padding: 4px 10px; }
.who span.away::before { background: #e0b04a; }
.menu a { color: var(--text); text-decoration: none; padding: 10px 12px; border-radius: 8px; }
.menu a:hover { background: var(--surface-2); }
.logo-text { font: 600 italic 15px Fraunces, Georgia, serif; letter-spacing: .02em; text-transform: none; }

/* ---------- character picker ---------- */
.card.wide { max-width: 560px; }
.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.char-card { position: relative; display: grid; gap: 8px; padding: 12px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-align: left; color: var(--text); font: inherit; transition: border-color .15s, background .15s, transform .1s; }
.char-card:hover { border-color: rgba(255, 122, 154, .5); }
.char-card[aria-checked="true"] { border-color: var(--rose); background: rgba(255, 122, 154, .12); }
.char-card[aria-checked="true"]::after { content: '✓'; position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%; background: var(--rose); color: #2a0f1a; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.char-card .pic { width: 64px; height: 64px; font-size: 26px; }
.char-card strong { font: 600 17px Fraunces, Georgia, serif; }
.char-card .from { font-size: 12px; color: var(--muted); }
.char-card .line { font-size: 12.5px; line-height: 1.4; color: #d9c6d1; }
.pick-hint { font-size: 13px; margin: 0; }

/* avatar: photo when available, otherwise a gradient initial */
.pic { border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: var(--me); color: #2a0f1a; font: 600 18px Fraunces, serif; flex: none; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.has-photo { background: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
