: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: #6b4e32;
  overflow: hidden;
  color: var(--ink);
}

.table-fill {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: #7a5636;
  background-image: url("../assets/wood-table.webp");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  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: relative;
  /* Full table — pieces can roam the whole viewport */
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
}

/* Ambient kitchen clutter — not interactive */
.props {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.prop {
  position: absolute;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 8px 14px rgba(40, 28, 18, 0.28));
  opacity: 0.92;
}

.prop--towel {
  left: 1%;
  bottom: 4%;
  width: min(34%, 280px);
  transform: rotate(-18deg);
}

.prop--apple {
  right: 3%;
  top: 6%;
  width: min(14%, 120px);
  transform: rotate(12deg);
}

.prop--ramekin {
  right: 2%;
  bottom: 8%;
  width: min(16%, 130px);
  transform: rotate(-8deg);
}

.tray {
  position: absolute;
  left: 50%;
  top: 50%;
  /* Cap tray size so the table around it stays large for scatter/drag.
     +20% vs previous 580px — nests stay same visual size (padded art). */
  width: min(62.4vw, 696px);
  aspect-ratio: 1420 / 1228;
  transform: translate(-50%, -50%);
  z-index: 1;
  filter: drop-shadow(0 14px 22px rgba(40, 28, 18, 0.35));
}

.tray__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  border-radius: 4px;
}

.slot {
  position: absolute;
  pointer-events: none;
  border-radius: 4px;
}

.tool {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  z-index: 5;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%) rotate(var(--angle, 0deg));
  filter: drop-shadow(0 8px 10px rgba(40, 28, 18, 0.28));
  transition: none;
  will-change: left, top, transform;
}

.tool img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.tool.is-dragging {
  cursor: grabbing;
  z-index: 20;
  filter: drop-shadow(0 16px 18px rgba(40, 28, 18, 0.4));
}

.tool.is-near-slot {
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.tool.is-settling {
  transition:
    left 0.38s cubic-bezier(0.22, 0.9, 0.28, 1),
    top 0.38s cubic-bezier(0.22, 0.9, 0.28, 1),
    transform 0.38s cubic-bezier(0.22, 0.9, 0.28, 1);
  z-index: 8;
}

.tool.is-placed {
  cursor: grab;
  pointer-events: auto;
  z-index: 3;
  /* No shadow — seated metal must sit flush in stamped nests */
  filter: none;
}

.tool.is-locked {
  cursor: default;
  pointer-events: none;
}

.toast {
  position: fixed;
  bottom: 28px;
  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);
  animation: toastIn 0.25s ease;
  max-width: min(92vw, 420px);
  text-align: center;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.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;
}

.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);
  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);
  animation: pop 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.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);
}

@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.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;
  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);
  color: #fff;
  box-shadow: 0 6px 16px rgba(196, 122, 90, 0.35);
}

.btn:active { transform: scale(0.97); }

.btn-again {
  background: #8a7a6a;
  box-shadow: 0 5px 14px rgba(58, 52, 46, 0.22);
}

.btn-continue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 14px;
  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) {
  .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;
  }
  .stage {
    width: min(100vw, 100%);
    height: 100dvh;
    padding-right: 8px;
  }
  .tray { width: min(84%, 432px); top: 52%; }
  .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;
  }
}
