:root {
  --ink: #4b3b7a;
  --pink: #ff6fa8;
  --lilac: #a98bff;
  --sky: #7cc6ff;
  --paper: #fffaf3;
  --font: ui-rounded, 'SF Pro Rounded', 'Arial Rounded MT Bold', 'Nunito', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

/* у слоёв поверх игры свой display — без этого скрытый слой невидимо ловит нажатия */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #ffd3ea;
  font-family: var(--font);
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* ─── рука-подсказка ─── */
#hand {
  position: fixed; left: 0; top: 0; z-index: 5; pointer-events: none;
  opacity: 0; transition: opacity .3s;
}
#hand.on { opacity: 1; }
#hand span {
  display: block; font-size: 64px; line-height: 1;
  transform: translate(-50%, -100%);
  filter: drop-shadow(0 4px 6px rgba(75, 59, 122, .35));
  animation: point 0.9s ease-in-out infinite;
}
@keyframes point {
  0%, 100% { transform: translate(-50%, -110%); }
  50% { transform: translate(-50%, -82%); }
}

/* ─── кнопки в углах ─── */
.corner { position: fixed; z-index: 6; display: grid; place-items: center; }
.album {
  left: calc(16px + var(--safe-l)); top: calc(16px + var(--safe-t));
  width: 76px; height: 76px; border-radius: 50%;
  background: #fff; box-shadow: 0 6px 0 #f2c6dc, 0 10px 24px rgba(160, 90, 150, .25);
}
.album svg { width: 52px; height: 52px; }
.album b {
  position: absolute; right: -4px; top: -4px; min-width: 30px; height: 30px; padding: 0 8px;
  border-radius: 15px; background: var(--pink); color: #fff; font-size: 17px; line-height: 30px; font-weight: 800;
  box-shadow: 0 2px 0 #e4508c;
}
.album.bump { animation: bump .7s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.3) rotate(-8deg); } 100% { transform: scale(1); } }

