:root {
  --wall: #d4ccc0;
  --wood: #c4a574;
  --wood-dark: #9a7a4e;
  --wood-edge: #8b6840;
  --frame-dark: #6e5230;
  --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;
  width: 100%;
  height: 100%;
  transform: none;
  left: 0;
  top: 0;
  background: var(--wall);
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  width: 100%;
  max-width: none;
  margin: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.grain {
  pointer-events: none;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: max(100vw, 2500px);
  height: max(100vh, 1400px);
  z-index: 2;
  opacity: 0.18;
  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");
}

.hint-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(244, 239, 230, 0.9);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(58, 52, 46, 0.12);
}

.hint-btn:hover { background: #fff; }
.hint-btn:active { transform: scale(0.97); }

.solve-btn {
  position: fixed;
  top: 70px;
  right: 18px;
  z-index: 50;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(196, 122, 90, 0.92);
  color: #fff;
  box-shadow: 0 4px 14px rgba(58, 52, 46, 0.12);
}

.solve-btn:hover { background: #b86a4c; }
.solve-btn:active { transform: scale(0.97); }

.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; }
.menu-btn:active { transform: scale(0.97); }

.stage {
  position: relative;
  width: min(98vw, 1000px);
  min-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

/* The artwork is itself a framed picture hanging on a wall, so the
   file carries its own wooden frame and a good deal of wall around
   it. Wrapping that in a second, CSS-drawn frame read as a picture of
   a picture, and leaving the wall in put a stray tan border around
   everything. Both are cut away here: the box ends on the wood, and
   the painted frame is the only frame.

   The still is 1536x1024 and its wood sits at x 368-1151, y 52-965,
   which is what the offsets below line up on. The winning clip was
   re-cut to that same crop (assets/cat-win-framed.*) so it simply
   fills the box - the original still had the old CSS frame's cream
   liner baked into it. */
.wall-art {
  position: absolute;
  left: 50%;
  top: calc((100% - 302px) / 2);
  transform: translate(-50%, -50%);
  width: min(268px, 32vw);
}

.cat-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 783 / 913;
  line-height: 0;
  overflow: hidden;
}

.cat-still {
  position: absolute;
  width: 196.17%;
  height: auto;
  left: -47%;
  top: -5.7%;
  border: 0;
  vertical-align: top;
}

.cat-win-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  border: 0;
}

.cat-frame.is-playing .cat-still {
  visibility: hidden;
}

.cat-win-video[hidden] {
  display: none !important;
}

.solved-ref-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(98vw, 1000px);
}

.solved-ref-wrap[hidden] {
  display: none !important;
}

.solved-label {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: #5a5048;
}

.solved-ref-img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 4px;
  box-shadow: 0 10px 28px rgba(58, 52, 46, 0.15);
}

.shelf {
  position: relative;
  width: 100%;
  filter: drop-shadow(0 12px 10px rgba(58, 52, 46, 0.2));
}

.shelf-front {
  height: 22px;
  margin: 0 1%;
  background: linear-gradient(180deg, var(--wood-dark), var(--wood-edge));
  border-radius: 0 0 6px 6px;
  clip-path: polygon(1% 0, 99% 0, 100% 100%, 0 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.1),
    0 10px 22px rgba(58, 52, 46, 0.22);
}

.shelf-shadow {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -14px;
  height: 22px;
  background: radial-gradient(ellipse at center, rgba(58, 52, 46, 0.28), transparent 68%);
  filter: blur(6px);
  z-index: -1;
}

.slots {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  height: 280px;
  padding: 0 2%;
  background: transparent;
}

.slot {
  position: relative;
  flex: 0 0 auto;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.slot.drop-target::before {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 0;
  height: 72%;
  border-radius: 4px;
  border: 2px dashed rgba(149, 88, 184, 0.45);
  background: rgba(149, 88, 184, 0.06);
  pointer-events: none;
}

.book {
  position: relative;
  width: 100%;
  border-radius: 2px 3px 1px 1px;
  cursor: grab;
  touch-action: none;
  box-shadow:
    var(--shadow-x, 0) 8px 10px -4px rgba(46, 35, 51, 0.3),
    var(--shadow-x, 0) 3px 4px rgba(46, 35, 51, 0.18);
  z-index: 3;
  overflow: hidden;
  background: transparent;
  transform: perspective(900px) rotateY(var(--iso-angle, 0deg));
  transform-origin: var(--iso-origin, center);
}

.book::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0%, transparent 18%, transparent 82%, rgba(0, 0, 0, 0.05) 100%);
}

.book .spine-img {
  width: 100%;
  height: 100%;
  display: block;
  background-repeat: no-repeat;
  border-radius: inherit;
}

.book .spine-img.spine-static {
  object-fit: fill;
  pointer-events: none;
}

.book .ornament,
.book .stitch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.book .stitch {
  z-index: 3;
}

.book .spine {
  width: 100%;
  height: 100%;
  display: block;
}

.book:active,
.book.dragging {
  cursor: grabbing;
  z-index: 30;
  box-shadow: 8px 14px 24px rgba(58, 52, 46, 0.32);
}

.book.dragging {
  transform: perspective(900px) rotateY(var(--iso-angle, 0deg)) scale(1.03);
}

.book.locked {
  cursor: default;
  pointer-events: none;
}

.book.correct-glow {
  box-shadow: 0 0 0 2px rgba(232, 212, 168, 0.6), 4px 6px 14px rgba(58, 52, 46, 0.18);
}

.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;
}

@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;
  top: auto;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
  background: none;
  backdrop-filter: 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: 22px;
  padding: 32px 28px 28px;
  text-align: center;
  max-width: 360px;
  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: 10px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #6a6058;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  font-family: var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
}

.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 10px;
  font-size: 1.6rem;
  font-weight: 700;
}

.win-text {
  margin: 0 0 22px;
  line-height: 1.45;
  color: #5c534a;
}

.win-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 700;
  font-size: 1rem;
  padding: 12px 26px;
  border-radius: 999px;
  background: var(--accent);
  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;
}

.btn-continue {
  border-radius: 14px;
}

.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) {
  .slots { height: 180px; }
  .hint-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + 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 {
    min-height: calc(100dvh - 16px);
    overflow: hidden;
  }
  #app {
    padding: 12px 8px;
    min-height: 100dvh;
  }
  .wall-art {
    top: 8%;
    width: min(320px, 68vw);
  }
  .shelf {
    max-width: calc(100vw - 16px);
    transform: scale(min(1, calc((100vw - 24px) / 680)));
    transform-origin: center bottom;
  }
  .win {
    bottom: max(12vh, calc(12px + env(safe-area-inset-bottom, 0px)));
    top: auto;
  }
  .win-card {
    max-height: min(48vh, 340px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 18px 16px;
  }
}
