:root {
  --bg: #F4F0FF;
  --card: #FFFFFF;
  --ink: #2E2A4A;
  --ink-soft: #6B6790;
  --violet: #8B6CF6;
  --violet-soft: #E4DCFF;
  --mint: #3CC9A0;
  --mint-soft: #D5F5EA;
  --sun: #FFC94D;
  --coral: #FF7A8A;
  --line: #DCD5F5;
  --radius: 26px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", "Segoe UI", Roboto, system-ui, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

.screen {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.icon-btn {
  width: 58px; height: 58px; border-radius: 20px; background: var(--card);
  font-size: 30px; display: grid; place-items: center; position: relative;
  box-shadow: 0 4px 0 var(--line);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.badge {
  position: absolute; right: -6px; top: -6px; min-width: 24px; height: 24px; padding: 0 6px;
  border-radius: 12px; background: var(--coral); color: #fff; font-size: 14px; font-weight: 800;
  display: grid; place-items: center;
}
.gear { opacity: .45; font-size: 24px; width: 48px; height: 48px; }
.gear.holding { opacity: 1; animation: holdspin 1.5s linear; }
@keyframes holdspin { to { transform: rotate(360deg); } }

/* ---------- вибір героя ---------- */
.hero-pick { justify-content: center; align-items: center; gap: 24px; }
.pick-title { font-size: 64px; animation: wave 1.4s ease-in-out infinite; }
@keyframes wave { 50% { transform: rotate(18deg); } }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; width: 100%; }
.hero-btn {
  aspect-ratio: 1; font-size: 64px; background: var(--card); border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--line);
}
.hero-btn:active { transform: scale(.94); }

/* ---------- головна ---------- */
.home { align-items: center; }
.hero-stage { flex: 1; display: grid; place-items: center; position: relative; width: 100%; min-height: 260px; }
.big-hero { font-size: 150px; line-height: 1; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 12px 0 rgba(139,108,246,.18)); }
@keyframes bob { 50% { transform: translateY(-12px); } }
.sleep .big-hero { animation: none; transform: rotate(-8deg); opacity: .85; }
.zzz { position: absolute; right: 18%; top: 18%; font-size: 44px; animation: zz 2s ease-in-out infinite; }
.moon { position: absolute; left: 14%; top: 8%; font-size: 48px; }
@keyframes zz { 50% { transform: translate(8px, -10px); opacity: .5; } }
.play-btn {
  width: 150px; height: 150px; border-radius: 50%; background: var(--mint); color: #fff;
  font-size: 66px; display: grid; place-items: center; padding-left: 10px;
  box-shadow: 0 10px 0 #2BA383; animation: breathe 1.8s ease-in-out infinite;
}
.play-btn:active { transform: translateY(6px); box-shadow: 0 4px 0 #2BA383; }
.play-btn.off { background: var(--violet-soft); color: var(--violet); box-shadow: 0 10px 0 var(--line); animation: none; padding-left: 0; font-size: 60px; }
.play-btn.small { width: 110px; height: 110px; font-size: 48px; padding-left: 0; animation: none; }
@keyframes breathe { 50% { transform: scale(1.05); } }
.sdots { display: flex; gap: 12px; margin: 26px 0 8px; }
.sdot { width: 22px; height: 22px; border-radius: 50%; background: var(--card); border: 3px solid var(--line); }
.sdot.on { background: var(--sun); border-color: #E8AF25; }

/* ---------- гра ---------- */
.pdots { display: flex; gap: 8px; flex: 1; justify-content: center; }
.pdot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); }
.pdot.on { background: var(--mint); }
.pdot.now { background: var(--violet); transform: scale(1.3); }
.mini-hero { font-size: 44px; width: 58px; text-align: center; }
.mini-hero.hop { animation: hop .6s ease; }
@keyframes hop { 30% { transform: translateY(-22px) rotate(-10deg); } 60% { transform: translateY(0) rotate(6deg); } }

.task { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 10px 0; }
.ask { font-size: 64px; }
.visual, .hint { display: flex; justify-content: center; width: 100%; }
.hint:empty { display: none; }
.hint { animation: pop .35s ease; opacity: .9; }

.expr {
  font-size: 58px; font-weight: 900; letter-spacing: 2px; background: var(--card);
  padding: 10px 26px; border-radius: var(--radius); box-shadow: 0 6px 0 var(--line); white-space: nowrap;
}
.q { color: var(--violet); display: inline-block; animation: qwiggle 1.6s ease-in-out infinite; }
@keyframes qwiggle { 50% { transform: rotate(-10deg) scale(1.1); } }

