@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito.woff2") format("woff2");
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  /* Kid look: change these to restyle the kid */
  --kid-skin: #f6c9a8;
  --kid-hair: #6b4434;
  --kid-shirt: #b9a3f0;

  --ink: #5b3a66;
  --pink: #ff8fab;
  --pink-deep: #f0668c;
  --card: rgba(255, 255, 255, 0.92);
  --counter: #f7b8c0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --u: min(1vw, 1.45vh); /* layout unit */
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #fde9dc;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

.k-skin { fill: var(--kid-skin); }
.k-hair { fill: var(--kid-hair); }
.k-shirt { fill: var(--kid-shirt); }
.k-shirt-stroke { stroke: var(--kid-shirt); }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: calc(var(--safe-top) + 96px) minmax(0, 1fr) auto auto;
  grid-template-areas: "top" "stage" "caption" "path";
}

#bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }

#stageWrap { grid-area: stage; position: relative; z-index: 1; min-height: 0; display: flex; }
#stage { width: 100%; height: 100%; overflow: visible; display: block; }

/* ---------- top row ---------- */
#controls {
  grid-area: top; z-index: 5;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: calc(var(--safe-top) + 14px) calc(var(--safe-right) + 16px) 0 calc(var(--safe-left) + 16px);
  pointer-events: none;
}
#controls > * { pointer-events: auto; }

.round-btn {
  display: flex; align-items: center; gap: 10px;
  height: 68px; min-width: 68px; padding: 0 22px 0 18px;
  border-radius: 34px; background: var(--card);
  box-shadow: 0 6px 0 rgba(170, 110, 130, .25), 0 10px 24px rgba(120, 70, 90, .12);
  font-weight: 900; font-size: 22px;
  transition: transform .12s;
}
.round-btn:active, .big-btn:active, .lang-btn:active { transform: translateY(3px) scale(.97); }
.round-btn svg { width: 30px; height: 30px; fill: var(--pink-deep); stroke: var(--pink-deep); stroke-width: 2; }
#icoPlay { display: none; }
#app.is-paused #icoPlay { display: block; }
#app.is-paused #icoPause { display: none; }
#pauseBtn { visibility: hidden; }
#app.is-running #pauseBtn, #app.is-paused #pauseBtn { visibility: visible; }

.lang-btn {
  display: flex; height: 68px; padding: 6px; border-radius: 34px; background: var(--card);
  box-shadow: 0 6px 0 rgba(170, 110, 130, .25), 0 10px 24px rgba(120, 70, 90, .12);
  font-weight: 900; font-size: 22px;
}
.lang-btn span { display: grid; place-items: center; min-width: 64px; border-radius: 28px; padding: 0 10px; color: #b49ab8; transition: background .2s, color .2s; }
#app[data-lang="en"] .lang-btn span[data-l="en"],
#app[data-lang="es"] .lang-btn span[data-l="es"] { background: var(--pink); color: #fff; }

/* ---------- banner ---------- */
#banner {
  position: absolute; z-index: 4;
  top: calc(var(--safe-top) + 12px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  max-width: calc(100% - 420px);
  padding: 10px 20px 10px 12px; min-height: 74px;
  background: var(--card); border-radius: 37px;
  box-shadow: 0 6px 0 rgba(170, 110, 130, .22), 0 12px 28px rgba(120, 70, 90, .12);
  opacity: 0; transition: opacity .3s;
}
#app[data-phase="intro"] #banner, #app[data-phase="brush"] #banner,
#app[data-phase="spit"] #banner, #app[data-phase="party"] #banner, #app[data-phase="done"] #banner { opacity: 1; }
#stepNum {
  flex: none; width: 54px; height: 54px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--pink); color: #fff; font-weight: 1000; font-size: 28px;
}
#app:not([data-phase="brush"]) #stepNum { display: none; }
.banner-text { min-width: 0; line-height: 1.08; }
#bannerTitle { font-weight: 1000; font-size: 28px; overflow-wrap: anywhere; }
#bannerDetail { font-weight: 800; font-size: 21px; color: #a1709f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#bannerDetail:empty { display: none; }
#motion { flex: none; width: 50px; height: 50px; color: var(--pink-deep); }

