:root {
  --bg: #16131c; --panel: #211c2a; --ink: #f1edf7; --muted: #a59cb4; --line: #342c40;
  --accent: #e7748f; --accent-ink: #fff; --her: #2c2436; --me: #3a3150; --warn: #f0b35a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; }
button.round { border-radius: 999px; width: 46px; height: 46px; padding: 0; flex: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=text], input[type=email], input[type=password] { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.muted { color: var(--muted); }
.screen { height: 100%; }

#auth, #terms { display: grid; place-items: center; padding: 16px; }
.card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.card h1 { margin: 0; font-size: 32px; letter-spacing: .02em; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.msg { min-height: 1.5em; margin: 0; font-size: 14px; color: var(--warn); }

#chat { display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; padding-bottom: env(safe-area-inset-bottom); }
.bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.grow { flex: 1; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
#stage { position: relative; height: 38vh; min-height: 220px; flex: none; }
#stage canvas { width: 100%; height: 100%; display: block; }
#subtitle { position: absolute; left: 16px; right: 16px; bottom: 10px; text-align: center; font-size: 17px; text-shadow: 0 1px 3px #000; }
#log { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.her { background: var(--her); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--me); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .emo { display: block; font-size: 11px; color: var(--muted); }
.notice { margin: 0 16px 8px; padding: 8px 12px; border: 1px solid var(--warn); color: var(--warn); border-radius: 10px; font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#composer { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
#mic.listening { background: var(--accent); border-color: var(--accent); }
.settings { margin: 0 16px; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 8px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.settings label.toggle { flex-direction: row; align-items: center; }
.settings p { margin: 0; font-size: 13px; }

/* terms: the document scrolls inside the card; one checkbox, one button */
.terms-card { width: min(640px, 100%); }
.terms-card h2 { margin: 0; font-size: 18px; }
#termsDoc { width: 100%; height: min(55vh, 520px); border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.agree { align-items: flex-start; color: var(--ink); line-height: 1.5; }
.agree input { margin-top: 4px; flex: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
