/* Merge Lab: puzzle scene, chapters, progress and purchase confirmation. */

.merge-energy-experiment .merge-stats {
  grid-template-columns: max-content max-content minmax(0,1fr) max-content max-content;
}

.merge-energy-experiment .merge-puzzle-stat {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-width: 0;
}

.merge-puzzle-stat-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  min-width: 29px;
  min-height: 29px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  transition: transform .15s ease,filter .15s ease;
}

.merge-puzzle-stat-button:hover,
.merge-puzzle-stat-button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.05);
  background: transparent !important;
  box-shadow: none !important;
  outline: none;
}

.merge-puzzle-stat-icon {
  display: block;
  width: 29px;
  height: 29px;
  filter: drop-shadow(0 2px 3px rgba(39,143,203,.24));
}

.merge-puzzle-stat-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.merge-puzzle-stat-icon path {
  fill: #67c9f4;
  stroke: #2f93c8;
  stroke-width: 1.1;
  stroke-linejoin: round;
}

.merge-puzzle-exchange {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  border: 1px solid rgba(255,255,255,.95);
  border-radius: 50%;
  background: #55be7d;
  color: #fff;
  box-shadow: 0 2px 5px rgba(44,119,78,.18);
  font: 900 8px/1 Arial,sans-serif;
  transform: rotate(-14deg);
  pointer-events: none;
}

.merge-energy-experiment .merge-puzzle-stat strong {
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.merge-puzzle-stat-button.is-active {
  filter: brightness(1.03);
  transform: translateY(-1px);
}

.merge-puzzle-stat-button.is-active .merge-puzzle-stat-icon path {
  fill: #82d7f8;
  stroke: #2585ba;
}

#merge-board-scene[hidden],
#merge-puzzle-scene[hidden] {
  display: none !important;
}

.merge-puzzle-scene {
  width: min(100%,792px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  transform-origin: center top;
  perspective: 1600px;
  position: relative;
  overflow: visible !important;
}

.merge-puzzle-board {
  position: relative;
  z-index: 3;
  width: min(100%,792px);
  aspect-ratio: 9/7;
  margin: 0 auto;
  overflow: hidden;
  box-sizing: border-box;
  border: 3px solid #e0aa5b;
  border-radius: 22px;
  background: #c8c3bb;
  box-shadow: 0 6px 0 #c48b43,0 14px 26px rgba(85,105,122,.16),inset 0 0 0 2px rgba(255,244,218,.68),inset 0 2px 0 rgba(255,255,255,.7);
  isolation: isolate;
  cursor: pointer;
}

.merge-puzzle-board.is-busy {
  cursor: wait;
  pointer-events: none;
}

.merge-puzzle-board::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 18px;
  box-shadow: inset 0 0 0 2px rgba(255,244,218,.68),inset 0 -2px 0 rgba(71,121,160,.16);
  pointer-events: none;
}

.merge-puzzle-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.merge-puzzle-piece-outline {
  fill: none;
  stroke: #7aaac5;
  stroke-width: 1.6;
  stroke-linejoin: round;
}

.merge-puzzle-reveal-piece {
  transform-box: fill-box;
  transform-origin: center;
  animation: merge-puzzle-piece-reveal .72s cubic-bezier(.2,.9,.2,1) both;
  pointer-events: none;
}

.merge-puzzle-reveal-art {
  filter: brightness(1.04) saturate(1.06);
}

.merge-puzzle-reveal-glow {
  fill: none;
  stroke: #fff4aa;
  stroke-width: 8;
  stroke-linejoin: round;
  stroke-linecap: round;
  opacity: .88;
  filter: drop-shadow(0 0 10px rgba(255,238,128,.78));
  animation: merge-puzzle-piece-glow .72s ease-out both;
}

.merge-puzzle-reveal-outline {
  fill: none;
  stroke: #7aaac5;
  stroke-width: 1.6;
  stroke-linejoin: round;
  opacity: .96;
}

@keyframes merge-puzzle-piece-reveal{0%{opacity:0;transform:scale(.72)}42%{opacity:1;transform:scale(1.06)}68%{opacity:1;transform:scale(.98)}100%{opacity:1;transform:scale(1)}}

@keyframes merge-puzzle-piece-glow{0%{opacity:0;stroke-width:14}30%{opacity:.95;stroke-width:10}100%{opacity:0;stroke-width:4}}

.merge-puzzle-toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  width: max-content;
  max-width: min(78%,420px);
  padding: 10px 16px;
  background: #fff !important;
  border: 0 !important;
  border-radius: 10px !important;
  box-shadow: 0 6px 18px rgba(41,65,52,.18) !important;
  color: #2f9f58 !important;
  font: 700 15px/1.35 ui-rounded,"Trebuchet MS","Comic Sans MS","Arial Rounded MT Bold","Segoe UI",system-ui,sans-serif !important;
  text-align: center;
  z-index: 180;
  pointer-events: none;
  white-space: normal;
  outline: 0 !important;
  text-shadow: none !important;
}

