/* ============================================================
   AVENTURA MATEMÁTICA — folha de estilo
   Tema: aventura espacial alegre para crianças
   ============================================================ */

:root {
  --space-1: #1a1247;
  --space-2: #2a1a6e;
  --space-3: #3d2699;

  --sun:   #ffcf3f;
  --coral: #ff6b6b;
  --mint:  #2fe3a8;
  --sky:   #46c9f5;
  --pink:  #ff85cf;
  --grape: #a06bff;

  --cream: #fff8ec;
  --ink:   #2b2350;
  --ink-soft: #6b6390;

  --card: #ffffff;
  --card-edge: #efe7ff;

  --r-lg: 32px;
  --r-md: 22px;
  --r-sm: 14px;

  --shadow-soft: 0 14px 30px rgba(20, 10, 60, 0.22);
  --shadow-pop: 0 8px 0 rgba(0, 0, 0, 0.14);

  --font-display: "Baloo 2", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  --font-ui: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  overflow: hidden;
}

body {
  background:
    radial-gradient(1200px 700px at 80% -10%, #43308f 0%, transparent 60%),
    radial-gradient(900px 600px at 0% 110%, #4a2ea0 0%, transparent 55%),
    linear-gradient(160deg, var(--space-2) 0%, var(--space-1) 55%, #120b33 100%);
  user-select: none;
}

/* ---------- Fundo estrelado + planetas ---------- */
#sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: twinkle var(--dur, 3s) ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .25; transform: scale(.7); } to { opacity: 1; transform: scale(1); } }

.planet { position: fixed; border-radius: 50%; z-index: 0; pointer-events: none; filter: saturate(1.1); }
.planet--a {
  width: 120px; height: 120px; top: 8%; right: 7%;
  background: radial-gradient(circle at 32% 30%, #ffe08a, var(--sun) 55%, #e79a2b);
  box-shadow: inset -12px -12px 0 rgba(0,0,0,.12), 0 0 40px rgba(255,207,63,.35);
  animation: bob 7s ease-in-out infinite;
}
.planet--b {
  width: 74px; height: 74px; bottom: 12%; left: 6%;
  background: radial-gradient(circle at 32% 30%, #b6f5df, var(--mint) 55%, #17a377);
  box-shadow: inset -8px -8px 0 rgba(0,0,0,.12);
  animation: bob 9s ease-in-out infinite reverse;
}
.planet--c {
  width: 46px; height: 46px; top: 26%; left: 12%;
  background: radial-gradient(circle at 32% 30%, #ffc0e6, var(--pink) 55%, #d64fa0);
  animation: bob 6s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-16px) rotate(6deg); } }

#confetti { position: fixed; inset: 0; z-index: 60; pointer-events: none; }

/* ---------- Estrutura de telas ---------- */
#app { position: relative; z-index: 10; height: 100%; }
.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: clamp(14px, 3vw, 28px);
  overflow: hidden;
}
.screen.is-active { display: flex; animation: screen-in .45s cubic-bezier(.2,.9,.3,1.3); }
@keyframes screen-in { from { opacity: 0; transform: scale(.96) translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Reveal (entrada em cascata) ---------- */
.reveal { animation: pop-up .6s both cubic-bezier(.2,.9,.3,1.3); }
.reveal--2 { animation-delay: .12s; }
.reveal--3 { animation-delay: .24s; }
@keyframes pop-up { from { opacity: 0; transform: translateY(24px) scale(.95); } to { opacity: 1; transform: none; } }

/* ============================================================
   TELA INICIAL
   ============================================================ */
#screen-home { align-items: center; justify-content: center; gap: clamp(16px, 3vh, 30px); text-align: center; }

.home-stars {
  position: absolute; top: clamp(14px, 3vw, 24px); right: clamp(14px, 3vw, 24px);
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.25);
  color: #fff; font-family: var(--font-display); font-weight: 700;
  padding: 8px 16px; border-radius: 999px; font-size: 20px;
  backdrop-filter: blur(4px);
}
.home-stars__icon { filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }

.home-hero { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.title {
  font-family: var(--font-display); font-weight: 800;
  line-height: .95; letter-spacing: .5px;
  font-size: clamp(38px, 9vw, 76px);
  display: flex; flex-direction: column;
}
.title__word { color: #fff; text-shadow: 0 4px 0 rgba(0,0,0,.18); }
.title__word--accent {
  background: linear-gradient(120deg, var(--sun), var(--coral) 45%, var(--pink));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 8px rgba(255,107,107,.35));
}
.subtitle { color: #d8ccff; font-size: clamp(15px, 2.4vw, 20px); font-weight: 500; }

.home-actions { display: flex; flex-direction: column; gap: 14px; width: min(340px, 82vw); }

/* ---------- Botões ---------- */
.btn {
  font-family: var(--font-display); font-weight: 700;
  border: none; cursor: pointer; border-radius: var(--r-md);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.btn:active { transform: translateY(4px); }
.btn--play {
  font-size: clamp(20px, 3vw, 26px); color: #4a2a00;
  padding: 18px 28px;
  background: linear-gradient(180deg, #ffe07a, var(--sun));
  box-shadow: 0 8px 0 #d99a1f, var(--shadow-soft);
}
.btn--play:active { box-shadow: 0 3px 0 #d99a1f; }
.btn--play__icon { font-size: .8em; }
.btn--soft {
  font-size: clamp(16px, 2.4vw, 20px); color: #fff;
  padding: 14px 24px;
  background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.28);
  box-shadow: var(--shadow-soft);
}

/* ---------- Coleção ---------- */
.collection {
  background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.2);
  border-radius: var(--r-md); padding: 14px 18px; width: min(460px, 88vw);
}
.collection__title { color: #cdbcff; font-size: 14px; margin-bottom: 8px; font-weight: 600; }
.collection__row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.sticker {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 24px;
  background: rgba(0,0,0,.18);
}
.sticker--locked { filter: grayscale(1) brightness(.5); opacity: .55; }
.sticker--new { animation: pop-up .5s both cubic-bezier(.2,.9,.3,1.6); box-shadow: 0 0 0 3px var(--sun); }

/* ============================================================
   MASCOTE
   ============================================================ */
.mascot-stage { width: clamp(140px, 34vw, 200px); height: clamp(140px, 34vw, 200px); }
.mascot-stage--small { width: 92px; height: 92px; }
.mascot { width: 100%; height: 100%; overflow: visible; animation: mascot-bob 3.2s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes mascot-bob { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }
.mascot .pupil { animation: blink 4.5s infinite; transform-origin: center; }
@keyframes blink { 0%,92%,100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
.mascot.is-celebrate { animation: mascot-cheer .6s ease; }
@keyframes mascot-cheer { 0%,100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-18px) scale(1.08) rotate(-4deg); } 70% { transform: translateY(-4px) scale(1.02) rotate(3deg); } }
.mascot.is-oops { animation: mascot-oops .5s ease; }
@keyframes mascot-oops { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

/* ============================================================
   TOPBAR (jogo e configurações)
   ============================================================ */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.topbar__title { color: #fff; font-family: var(--font-display); font-size: clamp(18px, 3vw, 24px); }
.topbar__spacer { flex: 1; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,.28);
  background: rgba(255,255,255,.14); color: #fff; font-size: 24px; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0; transition: transform .12s;
}
.icon-btn:active { transform: scale(.9); }

/* ============================================================
   CONFIGURAÇÕES
   ============================================================ */
#screen-settings { max-width: 640px; margin: 0 auto; width: 100%; }
.settings-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.card {
  background: var(--card); border-radius: var(--r-md); padding: 18px 20px;
  box-shadow: var(--shadow-soft); border: 2px solid var(--card-edge);
}
.card__title { font-family: var(--font-display); font-size: 20px; color: var(--ink); margin-bottom: 4px; }
.card__hint { color: var(--ink-soft); font-size: 14px; margin-bottom: 14px; }

.range-row { display: flex; gap: 14px; }
.stepper { flex: 1; background: #f3eeff; border-radius: var(--r-sm); padding: 12px; text-align: center; }
.stepper__label { display: block; color: var(--ink-soft); font-weight: 600; margin-bottom: 8px; }
.stepper__controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stepper__btn {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 26px; font-weight: 700; color: #fff; background: var(--grape);
  display: grid; place-items: center; transition: transform .1s, filter .1s;
}
.stepper__btn:active { transform: scale(.88); filter: brightness(.92); }
.stepper__value { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--ink); min-width: 48px; }

.ops-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.op-chip {
  border: 3px solid #eadfff; background: #faf7ff; border-radius: var(--r-sm);
  padding: 14px; cursor: pointer; display: flex; align-items: center; gap: 12px;
  transition: transform .12s, border-color .12s, background .12s;
}
.op-chip:active { transform: scale(.96); }
.op-chip__sym {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 26px; font-weight: 800; color: #fff;
  background: #cfc4e8;
}
.op-chip__name { font-family: var(--font-display); font-size: 17px; color: var(--ink-soft); }
.op-chip.is-on { border-color: var(--mint); background: #eafff7; }
.op-chip.is-on .op-chip__name { color: var(--ink); }
.op-chip[data-op="+"].is-on .op-chip__sym { background: var(--sky); }
.op-chip[data-op="-"].is-on .op-chip__sym { background: var(--coral); }
.op-chip[data-op="x"].is-on .op-chip__sym { background: var(--grape); }
.op-chip[data-op="/"].is-on .op-chip__sym { background: var(--mint); }

.pill-group { display: flex; gap: 10px; }
.pill {
  flex: 1; border: 3px solid #eadfff; background: #faf7ff; border-radius: var(--r-sm);
  padding: 14px; cursor: pointer; font-family: var(--font-display); font-size: 22px; font-weight: 700;
  color: var(--ink-soft); transition: transform .1s;
}
.pill:active { transform: scale(.95); }
.pill.is-on { background: var(--grape); border-color: var(--grape); color: #fff; }

.card--toggles { display: flex; flex-direction: column; gap: 6px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.toggle__text { font-family: var(--font-display); font-size: 17px; color: var(--ink); }
.switch {
  width: 62px; height: 36px; border-radius: 999px; border: none; cursor: pointer;
  background: #d9cfef; position: relative; transition: background .2s;
}
.switch__dot { position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: left .2s; }
.switch[aria-checked="true"] { background: var(--mint); }
.switch[aria-checked="true"] .switch__dot { left: 30px; }

.settings-footer { padding-top: 14px; }
.settings-footer .btn { width: 100%; }

/* ============================================================
   JOGO
   ============================================================ */
#screen-game { max-width: 620px; margin: 0 auto; width: 100%; }
.progress { flex: 1; display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: rgba(255,255,255,.25); transition: background .3s, transform .3s; }
.dot.is-done { background: var(--mint); }
.dot.is-current { background: var(--sun); transform: scale(1.35); }
.dot.is-miss { background: var(--coral); }
.round-stars {
  display: flex; align-items: center; gap: 5px; color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.24);
  padding: 6px 14px; border-radius: 999px;
}

.game-body { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 12px; min-height: 0; }

.buddy { display: flex; align-items: center; gap: 12px; align-self: flex-start; flex-shrink: 0; }
.bubble {
  position: relative; background: var(--card); color: var(--ink);
  font-family: var(--font-display); font-weight: 600; font-size: clamp(15px, 2.6vw, 19px);
  padding: 12px 18px; border-radius: 18px; box-shadow: var(--shadow-soft);
  max-width: 60vw;
}
.bubble::before { content: ""; position: absolute; left: -10px; top: 50%; transform: translateY(-50%); border: 10px solid transparent; border-right-color: var(--card); }
.bubble.is-happy { background: #eafff7; }
.bubble.is-sad { background: #fff0f0; }

/* Conta */
.problem {
  display: flex; align-items: center; justify-content: center; gap: clamp(8px, 2vw, 16px);
  flex-wrap: wrap; flex-shrink: 0;
}
.tile {
  font-family: var(--font-display); font-weight: 800; color: #fff;
  font-size: clamp(40px, 12vw, 84px); line-height: 1;
  min-width: clamp(66px, 18vw, 120px); padding: 10px 16px; border-radius: var(--r-md);
  display: grid; place-items: center; box-shadow: var(--shadow-pop);
}
.tile--a { background: linear-gradient(180deg, #6fd4ff, var(--sky)); }
.tile--b { background: linear-gradient(180deg, #ffa0d8, var(--pink)); }
.op-badge {
  font-family: var(--font-display); font-weight: 800; color: #fff;
  font-size: clamp(30px, 8vw, 56px);
  width: clamp(52px, 12vw, 76px); height: clamp(52px, 12vw, 76px);
  border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #ffd77a, var(--sun)); box-shadow: var(--shadow-pop); color: #5b3b00;
}
.equals { font-family: var(--font-display); font-weight: 800; color: #fff; font-size: clamp(30px, 8vw, 56px); }
.answer-slot {
  min-width: clamp(76px, 20vw, 130px); height: clamp(76px, 18vw, 120px);
  border-radius: var(--r-md); border: 5px dashed rgba(255,255,255,.5);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; color: #fff;
  font-size: clamp(40px, 12vw, 80px); background: rgba(255,255,255,.08);
  transition: transform .1s, border-color .2s, background .2s;
}
.answer-slot.has-value { border-style: solid; border-color: var(--sun); background: rgba(255,207,63,.15); }
.answer-slot.is-correct { border-color: var(--mint); background: rgba(47,227,168,.22); animation: pop-up .4s; }
.answer-slot.is-wrong { animation: shake .4s; border-color: var(--coral); }
.answer-slot__q { opacity: .55; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-12px); } 40% { transform: translateX(12px); } 60% { transform: translateX(-8px); } 80% { transform: translateX(8px); } }

/* Figuras de apoio — ocupa o espaço livre entre a conta e o teclado,
   com overflow oculto para NUNCA invadir o teclado. */
.aids {
  flex: 1 1 auto; min-height: 0; width: 100%; overflow: hidden;
  display: flex; align-items: center; align-content: center; justify-content: center;
  gap: 8px 14px; flex-wrap: wrap; padding: 0 4px;
}
.aid-group { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; background: rgba(255,255,255,.1); border-radius: 16px; max-width: 46vw; justify-content: center; }
.aid-item { font-size: clamp(20px, 4.5vw, 30px); line-height: 1; animation: pop-up .3s both; }
.aid-item.is-gone { opacity: .28; filter: grayscale(1); position: relative; }
.aid-item.is-gone::after { content: "✕"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--coral); font-weight: 800; }
.aid-op { font-family: var(--font-display); font-size: clamp(22px, 5vw, 34px); font-weight: 800; color: #fff; }

/* Teclado */
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 1.6vw, 12px);
  width: min(380px, 90vw); flex-shrink: 0;
}
.key {
  font-family: var(--font-display); font-weight: 700; font-size: clamp(24px, 6vw, 34px);
  color: var(--ink); background: var(--cream); border: none; cursor: pointer;
  padding: clamp(12px, 2.6vw, 18px) 0; border-radius: var(--r-sm);
  box-shadow: 0 5px 0 rgba(0,0,0,.16); transition: transform .08s, box-shadow .08s;
}
.key:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.16); }
.key--del { background: #ffd9d9; color: var(--coral); }
.key--ok { background: linear-gradient(180deg, #6bf0c0, var(--mint)); color: #06563b; box-shadow: 0 5px 0 #1a9d70; }
.key--ok:active { box-shadow: 0 1px 0 #1a9d70; }

/* ============================================================
   RESULTADO
   ============================================================ */
#screen-results { align-items: center; justify-content: center; }
.results-card {
  background: var(--card); border-radius: var(--r-lg); padding: clamp(22px, 5vw, 36px);
  box-shadow: var(--shadow-soft); text-align: center; width: min(440px, 90vw);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.results-card .mascot-stage { margin-top: -80px; }
.results-title { font-family: var(--font-display); font-weight: 800; font-size: clamp(28px, 6vw, 40px); color: var(--ink); }
.results-sub { color: var(--ink-soft); font-size: 16px; }
.results-stars { font-size: clamp(30px, 7vw, 44px); letter-spacing: 4px; min-height: 1em; }
.results-stars .rs { display: inline-block; animation: pop-up .4s both cubic-bezier(.2,.9,.3,1.6); }
.results-stat { display: flex; gap: 14px; width: 100%; }
.results-stat__box { flex: 1; background: #f3eeff; border-radius: var(--r-sm); padding: 14px; }
.results-stat__num { display: block; font-family: var(--font-display); font-weight: 800; font-size: 30px; color: var(--grape); }
.results-stat__label { color: var(--ink-soft); font-size: 13px; }
.results-sticker { background: #eafff7; border-radius: var(--r-sm); padding: 14px; width: 100%; }
.results-sticker p { color: var(--ink-soft); font-size: 14px; margin-bottom: 6px; }
.results-sticker__emoji { font-size: 46px; animation: pop-up .6s both cubic-bezier(.2,.9,.3,1.6); }
.results-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 4px; }
.results-actions .btn { width: 100%; }

/* ---------- Responsivo: telas largas ---------- */
@media (min-width: 720px) and (min-height: 560px) {
  .keypad { width: 360px; }
}
@media (max-height: 620px) {
  .buddy .mascot-stage--small { display: none; }
  .bubble::before { display: none; }
}

/* Acessibilidade: respeitar preferência por menos movimento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
}
