:root {
  --bg: #fefefe;
  --ink: #2b2733;
  --muted: #6e6a78;
  --brand: #b9a3da;
  --brand-ink: #3a2d52;
  --nia-bubble: #efe8f8;
  --me-bubble: #b9a3da;
  --line: #e6e1ee;
  --danger: #b3382c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17141c;
    --ink: #efeaf6;
    --muted: #a49fb0;
    --nia-bubble: #2a2336;
    --me-bubble: #7b63a8;
    --line: #2f2a3a;
    --danger: #ff8f84;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden, [hidden] { display: none !important; }

.screen { max-width: 640px; margin: 0 auto; min-height: 100dvh; padding: 24px 16px; }

/* Masuk */
#login { display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero { border-radius: 50%; margin-top: 12px; box-shadow: 0 6px 24px rgba(120, 90, 170, .25); }
h1 { margin: 12px 0 4px; font-size: 28px; }
.lead { margin: 0 0 20px; color: var(--muted); max-width: 32ch; }
#loginForm { width: 100%; max-width: 360px; text-align: left; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%;
}
input:focus-visible, button:focus-visible { outline: 3px solid var(--brand); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 12px;
  padding: 12px 18px; background: var(--brand); color: var(--brand-ink);
}
button:disabled { opacity: .6; cursor: default; }
button.ghost { background: transparent; color: var(--muted); font-weight: 500; padding: 8px 10px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.fine { color: var(--muted); font-size: 13px; margin-top: 18px; }

/* Obrolan */
#chat { display: flex; flex-direction: column; height: 100dvh; padding: 0; }
header {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line);
}
header img { border-radius: 50%; }
.who { flex: 1; display: grid; line-height: 1.2; }
.who small { color: var(--muted); }
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.msg.nia { align-self: flex-start; background: var(--nia-bubble); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--me-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg .en { font-weight: 500; }
.msg .note { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }
.msg .fix { display: block; margin-top: 6px; font-size: 14px; }
.msg .care {
  display: block; margin-top: 8px; padding: 8px 10px; font-size: 14px; border-radius: 10px;
  background: rgba(185, 163, 218, .25);
}
.msg.system { align-self: center; max-width: 92%; background: transparent; color: var(--muted); text-align: center; font-size: 14px; }
.typing { color: var(--muted); font-style: italic; }
#composer {
  display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
#composer input { flex: 1; min-width: 0; }
button.icon { font-size: 20px; line-height: 1; }
.status { margin: 0; padding: 6px 16px 0; min-height: 26px; font-size: 13px; color: var(--muted); text-align: center; }
.mic {
  flex: none; width: 46px; height: 46px; padding: 0; border-radius: 50%;
  font-size: 22px; line-height: 1; background: var(--nia-bubble); color: var(--ink);
}
.mic[hidden] { display: none; }
.mic[data-state="listen"] { background: var(--danger); color: #fff; }
.mic[data-state="wait"], .mic[data-state="think"], .mic[data-state="speak"] { background: var(--brand); color: var(--brand-ink); }
@media (prefers-reduced-motion: no-preference) {
  .mic[data-state="listen"] { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { transform: scale(1.12); } }
}
@media (prefers-reduced-motion: no-preference) {
  .msg { animation: pop .18s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(6px); } }
}