.merge-puzzle-toast[hidden] {
  display: none !important;
}

.merge-puzzle-toast img {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-left: 4px;
  object-fit: contain;
}

.merge-scene-entering {
  animation: merge-scene-in .56s cubic-bezier(.18,.84,.22,1) both;
}

.merge-scene-leaving {
  animation: merge-scene-out .46s cubic-bezier(.36,.04,.34,1) both;
  pointer-events: none;
}

@keyframes merge-scene-in{from{opacity:0;transform:translateY(20px) scale(.985)}to{opacity:1;transform:none}}

.merge-puzzle-scene.merge-scene-entering {
  animation-name: merge-puzzle-scene-in;
}

@keyframes merge-puzzle-scene-in{from{opacity:0;transform:translateY(16px) rotateX(3deg) scale(.985)}to{opacity:1;transform:none}}

@keyframes merge-scene-out{from{opacity:1;transform:none}to{opacity:0;transform:translateY(-12px) scale(.99)}}

.merge-puzzle-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 5200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(37,42,39,.58);
  backdrop-filter: blur(5px);
}

.merge-puzzle-confirm-overlay[hidden] {
  display: none !important;
}

.merge-puzzle-confirm-card {
  width: min(360px,calc(100vw - 28px));
  box-sizing: border-box;
  padding: 24px 22px 20px;
  border: 3px solid #c98a42;
  border-radius: 22px;
  background: linear-gradient(180deg,#fffaf0 0%,#f6ead1 100%);
  box-shadow: 0 7px 0 #b87636,0 18px 38px rgba(71,57,42,.24);
  text-align: center;
}

.merge-puzzle-confirm-card h2 {
  margin: 0 0 8px;
  color: #554f48;
  font: 900 20px/1.15 ui-rounded,"Trebuchet MS","Segoe UI",sans-serif;
}

.merge-puzzle-confirm-card p {
  margin: 0 0 18px;
  color: #7b7168;
  font: 600 13px/1.4 Arial,sans-serif;
}

.merge-puzzle-confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.merge-puzzle-confirm-actions button {
  min-width: 110px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font: 800 13px/1 Arial,sans-serif;
}

.merge-puzzle-confirm-cancel {
  background: #edf1ee;
  color: #59655e;
}

.merge-puzzle-confirm-ok {
  background: linear-gradient(180deg,#5bc989 0%,#49b877 100%);
  color: #fff;
  box-shadow: 0 4px 0 #35965d;
}

.merge-puzzle-confirm-optout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  color: #756c64;
  font: 600 12px/1.25 Arial,sans-serif;
  cursor: pointer;
}

.merge-puzzle-confirm-optout input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #52bd7d;
}

.merge-puzzle-cost-float {
  position: fixed;
  z-index: 6000;
  transform: translate(-50%,-50%);
  color: #fff;
  font: 900 19px/1 ui-rounded,"Trebuchet MS","Segoe UI",sans-serif;
  text-shadow: 0 2px 5px rgba(0,0,0,.35);
  pointer-events: none;
  animation: merge-puzzle-cost-float .9s ease-out forwards;
}

@keyframes merge-puzzle-cost-float{from{opacity:1;transform:translate(-50%,-50%) scale(.92)}to{opacity:0;transform:translate(-50%,-115%) scale(1.04)}}

.merge-quest-card[data-quest="6"] {
  background: transparent !important;
  box-shadow: none !important;
}

.merge-quest-card[data-quest="6"] .merge-puzzle-quest-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 51px;
  box-sizing: border-box;
  z-index: 210;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  padding: 0 14px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 5px rgba(75,85,75,.06);
  pointer-events: none;
}

.merge-puzzle-quest-progress strong {
  color: #2d5946;
  font: 800 13px/1 Arial,sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  text-shadow: none;
}

.merge-puzzle-quest-icon {
  display: block;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  filter: drop-shadow(0 1px 2px rgba(39,143,203,.22));
}

.merge-puzzle-quest-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.merge-puzzle-quest-icon path {
  fill: #67c9f4;
  stroke: #2f93c8;
  stroke-width: 1.1;
  stroke-linejoin: round;
}

body.merge-puzzle-mode .merge-quest-strip {
  margin-bottom: 16px;
}

.merge-puzzle-chapters {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: min(100%,792px);
  box-sizing: border-box;
  margin: 0 0 -3px;
  padding: 0 0 0 15px;
  align-self: center;
  overflow: visible;
}

.merge-puzzle-chapter-plaque {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 96px;
  width: 96px;
  height: 38px;
  box-sizing: border-box;
  margin: 0;
  padding: 0 12px;
  border-radius: 14px 14px 0 0;
  font: 900 16px/1 ui-rounded,"Trebuchet MS","Arial Rounded MT Bold","Segoe UI",system-ui,sans-serif;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}