/* ---------- mouth diagram ---------- */
#mouthCard {
  grid-area: stage; position: relative; z-index: 3; align-self: end; justify-self: end;
  margin: 0 calc(var(--safe-right) + 16px) 6px 0;
  width: clamp(130px, 17vw, 210px); aspect-ratio: 1;
  background: var(--card); border-radius: 28px; padding: 8px;
  box-shadow: 0 6px 0 rgba(170, 110, 130, .22), 0 12px 28px rgba(120, 70, 90, .12);
  opacity: 0; transition: opacity .3s;
}
#app[data-phase="brush"] #mouthCard { opacity: 1; }
#mouthMap { width: 100%; height: 100%; display: block; }
#mouthMap .zone { opacity: 0; transition: opacity .25s; }
#mouthMap .zone.on { opacity: 1; animation: glow 1.1s ease-in-out infinite alternate; }
@keyframes glow { from { filter: none; } to { filter: drop-shadow(0 0 5px #ffd166); } }
#app.is-paused * { animation-play-state: paused !important; }

/* ---------- caption ---------- */
#caption {
  grid-area: caption; z-index: 4; justify-self: center;
  position: relative;
  max-width: min(92vw, 900px);
  margin: 0 16px 8px;
  padding: 12px 26px; border-radius: 30px;
  background: #fff; font-weight: 900; font-size: clamp(20px, 2.6vw, 30px); line-height: 1.2; text-align: center;
  box-shadow: 0 6px 0 rgba(170, 110, 130, .22);
  opacity: 0; transform: translateY(6px) scale(.96);
  transition: opacity .2s, transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
#caption::before {
  content: ""; position: absolute; top: -14px; left: 70%;
  border: 14px solid transparent; border-top: 0; border-bottom-color: #fff;
}
#caption.show { opacity: 1; transform: none; }
#caption:empty { visibility: hidden; }

/* ---------- progress path ---------- */
#pathBar {
  grid-area: path; z-index: 2; position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 0 calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 18px);
  background: var(--counter);
}
#path { flex: 1; height: clamp(70px, 9vh, 100px); display: block; }
#timeLeft { flex: none; min-width: 98px; text-align: center; font-weight: 1000; font-size: 24px; color: #fff; text-shadow: 0 2px 0 rgba(180, 80, 110, .35); }
#stones circle { transition: fill .3s; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10;
  display: none; place-items: center;
  background: rgba(253, 233, 220, .55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
}
.card {
  text-align: center; padding: 30px 44px 36px; border-radius: 40px; background: var(--card);
  box-shadow: 0 8px 0 rgba(170, 110, 130, .22), 0 20px 50px rgba(120, 70, 90, .18);
  max-width: min(92vw, 640px);
}
.card h1 { margin: 0 0 6px; font-size: clamp(40px, 6vw, 64px); font-weight: 1000; color: var(--pink-deep); }
.card h2 { margin: 0 0 20px; font-size: clamp(28px, 4vw, 42px); font-weight: 1000; }
.card p { margin: 0 0 24px; font-size: clamp(18px, 2.4vw, 24px); font-weight: 800; color: #a1709f; }
.big-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 16px;
  min-width: 260px; height: 104px; padding: 0 44px; border-radius: 52px;
  background: var(--pink); color: #fff; font-weight: 1000; font-size: 40px; white-space: nowrap;
  box-shadow: 0 8px 0 var(--pink-deep), 0 16px 30px rgba(240, 102, 140, .35);
  animation: bob 1.6s ease-in-out infinite;
}
.big-btn svg { width: 44px; height: 44px; fill: #fff; stroke: #fff; stroke-width: 3; }
@keyframes bob { 50% { transform: translateY(-5px) scale(1.03); } }
#credits { display: block; margin-top: 14px; font-size: 13px; font-weight: 700; color: #c9aac6; text-decoration: none; }
#loadingNote { margin: 18px 0 0; font-size: 18px; visibility: hidden; }
#app.is-loading #loadingNote { visibility: visible; }
#app.is-loading #startBtn { opacity: .5; }

#app.is-ready #startCard { display: grid; }
#app.is-paused #pauseCard { display: grid; }
#app.is-done #doneCard { display: grid; background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; place-items: end center; padding-bottom: calc(var(--safe-bottom) + 130px); }
#app.is-done #doneCard .card { padding: 18px 30px 24px; }
#app.is-done #doneCard h2 { margin-bottom: 12px; }
#app.is-loading #startCard { display: grid; }

#confetti { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 6; pointer-events: none; }

/* ---------- portrait ---------- */
@media (orientation: portrait) {
  #app {
    grid-template-rows: calc(var(--safe-top) + 92px) auto minmax(0, 1fr) auto auto;
    grid-template-areas: "top" "banner" "stage" "caption" "path";
  }
  #banner {
    position: relative; grid-area: banner; top: auto; left: auto; transform: none;
    justify-self: center; max-width: calc(100% - 32px); margin: 0 16px 6px;
  }
  #mouthCard {
    align-self: start; justify-self: center;
    width: clamp(120px, 28vw, 240px); margin: 8px 0 0;
  }
  #app:not([data-phase="brush"]) #mouthCard { visibility: hidden; }
}

/* ---------- small screens (phones) ---------- */
@media (max-width: 600px), (max-height: 500px) {
  #app { grid-template-rows: calc(var(--safe-top) + 72px) minmax(0, 1fr) auto auto; }
  .round-btn, .lang-btn { height: 56px; font-size: 18px; }
  .round-btn { padding: 0 16px 0 14px; }
  .round-btn svg { width: 24px; height: 24px; }
  .lang-btn span { min-width: 50px; }
  #pauseLabel { display: none; }
  #banner { min-height: 60px; padding: 8px 16px 8px 10px; gap: 10px; max-width: calc(100% - 300px); }
  #stepNum { width: 44px; height: 44px; font-size: 22px; }
  #bannerTitle { font-size: 21px; }
  #bannerDetail { font-size: 17px; }
  #motion { width: 38px; height: 38px; }
  #caption { font-size: 19px; padding: 10px 18px; margin-bottom: 6px; }
  #timeLeft { font-size: 18px; min-width: 70px; }
  #path { height: 62px; }
  .big-btn { min-width: 200px; height: 84px; font-size: 30px; padding: 0 30px; gap: 12px; }
  .big-btn svg { width: 36px; height: 36px; }
  .card { padding: 22px 26px 28px; }
  #mouthCard { width: 120px; border-radius: 22px; }
}
@media (orientation: portrait) and (max-width: 600px) {
  #app { grid-template-rows: calc(var(--safe-top) + 72px) auto minmax(0, 1fr) auto auto; }
  #banner { max-width: calc(100% - 24px); }
  #mouthCard { width: 160px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  #mouthCard { width: 104px; }
  #caption { font-size: 17px; }
  #path { height: 50px; }
}
