:root {
  --wall: #e8dcc8;
  --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: var(--wall);
  overflow: hidden;
  color: var(--ink);
}

.wall-fill {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: #e6d7bf;
  background-image: url("../assets/level2-wallpaper.webp");
  background-repeat: repeat;
  background-size: 220px 220px;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;
  opacity: 0.16;
  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;
  width: min(98vw, 1100px);
  min-height: calc(100vh - 80px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery {
  position: relative;
  width: 100%;
  max-width: 980px;
  height: min(70vh, 520px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 30px;
}

.hanger {
  position: relative;
  flex: 0 0 auto;
  width: min(30vw, 250px);
  height: min(42vw, 350px);
  display: block;
  margin-top: var(--hang-y, 0px);
}

.hanger[data-id="0"] {
  margin-top: calc(var(--hang-y, 0px) - 5px);
  left: -30px;
}

.hanger[data-id="2"] {
  margin-top: calc(var(--hang-y, 0px) - 15px);
  left: 30px;
}

.hanger--center {
  width: min(18vw, 160px);
  height: min(18vw, 160px);
  z-index: 2;
}

.painting {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  transform-origin: 50% 10%;
  transform: rotate(var(--angle, 0deg));
  filter: drop-shadow(0 10px 12px rgba(46, 35, 51, 0.28));
  transition: filter 0.15s ease;
}

.painting .frame {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 12px;
  border-radius: 3px;
  pointer-events: none;
}

.painting--wood .frame {
  background:
    linear-gradient(145deg, #4a5560 0%, #2c3540 45%, #1f2730 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 0 0 3px rgba(0, 0, 0, 0.25);
}

.painting--gold .frame {
  background:
    linear-gradient(145deg, #e0b45a 0%, #c9963a 40%, #a67828 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 245, 210, 0.35),
    inset 0 0 0 3px rgba(90, 60, 10, 0.28);
}

.painting .mat {
  display: block;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 8px;
  background: #f3ebe0;
  border-radius: 1px;
  box-shadow: inset 0 0 0 1px rgba(58, 52, 46, 0.12);
}

.painting .art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 1px;
  pointer-events: none;
}

.painting:active,
.painting.is-dragging {
  cursor: grabbing;
  z-index: 10;
  filter: drop-shadow(0 14px 18px rgba(46, 35, 51, 0.36));
}

.painting.is-locked {
  cursor: default;
  pointer-events: none;
}

.painting.is-solved {
  filter: drop-shadow(0 0 0 2px rgba(232, 212, 168, 0.55)) drop-shadow(0 8px 12px rgba(46, 35, 51, 0.22));
}

.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: 100%;
    min-height: calc(100dvh - 16px);
    overflow: hidden;
    padding: 0 8px;
  }
  .gallery {
    gap: 10px;
    height: min(56vh, 380px);
    max-width: 100%;
    padding: 0 4px;
  }
  .hanger {
    width: min(28vw, 120px);
    height: min(40vw, 170px);
  }
  .hanger[data-id="0"],
  .hanger[data-id="2"] {
    left: 0;
  }
  .hanger--center {
    width: min(18vw, 88px);
    height: min(18vw, 88px);
  }
  .painting .frame { padding: 6px; }
  .painting .mat { padding: 4px; }
  .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;
  }
}
