:root {
  --brown: #7a4a2f;
  --outline: #f0c27b;
  --accent: #ff8e3c;
  --yellow: #ffd34d;
  --pink: #ff9eb5;
  --green: #6fcf6f;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, 'SF Pro Rounded', system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(160deg, #bfe6ff 0%, #e8f6ff 45%, #ffe9c9 100%);
  color: var(--brown);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 4px;
}

.title {
  flex: 1;
  font-size: 19px;
  font-weight: 800;
  color: #8a5a2b;
  text-shadow: 0 2px 0 #fff;
  white-space: nowrap;
  overflow: hidden;
}

.hdr-btn {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  border: 3px solid var(--outline);
  background: #fff;
  font-size: 21px;
  cursor: pointer;
  box-shadow: 0 3px 0 #e8c98e;
  padding: 0;
  line-height: 1;
}
.hdr-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #e8c98e; }

#stage {
  flex: 1;
  min-height: 230px;
  margin: 6px 12px;
  border-radius: 26px;
  overflow: hidden;
  background: #d6f1ff;
  box-shadow: inset 0 0 0 4px #fff, 0 8px 20px rgba(122, 74, 47, 0.18);
}
#stage svg { width: 100%; height: 100%; display: block; }

.strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 12px;
  scrollbar-width: none;
}
.strip::-webkit-scrollbar { display: none; }

.cat-btn {
  flex: none;
  border: 3px solid var(--outline);
  background: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 800;
  color: #8a5a2b;
  cursor: pointer;
  box-shadow: 0 3px 0 #e8c98e;
  font-family: inherit;
}
.cat-btn.active {
  background: var(--accent);
  border-color: #e0701f;
  color: #fff;
  box-shadow: 0 3px 0 #c05a14;
}
.cat-btn.photo-btn {
  background: var(--green);
  border-color: #4faf4f;
  color: #fff;
  box-shadow: 0 3px 0 #3f8f3f;
}
.cat-btn.ai-btn {
  background: #a06cd5;
  border-color: #7e4fb0;
  color: #fff;
  box-shadow: 0 3px 0 #6b3fa0;
}

.opt-btn {
  flex: none;
  width: 100px;
  border: 3px solid #ecd9b4;
  background: #fff;
  border-radius: 20px;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 3px 0 #e3cda0;
  font-family: inherit;
}
.opt-btn svg { width: 62px; height: 62px; }
.opt-btn .opt-label {
  font-size: 12px;
  font-weight: 700;
  color: #8a5a2b;
  line-height: 1.1;
  text-align: center;
}
.opt-btn .big-emoji { font-size: 42px; line-height: 62px; }
.opt-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px #ffd7b0, 0 3px 0 #e3cda0;
  transform: scale(1.06);
}

#tabs {
  display: flex;
  gap: 8px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}

