:root {
  --bg: #1d140e;
  --panel: #2a1d14;
  --line: #4a3524;
  --text: #f4e9d8;
  --muted: #b9a58c;
  --steve: #3a2819;
  --me: #c96f4a;
  --accent: #d9a441;
  --danger: #e0705a;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

/* ---------- scène ---------- */
#scene {
  position: relative;
  flex: 0 0 auto;
  height: min(42dvh, 360px);
  overflow: hidden;
  border-radius: 0 0 28px 28px;
  box-shadow: 0 10px 30px #0008;
}
#scene > svg { width: 100%; height: 100%; display: block; }
#scene header {
  position: absolute; inset: 0 0 auto 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: linear-gradient(#0009, #0000);
}
#scene h1 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: .2px; }
#demoBadge {
  position: absolute; left: 14px; top: calc(env(safe-area-inset-top) + 48px);
  font-size: 12px; padding: 4px 10px; border-radius: 99px;
  background: #000a; color: var(--accent);
}

.icon-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #0005; color: var(--text);
}
.icon-btn.primary { background: var(--me); color: #fff; }
.icon-btn:disabled { opacity: .4; }
#micBtn.listening { background: var(--danger); animation: pulse 1.1s ease-in-out infinite; }

.sky { fill: #8ec9e8; }
.sunmoon { fill: #ffe08a; }
.night .sky { fill: #1b2748; }
.night .sunmoon { fill: #e8ecf5; }

/* ---------- Steve beweegt ---------- */
.steve, .head, .eye, .brow, .mouth, .stache { transform-box: fill-box; transform-origin: center; }
.steve { animation: breathe 4.5s ease-in-out infinite; transform-origin: 50% 100%; }
.head { transition: transform .35s ease; transform-origin: 50% 90%; }
.eye { animation: blink 5.5s infinite; }
.brow { transition: transform .3s ease; }
.steam path { animation: steam 3s ease-in-out infinite; }
.steam path + path { animation-delay: 1.2s; }

.mouth { display: none; }
[data-mood="blij"] .m-smile,
[data-mood="knipoog"] .m-smile,
[data-mood="lachen"] .m-laugh,
[data-mood="verrast"] .m-o,
[data-mood="denken"] .m-flat,
[data-mood="zorgzaam"] .m-flat { display: block; }

.talking .mouth { display: none !important; }
.talking .m-talk { display: block !important; animation: talk .28s ease-in-out infinite alternate; }
.talking .stache { animation: stache .28s ease-in-out infinite alternate; }

[data-mood="lachen"] .head { animation: chuckle .35s ease-in-out 4 alternate; }
[data-mood="lachen"] .eye { transform: scaleY(.35); animation: none; }
[data-mood="lachen"] .brow { transform: translateY(-4px); }
[data-mood="verrast"] .brow { transform: translateY(-9px); }
[data-mood="verrast"] .eye { transform: scale(1.3); animation: none; }
[data-mood="denken"] .head { transform: rotate(-5deg); }
[data-mood="denken"] .brow-l { transform: translateY(-6px) rotate(-8deg); }
[data-mood="denken"] .brow-r { transform: translateY(2px) rotate(6deg); }
[data-mood="zorgzaam"] .head { transform: rotate(4deg); }
[data-mood="zorgzaam"] .brow-l { transform: rotate(-12deg) translateY(-2px); }
[data-mood="zorgzaam"] .brow-r { transform: rotate(12deg) translateY(-2px); }
[data-mood="knipoog"] .eye-r { transform: scaleY(.12); animation: none; }
[data-mood="knipoog"] .brow-r { transform: translateY(3px); }
[data-mood="knipoog"] .head { transform: rotate(3deg); }

@keyframes breathe { 50% { transform: scaleY(1.012); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97.5% { transform: scaleY(.08); } }
@keyframes talk { from { transform: scaleY(.25); } to { transform: scaleY(1); } }
@keyframes stache { to { transform: translateY(-1.5px); } }
@keyframes chuckle { to { transform: translateY(3px); } }
@keyframes steam { 0% { opacity: 0; transform: translateY(6px); } 40% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px #e0705a33; } }

/* ---------- gesprek ---------- */
#chat {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.msg {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.steve { align-self: flex-start; background: var(--steve); border-bottom-left-radius: 6px; }
.msg.me { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 6px; }
.msg.error { align-self: center; background: none; color: var(--danger); font-size: 14px; text-align: center; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 0; }
.msg.steve:empty::after { content: "● ● ●"; letter-spacing: 2px; font-size: 10px; color: var(--muted); animation: pulse-dots 1s infinite alternate; }
@keyframes pulse-dots { to { opacity: .3; } }

#composer {
  flex: 0 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--line);
}
#composer .icon-btn:not(.primary) { background: var(--steve); }
#input {
  flex: 1; min-width: 0;
  resize: none; max-height: 120px;
  padding: 10px 14px;
  font: inherit; font-size: 17px; color: var(--text);
  background: var(--steve);
  border: 1px solid var(--line); border-radius: 22px;
  outline: none;
}
#input:focus { border-color: var(--accent); }
#input::placeholder { color: var(--muted); }

/* ---------- notitieboekje ---------- */
#sheet { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.backdrop { position: absolute; inset: 0; background: #000a; }
.panel {
  position: relative;
  width: 100%; max-width: 560px; max-height: 82dvh; overflow-y: auto;
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
  background: var(--panel);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--line);
}
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.panel h2 { margin: 0 0 4px; font-size: 20px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.hint.small { font-size: 12px; text-align: center; margin: 14px 0 6px; }
#memList { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#memList li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px 8px 12px;
  background: #f4e9d8; color: #3a2819;
  border-radius: 10px; border-left: 4px solid var(--me);
  font-size: 15px;
}
#memList li span { flex: 1; overflow-wrap: anywhere; }
#memList li button { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%; font-size: 18px; color: #7a3b2e; }
#memList .empty { background: none; border: 1px dashed var(--line); color: var(--muted); padding: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.row input { width: 22px; height: 22px; accent-color: var(--accent); }
.panel button.danger, .panel button.close {
  width: 100%; min-height: 46px; margin-top: 8px; border-radius: 14px;
}
.panel button.danger { color: var(--danger); border: 1px solid var(--line); }
.panel button.close { background: var(--steve); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- taal + meeluisteren ---------- */
.tools { display: flex; align-items: center; gap: 8px; }
.pill {
  min-width: 44px; height: 44px; padding: 0 12px;
  border-radius: 22px; background: #0005;
  font-weight: 800; font-size: 14px; letter-spacing: .5px;
}
#listenBtn[aria-pressed="true"] { background: var(--danger); color: #fff; }
#listenBadge {
  position: absolute; left: 14px; bottom: 12px;
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; padding: 5px 12px; border-radius: 99px;
  background: #000b; color: #fff;
}
#listenBadge i { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: pulse-dots .9s infinite alternate; }
.msg.heard { align-self: stretch; max-width: none; background: none; padding: 0 6px; color: var(--muted); font-size: 13px; font-style: italic; }

/* ---------- hanger ---------- */
.block { border-top: 1px solid var(--line); padding: 12px 0 14px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.block h3 { margin: 0 0 6px; font-size: 16px; }
.panel button.plain { width: 100%; min-height: 46px; border-radius: 14px; background: var(--steve); }
.kv { margin: 0 0 10px; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
code { font-family: ui-monospace, Menlo, monospace; font-size: .92em; }
#hangerStatus.warn { color: var(--danger); }