/* предмети рядами по 5 */
.objs { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.orow { display: flex; gap: 6px; }
.obj { font-size: 44px; line-height: 1.1; animation: pop .35s ease backwards; }
.objs.sm .obj { font-size: 34px; }
.objs.xs .obj { font-size: 30px; }
.objs.xs .orow { gap: 2px; }
.obj.ghost { opacity: .22; filter: grayscale(1); }
.obj { position: relative; display: inline-block; }
.obj.gone b { font-weight: 400; display: inline-block; animation: fadeout .8s ease .7s forwards; }
.obj.gone::after { content: '✕'; position: absolute; inset: 0; display: grid; place-items: center; color: #E2405A; font-weight: 900; font-size: .95em; opacity: 0; animation: crossin .35s ease 1.2s forwards; }
@keyframes fadeout { to { opacity: .25; filter: grayscale(1); } }
@keyframes crossin { from { transform: scale(2); } to { opacity: 1; transform: scale(1); } }
.obj.arrive { animation: arrive .7s ease backwards; }
@keyframes arrive { from { transform: translateX(60px); opacity: 0; } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.orow .obj:nth-child(2) { animation-delay: .04s; } .orow .obj:nth-child(3) { animation-delay: .08s; }
.orow .obj:nth-child(4) { animation-delay: .12s; } .orow .obj:nth-child(5) { animation-delay: .16s; }
.addrow { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.plus { font-size: 44px; font-weight: 900; color: var(--violet); }

/* рамка з 10 клітинок: дві п'ятірки */
.frame { display: flex; flex-direction: column; gap: 0; background: var(--card); border: 4px solid var(--ink); border-radius: 14px; overflow: hidden; }
.frow { display: flex; }
.frow + .frow { border-top: 4px solid var(--ink); }
.cell { width: 56px; height: 56px; display: grid; place-items: center; position: relative; }
.cell + .cell { border-left: 3px solid var(--ink); }
.cell.a::after, .cell.b::after, .cell.x::after {
  content: ''; width: 70%; height: 70%; border-radius: 50%; background: var(--coral); animation: pop .3s ease backwards;
}
.cell.b::after { background: var(--violet); }
.cell.x::after { background: var(--coral); opacity: .3; }
.cell.x::before { content: '✕'; position: absolute; font-size: 38px; font-weight: 900; color: var(--ink); z-index: 1; }
.cell.empty { background: #FFF6D8; }
.cell.empty::after { content: ''; width: 66%; height: 66%; border-radius: 50%; border: 3px dashed #E8AF25; }
.cell.off { background: #E9E6F2; }
.frame.xs .cell { width: 26px; height: 26px; }
.frame.xs { border-width: 2px; border-radius: 8px; }
.frame.xs .frow + .frow { border-top-width: 2px; }
.frame.xs .cell + .cell { border-left-width: 1.5px; }

.flashbox { position: relative; }
.cloud { position: absolute; inset: -10px; display: grid; place-items: center; font-size: 120px; background: var(--bg); border-radius: 20px; opacity: 0; pointer-events: none; transition: opacity .4s; }
.flashbox.covered .cloud { opacity: 1; }

/* будиночок числа */
.house { display: flex; flex-direction: column; align-items: center; }
.roof {
  width: 220px; height: 92px; background: var(--coral); clip-path: polygon(50% 0, 100% 100%, 0 100%);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
}
.roof span { font-size: 50px; font-weight: 900; color: #fff; }
.rooms { display: flex; width: 190px; background: var(--card); border: 4px solid var(--ink); border-top: 0; border-radius: 0 0 16px 16px; }
.room { flex: 1; height: 92px; display: grid; place-items: center; font-size: 54px; font-weight: 900; }
.room + .room { border-left: 4px solid var(--ink); }
.room.q { color: var(--violet); animation: qwiggle 1.6s ease-in-out infinite; }

/* тарілки: таблиця Діани */
.seq { display: flex; gap: 10px; font-size: 40px; font-weight: 900; flex-wrap: wrap; justify-content: center; }
.seq span { background: var(--card); border-radius: 16px; padding: 4px 14px; box-shadow: 0 4px 0 var(--line); }
.seq .q { color: var(--violet); }
.plates { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 100%; }
.plate {
  min-width: 70px; min-height: 70px; padding: 8px; border-radius: 50%; background: #fff;
  border: 4px solid var(--violet-soft); display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 2px; font-size: 22px; max-width: 132px;
}
.plate.last { border-color: var(--violet); border-style: dashed; }
.plate i { width: 14px; height: 14px; border-radius: 50%; background: var(--coral); display: inline-block; margin: 1px; }

/* кнопки відповіді */
.answers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding-bottom: 8px; }
.ans {
  height: 104px; border-radius: var(--radius); background: var(--card); font-size: 54px; font-weight: 900;
  box-shadow: 0 8px 0 var(--line); position: relative; transition: transform .1s;
}
.ans:active { transform: translateY(5px); box-shadow: 0 3px 0 var(--line); }
.ans.right, .side.right, .eq.right { background: var(--mint); color: #fff; box-shadow: 0 8px 0 #2BA383; animation: pop .3s ease; }
.ans.wrong, .side.wrong, .eq.wrong { animation: shake .4s ease; opacity: .35; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pulse { animation: pulse 1s ease-in-out infinite !important; outline: 5px solid var(--sun); }
@keyframes pulse { 50% { transform: scale(1.06); } }

.cmp { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding-bottom: 8px; }
.side {
  min-height: 150px; border-radius: var(--radius); background: var(--card); box-shadow: 0 8px 0 var(--line);
  display: grid; place-items: center; padding: 10px; position: relative;
}
.eq { height: 58px; width: 120px; justify-self: center; border-radius: 22px; background: var(--violet-soft); font-size: 40px; font-weight: 900; color: var(--violet); box-shadow: 0 6px 0 var(--line); position: relative; }
.bignum { font-size: 72px; font-weight: 900; }
.g-compare .task { flex: 0 0 auto; padding: 4px 0; }
.g-compare .ask { font-size: 52px; animation: chomp 1.2s ease-in-out infinite; }
@keyframes chomp { 50% { transform: scale(1.12) rotate(-6deg); } }

.hand { position: absolute; font-size: 52px; pointer-events: none; z-index: 5; animation: tap 1s ease-in-out infinite; filter: drop-shadow(0 4px 4px rgba(0,0,0,.2)); }
@keyframes tap { 50% { transform: translateY(-16px); } }

.spark { position: absolute; left: 50%; top: 30%; font-size: 26px; pointer-events: none; animation: spark .8s ease-out forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(.6); opacity: 0; } }

/* ---------- нагорода ---------- */
.reward { align-items: center; justify-content: center; gap: 26px; overflow: hidden; }
.big-hero.happy { animation: hop 1s ease infinite; font-size: 120px; }
.gift { font-size: 130px; animation: wiggle 1s ease-in-out infinite; }
@keyframes wiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
.sticker-won { font-size: 150px; animation: grow .6s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes grow { from { transform: scale(0) rotate(-40deg); } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall 2.4s linear forwards; }
@keyframes fall { to { transform: translateY(105dvh) rotate(540deg); } }

/* ---------- альбом ---------- */
.album-count { font-size: 24px; font-weight: 900; color: var(--violet); }
.album-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding-top: 12px; }
.slot { aspect-ratio: 1; border-radius: 18px; background: var(--card); border: 3px dashed var(--line); display: grid; place-items: center; font-size: 36px; }
.slot.got { border: 3px solid var(--violet-soft); animation: pop .3s ease backwards; }

/* ---------- батьківський екран ---------- */
.parent { user-select: text; -webkit-user-select: text; font-size: 15px; line-height: 1.45; gap: 12px; max-width: 760px; }
.parent h2 { margin: 6px 0 0; font-size: 24px; }
.parent h3 { margin: 0 0 8px; font-size: 17px; }
.parent section { background: var(--card); border-radius: 18px; padding: 14px 16px; }
.parent p { margin: 6px 0; }
.parent table { border-collapse: collapse; width: 100%; font-size: 14px; }
.parent th, .parent td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
.parent th { font-weight: 700; color: var(--ink-soft); font-size: 12px; }
.parent ul { margin: 4px 0; padding-left: 20px; }
.ptop { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.ver { font-size: 12px; color: var(--ink-soft); }
.note { font-size: 13px; color: var(--ink-soft); }
.err { color: #C2334A; font-weight: 700; }
.pbtn { background: var(--violet); color: #fff; padding: 9px 14px; border-radius: 12px; font-weight: 700; margin: 2px 0; }
.pbtn.ghost { background: var(--violet-soft); color: var(--violet); }
.pbtn.on { background: var(--mint); }
.danger { background: transparent !important; text-align: center; }
.family-code { font-size: 22px; font-weight: 900; letter-spacing: 1px; background: var(--violet-soft); border-radius: 12px; padding: 8px 12px; display: inline-block; user-select: all; }
.parent input { font: inherit; padding: 9px 12px; border-radius: 12px; border: 2px solid var(--line); width: 220px; max-width: 100%; }
.bond-grid { display: flex; flex-direction: column; gap: 5px; }
.frow-p { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.frow-p b { width: 26px; font-size: 18px; }
.frow-p b.locked { color: #BDB8D6; }
.fc { display: inline-flex; flex-direction: column; align-items: center; padding: 3px 8px; border-radius: 8px; font-weight: 700; font-size: 13px; background: #EEECF5; color: #8A86A6; min-width: 46px; }
.fc small { font-weight: 600; font-size: 10px; opacity: .8; }
.fc.learn { background: #FFF0C2; color: #8A6400; }
.fc.digits { background: #D9F3E9; color: #237A60; }
.fc.done { background: var(--mint); color: #fff; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 380px) {
  .cell { width: 48px; height: 48px; }
  .expr { font-size: 46px; padding: 8px 18px; }
  .ans { height: 92px; font-size: 46px; }
  .big-hero { font-size: 120px; }
  .obj { font-size: 38px; }
}
@media (max-height: 680px) {
  .big-hero { font-size: 110px; }
  .play-btn { width: 120px; height: 120px; font-size: 52px; }
  .task { gap: 10px; }
}