.tab-btn {
  flex: 1;
  height: 66px;
  font-size: 15px;
  padding: 0 4px;
  border-radius: 22px;
  border: 3px solid var(--outline);
  background: #fff;
  font-size: 17px;
  font-weight: 800;
  color: #8a5a2b;
  cursor: pointer;
  box-shadow: 0 4px 0 #e8c98e;
  font-family: inherit;
}
.tab-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #e8c98e; }
.tab-house.active { background: var(--yellow); border-color: #e8b32f; box-shadow: 0 4px 0 #c9941c; }
.tab-char.active { background: var(--pink); border-color: #f07e97; box-shadow: 0 4px 0 #d1627b; }
.tab-toy { background: #ffe9c9; border-color: #eec48a; color: #8a5a2b; }
.tab-toy.active { background: #c9b1f0; border-color: #a98fdd; box-shadow: 0 4px 0 #9676cc; }
.save-btn { background: var(--green); border-color: #4faf4f; color: #fff; box-shadow: 0 4px 0 #3f8f3f; }

#overlay, #aiOverlay {
  position: fixed;
  inset: 0;
  background: rgba(60, 35, 20, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
#overlay .card, #aiOverlay .card {
  background: #fff;
  border-radius: 26px;
  padding: 20px;
  max-width: 430px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  max-height: 90vh;
  overflow-y: auto;
}
.card-title { font-size: 22px; font-weight: 800; margin-bottom: 12px; }
#overlayImg, #aiOverlayImg { width: 100%; border-radius: 16px; border: 3px solid var(--outline); }
.hint { font-size: 14px; color: #8a5a2b; margin: 12px 0 6px; }
.card-btns { display: flex; gap: 10px; margin-top: 10px; }
.big-btn {
  flex: 1;
  display: block;
  padding: 14px 10px;
  border-radius: 18px;
  border: 3px solid #4faf4f;
  background: var(--green);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.big-btn.gray { border-color: #b9b09e; background: #e8e2d4; color: #7a4a2f; }
.big-btn.purple { border-color: #7e4fb0; background: #a06cd5; color: #fff; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translateX(-50%);
  background: #4a3b32;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 999px;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

@keyframes smoke {
  0%   { transform: translateY(0) scale(1); opacity: 0.85; }
  100% { transform: translateY(-80px) scale(1.7); opacity: 0; }
}
.smoke  { animation: smoke 2.8s linear infinite; }
.smoke2 { animation: smoke 2.8s linear infinite; animation-delay: 0.95s; }
.smoke3 { animation: smoke 2.8s linear infinite; animation-delay: 1.9s; }

/* живость: моргание, покачивание, облака, бабочка */
@keyframes blink {
  0%, 93%, 100% { opacity: 1; }
  95.5% { opacity: 0; }
}
.eye-open { animation: blink 4.2s infinite; }

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
.char-bob { animation: bob 2.8s ease-in-out infinite; }

@keyframes drift {
  from { transform: translateX(-14px); }
  to   { transform: translateX(14px); }
}
.cloud-drift { animation: drift 26s ease-in-out infinite alternate; }

@keyframes fly {
  0%   { transform: translate(40px, 150px); }
  20%  { transform: translate(240px, 60px); }
  40%  { transform: translate(430px, 170px); }
  60%  { transform: translate(620px, 80px); }
  80%  { transform: translate(780px, 150px); }
  100% { transform: translate(40px, 150px); }
}
.butterfly { animation: fly 26s linear infinite; }
@keyframes flap {
  0%, 100% { transform: scaleX(1); }
  50% { transform: scaleX(0.15); }
}
.bf-wing {
  animation: flap 0.5s ease-in-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}

/* мини-задание «Собери такой же!» */
#taskCard {
  position: fixed;
  top: 62px;
  right: 10px;
  z-index: 45;
  background: #fff;
  border: 3px solid var(--accent);
  border-radius: 18px;
  padding: 6px 8px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(122, 74, 47, 0.3);
  width: 116px;
}
#taskCard .task-title { font-size: 12px; font-weight: 800; color: #8a5a2b; }
#taskCard svg { width: 100px; height: 78px; display: block; margin: 2px auto; border-radius: 10px; }
#taskCount { font-size: 13px; font-weight: 800; color: #e0701f; }
#taskCard.done { border-color: var(--green); }
#taskCard.done #taskCount { color: #3f8f3f; }

/* конфетти */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.cf { position: absolute; top: -24px; width: 11px; height: 15px; border-radius: 3px; opacity: 0.95; animation: fall linear forwards; }
@keyframes fall {
  to { transform: translateY(112vh) rotate(720deg); opacity: 0.7; }
}

/* сохранение: рамки, стикеры, подпись */
.frame-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0 4px; }
.frame-btn { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #ecd9b4; cursor: pointer; flex: none; padding: 0; }
.frame-btn.active { border-color: var(--accent); box-shadow: 0 0 0 4px #ffd7b0; transform: scale(1.1); }
.sticker-row { display: flex; gap: 8px; justify-content: center; margin: 4px 0; }
.sticker-btn { width: 46px; height: 46px; border-radius: 14px; border: 3px solid #ecd9b4; background: #fff; font-size: 24px; cursor: pointer; padding: 0; line-height: 1; }
.sticker-btn.active { border-color: var(--accent); box-shadow: 0 0 0 4px #ffd7b0; transform: scale(1.08); }
#captionInput {
  width: 100%;
  margin: 8px 0 4px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 3px solid var(--outline);
  font-size: 16px;
  font-weight: 700;
  color: var(--brown);
  font-family: inherit;
  text-align: center;
}

/* альбом */
.album-tab { background: #c9b1f0; border-color: #a98fdd; color: #5b3f96; box-shadow: 0 4px 0 #9676cc; }
.album-card { max-width: 560px; }
.album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-height: 52vh;
  overflow-y: auto;
  margin: 10px 0;
  padding: 2px;
}
.album-item { position: relative; border-radius: 14px; overflow: hidden; border: 3px solid var(--outline); background: #fff; }
.album-item img { width: 100%; display: block; cursor: pointer; }
.album-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #c96f4a;
  background: #fff;
  color: #c96f4a;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.album-del.armed { background: #e85d5d; color: #fff; border-color: #b23a3a; }
.album-empty { color: #8a5a2b; font-size: 15px; font-weight: 700; padding: 20px 10px; }
#albumView img { width: 100%; border-radius: 16px; border: 3px solid var(--outline); }
#albumView .album-caption { font-size: 18px; font-weight: 800; color: #8a5a2b; margin-top: 8px; }

/* модный батл */
.fashion-btn { background: #ff8fb3; border-color: #f07e97; color: #fff; box-shadow: 0 3px 0 #d1627b; }
#fashionChip {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 3px solid #ff8fb3;
  border-radius: 999px;
  padding: 6px 6px 6px 16px;
  box-shadow: 0 8px 20px rgba(122, 74, 47, 0.28);
  max-width: 92vw;
}
#fashionChip .chip-text { font-size: 14px; font-weight: 800; color: #8a5a2b; white-space: nowrap; }
#fashionChip .chip-btn {
  border: 0;
  background: #ff8fb3;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
}
#fashionChip .chip-x {
  border: 0;
  background: #f0e6d2;
  color: #8a5a2b;
  font-weight: 800;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}
.fashion-card { max-width: 560px; }
.runway-wrap { margin: 8px 0; }
.runway-wrap svg { width: 100%; display: block; border-radius: 16px; }
#fashionOverlay { position: fixed; inset: 0; background: rgba(60, 35, 20, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 56; }
#fashionOverlay .card { background: #fff; border-radius: 26px; padding: 18px; width: 100%; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); max-height: 92vh; overflow-y: auto; }
.fash-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0; }
.fash-side { flex: 1; background: #fdf6e9; border-radius: 18px; padding: 8px; }
.fash-bust { width: 80px; height: 104px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #fdf3e0; }
.fash-bust svg { width: 100%; height: 100%; }
.fash-name { font-size: 13px; font-weight: 800; color: #8a5a2b; margin-top: 4px; }
.fash-stars { font-size: 13px; line-height: 1.2; margin: 4px 0; }
.fash-vs { font-size: 18px; font-weight: 900; color: #d1627b; }
.fash-total { font-size: 15px; font-weight: 900; color: #e0701f; }
.fash-winner { font-size: 20px; font-weight: 900; color: #3f8f3f; margin: 10px 0 4px; }
@keyframes catwalk { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }
.runway-char { animation: catwalk 1.5s ease-in-out infinite; }
.runway-char.r2 { animation-delay: -0.75s; }
@keyframes sparkle { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
.runway-sparkle { animation: sparkle 1.2s infinite; }
@keyframes starpop { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.fash-stars .star { display: inline-block; animation: starpop 0.35s ease-out both; }

/* меню заданий */
#taskMenu { position: fixed; inset: 0; background: rgba(60, 35, 20, 0.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 55; }
#taskMenu .card { background: #fff; border-radius: 26px; padding: 22px; max-width: 360px; width: 100%; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); }
.task-menu-btn { display: block; width: 100%; margin-top: 10px; }

@media (min-width: 760px) {
  .opt-btn { width: 112px; }
  #stage { min-height: 300px; }
  header { padding-top: 14px; }
}
