/* Cari Monsters — app shell.
   Visual language borrowed from the "Night Mouth" scroll world: deep blue-black
   cave, warm paper text, monster colours as the only saturated accents. */

@font-face { font-family: 'Baloo 2'; src: local('Baloo 2'); font-display: swap; }

:root {
  --ink: #05060f;
  --cave: #0a0e22;
  --cave-2: #141a3a;
  --paper: #f6f1e6;
  --muted: #9aa2c4;
  --red: #e23b3b;
  --pink: #f07ab0;
  --green: #3ea34a;
  --gold: #ffc94d;
  --radius: 20px;
  --tap: 56px; /* minimum touch target — small hands, wet fingers */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: 'Baloo 2', 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app {
  position: relative;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 15%, var(--cave-2) 0%, var(--cave) 55%, var(--ink) 100%);
}

/* ---------- screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  opacity: 0;
  visibility: hidden;
  transform: scale(0.98);
  transition: opacity .28s ease, transform .28s ease, visibility .28s;
}
.screen.active { opacity: 1; visibility: visible; transform: none; }

h1 { font-size: clamp(28px, 8vw, 44px); margin: 0 0 6px; letter-spacing: -0.02em; }
h2 { font-size: clamp(20px, 5.5vw, 28px); margin: 0 0 4px; }
p.sub { color: var(--muted); margin: 0 0 24px; font-size: 16px; line-height: 1.5; }

/* ---------- buttons ---------- */

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

.btn {
  min-height: var(--tap);
  padding: 14px 26px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .12s ease, filter .12s ease;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(160deg, var(--gold), #ffab2e); }
.btn.spray { background: linear-gradient(160deg, #6fe3ff, #2fb8e6); font-size: 22px; }
.btn.ghost { background: rgba(255,255,255,.08); color: var(--paper); }
.btn.full { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.stack { display: flex; flex-direction: column; gap: 12px; margin-top: auto; }

/* ---------- title screen ---------- */

.brandmark {
  font-size: clamp(34px, 10vw, 56px);
  line-height: 1.05;
  margin: 0;
  text-shadow: 0 6px 0 rgba(0,0,0,.35);
}
.brandmark em { font-style: normal; color: var(--gold); display: block; }

.hero-monsters {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 4px;
  margin: 8px 0 4px;
  flex: 1;
  min-height: 0;
}
.hero-monsters img {
  width: 33%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.5));
  animation: bob 3.2s ease-in-out infinite;
}
.hero-monsters img:nth-child(2) { animation-delay: -1.1s; transform: scale(1.12); z-index: 2; }
.hero-monsters img:nth-child(3) { animation-delay: -2.2s; }

@keyframes bob { 0%,100% { translate: 0 0; } 50% { translate: 0 -10px; } }

/* ---------- profiles ---------- */

.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding: 4px 0 12px;
  flex: 1;
  align-content: start;
}
.profile-card {
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: rgba(255,255,255,.07);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  position: relative;
  border: 2px solid transparent;
  transition: border-color .15s, background .15s;
}
.profile-card.selected { border-color: var(--gold); background: rgba(255,201,77,.14); }
.profile-card .dot { width: 34px; height: 34px; border-radius: 50%; }
.profile-card .meta { font-size: 12px; color: var(--muted); font-weight: 500; }
.profile-card.add { border: 2px dashed rgba(255,255,255,.25); font-size: 30px; color: var(--muted); }
.profile-card .del {
  position: absolute; top: 4px; right: 6px;
  width: 26px; height: 26px; line-height: 1;
  color: var(--muted); font-size: 17px;
}

/* ---------- brushing screen ---------- */

#stage-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror — kids expect a mirror, not a photo */
  /* Kept bright: the child's own face is the stage, not a backdrop. */
  filter: saturate(.9) brightness(.82);
}
#fx-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 1;
  pointer-events: none;
}
#brush-screen { padding: 0; }
#brush-screen .layer {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(5,6,15,.68) 0%, rgba(5,6,15,.04) 30%, rgba(5,6,15,.86) 100%);
}

.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer {
  font-size: 42px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1;
  text-shadow: 0 3px 0 rgba(0,0,0,.4);
  transition: color .2s, scale .2s;
}
.timer.urgent { color: var(--gold); scale: 1.08; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0,0,0,.4); color: var(--paper);
  font-size: 19px; line-height: 1;
  display: grid; place-items: center;
}

