:root {
  --bg: #eef5ff;
  --ink: #1d2b44;
  --muted: #5b6b85;
  --line: #d7e6fb;
  --card: #ffffff;
  --blue: #2f6fde;
  --blue-dark: #1d4fa8;
  --orange: #ff7a00;
  --orange-dark: #c45d00;
  --green: #2e9e4f;
  --green-dark: #1f7339;
  --red: #e53935;
  --radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, Roboto, "Segoe UI", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100dvh;
}

#app {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Болтик и его реплики ---------- */

#talk {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 3px solid var(--line);
  min-height: 84px;
}

.helper {
  flex: none;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
}
.helper svg { width: 68px; height: 68px; display: block; }
.helper img {
  width: 68px;
  height: 68px;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--blue);
}
.helper .mouth { transform-box: fill-box; transform-origin: center; }
.helper.talking .mouth { animation: talk 0.22s infinite alternate ease-in-out; }
.helper.talking img { animation: pulse 0.35s infinite alternate ease-in-out; }
.helper .eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.helper-name { font-weight: 700; color: var(--blue-dark); font-size: 16px; margin-left: -8px; writing-mode: vertical-rl; transform: rotate(180deg); }
@keyframes talk { to { transform: scaleY(1.8); } }
@keyframes pulse { to { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(47, 111, 222, 0.25); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }

.bubble {
  flex: 1;
  font-size: 22px;
  line-height: 1.3;
  font-weight: 500;
  white-space: pre-line;
}

/* ---------- Кнопки ---------- */

.btn {
  font: 600 20px/1.1 inherit;
  font-family: inherit;
  min-height: 56px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 0;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 4px 0 #c5d6ee;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c5d6ee; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.primary { background: var(--orange); color: #fff; box-shadow: 0 4px 0 var(--orange-dark); }
.btn.primary:active { box-shadow: 0 1px 0 var(--orange-dark); }
.btn.green { background: var(--green); color: #fff; box-shadow: 0 4px 0 var(--green-dark); }
.btn.on { background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark); }
.btn.on:active { box-shadow: 0 1px 0 var(--blue-dark); }
.btn.big { min-height: 72px; font-size: 24px; }
.btn.icon { width: 64px; height: 64px; padding: 0; font-size: 30px; }
.btn.small { min-height: 44px; font-size: 17px; padding: 0 12px; }

/* ---------- Верхняя панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0 6px; font-size: 28px; }
.topbar .spacer { flex: 1; }

/* ---------- Главный экран ---------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 20px;
  overflow: auto;
}
.home h1 { font-size: 44px; margin: 0; color: var(--blue-dark); }
.tiles { display: flex; gap: 24px; flex-wrap: wrap; justify-content: center; }
.tile {
  width: 300px;
  min-height: 230px;
  border: 0;
  border-radius: 28px;
  background: var(--card);
  box-shadow: 0 6px 0 #c5d6ee;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 18px;
}
.tile:active { transform: translateY(4px); box-shadow: 0 2px 0 #c5d6ee; }
.tile .emoji { font-size: 76px; line-height: 1; }
.tile .title { font-size: 30px; font-weight: 700; }
.tile .sub { font-size: 18px; color: var(--muted); }
.home .grown-ups { margin-top: 8px; }

/* ---------- Рабочая область ---------- */

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
  padding: 0 14px 12px;
  position: relative;
}
.canvas-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  position: relative;
}
.canvas-wrap canvas { touch-action: none; border-radius: 24px; display: block; }
.scene-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  border-radius: 24px;
  overflow: hidden;
  background: #cfe8ff;
}
.scene-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.side {
  width: 250px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 2px 2px 6px;
}
.side .label { font-size: 16px; color: var(--muted); font-weight: 600; margin-top: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.side .grow { flex: 1; }

.dot { display: inline-block; border-radius: 50%; background: currentColor; }

.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.swatch {
  height: 48px;
  border-radius: 14px;
  border: 4px solid transparent;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.18);
  cursor: pointer;
}
.swatch.on { border-color: var(--ink); }

