/* A picture book that woke up: warm paper, ink lines, colours lifted from the
   illustration. Very little UI; the camera and the character are the page. */

:root {
  --paper: #FBF4E6;
  --paper-2: #F3E7CF;
  --ink: #3B2326;
  --ink-soft: rgba(59, 35, 38, .72);
  --hair: #7E2F3B;
  --teal: #4FB3A2;
  --mustard: #F2B544;
  --coral: #E8645A;
  --shadow: 0 10px 30px rgba(59, 35, 38, .22);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'Fredoka', 'Rubik', system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #1d1414;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- stage ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; }
/* MindAR injects its own video + canvas; keep them full-bleed. */
#stage video, #stage canvas { position: absolute !important; }
#stage.demo-bg {
  background:
    radial-gradient(120% 70% at 50% 110%, #E9D6B3 0%, transparent 60%),
    linear-gradient(180deg, #F7EEDC 0%, #EFDDBD 100%);
}

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 30;
  display: none; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(90% 60% at 80% 0%, rgba(242, 181, 68, .22), transparent 70%),
    radial-gradient(90% 60% at 10% 100%, rgba(79, 179, 162, .20), transparent 70%),
    var(--paper);
}
.screen.show { display: flex; }

.start-card { width: min(420px, 100%); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.start-poster {
  height: min(38vh, 330px); width: auto;
  filter: drop-shadow(0 14px 18px rgba(59, 35, 38, .18));
  animation: bob 3.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px) rotate(-1deg); } }
h1 { margin: 4px 0 0; font-size: clamp(26px, 7vw, 34px); font-weight: 700; line-height: 1.15; color: var(--hair); }
.start-sub { margin: 0 0 6px; font-size: 17px; line-height: 1.45; color: var(--ink-soft); max-width: 30ch; }

.btn-primary, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 58px; width: 100%; padding: 0 22px; border-radius: 999px;
  font-size: 20px; font-weight: 600;
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn-primary { background: var(--coral); color: #fff; box-shadow: 0 6px 0 #B9463E, var(--shadow); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #B9463E, var(--shadow); }
.btn-secondary { background: transparent; color: var(--ink); border: 2px solid rgba(59, 35, 38, .25); }
.btn-secondary:active { transform: scale(.98); }
.btn-primary.small, .btn-secondary.small { min-height: 48px; font-size: 17px; width: auto; }
.btn-icon { width: 26px; height: 26px; }

.parent-note { margin-top: 6px; width: 100%; text-align: start; font-size: 14px; line-height: 1.5; color: var(--ink-soft); }
.parent-note summary { cursor: pointer; font-weight: 500; text-align: center; list-style: none; padding: 8px; }
.parent-note summary::-webkit-details-marker { display: none; }
.parent-note summary::before { content: '🔒 '; }
.parent-note p { margin: 6px 0; padding: 0 6px; }

/* ---------- loading ---------- */
.loading-card { text-align: center; }
.loading-card p { font-size: 19px; margin: 18px 0 14px; }
.progress { width: 220px; height: 10px; border-radius: 99px; background: var(--paper-2); overflow: hidden; margin: 0 auto; }
.progress i { display: block; height: 100%; width: 100%; background: var(--teal); border-radius: 99px; transform: scaleX(0); transform-origin: right; transition: transform .25s ease; }
.book-anim { display: flex; gap: 6px; justify-content: center; height: 48px; align-items: flex-end; }
.book-anim span { width: 16px; height: 44px; border-radius: 4px; background: var(--mustard); animation: flip 1.1s ease-in-out infinite; transform-origin: bottom; }
.book-anim span:nth-child(2) { background: var(--teal); animation-delay: .15s; }
.book-anim span:nth-child(3) { background: var(--coral); animation-delay: .3s; }
@keyframes flip { 50% { transform: scaleY(.55); } }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 20; display: none; pointer-events: none; }
.hud.show { display: block; }
.hud > * { pointer-events: auto; }