.combo { text-align: center; line-height: 1; }
.combo[hidden] { display: none; }
.combo b {
  display: block; font-size: 30px; color: var(--gold);
  text-shadow: 0 3px 0 rgba(0,0,0,.4);
  animation: comboPop .22s ease;
}
.combo span { font-size: 11px; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
@keyframes comboPop { from { scale: 1.4; } to { scale: 1; } }

/* ---------- mouth map ---------- */

.zone-guide { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.mouth-map { width: 96px; flex: none; }
.mouth-outline { fill: rgba(0,0,0,.35); stroke: rgba(255,255,255,.35); stroke-width: 2; }
.quad { fill: rgba(255,255,255,.09); transition: fill .3s; }
.quad.on { fill: var(--gold); animation: quadPulse 1.4s ease-in-out infinite; }
.quad.done { fill: rgba(255,201,77,.3); }
@keyframes quadPulse { 0%,100% { opacity: .65; } 50% { opacity: 1; } }
.zone-text .z { font-size: 19px; font-weight: 700; }
.zone-text .h { font-size: 13px; color: var(--muted); }

/* ---------- speech bubble ---------- */

.bubble {
  position: absolute;
  top: 2%;
  left: 50%;
  translate: -50% 0;
  max-width: 78%;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.32;
  padding: 11px 15px;
  border-radius: 16px;
  box-shadow: 0 8px 20px rgba(0,0,0,.45);
  text-align: center;
  z-index: 4;
  animation: bubbleIn .26s cubic-bezier(.2,1.5,.4,1);
}
.bubble[hidden] { display: none; }
.bubble::after {
  content: '';
  position: absolute;
  bottom: -9px; left: 50%;
  translate: -50% 0;
  border: 9px solid transparent;
  border-top-color: var(--paper);
  border-bottom: 0;
}
.bubble.leaving { animation: bubbleOut .2s ease forwards; }
@keyframes bubbleIn { from { scale: .5; opacity: 0; } }
@keyframes bubbleOut { to { scale: .85; opacity: 0; } }

/* ---------- gold germ alert ---------- */

.gold-alert {
  position: absolute;
  bottom: 4%;
  left: 50%;
  translate: -50% 0;
  background: linear-gradient(160deg, var(--gold), #ffab2e);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  padding: 9px 18px;
  border-radius: 999px;
  white-space: nowrap;
  z-index: 4;
  box-shadow: 0 6px 18px rgba(255,201,77,.5);
  animation: alertPulse .7s ease-in-out infinite;
}
.gold-alert[hidden] { display: none; }
@keyframes alertPulse {
  0%,100% { scale: 1; }
  50% { scale: 1.07; }
}

/* ---------- catch capsule ---------- */

.capsule {
  position: absolute;
  width: 74px; height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #b8f2ff, #2fb8e6 60%, #1d7fa3);
  box-shadow: 0 10px 26px rgba(0,0,0,.5), inset 0 -8px 16px rgba(0,0,0,.25);
  display: grid; place-items: center;
}
.capsule[hidden] { display: none; }
.capsule::after {
  content: '';
  width: 100%; height: 7px;
  background: rgba(5,6,15,.6);
}
.capsule.wiggle { animation: wiggle .55s ease-in-out 3; }
@keyframes wiggle {
  0%,100% { rotate: 0deg; }
  25% { rotate: -17deg; }
  75% { rotate: 17deg; }
}
.capsule.settled { animation: settle .4s ease forwards; }
@keyframes settle { to { scale: 1.1; box-shadow: 0 0 40px 10px rgba(255,201,77,.6); } }

/* Monster shrinking into the capsule. */
#brush-monster.sucked { animation: suck .6s cubic-bezier(.5,-0.2,.8,.4) forwards; }
@keyframes suck { to { scale: .05; opacity: 0; rotate: 300deg; } }

.zone-pips { display: flex; gap: 6px; margin: 12px 0 0; }
.zone-pips span {
  height: 6px; flex: 1; border-radius: 3px;
  background: rgba(255,255,255,.16);
  transition: background .3s;
}
.zone-pips span.done { background: var(--gold); }
.zone-pips span.current { background: var(--paper); }

.monster-stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  position: relative;
}
.monster-stage img {
  width: min(62vw, 300px);
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.6));
  transition: filter .3s;
}
.monster-stage img.struggling { animation: shake .32s ease-in-out infinite; }
@keyframes shake {
  0%,100% { rotate: -4deg; scale: 1; }
  50% { rotate: 4deg; scale: 1.04; }
}
/* Idle bob when no brushing is detected — the monster looks smug, not frozen. */
.monster-stage img.smug { animation: bob 2.4s ease-in-out infinite; }

/* A shiny is a rare colour-shifted variant — collection depth without new art. */
.monster-stage img.shiny,
.result-monster.shiny,
.slot img.shiny {
  filter: hue-rotate(155deg) saturate(1.5) drop-shadow(0 0 16px rgba(255,201,77,.9));
}
.shiny-badge {
  display: inline-block;
  background: var(--gold); color: var(--ink);
  font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  margin-left: 8px; vertical-align: middle;
}