.merge-puzzle-chapter-plaque.is-active {
  border: 3px solid #b87835;
  border-bottom-color: #c48b43;
  background: linear-gradient(180deg,#e8b76f 0%,#d99a4c 58%,#ce8d40 100%);
  box-shadow: inset 0 2px 0 rgba(255,238,198,.48),inset 0 -1px 0 rgba(121,70,25,.18),0 3px 7px rgba(95,58,28,.13);
  color: #70451f;
  text-shadow: 0 1px 0 rgba(255,231,184,.62);
}

.merge-puzzle-chapter-plaque.is-active::before,
.merge-puzzle-chapter-plaque.is-active::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  height: 1px;
  border-radius: 50%;
  background: rgba(132,77,31,.15);
  pointer-events: none;
}

.merge-puzzle-chapter-plaque.is-active::before {
  top: 11px;
}

.merge-puzzle-chapter-plaque.is-active::after {
  bottom: 9px;
}

.merge-puzzle-chapter-plaque.is-inactive {
  border: 2px solid #cfd5db;
  border-bottom-color: #dfe4e8;
  border-radius: 15px 15px 0 0;
  background: linear-gradient(180deg,#f4f6f8 0%,#e9edf1 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.86);
  color: #a4adb6;
  text-shadow: none;
  opacity: .92;
  transform: translateY(2px);
}

body:not(.merge-puzzle-mode) .merge-quest-card[data-quest="6"] {
  display: none !important;
}

body.merge-puzzle-mode .merge-quest-card:not([data-quest="6"]) {
  display: none !important;
}

body.merge-puzzle-mode .merge-quest-card[data-quest="6"] {
  display: block !important;
}

@media (max-width:640px) {
  .merge-energy-experiment .merge-stats {
    grid-template-columns: max-content max-content minmax(0,1fr) max-content max-content;
  }

  .merge-stat strong,
  .merge-energy-experiment .merge-puzzle-stat strong {
    font-size: 16px !important;
    line-height: 1;
  }

  .merge-puzzle-stat-button,
  .merge-puzzle-stat-icon {
    width: 23px;
    height: 23px;
    min-width: 23px;
    min-height: 23px;
  }

  .merge-energy-experiment .merge-puzzle-stat {
    gap: 4px;
  }

  .merge-puzzle-exchange {
    width: 10px;
    height: 10px;
    font-size: 6px;
    right: -1px;
    bottom: -1px;
  }

  .merge-quest-card[data-quest="6"] .merge-puzzle-quest-progress {
    gap: 4px;
    padding: 0 12px;
  }

  .merge-puzzle-quest-progress strong {
    font-size: 12px;
  }

  .merge-puzzle-quest-icon {
    width: 18px;
    height: 18px;
    flex-basis: 18px;
  }

  .merge-puzzle-chapters {
    padding-left: 8px;
  }

  .merge-puzzle-chapter-plaque {
    border-width: 2px;
    padding: 0 6px;
  }

  .merge-puzzle-chapter-plaque.is-active::before {
    top: 10px;
  }

  .merge-puzzle-chapter-plaque.is-active::after {
    bottom: 8px;
  }

  .merge-puzzle-board {
    border-radius: 15px;
    border-width: 2px;
    box-shadow: 0 4px 0 #c48b43,0 9px 18px rgba(85,105,122,.14),inset 0 0 0 1px rgba(255,244,218,.68);
  }

  .merge-puzzle-board::after {
    border-radius: 13px;
  }

  .merge-puzzle-toast {
    max-width: min(82%,320px);
    font-size: 13px !important;
    padding: 8px 14px;
  }
}

.merge-puzzle-chapter-plaque:focus-visible,
.merge-puzzle-board:focus-visible {
  outline: 3px solid #278f60;
  outline-offset: 4px;
}

.merge-puzzle-chapter-plaque:disabled {
  cursor: default;
}

.merge-puzzle-chapter-plaque.is-locked {
  opacity: .65;
}

.merge-puzzle-chapter-plaque.is-inactive:not(.is-locked) {
  color: #627769;
  border-color: #acbfad;
  background: #edf4e9;
  opacity: 1;
}

.merge-puzzle-chapter-plaque.is-complete:not(.is-active) {
  color: #237849;
  background: #e1f2dc;
}

.merge-puzzle-board.is-complete {
  cursor: default;
}

.merge-puzzle-color-outline {
  fill: none;
  stroke: #fff;
  stroke-width: 1.1;
  stroke-opacity: .3;
  stroke-linejoin: round;
  pointer-events: none;
}

.merge-puzzle-toast.is-error {
  color: #b74e42 !important;
}

@media (max-width:640px) {
  .merge-puzzle-chapter-plaque {
    height: 34px;
    font-size: 11px;
    flex: 1 1 0;
    width: auto;
    max-width: 96px;
  }

  .merge-puzzle-chapters {
    gap: 4px;
    margin-bottom: -2px;
    padding-right: 8px;
  }
}

@media (prefers-reduced-motion:reduce) {
  .merge-scene-entering,
  .merge-scene-leaving,
  .merge-puzzle-reveal-piece,
  .merge-puzzle-reveal-glow,
  .merge-puzzle-cost-float {
    animation-duration: .01ms !important;
  }
}
