/* BookNoy – theme add-ons, wooden box, tiles, mobile-first */

/* Wooden chest button – centered, highlighted, src swapped on hover via JS */
.bn-wooden-chest-btn {
  display: block;
  padding: 0.75rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.2s ease;
}
.bn-wooden-chest-btn:hover {
  transform: scale(1.03);
}
.bn-wooden-chest-btn:active {
  transform: scale(0.98);
  box-shadow: 0 2px 12px rgba(11, 91, 43, 0.15), 0 0 16px rgba(141, 235, 59, 0.25);
}
.bn-wooden-chest-btn:focus-visible {
  outline: none;
  border-color: #2FBF4A;
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.5);
}

.bn-chest-single {
  display: block;
  width: 100%;
  height: auto;
  max-height: 180px;
  object-fit: contain;
  object-position: center;
}

/* BookNoy hero sprite (progress 1–12) */
#booknoy-hero-sprite,
#booknoy-card-sprite {
  transition: opacity 0.2s ease;
}

@keyframes bounce-slow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.animate-bounce-slow {
  animation: bounce-slow 2s ease-in-out infinite;
}

/* Wooden box modal – backdrop */
#wooden-box-modal {
  backdrop-filter: blur(6px);
}

/* Wooden box – lid (closed state) */
.box-lid {
  height: 12px;
  background: linear-gradient(180deg, #A56A3A 0%, #6A3E22 100%);
  border-bottom: 2px solid #6A3E22;
  flex-shrink: 0;
  transition: transform 0.35s ease, opacity 0.3s ease;
}

#wooden-box-modal:not(.open) .box-lid {
  height: 12px;
}

/* Box open: lid “opens” (visual flip/scale) */
#wooden-box-modal.open .box-lid {
  transform: scaleY(0);
  opacity: 0;
  height: 0;
  overflow: hidden;
  border: none;
}

/* Modal card open animation */
#wooden-box-modal.open .bn-modal {
  animation: bn-box-open 0.35s ease;
}

@keyframes bn-box-open {
  0% { transform: scale(0.96); opacity: 0.95; }
  100% { transform: scale(1); opacity: 1; }
}

/* Tile available – hover lift, active press */
.tile-available:hover {
  transform: translateY(-2px);
}
.tile-available:active {
  transform: scale(0.97);
}

/* Success flash after completing a tile */
@keyframes success-flash {
  0% { background-color: rgba(141, 235, 59, 0.35); }
  100% { background-color: var(--bn-cream, #FFF7E6); }
}
.tile-success {
  animation: success-flash 0.6s ease;
}

/* Safe area for sticky button on mobile */
@media (max-width: 640px) {
  main { padding-bottom: 6rem; }
}

/* Chest in modal: open animation (scale + slight rotate) */
.bn-chest-in-modal {
  max-width: 10rem;
  height: auto;
  object-fit: contain;
}
#wooden-box-modal.open .bn-chest-in-modal.bn-chest-opened {
  animation: bn-chest-open 0.5s ease forwards;
}
@keyframes bn-chest-open {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  40% { transform: scale(1.05) rotate(-2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Tile: cream surface, wood border, soft shadow (base) */
.bn-tile-box {
  background-color: var(--bn-cream);
  border: 2px solid var(--bn-wood-mid);
  border-radius: 0.75rem;
  padding: 1rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(106, 62, 34, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  min-height: 5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}
.bn-tile-box:hover:not(:disabled):not(.bn-tile-done):not(.bn-tile-loading) {
  border-color: var(--bn-lime);
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.35), 0 4px 12px rgba(106, 62, 34, 0.15);
  transform: translateY(-2px);
}
.bn-tile-box:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.5);
}
.bn-tile-box:disabled {
  cursor: not-allowed;
  opacity: 0.85;
}

/* Completed tile: green overlay + ✓ Saved */
.bn-tile-done {
  background-color: rgba(47, 191, 74, 0.12);
  border-color: rgba(47, 191, 74, 0.5);
  pointer-events: none;
  cursor: default;
}
.bn-tile-done .bn-tile-saved-stamp {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--bn-forest);
  margin-top: 0.25rem;
}
.bn-tile-saved-stamp {
  display: none;
}

/* Loading state: spinner inside tile */
/* Loading state: tile disabled while processing */
.bn-tile-loading {
  pointer-events: none;
  cursor: wait;
  opacity: 0.85;
}

/* Error: shake */
.bn-tile-shake {
  animation: bn-shake 0.5s ease;
}
@keyframes bn-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

/* Success: stamp pop-in */
.bn-stamp-pop {
  animation: bn-stamp-pop 0.4s ease;
}
@keyframes bn-stamp-pop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Explosive burst + pop when tile marked complete */
.bn-confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bn-confetti-burst-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  left: 50%;
  top: 50%;
  margin-left: -5px;
  margin-top: -5px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
  animation: bn-burst-out 0.9s ease-out forwards;
  animation-delay: var(--delay, 0s);
  opacity: 0;
}

@keyframes bn-burst-out {
  0% {
    transform: translate(0, 0) scale(0);
    opacity: 1;
  }
  15% {
    transform: translate(0, 0) scale(1.3);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0.4);
    opacity: 0;
  }
}

.bn-confetti-pop {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 211, 74, 0.9) 0%, rgba(141, 235, 59, 0.5) 40%, transparent 70%);
  box-shadow: 0 0 60px 20px rgba(246, 211, 74, 0.5), 0 0 100px 40px rgba(141, 235, 59, 0.25);
  animation: bn-pop-flash 0.5s ease-out forwards;
  pointer-events: none;
}

