:root {
  color-scheme: dark;

  font-family:
    "Pretendard",
    "Segoe UI",
    sans-serif;

  --gold-light: #fff1bd;
  --gold: #d6a949;
  --gold-dark: #765019;

  --card-width: 390px;
  --card-ratio: 4 / 5;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;

  margin: 0;
  padding: 0;

  overflow: hidden;
  background: #08090d;
}

button {
  font: inherit;
}

.app {
  position: relative;

  display: grid;
  place-items: center;

  width: 100%;
  height: 100%;

  overflow: hidden;

  color: white;
  background: #08090d;
}

.background {
  position: absolute;
  inset: 0;

  background:
    radial-gradient(
      circle at 50% 45%,
      rgba(90, 75, 46, 0.35),
      transparent 35%
    ),
    radial-gradient(
      circle at center,
      #20232a,
      #08090d 72%
    );
}

/* =========================
   카드 영역
========================= */

.showcase {
  position: relative;
  z-index: 2;

  display: flex;
  flex-direction: column;
  align-items: center;

  perspective: 1600px;
  perspective-origin: 50% 45%;
}

.card-stage {
  position: relative;

  width: min(
    var(--card-width),
    calc((100vh - 110px) * 0.8),
    calc(100vw - 40px)
  );

  aspect-ratio: var(--card-ratio);

  outline: none;
  cursor: pointer;

  /*
    중요:
    perspective는 카드 부모에 있어야 합니다.
  */
  perspective: 1600px;
  perspective-origin: center;

  -webkit-tap-highlight-color: transparent;
}

.card-stage:focus-visible {
  border-radius: 24px;

  outline: 2px solid var(--gold-light);
  outline-offset: 8px;
}

/*
  그림자는 회전하는 photo-card가 아니라
  별도의 형제 요소에 적용합니다.

  photo-card에 filter를 적용하면 3D가 평면화될 수 있습니다.
*/
.card-shadow {
  position: absolute;

  right: 7%;
  bottom: -7%;
  left: 7%;

  height: 12%;

  opacity: 0.55;

  background: rgba(0, 0, 0, 0.9);
  border-radius: 50%;

  filter: blur(19px);

  transform:
    rotateX(78deg)
    translateZ(-40px);

  transition:
    opacity 450ms ease,
    transform 900ms ease;
}

.card-stage.is-flipping .card-shadow {
  opacity: 0.25;

  transform:
    rotateX(78deg)
    translateZ(-40px)
    scaleX(0.6);
}

/* =========================
   실제 회전하는 카드
========================= */

.photo-card {
  position: relative;

  width: 100%;
  height: 100%;

  transform:
    rotateY(0deg)
    rotateX(0deg);

  transform-style: preserve-3d;
  transform-origin: center center;

  transition:
    transform 1000ms
    cubic-bezier(0.2, 0.78, 0.18, 1);

  will-change: transform;
}

/*
  앞면 상태에서는 카드 전체가 실제로 180도 회전합니다.
*/
.card-stage.is-front .photo-card {
  transform:
    rotateY(180deg)
    rotateX(0deg);
}

/*
  회전 중 살짝 위로 뜨는 느낌입니다.
  filter는 절대 photo-card에 넣지 않습니다.
*/
.card-stage.is-flipping .photo-card {
  animation:
    card-lift 1000ms ease;
}

@keyframes card-lift {
  0%,
  100% {
    translate: 0 0;
  }

  50% {
    translate: 0 -14px;
  }
}

/* =========================
   앞면과 뒷면 공통
========================= */

.card-face {
  position: absolute;
  inset: 0;

  overflow: hidden;

  border-radius: 23px;

  /*
    반대 방향을 보고 있는 면을 숨깁니다.
  */
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;

  transform-style: preserve-3d;

  box-shadow:
    0 28px 65px rgba(0, 0, 0, 0.55);
}

/*
  Safari 및 일부 Chromium 환경에서
  앞뒷면이 겹쳐 깜빡이는 현상을 방지합니다.
*/
.card-back {
  transform:
    rotateY(0deg)
    translateZ(1px);
}

.card-front {
  transform:
    rotateY(180deg)
    translateZ(1px);
}

/* =========================
   카드 뒷면
========================= */

.card-back {
  background:
    linear-gradient(
      145deg,
      #343b47,
      #11151c 52%,
      #392a16
    );

  border:
    1px solid rgba(255, 237, 193, 0.42);
}

.back-pattern {
  position: absolute;
  inset: 0;

  opacity: 0.1;

  background:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.45) 0,
      rgba(255, 255, 255, 0.45) 1px,
      transparent 1px,
      transparent 13px
    );
}

.back-frame {
  position: absolute;
  inset: 14px;

  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;

  padding-bottom: 22px;

  border:
    1px solid rgba(255, 231, 171, 0.32);
  border-radius: 17px;

  transform: translateZ(18px);
}

