:root {
  --ink: #2e2438;
  --cream: #f4efe6;
  --accent: #c47a5a;
  --sage: #b8c095;
  --font: "Manrope", system-ui, sans-serif;
  /* Клубки ×2 к уровню с игрушками; размеры различаются через --yarn-scale */
  --toy: clamp(136px, 22vmin, 236px);
  --basket-w: min(calc(var(--toy) * 2.7), 92vw, 920px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: var(--font);
  background: var(--sage);
  overflow: hidden;
  color: var(--ink);
}

.wall-fill {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: var(--sage);
  background-image: url("../assets/wallpaper.webp");
  background-repeat: repeat;
  background-size: 220px auto;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: 100%;
  padding: 0;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;
  opacity: 0.08;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

.sound-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: rgba(244, 239, 230, 0.92);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(30, 18, 40, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sound-btn:hover { background: #fff; }
.sound-btn:active { transform: scale(0.97); }
.sound-btn[aria-pressed="false"] { opacity: 0.72; }
.sound-btn[aria-pressed="false"] .sound-btn__wave { opacity: 0.25; }
.sound-btn[aria-pressed="false"] .sound-btn__mute { display: block; }
.sound-btn__mute[hidden] { display: none; }

.hint-btn,
.solve-btn {
  position: fixed;
  z-index: 50;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(30, 18, 40, 0.18);
}

.hint-btn {
  top: 18px;
  right: 72px;
  background: rgba(244, 239, 230, 0.9);
  color: var(--ink);
}

.hint-btn:hover { background: #fff; }

.solve-btn {
  top: 70px;
  right: 18px;
  background: rgba(196, 122, 90, 0.92);
  color: #fff;
}

.solve-btn:hover { background: #b86a4c; }

.menu-btn {
  position: fixed;
  top: 122px;
  right: 18px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(90, 70, 110, 0.92);
  color: #fff;
  box-shadow: 0 4px 14px rgba(30, 18, 40, 0.18);
}

.menu-btn:hover { background: #4e3c62; }

.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  z-index: 5;
}

.basket {
  position: absolute;
  left: 50%;
  top: 48%;
  width: var(--basket-w);
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
}

.basket img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 14px 18px rgba(40, 50, 30, 0.22));
}

.basket-mouth {
  position: absolute;
  left: 16%;
  top: 20%;
  width: 68%;
  height: 56%;
  border-radius: 50%;
  pointer-events: none;
}

.toy {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  z-index: 5;
  width: auto;
  height: calc(var(--toy) * var(--yarn-scale, 1));
  transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
  filter: drop-shadow(0 8px 10px rgba(40, 50, 30, 0.28));
  will-change: left, top, transform;
}

.toy[data-id="cream"] { --yarn-scale: 0.72; }
.toy[data-id="rose"] { --yarn-scale: 0.82; }
.toy[data-id="sky"] { --yarn-scale: 0.9; }
.toy[data-id="lavender"] { --yarn-scale: 0.98; }
.toy[data-id="mustard"] { --yarn-scale: 1.06; }
.toy[data-id="sage"] { --yarn-scale: 1.14; }
.toy[data-id="peach"] { --yarn-scale: 1.22; }
.toy[data-id="coral"] { --yarn-scale: 1.3; }

.toy img {
  display: block;
  width: auto;
  height: 100%;
  max-width: none;
  object-fit: contain;
  pointer-events: none;
}

.toy.is-dragging {
  cursor: grabbing;
  z-index: 20;
  filter: drop-shadow(0 14px 16px rgba(40, 50, 30, 0.36));
}

.toy.is-settling,
.toy.is-dropping {
  transition:
    left 0.4s cubic-bezier(0.22, 0.9, 0.28, 1),
    top 0.4s cubic-bezier(0.34, 1.15, 0.64, 1),
    transform 0.4s cubic-bezier(0.22, 0.9, 0.28, 1);
  z-index: 8;
}

.toy.is-placed {
  cursor: grab;
  z-index: 4;
  filter: drop-shadow(0 3px 5px rgba(40, 50, 30, 0.2));
}

.toy.is-locked {
  cursor: default;
  pointer-events: none;
}

.toast {
  position: fixed;
  bottom: 14vh;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  margin: 0;
  padding: 12px 20px;
  border-radius: 14px;
  background: rgba(46, 36, 56, 0.9);
  color: var(--cream);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-width: min(92vw, 420px);
  text-align: center;
}

.toast[hidden],
.win[hidden] {
  display: none !important;
}

.win {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 20vh;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-card {
  position: relative;
  pointer-events: auto;
  background: var(--cream);
  border-radius: 18px;
  padding: 18px 22px 16px;
  text-align: center;
  max-width: 380px;
  width: calc(100% - 40px);
  box-shadow: 0 16px 40px rgba(30, 18, 40, 0.3);
  animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.win-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6a6058;
  font-size: 1.45rem;
  cursor: pointer;
}

.win-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
}

.win-text {
  margin: 0 0 12px;
  line-height: 1.35;
  font-size: 0.92rem;
  color: #5c534a;
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 10px 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.btn-again {
  background: #8a7a6a;
}

.btn-continue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 14px;
  text-decoration: none;
}

.btn-continue__tri {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
}

@media (max-width: 640px) {
  .sound-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    width: 40px;
    height: 40px;
  }
  .hint-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(58px + env(safe-area-inset-right, 0px));
    font-size: 0.78rem;
    padding: 8px 12px;
  }
  .solve-btn {
    top: calc(54px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    font-size: 0.78rem;
    padding: 8px 12px;
  }
  .menu-btn {
    top: calc(96px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    font-size: 0.78rem;
    padding: 8px 12px;
  }
  :root {
    --toy: clamp(104px, 22vmin, 168px);
    --basket-w: min(calc(var(--toy) * 2.6), 90vw, 420px);
  }
  .win {
    bottom: max(12vh, calc(12px + env(safe-area-inset-bottom, 0px)));
  }
  .win-card {
    max-height: min(48vh, 340px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