/* The cage of bacteria holding the monster — thins out as you brush. */
.cage {
  position: absolute;
  inset: 12% 18%;
  border-radius: 50%;
  border: 3px dashed rgba(140, 220, 120, .75);
  pointer-events: none;
  transition: opacity .4s, scale .4s;
  animation: spin 14s linear infinite;
}
@keyframes spin { to { rotate: 360deg; } }

.health-wrap { margin-top: 8px; }
.health-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.health-bar { height: 14px; border-radius: 999px; background: rgba(255,255,255,.14); overflow: hidden; }
.health-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #8fd94f, #4fae2e);
  transition: width .25s ease;
}

.brush-cue {
  margin-top: 12px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  min-height: 26px;
  transition: color .2s, opacity .2s;
}
.brush-cue.idle { color: var(--gold); animation: pulse 1.1s ease-in-out infinite; }
.brush-cue.active { color: #8fd94f; }
@keyframes pulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }

/* ---------- spray step ---------- */

.spray-burst {
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 62%, rgba(111,227,255,.55), transparent 62%);
  opacity: 0;
  z-index: 3;
}
.spray-burst.go { animation: burst .9s ease-out forwards; }
@keyframes burst {
  0% { opacity: 0; scale: .6; }
  35% { opacity: 1; scale: 1.05; }
  100% { opacity: 0; scale: 1.3; }
}

/* ---------- result ---------- */

.result-monster {
  width: min(58vw, 260px);
  margin: 12px auto;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.55));
  animation: pop .5s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { scale: .4; opacity: 0; } to { scale: 1; opacity: 1; } }

.stat-row { display: flex; gap: 10px; margin: 16px 0; }
.stat {
  flex: 1;
  background: rgba(255,255,255,.07);
  border-radius: 16px;
  padding: 14px 10px;
  text-align: center;
}
.stat b { display: block; font-size: 26px; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- collection ---------- */

.collection-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  overflow-y: auto;
  flex: 1;
  align-content: start;
  padding-bottom: 12px;
}
.slot {
  aspect-ratio: .82;
  border-radius: var(--radius);
  background: rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
}
.slot img { width: 78%; object-fit: contain; }
.slot.locked img { filter: brightness(0) invert(.22); }
.slot { position: relative; }
.slot .n { font-size: 13px; font-weight: 700; }
.slot .c { font-size: 11px; color: var(--muted); }
.slot .out-now {
  position: absolute; top: 6px; right: 6px;
  background: var(--gold); color: var(--ink);
  font-size: 9px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 999px;
}

/* Who's around right now, shown before you start. */
.now-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.07);
  border-radius: 16px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 14px;
}
.now-banner img { width: 34px; height: 34px; object-fit: contain; flex: none; }
.now-banner b { color: var(--gold); }

/* ---------- settings ---------- */

.row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 0;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.row .lbl { font-size: 17px; font-weight: 600; }
.row .desc { font-size: 13px; color: var(--muted); font-weight: 400; }
.seg { display: flex; background: rgba(255,255,255,.08); border-radius: 999px; padding: 4px; }
.seg button {
  padding: 9px 15px; border-radius: 999px; font-size: 15px; font-weight: 700;
  color: var(--muted);
}
.seg button.on { background: var(--paper); color: var(--ink); }

.recap { display: flex; gap: 6px; align-items: flex-end; height: 64px; margin-top: 10px; }
.recap div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.recap .bar { width: 100%; background: rgba(255,255,255,.12); border-radius: 5px; transition: height .3s; }
.recap .bar.has { background: var(--gold); }
.recap .d { font-size: 11px; color: var(--muted); }

.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.topbar .back { font-size: 26px; width: 40px; }
.topbar h2 { margin: 0; }

.note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin-top: 14px;
}

.error {
  background: rgba(226,59,59,.16);
  border: 1px solid rgba(226,59,59,.4);
  border-radius: 14px;
  padding: 14px;
  font-size: 15px;
  margin-bottom: 14px;
}

/* ---------- sheet ---------- */

.sheet-wrap {
  position: absolute; inset: 0; z-index: 20;
  display: grid; align-items: end;
  background: rgba(5,6,15,.72);
  backdrop-filter: blur(3px);
  animation: fade .2s ease;
}
.sheet-wrap[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  background: var(--cave-2);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  animation: rise .26s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise { from { translate: 0 100%; } }

.sheet h2 { margin-bottom: 14px; }
.sheet input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.28);
  color: var(--paper);
  font: inherit;
  font-size: 18px;
}
.sheet input:focus { outline: none; border-color: var(--gold); }

.swatches { display: flex; gap: 10px; margin: 16px 0 4px; flex-wrap: wrap; }
.swatches button {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid transparent;
}
.swatches button.on { border-color: var(--paper); }

.sheet-msg { color: var(--muted); font-size: 14px; margin: 12px 0 0; line-height: 1.45; }
.sheet .stack { margin-top: 18px; }

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