.back-emblem {
  position: absolute;

  top: 50%;
  left: 50%;

  display: grid;
  place-items: center;

  width: 126px;
  height: 126px;

  color: var(--gold-light);

  background:
    radial-gradient(
      circle at 35% 25%,
      #765b34,
      #241b11 72%
    );

  border:
    2px solid rgba(255, 238, 194, 0.48);
  border-radius: 50%;

  transform: translate(-50%, -50%);

  box-shadow:
    0 0 25px rgba(214, 169, 73, 0.22);
}

.back-emblem span {
  font-size: 51px;
}

.back-frame strong {
  color: rgba(255, 243, 210, 0.68);

  font-family: "Courier New", monospace;
  font-size: 10px;
  letter-spacing: 0.15em;
}

.back-frame small {
  margin-top: 6px;

  color: rgba(255, 255, 255, 0.28);

  font-family: "Courier New", monospace;
  font-size: 8px;
  letter-spacing: 0.13em;
}

/* =========================
   카드 앞면
========================= */

.card-front {
  background:
    linear-gradient(
      155deg,
      #fff9ef,
      #d9d0c2
    );

  border:
    1px solid rgba(255, 248, 226, 0.72);
}

.front-frame {
  position: absolute;
  inset: 11px;

  display: flex;
  flex-direction: column;

  overflow: hidden;

  background: #ede5d9;

  border:
    1px solid rgba(92, 70, 38, 0.21);
  border-radius: 16px;

  transform: translateZ(18px);
}

.card-header {
  display: flex;
  flex: 0 0 34px;
  justify-content: space-between;
  align-items: center;

  padding: 0 11px;

  color: #75644c;
  background: rgba(255, 255, 255, 0.38);

  border-bottom:
    1px solid rgba(91, 72, 43, 0.13);

  font-family: "Courier New", monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.photo-window {
  position: relative;

  flex: 1;
  min-height: 0;

  overflow: hidden;
  background: #fff;
}

.photo-window img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;
  object-position: center 45%;

  pointer-events: none;
  user-select: none;
}

.hologram {
  position: absolute;
  inset: -25%;

  opacity: 0;

  background:
    linear-gradient(
      112deg,
      transparent 18%,
      rgba(113, 224, 255, 0.13) 30%,
      rgba(255, 206, 120, 0.14) 42%,
      rgba(219, 167, 255, 0.13) 54%,
      rgba(255, 255, 255, 0.2) 66%,
      transparent 78%
    );

  mix-blend-mode: screen;

  transform: translateX(-55%);

  pointer-events: none;
}

.card-stage.is-front:not(.is-flipping) .hologram {
  opacity: 1;

  animation:
    hologram-sweep 2.8s linear infinite;
}

@keyframes hologram-sweep {
  from {
    transform: translateX(-55%);
  }

  to {
    transform: translateX(55%);
  }
}

.card-footer {
  display: flex;
  flex: 0 0 68px;
  justify-content: space-between;
  align-items: flex-end;

  padding: 10px 12px;

  background:
    linear-gradient(
      180deg,
      #eee7dc,
      #d8cdbd
    );

  border-top:
    1px solid rgba(96, 77, 47, 0.14);
}

.card-footer strong,
.card-footer span {
  display: block;
}

.card-footer > div:first-child strong {
  color: #2f2518;

  font-size: 19px;
  letter-spacing: -0.03em;
}

.card-footer > div:first-child span {
  margin-top: 3px;

  color: #796851;

  font-size: 8px;
  letter-spacing: 0.12em;
}

.rarity {
  text-align: right;
}

.rarity span {
  color: #89745a;

  font-size: 7px;
  letter-spacing: 0.13em;
}

.rarity strong {
  margin-top: 3px;

  color: #9b7026;
  font-size: 13px;
}

/* =========================
   버튼
========================= */

.flip-button {
  min-width: 150px;
  min-height: 45px;

  margin-top: 19px;
  padding: 0 21px;

  color: #18130b;

  background:
    linear-gradient(
      180deg,
      #f8e3a8,
      #c99435
    );

  border: 1px solid #ffefbf;
  border-radius: 6px;

  font-weight: 900;

  box-shadow:
    0 10px 25px rgba(160, 111, 37, 0.2),
    inset 0 1px rgba(255, 255, 255, 0.72);

  cursor: pointer;

  transition:
    transform 130ms ease,
    filter 130ms ease;
}

.flip-button:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-2px);
}

.flip-button:active:not(:disabled) {
  transform: translateY(1px);
}

.flip-button:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* =========================
   앞면 공개 파티클
========================= */

.particle-layer {
  position: absolute;
  z-index: 20;
  inset: 0;

  overflow: hidden;

  pointer-events: none;
}

.particle {
  position: absolute;

  color: var(--particle-color);
  font-size: var(--particle-size);

  text-shadow:
    0 0 8px currentColor;

  animation:
    particle-burst
    var(--particle-duration)
    ease-out
    forwards;
}

@keyframes particle-burst {
  0% {
    opacity: 0;

    transform:
      translate(0, 0)
      rotate(0deg)
      scale(0.2);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;

    transform:
      translate(
        var(--particle-x),
        var(--particle-y)
      )
      rotate(var(--particle-rotation))
      scale(1.1);
  }
}