:root {
  --navy: #1f2a44;
  --gold: #e2c58b;
  --cream: #faf7f0;
  --line: #e7dfce;
  --muted: #6b6558;
  --red: #b3202a;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: #26231d; background: var(--cream); font-size: 15px; line-height: 1.55;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #2f6fed; outline-offset: 2px; }

.app { position: relative; display: flex; flex-direction: column; height: 100%; max-width: 560px; margin: 0 auto; background: #fff; overflow: hidden; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--navy); color: #fff; }
.title { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.title strong { font-size: 15px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--gold); color: var(--navy); font-weight: 700; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent; color: inherit; font-size: 18px; }
.top .icon-btn:hover { background: rgba(255,255,255,.12); }

.stage { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: linear-gradient(#fff6e3, #fff); border-bottom: 1px solid var(--line); }
.avatar { position: relative; flex: 0 0 auto; width: 128px; height: 138px; border-radius: 18px; overflow: hidden; border: 2px solid var(--gold); background: #fff6e3; }
.avatar svg { display: block; width: 100%; height: 100%; }
.avatar.speaking svg { animation: bob 1.1s ease-in-out infinite; }
.speaking-dot { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(31,42,68,.82); color: #fff; font-size: 11px; text-align: center; padding: 1px 0; }
.hello { margin: 0; font-size: 14px; color: #3d3829; }
.lid { transform-box: fill-box; transform-origin: center top; transform: scaleY(0); animation: blink 5s infinite; }
#mouth-inside { transform-box: fill-box; transform-origin: center; transform: scaleY(0.04); }
#lip-lower { transform-box: fill-box; transform-origin: center top; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(0); } 96.5% { transform: scaleY(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-1.5px); } }

.log { flex: 1 1 auto; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #fff; overscroll-behavior: contain; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.msg.bot { align-self: flex-start; background: var(--cream); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg .say { display: inline-block; margin-left: 6px; border: 0; background: transparent; font-size: 14px; padding: 0 4px; opacity: .7; }
.msg.typing { color: var(--muted); }
.msg.err { background: #fdecea; border-color: #f2b8b5; }

.chips { display: flex; gap: 6px; padding: 6px 12px; overflow-x: auto; white-space: nowrap; border-top: 1px solid var(--line); background: #fff; scrollbar-width: thin; }
.chips:empty { display: none; }
.chip { flex: 0 0 auto; min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--gold); background: #fffaf0; color: var(--navy); font-size: 13px; }
.chip:hover { background: var(--gold); }

.actions { display: flex; gap: 6px; padding: 6px 12px 0; }
.act { flex: 1; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; border: 1px solid var(--navy); background: #fff; color: var(--navy); font-weight: 700; font-size: 14px; text-decoration: none; padding: 0 8px; }
.act.primary { background: var(--navy); color: #fff; }
.act.wide { width: 100%; margin-top: 8px; }

.composer { display: flex; align-items: center; gap: 6px; padding: 8px 12px 2px; }
.composer input { flex: 1 1 auto; min-width: 0; min-height: 44px; padding: 8px 12px; border-radius: 22px; border: 1px solid #cfc6b0; background: #fff; font-size: 16px; }
.round { flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: 1px solid #cfc6b0; background: #fff; font-size: 18px; }
.round.send { background: var(--navy); border-color: var(--navy); color: #fff; }
.round.on { background: var(--gold); border-color: var(--navy); }
.round.listening { background: var(--red); border-color: var(--red); color: #fff; animation: pulse 1.1s infinite; }
.round:disabled { opacity: .4; cursor: not-allowed; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(179,32,42,.2); } }

.status { margin: 0; padding: 0 14px; min-height: 18px; font-size: 12.5px; color: var(--red); }
.notice { margin: 0; padding: 2px 14px calc(8px + env(safe-area-inset-bottom)); font-size: 11px; line-height: 1.45; color: var(--muted); }

.sheet { position: absolute; inset: 0; background: rgba(31,42,68,.5); display: flex; align-items: flex-end; z-index: 10; }
.sheet-body { width: 100%; max-height: 92%; overflow-y: auto; background: #fff; border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body label { display: block; margin-top: 10px; font-size: 13px; font-weight: 700; }
.sheet-body input:not([type=checkbox]), .sheet-body select, .sheet-body textarea { display: block; width: 100%; margin-top: 4px; min-height: 44px; padding: 8px 10px; border: 1px solid #cfc6b0; border-radius: 10px; font-size: 16px; background: #fff; font-weight: 400; }
.sheet-body .consent { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; font-size: 12.5px; }
.sheet-body .consent input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }
.sheet-body .ok { color: #1c6b3a; }

@media (prefers-reduced-motion: reduce) {
  .lid, .avatar.speaking svg, .round.listening { animation: none; }
}
