:root {
  --bg: #fbf6f1;
  --card: #ffffff;
  --text: #4a4458;
  --muted: #8d869b;
  --line: #efe6ee;
  --j: #f8cfd9;
  --j-strong: #e98aa3;
  --m: #c9e2f7;
  --m-strong: #6fa8d8;
  --ai: #e6e0f8;
  --ai-strong: #9a8bd6;
  --mint: #d5f0e3;
  --primary: #b9a6ec;
  --primary-strong: #9c86e0;
  --danger: #d9677f;
  --radius: 20px;
  --shadow: 0 6px 24px rgba(120, 100, 150, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* One solid color everywhere, matching theme-color, so phone browser bars blend in. */
html, body { height: 100%; background: var(--bg); }
body {
  margin: 0;
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}
h1 { font-size: 1.6rem; margin: 0 0 .4rem; font-weight: 800; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; font-weight: 800; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: .95rem; }

.view { min-height: 100%; }
.center { display: grid; place-items: center; padding: 16px; }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.narrow { width: 100%; max-width: 380px; text-align: center; }
.logo { font-size: 3rem; }

input, textarea {
  font: inherit; color: inherit;
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fffdfb;
  outline: none;
  transition: border-color .2s;
}
input:focus, textarea:focus { border-color: var(--primary); }
#login-form, #identify-form { display: grid; gap: 12px; margin-top: 16px; }
.who-btn.selected.j { border-color: var(--j-strong); }
.who-btn.selected.m { border-color: var(--m-strong); }

.btn {
  font: inherit; font-weight: 700;
  border: 0; border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer;
  transition: transform .1s, background .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: white; }
.btn.primary:hover:not(:disabled) { background: var(--primary-strong); }
.btn.ghost { background: transparent; color: var(--muted); border: 2px solid var(--line); }
.btn.ghost:hover { color: var(--text); }
.btn.big { padding: 15px 30px; font-size: 1.1rem; margin-top: 8px; }
.btn.small { padding: 6px 14px; font-size: .9rem; }
.icon-btn { background: none; border: 0; font-size: 1.3rem; color: var(--muted); cursor: pointer; padding: 6px; }

.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.who-btn {
  font: inherit; font-weight: 700; color: var(--text);
  display: grid; justify-items: center; gap: 10px;
  padding: 22px 10px; border-radius: var(--radius); cursor: pointer;
  border: 2px solid transparent; transition: transform .15s, border-color .2s;
}
.who-btn.j { background: #fdeef2; }
.who-btn.m { background: #eaf3fc; }
.who-btn:hover { transform: translateY(-2px); }
.who-btn.j:hover { border-color: var(--j-strong); }
.who-btn.m:hover { border-color: var(--m-strong); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 800; font-size: .9rem; color: white; flex: none;
}
.avatar.big { width: 64px; height: 64px; font-size: 1.6rem; }
.avatar.j { background: var(--j-strong); }
.avatar.m { background: var(--m-strong); }
.avatar.ai { background: var(--ai-strong); }

/* App layout */
#view-app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg);
}
.brand { font-weight: 800; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.chip {
  font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer;
  border: 0; border-radius: 999px; padding: 5px 12px 5px 5px;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip.j { background: var(--j); }
.chip.m { background: var(--m); }
.chip .avatar { width: 26px; height: 26px; font-size: .8rem; }

.lobby {
  flex: 1; overflow-y: auto; padding: 16px 16px 48px;
  display: grid; gap: 16px; align-content: start;
  width: 100%; max-width: 680px; margin: 0 auto;
}
.hero { text-align: center; }
.tips ul { margin: 0; padding-left: 1.1rem; display: grid; gap: 6px; }
.summary-card { background: var(--mint); }
.summary-card p { margin: 0; white-space: pre-wrap; }
.history-item { border-top: 1px solid var(--line); padding: 12px 0; }
.history-item:first-child { border-top: 0; padding-top: 0; }
.history-item .date { font-weight: 700; font-size: .9rem; color: var(--muted); }
.history-item p { margin: 4px 0 0; white-space: pre-wrap; }

/* Content scrolling under the edges fades out instead of being cut off. */
.lobby, .messages {
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 36px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 36px), transparent 100%);
}

/* Chat */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 760px; margin: 0 auto; }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px;
  font-size: .9rem; color: var(--muted);
}
.session-label { font-weight: 700; }
.end-btn {
  margin-left: auto; font: inherit; font-size: .85rem; font-weight: 700;
  color: var(--muted); background: none; border: 0; padding: 6px 4px; cursor: pointer;
}
.end-btn:hover { color: var(--text); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #7fd1a4; box-shadow: 0 0 0 4px #d5f0e3; }
.messages { flex: 1; overflow-y: auto; padding: 8px 16px 28px; display: flex; flex-direction: column; gap: 12px; }

.end-banner {
  margin: 0 16px 6px; padding: 10px 14px; border-radius: 16px;
  background: var(--mint); font-size: .9rem; font-weight: 600;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.link-btn {
  margin-left: auto; font: inherit; font-weight: 800; font-size: .9rem;
  background: white; color: var(--text); border: 0; border-radius: 999px; padding: 6px 14px; cursor: pointer;
}

.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; animation: pop .25s ease-out; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 10px 14px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: 0 2px 8px rgba(120,100,150,.06);
}
.msg.j .bubble { background: var(--j); }
.msg.m .bubble { background: var(--m); }
.msg.ai .bubble { background: var(--ai); }
.msg.mine .bubble { border-bottom-right-radius: 6px; }
.msg:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.msg .who { font-size: .75rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg.mine .who { text-align: right; }
.msg.private .bubble { background: #fff; border: 2px dashed var(--ai-strong); }
.msg.private.j .bubble, .msg.private.m .bubble { border-color: var(--muted); }
.msg .pill { font-size: .72rem; font-weight: 700; color: var(--ai-strong); }
.typing-dots span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--ai-strong); animation: blink 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

.composer { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer-row { display: flex; gap: 6px; align-items: flex-end; }
.field { flex: 1; position: relative; min-width: 0; }
.composer textarea {
  display: block; resize: none; max-height: 160px;
  border-radius: 22px; padding: 11px 16px; min-height: 46px; background: white;
}
.composer.is-private textarea { border-style: dashed; border-color: var(--ai-strong); background: #faf8ff; }
.private-hint { font-size: .78rem; font-weight: 700; color: #7a6cc2; padding: 0 0 6px 54px; }
.voice {
  position: absolute; inset: 0; display: flex; align-items: center; gap: 10px;
  padding: 0 6px 0 16px; border-radius: 22px; background: #fff3f5; border: 2px solid var(--j);
  font-weight: 700; color: var(--danger);
}
.voice.busy { background: #f6f3ff; border-color: var(--ai); color: #5d4fa3; }
.voice.failed { background: #fff; border-color: var(--danger); }
.voice.failed .voice-label { font-size: .85rem; color: var(--text); }
.voice-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.voice-level { flex: 1; display: flex; align-items: center; gap: 3px; height: 24px; min-width: 0; }
.voice-level i { width: 4px; height: 4px; border-radius: 2px; background: var(--danger); opacity: .7; transition: height .08s; }
.voice.busy .voice-level, .voice.failed .voice-level { display: none; }
.voice.busy .rec-dot { background: var(--ai-strong); }
.voice.failed .rec-dot { display: none; }
.voice-action {
  margin-left: auto; font: inherit; font-size: .85rem; font-weight: 800; color: var(--muted);
  background: white; border: 0; border-radius: 999px; padding: 6px 12px; min-height: 32px; cursor: pointer;
}
.voice-action + .voice-action { margin-left: 0; }
.rec-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1.2s infinite; }

.round-btn {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: transparent; color: var(--muted);
  transition: background .2s, color .2s, transform .1s;
}
.round-btn:active { transform: scale(.94); }
.round-btn:disabled { opacity: .5; cursor: default; }
.round-btn.lock { width: 40px; }
.round-btn.lock[aria-pressed="true"] { background: var(--ai); color: #5d4fa3; }
.round-btn.mic { background: var(--ai); color: #5d4fa3; }
.round-btn.mic .i-stop { display: none; }
.round-btn.mic.recording-on { background: var(--danger); color: white; }
.round-btn.mic.recording-on .i-mic { display: none; }
.round-btn.mic.recording-on .i-stop { display: block; }
.round-btn.send { background: var(--primary); color: white; }
.round-btn.send:hover:not(:disabled) { background: var(--primary-strong); }

dialog {
  border: 0; border-radius: var(--radius); padding: 24px; max-width: min(400px, calc(100vw - 32px));
  color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(74, 68, 88, .35); backdrop-filter: blur(2px); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; z-index: 10; max-width: calc(100vw - 32px); text-align: center;
}

@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
