:root {
  --ink: #3a342e;
  --cream: #f4efe6;
  --accent: #c47a5a;
  --font: "Manrope", system-ui, sans-serif;
}

* {
  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: #e8d2b8;
  overflow: hidden;
  color: var(--ink);
}

.wall-fill {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: #e8d2b8;
  background-image: url("../assets/wallpaper.webp");
  background-repeat: repeat;
  background-size: 420px 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;
}

.rail-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(96vw, 1440px);
  transform: translate(-50%, -50%);
  z-index: 2;
  height: 56px;
}

.rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
  border-radius: 6px;
  background:
    linear-gradient(180deg, #4a4a4a 0%, #2a2a2a 45%, #1a1a1a 100%);
  box-shadow:
    0 10px 16px rgba(40, 28, 18, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.rail::before,
.rail::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transform: translateY(-50%);
  background:
    radial-gradient(circle at 35% 30%, #ddd 0 35%, #888 55%, #444 100%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.rail::before { left: 14px; }
.rail::after { right: 14px; }

.slot {
  position: absolute;
  top: 50%;
  width: 12%;
  height: 440px;
  transform: translate(-50%, -42%);
  pointer-events: none;
  border-radius: 8px;
}

.slot[data-id="0"] { left: 8%; }
.slot[data-id="1"] { left: 22%; }
.slot[data-id="2"] { left: 36%; }
.slot[data-id="3"] { left: 50%; }
.slot[data-id="4"] { left: 64%; }
.slot[data-id="5"] { left: 78%; }
.slot[data-id="6"] { left: 92%; }

.knife {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  z-index: 5;
  width: auto;
  height: clamp(300px, 52vh, 480px);
  transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
  filter: drop-shadow(0 10px 14px rgba(40, 28, 18, 0.35));
  will-change: left, top, transform;
}

.knife img {
  display: block;
  width: auto;
  height: 100%;
  max-width: none;
  object-fit: contain;
  pointer-events: none;
}

.knife--chef { height: clamp(340px, 60vh, 540px); }
.knife--santoku { height: clamp(310px, 54vh, 490px); }
.knife--serrated { height: clamp(290px, 50vh, 450px); }
.knife--utility { height: clamp(260px, 44vh, 400px); }
.knife--paring { height: clamp(220px, 36vh, 330px); }

.knife.is-dragging {
  cursor: grabbing;
  z-index: 20;
  filter: drop-shadow(0 16px 18px rgba(40, 28, 18, 0.4));
}

.knife.is-settling,
.knife.is-dropping {
  transition:
    left 0.42s cubic-bezier(0.22, 0.9, 0.28, 1),
    top 0.42s cubic-bezier(0.34, 1.2, 0.64, 1),
    transform 0.42s cubic-bezier(0.22, 0.9, 0.28, 1);
  z-index: 8;
}

.knife.is-placed {
  cursor: grab;
  z-index: 3;
  filter: drop-shadow(0 4px 6px rgba(40, 28, 18, 0.22));
}

.knife.is-locked {
  cursor: default;
  pointer-events: none;
}

.counter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  width: 100%;
  height: calc(10vh + min(22vh, 200px));
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  line-height: 0;
}

.counter__wood {
  flex: 0 0 min(22vh, 200px);
  width: 100%;
  overflow: hidden;
}

.counter__wood-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.counter__cabinets {
  flex: 0 0 10vh;
  width: 100%;
  overflow: hidden;
}

.counter__cabinets-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.toast {
  position: fixed;
  bottom: calc(10vh + min(22vh, 200px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
  margin: 0;
  padding: 12px 20px;
  border-radius: 14px;
  background: rgba(58, 52, 46, 0.88);
  color: var(--cream);
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: min(92vw, 420px);
  text-align: center;
}

.toast[hidden],
.win[hidden] {
  display: none !important;
}

.win {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 18vh;
  z-index: 60;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
}

.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(58, 52, 46, 0.25);
}

.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;
  }
  .knife { height: clamp(160px, 34vh, 280px); }
  .knife--chef { height: clamp(190px, 40vh, 320px); }
  .knife--santoku { height: clamp(175px, 37vh, 300px); }
  .knife--serrated { height: clamp(165px, 35vh, 280px); }
  .knife--utility { height: clamp(145px, 30vh, 250px); }
  .knife--paring { height: clamp(120px, 26vh, 210px); }
  .rail-wrap {
    width: min(98vw, 720px);
    top: 44%;
    height: 64px;
  }
  .slot {
    width: max(12%, 44px);
    height: 300px;
    transform: translate(-50%, -40%);
  }
  .counter { height: calc(8vh + min(14vh, 120px)); }
  .counter__wood { flex-basis: min(14vh, 120px); }
  .win {
    bottom: max(14vh, calc(12px + env(safe-area-inset-bottom, 0px)));
  }
  .win-card {
    max-height: min(48vh, 340px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
