/* Bramble — storybook woodland at dusk.
   Palette: parchment cream, deep moss & pine, caramel brown, one gold magic accent.
   Never pink-glam (DESIGN_BRIEF.md §3.1). */

:root {
  --parchment: #f6efdd;
  --parchment-deep: #ecdfc3;
  --ink: #3b2f23;
  --ink-soft: #6b5a44;
  --moss: #4a5d3a;
  --pine: #2e4030;
  --caramel: #b07d3f;
  --cocoa: #7a5a35;
  --gold: #f4b942;
  --gold-deep: #c99b4f;
  --blush: #d9a08a;
  --card: #fbf6e9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Andika", "Comic Sans MS", sans-serif;
  color: var(--ink);
  background: var(--pine);
  overflow-x: hidden;
}

/* dusk atmosphere behind the parchment */
.dusk {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(120% 90% at 50% -10%, #55684422 0%, transparent 60%),
    radial-gradient(100% 70% at 50% 110%, #1d2b1f 0%, transparent 55%),
    linear-gradient(180deg, #38503a 0%, #2e4030 45%, #263528 100%);
}
.grain {
  position: fixed; inset: 0; z-index: 1; pointer-events: none; opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.page {
  position: relative; z-index: 2;
  max-width: 560px; margin: 0 auto;
  min-height: 100dvh;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- masthead ---------- */
.masthead { text-align: center; color: var(--parchment); padding-top: 4px; }
.wordmark {
  font-family: "Fraunces", serif;
  font-weight: 750; font-size: clamp(40px, 11vw, 56px);
  letter-spacing: .5px; line-height: 1;
  color: var(--parchment);
  text-shadow: 0 2px 0 #1d2b1f88;
}
.wordmark::after { content: "✦"; color: var(--gold); font-size: .45em; vertical-align: super; margin-left: 6px; }
.tagline { font-size: 14px; color: #cfd8c0; margin-top: 6px; font-style: italic; }

/* ---------- stage card ---------- */
.stage {
  background:
    radial-gradient(140% 100% at 50% 0%, var(--card) 0%, var(--parchment) 70%, var(--parchment-deep) 100%);
  border-radius: 26px;
  border: 2px solid #d8c69e;
  box-shadow: 0 18px 40px -18px #00000088, inset 0 0 0 6px #fff7e433;
  padding: 20px 16px 18px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}

.unicorn-btn {
  width: min(64vw, 260px); aspect-ratio: 1;
  border: none; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease;
}
.unicorn-btn:active { transform: scale(.96); }

.unicorn { width: 100%; height: 100%; overflow: visible; }

/* --- unicorn anatomy --- */
.face   { fill: #efe4c9; stroke: var(--cocoa); stroke-width: 3.5; }
.muzzle { fill: #f8f1de; stroke: var(--cocoa); stroke-width: 3; }
.ear    { fill: #efe4c9; stroke: var(--cocoa); stroke-width: 3.5; }
.ear-inner { fill: var(--blush); opacity: .7; }
.mane   { fill: var(--caramel); stroke: var(--cocoa); stroke-width: 2.5; opacity: .95; }
.eye    { fill: var(--ink); }
.glint  { fill: #fff; }
.blush  { fill: var(--blush); opacity: .55; }
.nostril, .mouth { stroke: var(--cocoa); stroke-width: 3; fill: none; stroke-linecap: round; }
.horn-sparks circle, .think-sparks circle { fill: var(--gold); opacity: 0; }
.ear-halo { opacity: 0; }

/* breathing — always */
.head { transform-origin: 120px 130px; animation: breathe 3.6s ease-in-out infinite; }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.025); } }

/* blink */
.eyes { animation: blink 5.2s infinite; transform-origin: 120px 120px; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96.5% { transform: scaleY(.08); } }

/* ---------- states ---------- */
/* listening: the ear GLOWS — the honest indicator (brief §6) */
body[data-state="listening"] .ear-halo { animation: halo 1.6s ease-in-out infinite; }
@keyframes halo { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
body[data-state="listening"] .horn-sparks circle { animation: twinkle 1.8s infinite; }
body[data-state="listening"] .status-dot { background: var(--gold); box-shadow: 0 0 10px var(--gold); }

/* thinking: sparkles orbit */
body[data-state="thinking"] .think-sparks { animation: orbit 2.2s linear infinite; transform-origin: 120px 120px; }
body[data-state="thinking"] .think-sparks circle { opacity: .9; }
@keyframes orbit { to { transform: rotate(360deg); } }
body[data-state="thinking"] .status-dot { background: var(--caramel); }

/* ack reaction clip playing while he thinks: the ears perk up.
   body.ack is set by app.js for the duration of kind="ack" audio. */
.ear, .ear-inner {
  transform-box: fill-box; transform-origin: 50% 90%;
  transition: transform .28s cubic-bezier(.34, 1.56, .64, 1);
}
body.ack[data-state="thinking"] .ear-left  { transform: rotate(-8deg) translateY(-3px); }
body.ack[data-state="thinking"] .ear-right { transform: rotate(8deg)  translateY(-3px); }
body.ack[data-state="thinking"] .ear-inner { transform: rotate(-8deg) translateY(-3px); }

/* speaking: mouth bobs, horn twinkles */
body[data-state="speaking"] .mouth { animation: chat .34s ease-in-out infinite alternate; }
@keyframes chat { from { d: path("M108 172 Q120 182 132 172"); } to { d: path("M108 174 Q120 190 132 174"); } }
body[data-state="speaking"] .head { animation: bob .68s ease-in-out infinite, breathe 3.6s ease-in-out infinite; }
@keyframes bob { 0%,100% { rotate: 0deg; } 30% { rotate: 1.6deg; } 70% { rotate: -1.4deg; } }
body[data-state="speaking"] .horn-sparks circle { animation: twinkle 1.1s infinite; }
body[data-state="speaking"] .status-dot { background: var(--moss); }

@keyframes twinkle { 0%,100% { opacity: 0; } 50% { opacity: 1; } }

/* idle/sleep: eyes droop */
body[data-state="idle"] .eyes { transform: scaleY(.55); transform-origin: 120px 120px; animation: none; }
body[data-state="idle"] .status-dot { background: #8b8b7a; }

/* ---------- status ---------- */
.status {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; color: var(--ink-soft);
}
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #8b8b7a; transition: background .3s;
}

/* ---------- transcript scroll ---------- */
.scroll {
  flex: 1; min-height: 120px;
  display: flex; flex-direction: column; gap: 10px;
  padding: 4px 2px 8px;
  overflow-y: auto;
}
.bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15.5px; line-height: 1.45;
  animation: pop .22s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } }
.bubble.child {
  align-self: flex-end;
  background: var(--parchment);
  border: 1.5px solid #d8c69e;
  border-bottom-right-radius: 6px;
  color: var(--ink);
}
.bubble.bramble {
  align-self: flex-start;
  background: #405236;
  border: 1.5px solid #55684455;
  border-bottom-left-radius: 6px;
  color: #f2eeda;
}
.bubble.bramble b { color: var(--gold); font-weight: 700; }
.bubble.system {
  align-self: center; text-align: center;
  background: none; border: none;
  color: #b9c4a8; font-size: 13px; font-style: italic;
}

/* ---------- grown-ups drawer ---------- */
.drawer {
  background: #24321f;
  border: 1.5px solid #3c4f33;
  border-radius: 16px;
  color: #d6ddc8;
  padding: 10px 14px;
}
.drawer summary {
  cursor: pointer; font-size: 13.5px; letter-spacing: .06em;
  text-transform: uppercase; color: #a9b795;
}
.drawer-grid {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 0 6px;
  font-size: 14px;
}
.drawer-grid label { display: flex; gap: 6px; align-items: center; }
.drawer select, .drawer button {
  font-family: inherit; font-size: 14px;
  background: var(--parchment); color: var(--ink);
  border: 1.5px solid #d8c69e; border-radius: 8px; padding: 5px 8px;
}
.drawer button { cursor: pointer; background: var(--caramel); color: #fff8ea; border-color: var(--cocoa); }
.timings { font-size: 12px; color: #94a380; width: 100%; font-variant-numeric: tabular-nums; }
.smallprint { font-size: 12px; color: #8a9878; padding-bottom: 6px; line-height: 1.5; }

@media (min-width: 700px) {
  .page { padding-top: 40px; }
}