@keyframes bn-pop-flash {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  30% {
    transform: scale(3);
    opacity: 0.9;
  }
  100% {
    transform: scale(5);
    opacity: 0;
  }
}

/* Recommended tile: pulse ring */
.bn-tile-recommended {
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.5), 0 2px 8px rgba(106, 62, 34, 0.12);
  animation: bn-tile-pulse 2s ease-in-out infinite;
}
@keyframes bn-tile-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.5), 0 2px 8px rgba(106, 62, 34, 0.12); }
  50% { box-shadow: 0 0 0 6px rgba(141, 235, 59, 0.25), 0 4px 12px rgba(106, 62, 34, 0.15); }
}

/* Skeleton loading for tiles */
.bn-skeleton {
  background: linear-gradient(90deg, var(--bn-border) 25%, var(--bn-card) 50%, var(--bn-border) 75%);
  background-size: 200% 100%;
  animation: bn-skeleton-shine 1s ease-in-out infinite;
  border-radius: 0.75rem;
  min-height: 5rem;
}
@keyframes bn-skeleton-shine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Filter chips (sticky bottom) */
.bn-filter-chip {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 9999px;
  border: 2px solid var(--bn-border);
  background-color: var(--bn-cream);
  color: var(--bn-ink);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
}
.bn-filter-chip:hover {
  border-color: var(--bn-forest);
  background-color: rgba(141, 235, 59, 0.1);
}
.bn-filter-chip.active {
  border-color: var(--bn-forest);
  background-color: rgba(47, 191, 74, 0.15);
  color: var(--bn-forest);
}
.bn-filter-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(141, 235, 59, 0.5);
}

/* Modal wood styling */
.bn-modal-wood {
  border: 3px solid var(--bn-wood-mid);
  box-shadow: 0 25px 50px -12px rgba(5, 53, 26, 0.4);
}

/* Verified badge in Wooden Box header */
.bn-verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: rgba(141, 235, 59, 0.18);
  border: 1px solid rgba(141, 235, 59, 0.45);
  color: #E9FFE0;
}
.bn-verified-badge::before {
  content: '';
  width: 12px;
  height: 12px;
  display: inline-block;
  background: radial-gradient(circle at 30% 30%, rgba(246, 211, 74, 0.9), rgba(47, 191, 74, 0.9));
  clip-path: polygon(50% 0%, 88% 12%, 100% 44%, 82% 88%, 50% 100%, 18% 88%, 0% 44%, 12% 12%);
  box-shadow: 0 0 10px rgba(141, 235, 59, 0.25);
}

/* Switch (toggle) */
.bn-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  user-select: none;
}
.bn-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.bn-switch-track {
  width: 48px;
  height: 28px;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.12);
  border: 2px solid rgba(11, 91, 43, 0.35);
  transition: background 0.2s, border-color 0.2s;
  position: relative;
}
.bn-switch-track::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 3px;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  border-radius: 9999px;
  background: var(--bn-card);
  border: 2px solid rgba(11, 91, 43, 0.35);
  transition: transform 0.2s, background 0.2s;
  box-shadow: 0 2px 8px rgba(11, 91, 43, 0.15);
}
.bn-switch input:checked + .bn-switch-track {
  background: rgba(47, 191, 74, 0.22);
  border-color: rgba(141, 235, 59, 0.65);
}
.bn-switch input:checked + .bn-switch-track::after {
  transform: translate(20px, -50%);
  background: rgba(246, 211, 74, 0.95);
  border-color: rgba(11, 91, 43, 0.6);
}
.bn-switch input:focus-visible + .bn-switch-track {
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.45);
}
.bn-switch input:disabled + .bn-switch-track {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Stepper */
.bn-stepper {
  display: grid;
  gap: 0.4rem;
}
.bn-step {
  position: relative;
  padding-left: 1.4rem;
  color: rgba(15, 23, 42, 0.85);
}
.bn-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25rem;
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.18);
  border: 2px solid rgba(11, 91, 43, 0.25);
}
.bn-step.active::before {
  background: rgba(141, 235, 59, 0.95);
  border-color: rgba(11, 91, 43, 0.65);
  box-shadow: 0 0 0 3px rgba(141, 235, 59, 0.25);
}
.bn-step.done {
  opacity: 0.7;
}
.bn-step.done::before {
  background: rgba(47, 191, 74, 0.9);
  border-color: rgba(11, 91, 43, 0.65);
}

/* Tile CTA + verified pill */
.bn-tile-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 800;
  border: 1px solid rgba(11, 91, 43, 0.35);
  background: rgba(246, 211, 74, 0.25);
  color: var(--bn-forest);
}
.bn-tile-verified-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.4rem;
  border-radius: 9999px;
  font-size: 0.65rem;
  font-weight: 800;
  background: rgba(141, 235, 59, 0.22);
  border: 1px solid rgba(141, 235, 59, 0.55);
  color: var(--bn-forest);
}
.bn-tile-verified-pill::before {
  content: '';
  width: 12px;
  height: 10px;
  margin-right: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #14F195 0%, #9945FF 100%);
  box-shadow: 0 0 10px rgba(153, 69, 255, 0.18);
}

/* Verified completion flip */
@keyframes bn-tile-flip {
  0% { transform: perspective(900px) rotateY(0deg); }
  45% { transform: perspective(900px) rotateY(18deg) scale(1.02); }
  100% { transform: perspective(900px) rotateY(0deg); }
}
.bn-tile-flip {
  animation: bn-tile-flip 0.35s ease;
}