.gear {
  right: calc(14px + var(--safe-r)); top: calc(14px + var(--safe-t));
  width: 46px; height: 46px; border-radius: 50%;
  color: rgba(75, 59, 122, .35); background: rgba(255, 255, 255, .35);
}
.gear svg { width: 30px; height: 30px; }
.gear .ring {
  position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(var(--lilac) calc(var(--k, 0) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%);
  mask: radial-gradient(circle, transparent 58%, #000 60%);
}
.gear.hold .ring { animation: hold 1.5s linear forwards; }
@property --k { syntax: '<number>'; inherits: false; initial-value: 0; }
@keyframes hold { to { --k: 1; } }

/* ─── экран «Играть» ─── */
.start {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center;
  background:
    radial-gradient(120% 90% at 50% 110%, rgba(255, 238, 248, .2), rgba(255, 214, 236, .55) 60%),
    linear-gradient(180deg, rgba(168, 200, 255, .55), rgba(255, 211, 234, .35));
  transition: opacity .7s, transform .7s;
}
.start.gone { opacity: 0; transform: scale(1.06); pointer-events: none; }
.start-in { display: grid; justify-items: center; gap: clamp(18px, 4vh, 36px); padding: 16px; text-align: center; }
.start h1 {
  margin: 0; font-weight: 900; line-height: .95; letter-spacing: -.01em;
  font-size: clamp(44px, 9vmin, 96px);
  color: #fff;
  text-shadow: 0 4px 0 #ff8fc0, 0 8px 0 #a98bff, 0 14px 28px rgba(110, 70, 160, .35);
}
.start h1 span { font-size: .62em; display: inline-block; margin-top: .25em; }

.play {
  position: relative; width: clamp(140px, 24vmin, 190px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #ff8fc0, #ff5f9e 55%, #b36bff);
  box-shadow: 0 10px 0 #c94b8f, 0 18px 40px rgba(160, 60, 140, .4), inset 0 -10px 20px rgba(120, 40, 160, .25), inset 0 8px 14px rgba(255, 255, 255, .45);
  opacity: .55; transform: scale(.92); transition: opacity .4s, transform .4s;
  pointer-events: none;
}
.play svg { width: 52%; height: 52%; transform: translateX(6%); filter: drop-shadow(0 3px 0 rgba(150, 40, 110, .4)); }
.start.ready .play { opacity: 1; transform: none; pointer-events: auto; animation: breathe 1.8s ease-in-out infinite; }
.start.ready .play:active { transform: translateY(6px) scale(.97); box-shadow: 0 4px 0 #c94b8f, 0 8px 20px rgba(160, 60, 140, .4); }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.play .load {
  position: absolute; inset: -12px; border-radius: 50%;
  background: conic-gradient(#fff calc(var(--p, 0) * 360deg), rgba(255, 255, 255, .35) 0);
  -webkit-mask: radial-gradient(circle, transparent 64%, #000 65.5%);
  mask: radial-gradient(circle, transparent 64%, #000 65.5%);
  transition: opacity .4s;
}
.start.ready .play .load { opacity: 0; }

/* ─── награда ─── */
.reward { position: fixed; inset: 0; z-index: 9; display: grid; place-items: center; overflow: hidden; }
.reward .bg {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(255, 245, 252, .55), rgba(120, 90, 170, .45));
}
.reward .bg, .reward .rays { opacity: 0; transition: opacity .4s; }
.reward.on .bg, .reward.on .rays { opacity: 1; }
.reward .rays {
  position: absolute; width: 150vmax; height: 150vmax;
  background: repeating-conic-gradient(rgba(255, 255, 255, .35) 0 10deg, transparent 10deg 22.5deg);
  -webkit-mask: radial-gradient(circle, #000 10%, transparent 55%);
  mask: radial-gradient(circle, #000 10%, transparent 55%);
  animation: spin 16s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }
.reward img {
  position: relative; width: min(56vmin, 360px); aspect-ratio: 1;
  filter: drop-shadow(5px 0 0 #fff) drop-shadow(-5px 0 0 #fff) drop-shadow(0 5px 0 #fff) drop-shadow(0 -5px 0 #fff) drop-shadow(0 10px 14px rgba(90, 50, 130, .35));
  transform: scale(.2) rotate(-25deg);
}
.reward.on img { animation: pop .8s cubic-bezier(.3, 1.6, .5, 1) forwards; }
@keyframes pop { to { transform: scale(1) rotate(-4deg); } }

/* ─── листы: альбом и меню взрослых ─── */
.sheet {
  position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; padding: 16px;
  background: rgba(75, 59, 122, .35);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .3s;
}
.sheet[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  position: relative; background: var(--paper); border-radius: 36px;
  box-shadow: 0 10px 0 #f0d7e6, 0 24px 60px rgba(75, 59, 122, .35);
  animation: rise .45s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes rise { from { transform: translateY(40px) scale(.9); opacity: 0; } }

.album-sheet .card {
  width: min(92vw, 860px); max-height: calc(100vh - 32px); overflow: auto;
  padding: clamp(18px, 4vmin, 36px);
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 200, 225, .45), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(190, 170, 255, .35), transparent 45%),
    var(--paper);
}
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: clamp(8px, 2vmin, 18px); }
@media (orientation: portrait) { .grid { grid-template-columns: repeat(4, 1fr); } }
.slot {
  position: relative; aspect-ratio: 1; border-radius: 50%;
  border: 4px dashed rgba(169, 139, 255, .45);
  background: rgba(255, 255, 255, .6);
  display: grid; place-items: center;
}
.slot::after { content: '★'; font-size: clamp(22px, 5vmin, 40px); color: rgba(169, 139, 255, .3); }
.slot.got { border: 0; background: none; transform: rotate(var(--tilt)); }
.slot.got::after { content: none; }
.slot img {
  width: 100%; height: 100%;
  filter: drop-shadow(3px 0 0 #fff) drop-shadow(-3px 0 0 #fff) drop-shadow(0 3px 0 #fff) drop-shadow(0 -3px 0 #fff) drop-shadow(0 5px 6px rgba(90, 50, 130, .3));
}
.slot b {
  position: absolute; right: 2%; bottom: 4%; padding: 2px 8px; border-radius: 12px;
  background: var(--lilac); color: #fff; font-size: 15px; transform: rotate(calc(var(--tilt) * -1));
}
.close {
  position: absolute; right: -10px; top: -10px; width: 60px; height: 60px; border-radius: 50%;
  background: var(--pink); box-shadow: 0 5px 0 #d24b86; display: grid; place-items: center; z-index: 1;
}
.close svg { width: 30px; height: 30px; }

.parent { width: min(92vw, 420px); padding: 28px 24px 22px; display: grid; gap: 12px; }
.parent h2 { margin: 0 0 4px; font-size: 24px; text-align: center; }
.parent button {
  padding: 16px 18px; border-radius: 18px; font-size: 18px; font-weight: 700;
  background: #f1ebff; color: var(--ink);
}
.parent button.ghost { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #d24b86; }
.parent p { margin: 6px 4px 0; font-size: 14px; line-height: 1.4; opacity: .7; text-align: center; }

/* ─── конец игры: «ещё раз» и «домой» ─── */
.again {
  position: fixed; z-index: 7; left: 0; right: 0; bottom: calc(28px + var(--safe-b));
  display: flex; justify-content: center; gap: clamp(22px, 6vw, 48px); pointer-events: none;
}
.again button {
  pointer-events: auto; width: 104px; height: 104px; border-radius: 50%;
  display: grid; place-items: center;
  animation: rise .6s cubic-bezier(.3, 1.5, .5, 1), breathe 2.2s ease-in-out .6s infinite;
}
.again .again-btn { background: linear-gradient(160deg, #8f9bff, #a98bff 60%, #ff8fc0); box-shadow: 0 8px 0 #6c5fc9, 0 14px 30px rgba(60, 40, 140, .45); }
.again .home-btn { background: linear-gradient(160deg, #ffb26b, #ff8fc0 70%); box-shadow: 0 8px 0 #d86a8e, 0 14px 30px rgba(160, 60, 100, .4); animation-delay: 0s, .9s; }
.again svg { width: 56px; height: 56px; }

/* ─── домой во время игры ─── */
.home {
  right: calc(72px + var(--safe-r)); top: calc(14px + var(--safe-t));
  width: 62px; height: 62px; border-radius: 50%;
  background: #fff; box-shadow: 0 5px 0 #f2c6dc, 0 8px 18px rgba(160, 90, 150, .22);
}
.home svg { width: 38px; height: 38px; }
.home:active { transform: translateY(4px); box-shadow: 0 1px 0 #f2c6dc; }

/* ─── главный экран: плитки игр ─── */
.hub {
  position: fixed; z-index: 4; display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  --t: min(15.5vw, 25vh, 178px); --gap: clamp(10px, 1.6vmin, 18px);
  right: calc(20px + var(--safe-r)); top: calc(96px + var(--safe-t)); bottom: calc(20px + var(--safe-b));
  width: calc(var(--t) * 4 + var(--gap) * 3);
}
.tiles { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: var(--gap); pointer-events: auto; }
@media (orientation: portrait) {
  .hub {
    --t: min(28vw, 14.5vh, 150px);
    left: 0; right: 0; top: auto; width: auto; height: calc(var(--t) * 4 + var(--gap) * 3 + 12px);
    bottom: calc(16px + var(--safe-b)); padding: 0 16px;
  }
  .tiles { width: calc(var(--t) * 3 + var(--gap) * 2); }
}
.tile {
  position: relative; width: var(--t); height: var(--t); border-radius: 30%;
  /* фон насыщеннее, блик маленький: светлые игрушки на пастели иначе теряются */
  background:
    radial-gradient(55% 45% at 28% 18%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 70%),
    linear-gradient(155deg, color-mix(in srgb, var(--c1) 82%, #ff7fb8) 0%, color-mix(in srgb, var(--c2) 78%, #7f6cf0) 100%);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, .9), 0 7px 0 rgba(150, 90, 160, .28), 0 12px 24px rgba(120, 70, 150, .22);
  opacity: 0; transform: scale(.6) translateY(20px);
  transition: transform .2s;
}
.hub.on .tile { animation: tileIn .55s cubic-bezier(.3, 1.6, .5, 1) var(--d) forwards; }
@keyframes tileIn { to { opacity: 1; transform: none; } }
.tile:active { transform: translateY(5px) scale(.97); }
.tile.bump { animation: bump .7s cubic-bezier(.3, 1.8, .5, 1) !important; opacity: 1; }
.tile img { position: absolute; inset: 6%; width: 88%; height: 88%; object-fit: contain; filter: drop-shadow(0 6px 8px rgba(70, 30, 110, .35)) saturate(1.2) contrast(1.05); pointer-events: none; }
.tile .done {
  position: absolute; right: -4px; top: -4px; width: 34%; height: 34%; max-width: 46px; max-height: 46px;
  display: grid; place-items: center; border-radius: 50%; background: #ffd54a; color: #fff;
  font-size: clamp(16px, calc(var(--t) * .2), 26px); box-shadow: 0 3px 0 #f0a800; text-shadow: 0 1px 0 #e09400;
}
.tile .ring {
  position: absolute; inset: -5px; border-radius: 32%; opacity: 0;
  background: conic-gradient(#fff calc(var(--p, 0) * 360deg), rgba(255, 255, 255, .25) 0);
  -webkit-mask: radial-gradient(closest-side, transparent 88%, #000 90%);
  mask: radial-gradient(closest-side, transparent 88%, #000 90%);
}
.tile.loading .ring { opacity: 1; }

.curtain { position: fixed; inset: 0; z-index: 20; background: #fff6fb; opacity: 0; pointer-events: none; transition: opacity .6s; }
.curtain.on { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .play, .again button, #hand span, .reward .rays, .tile { animation: none !important; }
  .tile { opacity: 1; transform: none; }
}