.hud-top {
  position: absolute; top: 0; inset-inline: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(12px + var(--safe-top)) 14px 12px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-actions { display: flex; gap: 10px; margin-inline-start: auto; }
.badge {
  background: var(--mustard); color: var(--ink); font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 99px; box-shadow: var(--shadow);
}

.icon-btn {
  width: 48px; height: 48px; padding: 12px; border-radius: 50%;
  background: rgba(251, 244, 230, .92); color: var(--ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.icon-btn.small { width: 52px; height: 52px; padding: 13px; }
.icon-btn[aria-pressed="false"] { opacity: .6; }
.icon-btn .vol-off { display: none; }
.icon-btn[aria-pressed="false"] .vol-on { display: none; }
.icon-btn[aria-pressed="false"] .vol-off { display: block; }
.icon-btn .vol-on, .icon-btn .vol-off { width: 100%; height: 100%; }

/* aim guide */
.aim {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  pointer-events: none; opacity: 0; transition: opacity .35s ease;
}
.aim.show { opacity: 1; }
.aim-frame { position: relative; width: min(62vw, 300px); aspect-ratio: 1 / 1.3; animation: breathe 2.4s ease-in-out infinite; }
.aim-frame i { position: absolute; width: 38px; height: 38px; border: 5px solid var(--paper); filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.aim-frame i:nth-child(1) { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.aim-frame i:nth-child(2) { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.aim-frame i:nth-child(3) { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.aim-frame i:nth-child(4) { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
@keyframes breathe { 50% { transform: scale(1.04); } }
.aim p {
  margin: 0; padding: 10px 18px; border-radius: 99px; font-size: 18px; font-weight: 500;
  background: rgba(251, 244, 230, .94); box-shadow: var(--shadow); max-width: 86vw; text-align: center;
}

/* bottom */
.hud-bottom {
  position: absolute; bottom: 0; inset-inline: 0;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 0 16px calc(16px + var(--safe-bottom));
  pointer-events: none;
}
.hud-bottom > * { pointer-events: auto; }

.caption {
  /* A speech bubble at the top: the character's body stays visible below it. */
  position: absolute; top: calc(72px + var(--safe-top)); inset-inline: 0; margin: 0 auto;
  width: fit-content; max-width: min(92vw, 480px);
  padding: 12px 18px; border-radius: var(--radius);
  background: rgba(251, 244, 230, .95); box-shadow: var(--shadow);
  font-size: 19px; line-height: 1.45; text-align: center;
  opacity: 0; transform: translateY(-8px); transition: opacity .25s ease, transform .25s ease;
  max-height: 34vh; overflow: hidden; pointer-events: none;
}
.caption::after {
  content: ''; position: absolute; bottom: -9px; left: 50%; margin-left: -10px;
  border: 10px solid transparent; border-bottom: 0; border-top-color: rgba(251, 244, 230, .95);
}
.caption.show { opacity: 1; transform: none; }
.caption.user { background: rgba(79, 179, 162, .95); color: #fff; font-size: 16px; }
.caption.user::after { border-top-color: rgba(79, 179, 162, .95); }
.hide-captions .caption { display: none; }

.chips {
  display: flex; flex-wrap: nowrap; gap: 8px; max-width: 100vw; overflow-x: auto;
  padding: 2px 16px 4px; margin: 0 -16px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
          mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip {
  flex: none; padding: 9px 15px; border-radius: 99px; font-size: 16px; font-weight: 500; white-space: nowrap;
  background: rgba(251, 244, 230, .93); box-shadow: 0 3px 10px rgba(0,0,0,.15);
}
.chip:active { transform: scale(.96); }

.controls { display: flex; align-items: center; justify-content: center; gap: 22px; width: 100%; }
.controls .spacer { width: 52px; }

/* the big talk button */
.talk {
  position: relative; width: 92px; height: 92px; border-radius: 50%; padding: 26px;
  background: var(--coral); color: #fff;
  box-shadow: 0 6px 0 #B9463E, 0 12px 26px rgba(0,0,0,.28);
  transition: transform .15s ease, background .2s ease;
}
.talk:active { transform: translateY(3px); }
.talk .i-stop, .talk .i-dots { display: none; }
.talk-ring {
  position: absolute; inset: -9px; border-radius: 50%;
  border: 5px solid rgba(232, 100, 90, .45); pointer-events: none;
  transform: scale(var(--lvl, 1)); transition: transform .08s linear, border-color .2s ease;
}
.talk[data-state="listening"] { background: var(--teal); box-shadow: 0 6px 0 #33887A, 0 12px 26px rgba(0,0,0,.28); }
.talk[data-state="listening"] .talk-ring { border-color: rgba(79, 179, 162, .6); }
.talk[data-state="listening"] .i-mic { display: none; }
.talk[data-state="listening"] .i-stop { display: block; }
.talk[data-state="thinking"] { background: var(--mustard); color: var(--ink); box-shadow: 0 6px 0 #C38C24, 0 12px 26px rgba(0,0,0,.28); }
.talk[data-state="thinking"] .i-mic { display: none; }
.talk[data-state="thinking"] .i-dots { display: flex; }
.talk[data-state="speaking"] .i-mic { display: none; }
.talk[data-state="speaking"] .i-stop { display: block; }
.talk[data-state="speaking"] .talk-ring { animation: pulse 1.2s ease-in-out infinite; }
.talk[data-state="disabled"] { background: #B7A99A; box-shadow: 0 6px 0 #8E8174; }
@keyframes pulse { 50% { transform: scale(1.1); opacity: .5; } }
.i-dots { position: absolute; inset: 0; align-items: center; justify-content: center; gap: 6px; }
.i-dots i { width: 10px; height: 10px; border-radius: 50%; background: currentColor; animation: dot 1s ease-in-out infinite; }
.i-dots i:nth-child(2) { animation-delay: .15s; }
.i-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { transform: translateY(-6px); opacity: .5; } }

.talk-label {
  margin: 0; font-size: 16px; font-weight: 600; color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.6), 0 0 12px rgba(0,0,0,.35);
}

/* type form */
.type-form {
  position: absolute; inset-inline: 12px; bottom: calc(12px + var(--safe-bottom));
  display: flex; gap: 8px; padding: 8px; border-radius: 99px;
  background: var(--paper); box-shadow: var(--shadow); z-index: 5;
}
.type-form[hidden] { display: none; }
.type-form input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font: inherit; font-size: 18px; padding: 0 14px; color: var(--ink);
  -webkit-user-select: text; user-select: text;
}

/* notice */
.notice { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(29, 20, 20, .45); }
.notice[hidden] { display: none; }
.notice-card { width: min(380px, 100%); background: var(--paper); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); text-align: center; }
.notice-card p { font-size: 18px; line-height: 1.5; margin: 0 0 16px; }
.notice-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.notice-actions button:empty { display: none; }

@media (prefers-reduced-motion: reduce) {
  .start-poster, .aim-frame, .book-anim span, .talk-ring, .i-dots i { animation: none !important; }
}
