:root {
  --ink: #3a342e;
  --cream: #f4efe6;
  --accent: #c47a5a;
  --purple: #4f536a;
  --font: "Manrope", system-ui, sans-serif;
  --gap-ratio: 0.02;
}

* {
  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: #5c8a62;
  overflow: hidden;
  color: var(--ink);
}

.wall-fill {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: #5c8a62;
  background-image: url("../assets/wallpaper.webp");
  background-repeat: repeat;
  background-size: 360px 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.14;
  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(58, 52, 46, 0.12);
  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(58, 52, 46, 0.12);
}

.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(138, 122, 106, 0.92);
  color: #fff;
  box-shadow: 0 4px 14px rgba(58, 52, 46, 0.12);
}

.menu-btn:hover { background: #7a6b5c; }

.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  z-index: 5;
}

/* 3 stickers + 2 gaps (2% play / 1% glued) */
.board {
  --sticker: min(36vw, 30vh, 300px);
  --gap: calc(var(--sticker) * var(--gap-ratio));
  position: absolute;
  left: 50%;
  top: 46%;
  width: calc(var(--sticker) * 3 + var(--gap) * 2);
  height: calc(var(--sticker) * 3 + var(--gap) * 2);
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: repeat(3, var(--sticker));
  grid-template-rows: repeat(3, var(--sticker));
  gap: var(--gap);
  z-index: 1;
  transition:
    gap 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    width 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.board.is-glued {
  --gap-ratio: 0;
}

.slot {
  border-radius: 18px;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.slot.is-hint {
  background: transparent;
  box-shadow: none;
}

.sticker {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--sticker-size, min(36vw, 30vh, 300px));
  height: var(--sticker-size, min(36vw, 30vh, 300px));
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  z-index: 10;
  transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
  touch-action: none;
  filter: drop-shadow(0 4px 8px rgba(40, 28, 18, 0.18));
  transition: filter 0.15s ease;
}

.sticker img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sticker.is-dragging {
  cursor: grabbing;
  z-index: 40;
  filter: drop-shadow(0 10px 18px rgba(40, 28, 18, 0.28));
}

.sticker.is-settling {
  transition:
    left 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.34s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
}

.sticker.is-dropping {
  transition:
    left 0.42s cubic-bezier(0.33, 0.9, 0.45, 1),
    top 0.42s cubic-bezier(0.55, 0.06, 0.68, 0.19),
    transform 0.42s cubic-bezier(0.33, 0.9, 0.45, 1);
}

.sticker.is-placed {
  z-index: 8;
}

.sticker.is-locked {
  cursor: default;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(40, 28, 18, 0.12));
}

.sticker.is-gluing {
  transition:
    left 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    top 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.55s ease;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 60;
  margin: 0;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(58, 52, 46, 0.88);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.win {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 20vh;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
  animation: fadeIn 0.35s ease;
}

.win[hidden],
.toast[hidden] {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.win-card {
  position: relative;
  pointer-events: auto;
  background: var(--cream, #f7f1e8);
  border-radius: 18px;
  padding: 18px 22px 16px;
  text-align: center;
  max-width: 380px;
  width: calc(100% - 40px);
  box-shadow: 0 16px 40px rgba(40, 28, 18, 0.28);
  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;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font);
}

.win-close:hover {
  background: rgba(58, 52, 46, 0.08);
  color: var(--ink);
}

.win-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--purple, #5c3f7a);
}

.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;
  align-items: stretch;
}

.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, #c47a5a);
  color: #fff;
  box-shadow: 0 6px 16px rgba(196, 122, 90, 0.35);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn:active { transform: scale(0.97); }

.btn-again {
  background: #8a7a6a;
  box-shadow: 0 5px 14px rgba(58, 52, 46, 0.22);
  color: #fff;
}

.btn-continue {
  background: var(--purple, #5c3f7a);
  color: #fff;
  border-radius: 14px;
  padding: 10px 18px;
  line-height: 1.2;
}

.btn-continue__tri {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
  flex: 0 0 auto;
}

.btn-continue__label {
  text-align: left;
}

@media (max-width: 640px) {
  .board {
    --sticker: min(28vw, 22vh, 110px);
    top: 46%;
  }

  .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;
  }
  .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;
  }
}
