:root {
  --card-w: clamp(76px, min(10.2vw, calc((100vh - 110px) / 4.2)), 150px);
  --card-h: calc(var(--card-w) * 1.4);
  --gap-x: 0px;
  --gap-y: 0px;
  --ease-out: cubic-bezier(.16,.78,.18,1);
  --ease-pop: cubic-bezier(.2,1.3,.28,1);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(50, 63, 93, .42), transparent 38%),
    linear-gradient(180deg, #111725 0%, #070910 62%, #030407 100%);
  color: #fff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
}

button {
  font: inherit;
}

.app {
  position: relative;
  width: 100vw;
  height: 100vh;
  min-height: 620px;
  isolation: isolate;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 25%, rgba(255,255,255,.05), transparent 26%),
    repeating-linear-gradient(
      90deg,
      rgba(255,255,255,.012) 0,
      rgba(255,255,255,.012) 1px,
      transparent 1px,
      transparent 9px
    );
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  perspective: 1600px;
}

.set-name {
  display: none;
}

.load-error {
  position: fixed;
  top: 54px;
  left: 50%;
  z-index: 250;
  transform: translateX(-50%);
  color: #fecaca;
  font-size: 13px;
  font-weight: 800;
}

.volume-button {
  position: absolute;
  top: 20px;
  left: 24px;
  z-index: 230;
  min-width: 78px;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(11,15,25,.78);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,.3);
  backdrop-filter: blur(8px);
}

.volume-button:hover,
.volume-button:focus-visible {
  border-color: rgba(125,211,252,.8);
  background: rgba(30,41,59,.9);
  outline: none;
}

.pack-button:disabled {
  cursor: wait;
  opacity: .65;
}

.pack-area {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 20;
  transition: opacity .3s ease;
}

.pack-button {
  position: relative;
  border: 0;
  background: none;
  color: #fff;
  padding: 0;
  cursor: pointer;
  outline: none;
}

.pack-shell {
  position: relative;
  isolation: isolate;
  width: min(34vw, 350px);
  min-width: 230px;
  filter: drop-shadow(0 28px 35px rgba(0,0,0,.48));
  transform-origin: center;
  animation: packGlow 4.8s ease-in-out infinite;
  transition: transform .22s ease, filter .22s ease;
}

.pack-shell::before,
.pack-shell::after {
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
  border-radius: 46%;
}

.pack-shell::before {
  inset: 2% -9% 0;
  background:
    radial-gradient(ellipse at center, rgba(224, 242, 254, .72) 0 38%, rgba(56, 189, 248, .46) 53%, rgba(99, 102, 241, .24) 67%, transparent 76%);
  filter: blur(24px);
  opacity: .58;
  animation: packAuraBreathe 4.8s ease-in-out infinite;
}

.pack-shell::after {
  inset: 5% -5% 3%;
  border: 1px solid rgba(224, 242, 254, .28);
  background: radial-gradient(ellipse, rgba(255, 255, 255, .18), transparent 66%);
  box-shadow:
    0 0 34px rgba(56, 189, 248, .24),
    inset 0 0 32px rgba(129, 140, 248, .12);
  filter: blur(8px);
  opacity: .54;
  animation: packAuraPulse 4.8s ease-in-out infinite;
}

@keyframes packAuraBreathe {
  0%, 100% { opacity: .42; transform: scale(.94); }
  50% { opacity: .82; transform: scale(1.1); }
}

@keyframes packAuraPulse {
  0%, 100% { opacity: .3; transform: scale(.97); }
  50% { opacity: .66; transform: scale(1.065); }
}

@keyframes packGlow {
  0%, 100% {
    filter:
      drop-shadow(0 28px 35px rgba(0,0,0,.48))
      drop-shadow(0 0 6px rgba(186,230,253,.18));
  }
  50% {
    filter:
      drop-shadow(0 28px 35px rgba(0,0,0,.48))
      drop-shadow(0 0 15px rgba(224,242,254,.65))
      drop-shadow(0 0 32px rgba(56,189,248,.38));
  }
}

.pack-button:hover .pack-shell {
  transform: translateY(-4px) scale(1.025);
  filter: drop-shadow(0 34px 42px rgba(0,0,0,.55));
}

.pack-button:focus-visible .pack-shell {
  outline: 3px solid rgba(255,255,255,.8);
  outline-offset: 10px;
  border-radius: 12px;
}

.pack-body-img,
.pack-top img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}

.pack-body-img {
  will-change: clip-path;
}

.pack-cutting .pack-body-img {
  animation: packBodyCut .01s linear .4s forwards;
}