@media (max-aspect-ratio: 1/1) {
  .stage { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .side .label { display: none; }
  .side .grow { display: none; }
  .swatches { grid-template-columns: repeat(8, 40px); }
}

/* ---------- Карточка миссии ---------- */

.mission-card {
  position: absolute;
  left: 12px;
  top: 12px;
  max-width: min(420px, calc(100% - 24px));
  background: rgba(255, 255, 255, 0.94);
  border-radius: 18px;
  padding: 12px 16px;
  box-shadow: 0 4px 14px rgba(29, 43, 68, 0.15);
  font-size: 18px;
  line-height: 1.3;
  pointer-events: none;
}
.mission-card .m-title { font-weight: 700; font-size: 20px; }
.mission-card .m-progress { margin-top: 6px; font-weight: 700; color: var(--blue-dark); }
.mission-card.done { background: #e3f7e9; }
.mission-card.done .m-progress { color: var(--green-dark); }

/* ---------- Предпросмотр печати ---------- */

.preview {
  position: absolute;
  inset: 0 14px 12px;
  display: flex;
  gap: 12px;
  background: var(--bg);
}
.preview .viewer {
  flex: 1;
  min-width: 0;
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  background: #eaf3ff;
  position: relative;
}
.preview .viewer canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.preview .back-float { position: absolute; left: 12px; top: 12px; z-index: 2; }
.preview .facts { font-size: 18px; line-height: 1.45; background: var(--card); border-radius: 18px; padding: 10px 14px; }
.preview .facts .warn { color: var(--orange-dark); font-weight: 600; }
.preview .facts .bad { color: var(--red); font-weight: 700; }
.preview h2 { margin: 4px 0; font-size: 26px; }
@media (max-aspect-ratio: 1/1) {
  .preview { flex-direction: column; }
}

/* ---------- Окна ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(29, 43, 68, 0.45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: var(--bg);
  border-radius: 26px;
  padding: 20px;
  width: min(640px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal h2 { margin: 0 0 4px; font-size: 28px; }
.mission-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  justify-content: flex-start;
  min-height: 76px;
  padding: 10px 16px;
}
.mission-btn .m-emoji { font-size: 38px; }
.mission-btn .m-text { flex: 1; }
.mission-btn .m-name { font-size: 22px; font-weight: 700; }
.mission-btn .m-desc { font-size: 16px; font-weight: 400; color: var(--muted); margin-top: 3px; }
.mission-btn .m-star { font-size: 30px; }

/* ---------- Экран для взрослых ---------- */

.parent {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  -webkit-user-select: text;
  user-select: text;
}
.parent .note { color: var(--muted); font-size: 17px; line-height: 1.4; max-width: 900px; }
.parent h2 { font-size: 22px; margin: 22px 0 8px; }
.phrase {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: 16px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.phrase .p-text { flex: 1; font-size: 18px; line-height: 1.35; }
.phrase .p-state { font-size: 14px; color: var(--muted); width: 100px; text-align: center; }
.phrase .p-state.rec { color: var(--green-dark); font-weight: 700; }
.phrase.recording { outline: 4px solid var(--red); }
.parent h3 { font-size: 18px; margin: 16px 0 6px; color: var(--muted); }
.card-block { background: var(--card); border-radius: 20px; padding: 6px 16px 14px; margin: 12px 0; max-width: 1000px; }
.card-block h2 { margin-top: 10px; }
.text-input {
  font: 500 18px inherit;
  font-family: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  border: 3px solid var(--line);
  min-width: 200px;
}
.p-edit {
  flex: 1;
  font: 400 17px/1.35 inherit;
  font-family: inherit;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 6px 8px;
  resize: vertical;
  background: #f6f9ff;
  color: var(--ink);
}
.p-edit:focus { border-color: var(--blue); outline: none; background: #fff; }
.p-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.photo-preview { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; border: 3px solid var(--blue); }
.phrase.printed { opacity: 0.6; }
.home .bottom-links { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.gate { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; font-size: 22px; padding-top: 20px; }
.gate input {
  font: 600 28px inherit;
  font-family: inherit;
  width: 160px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 3px solid var(--line);
}

/* ---------- Конфетти ---------- */

.confetti {
  position: fixed;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  z-index: 100;
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}