@keyframes packBodyCut {
  to { clip-path: inset(14% 0 0 0); }
}

.pack-top {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 86% 0);
  transform-origin: 50% 13%;
  pointer-events: none;
  z-index: 4;
  will-change: opacity, transform, filter, clip-path;
}

.cut-line {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 13.7%;
  height: 3px;
  z-index: 5;
  opacity: 0;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, transparent, #fff 10%, #fff 90%, transparent);
  box-shadow:
    0 0 7px rgba(255,255,255,.95),
    0 0 17px rgba(255,255,255,.8),
    0 0 36px rgba(255,255,255,.45);
}

.pack-prompt {
  display: none;
}

.pack-cutting .cut-line {
  animation: cutSweep .42s cubic-bezier(.16,.72,.2,1) forwards;
}

@keyframes cutSweep {
  0% { opacity: 0; transform: scaleX(0); }
  18% { opacity: 1; }
  72% { opacity: 1; transform: scaleX(1); }
  100% { opacity: 0; transform: scaleX(1); }
}

.pack-top-fly {
  animation: packTopDisintegrate .62s cubic-bezier(.2,.62,.28,1) forwards;
}

@keyframes packTopDisintegrate {
  0% {
    clip-path: inset(0 0 86% 0);
    transform: translate3d(0,0,0) scale(1);
    filter: brightness(1) blur(0);
    opacity: 1;
  }
  24% {
    clip-path: inset(0 0 86% 0);
    transform: translate3d(0,-1px,0) scale(1.005, .98);
    filter: brightness(2.8) saturate(.3) blur(.4px);
    opacity: 1;
  }
  58% {
    clip-path: inset(0 0 90% 0);
    transform: translate3d(0,-7px,0) scale(1.035, .7);
    filter: brightness(3.8) saturate(0) blur(3px);
    opacity: .58;
  }
  100% {
    clip-path: inset(0 0 99.5% 0);
    transform: translate3d(0,-14px,0) scale(1.09, .08);
    filter: brightness(5) saturate(0) blur(8px);
    opacity: 0;
  }
}

.pack-exit {
  animation: packExit .72s cubic-bezier(.55,.02,.76,.44) forwards;
}

@keyframes packExit {
  to {
    transform: translate3d(-115vw, 7vh, -200px) rotateZ(-23deg) scale(.78);
    opacity: 0;
  }
}

.cards-layer {
  position: absolute;
  inset: 0;
  /* Keep card faces above the rare rainbow backdrop. Child z-index values
     cannot escape this stacking context, so the layer itself must be higher. */
  z-index: 100;
  pointer-events: none;
  transform-style: preserve-3d;
}

.cards-layer.is-interactive {
  pointer-events: auto;
}

.cards-layer.is-interactive .card {
  cursor: pointer;
}

.cards-layer.is-interactive .card:hover,
.cards-layer.is-interactive .card:focus-visible {
  z-index: 180 !important;
  filter: brightness(1.08) drop-shadow(0 0 13px rgba(125,211,252,.72));
  outline: 2px solid rgba(125,211,252,.9);
  outline-offset: 3px;
}

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--card-w);
  height: var(--card-h);
  transform: translate(-50%, -50%);
  perspective: 1200px;
  will-change: transform, left, top, filter, opacity;
  transform-style: preserve-3d;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateY(0deg);
  transition: transform .42s cubic-bezier(.2,.72,.28,1);
  will-change: transform;
}

.card-side {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: clamp(7px, .7vw, 11px);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fff;
}

.card-side img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.card-back {
  transform: rotateY(0deg);
  box-shadow: 0 8px 22px rgba(0,0,0,.52);
}

.card-front {
  transform: rotateY(180deg);
  box-shadow: 0 10px 26px rgba(0,0,0,.52);
}

.card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.card.flipping {
  z-index: 80 !important;
  filter: drop-shadow(0 18px 28px rgba(0,0,0,.62));
}

.card.dimmed {
  filter: brightness(.32) saturate(.65);
  transition: filter .45s ease;
}

.card.rare-card {
  z-index: 100;
}

.card.rare-center {
  z-index: 150;
  filter: drop-shadow(0 24px 50px rgba(0,0,0,.78));
}

.card.rare-center .card-inner {
  transition-duration: .7s;
}

.white-mask,
.glass-shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.white-mask {
  z-index: 6;
  background:
    radial-gradient(circle at 50% 44%, #fff 0%, #fff 44%, #eef4ff 70%, #fff 100%);
  opacity: 0;
  box-shadow:
    inset 0 0 30px rgba(255,255,255,.9),
    0 0 25px rgba(255,255,255,.9);
}

.rare-revealing .white-mask {
  opacity: 1;
}

.rare-revealed .white-mask {
  animation: maskOut .34s ease-out forwards;
}

@keyframes maskOut {
  0% { opacity: 1; }
  45% { opacity: 1; }
  100% { opacity: 0; }
}

.glass-shine {
  z-index: 8;
  overflow: hidden;
  border-radius: inherit;
}

.glass-shine::before {
  content: "";
  position: absolute;
  top: -35%;
  bottom: -35%;
  left: -70%;
  width: 35%;
  transform: skewX(-20deg);
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255,255,255,.12) 24%,
    rgba(255,255,255,.92) 50%,
    rgba(220,245,255,.30) 64%,
    transparent
  );
  filter: blur(3px);
}

.glass-shine.run::before {
  animation: glassSweep .55s cubic-bezier(.22,.64,.34,1) forwards;
}

@keyframes glassSweep {
  from { left: -70%; }
  to { left: 140%; }
}

.rare-backdrop {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(76vw, 850px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%) scale(.18);
  pointer-events: none;
  opacity: 0;
  z-index: 90;
}

.rainbow-aura,
.rainbow-rays,
.sparkles {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.rainbow-aura {
  background:
    conic-gradient(
      from 20deg,
      #ff3d71,
      #ffda5f,
      #6cffba,
      #65d8ff,
      #8573ff,
      #ee6eff,
      #ff3d71
    );
  filter: blur(70px) saturate(1.35);
  opacity: .75;
}

.rainbow-rays {
  inset: 9%;
  background:
    repeating-conic-gradient(
      from 0deg,
      rgba(255,255,255,.72) 0deg 1.3deg,
      transparent 1.3deg 11deg
    );
  filter: blur(1.5px);
  opacity: .26;
  animation: rotateRays 4s linear infinite;
}

@keyframes rotateRays {
  to { transform: rotate(360deg); }
}

.sparkles {
  background:
    radial-gradient(circle at 18% 34%, rgba(255,255,255,.95) 0 2px, transparent 3px),
    radial-gradient(circle at 76% 25%, rgba(255,255,255,.9) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 75%, rgba(255,255,255,.9) 0 1.7px, transparent 3px),
    radial-gradient(circle at 27% 72%, rgba(255,255,255,.9) 0 1.6px, transparent 3px),
    radial-gradient(circle at 48% 12%, rgba(255,255,255,.95) 0 1.4px, transparent 3px);
  animation: sparklePulse 1.15s ease-in-out infinite alternate;
}

@keyframes sparklePulse {
  to { transform: scale(1.05); opacity: .45; }
}

.rare-backdrop.active {
  animation: rareBackdrop .95s cubic-bezier(.15,.82,.18,1) forwards;
}

@keyframes rareBackdrop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.18) rotate(-25deg); }
  42% { opacity: .92; transform: translate(-50%, -50%) scale(1.08) rotate(10deg); }
  100% { opacity: .42; transform: translate(-50%, -50%) scale(.92) rotate(22deg); }
}

.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #fff;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
}

.screen-flash.active {
  animation: screenFlash .24s ease-out forwards;
}

@keyframes screenFlash {
  0% { opacity: 0; }
  20% { opacity: .94; }
  100% { opacity: 0; }
}

.reset-button {
  position: absolute;
  left: 50%;
  z-index: 220;
  transform: translateX(-50%) translateY(16px);
  border: 1px solid rgba(255,255,255,.48);
  background: rgba(11,15,25,.82);
  color: #fff;
  border-radius: 999px;
  padding: 13px 27px;
  letter-spacing: .08em;
  font-weight: 800;
  box-shadow:
    0 10px 28px rgba(0,0,0,.38),
    inset 0 0 18px rgba(255,255,255,.04);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity .25s ease,
    transform .25s ease,
    background .2s ease;
}

.reset-button {
  top: 20px;
  right: 24px;
  bottom: auto;
  left: auto;
  transform: translateY(-10px);
}

.reset-button.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.reset-button:hover {
  background: rgba(36,44,66,.92);
}

@media (max-width: 760px) {
  :root {
    --card-w: clamp(60px, min(17vw, calc((100vh - 100px) / 4.2)), 105px);
    --gap-x: 0px;
    --gap-y: 0px;
  }

  .app {
    min-height: 520px;
  }

  .pack-shell {
    width: min(64vw, 320px);
  }

}


/* クリック入力の優先順位を明示 */
.pack-area,
.pack-button {
  pointer-events: auto;
}

.reset-button {
  pointer-events: none;
}

.reset-button.show {
  pointer-events: auto;
}
