/**
 * cr-coin.css — MONKOS Cr(크립) 코인 모션 시스템
 * 설계: 철창이 (웹 Claude) / 구현: 막내3
 * 4단계 모션 강도: ① Idle → ② Event → ③ Feed → ④ ThankYou
 */

/* ===== 2. 공통 디자인 토큰 ===== */
:root {
  /* Gold Palette */
  --cr-gold-primary: #f7d06b;
  --cr-gold-light: #fceabb;
  --cr-gold-dark: #d4a017;
  --cr-gold-deep: #a37920;
  --cr-gold-border: #c4942a;
  --cr-gold-text: #8b6914;

  /* Conic Gradient (금화 메탈릭) */
  --cr-coin-gradient: conic-gradient(
    from 0deg,
    #f7d06b 0deg,
    #fceabb 45deg,
    #e8b730 90deg,
    #f7d06b 135deg,
    #fceabb 180deg,
    #d4a017 225deg,
    #f7d06b 270deg,
    #fceabb 315deg,
    #e8b730 360deg
  );

  /* Coin Back (M면) */
  --cr-coin-back-gradient: conic-gradient(
    from 180deg,
    #e8b730 0deg,
    #fceabb 45deg,
    #f7d06b 90deg,
    #d4a017 135deg,
    #fceabb 180deg,
    #f7d06b 225deg,
    #e8b730 270deg,
    #fceabb 315deg,
    #d4a017 360deg
  );

  /* Glow & Shadow */
  --cr-glow: rgba(247, 208, 107, 0.3);
  --cr-glow-strong: rgba(247, 208, 107, 0.5);
  --cr-shadow: 0 0 0 3px #c4942a, 0 0 0 6px #a37920;
  --cr-shadow-sm: 0 0 0 1.5px #c4942a;

  /* Sparkle */
  --cr-sparkle-color: #fceabb;
  --cr-sparkle-glow: 0 0 6px 2px rgba(252, 234, 187, 0.6);

  /* Typography */
  --cr-font: 'Space Mono', monospace;

  /* Timing */
  --cr-idle-duration: 6s;
  --cr-event-duration: 4.5s;
  --cr-feed-duration: 12s;
  --cr-thankyou-duration: 5s;
}

/* ===== 코인 공통 구조 (Base Face) ===== */
.cr-coin-face {
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.4) 0%, transparent 50%),
    var(--cr-coin-gradient);
  box-shadow:
    var(--cr-shadow),
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -3px 6px rgba(0,0,0,0.2),
    0 8px 30px var(--cr-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.cr-coin-face::before {
  content: '';
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid rgba(196, 148, 42, 0.5);
}

.cr-coin-face::after {
  content: '';
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px dashed rgba(196, 148, 42, 0.3);
}

.cr-symbol {
  font-family: var(--cr-font);
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5), 0 -1px 0 rgba(0,0,0,0.15);
  line-height: 1;
}


/* ============================================================
   3-① 헤더 Idle Spin Shimmer (28×28px, animation: infinite)
   ============================================================ */

.header-balance {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(247, 208, 107, 0.08);
  border: 1px solid rgba(247, 208, 107, 0.15);
  border-radius: 24px;
  padding: 6px 16px 6px 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.header-balance:hover {
  background: rgba(247, 208, 107, 0.14);
  border-color: rgba(247, 208, 107, 0.3);
}

.balance-amount {
  font-family: var(--cr-font);
  font-size: 14px;
  font-weight: 700;
  color: var(--cr-gold-primary);
}

.balance-unit {
  font-size: 11px;
  color: var(--cr-gold-deep);
  font-weight: 600;
}

.header-coin-wrap {
  width: 28px;
  height: 28px;
  perspective: 400px;
  position: relative;
}

.header-coin {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: relative;
  animation: headerIdleSpin 6s ease-in-out infinite;
  transform-style: preserve-3d;
}

.header-coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.4) 0%, transparent 50%),
    var(--cr-coin-gradient);
  box-shadow: var(--cr-shadow-sm),
    inset 0 1px 2px rgba(255,255,255,0.5),
    inset 0 -1px 3px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 28px에서는 내부 링 생략 (가독성) */
.header-coin-face::before,
.header-coin-face::after { display: none; }

.header-coin-face .cr-sym {
  font-family: var(--cr-font);
  font-size: 11px;
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 0.5px 0 rgba(255,255,255,0.5);
}

/* 빛줄기 (shimmer) */
.header-shimmer {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(
    105deg,
    transparent 25%,
    rgba(255,255,255,0.6) 45%,
    rgba(255,255,255,0.8) 50%,
    rgba(255,255,255,0.6) 55%,
    transparent 75%
  );
  mix-blend-mode: overlay;
  pointer-events: none;
  animation: headerShimmer 6s ease-in-out infinite;
  z-index: 2;
}

/* 간헐적 스핀: 앞쪽 16%만 움직이고 나머지 정지 */
@keyframes headerIdleSpin {
  0%, 100% { transform: rotateY(0deg) rotateZ(0deg); }
  8%       { transform: rotateY(20deg) rotateZ(1.5deg); }
  16%      { transform: rotateY(0deg) rotateZ(0deg); }
}

@keyframes headerShimmer {
  0%, 4%  { opacity: 0; transform: translateX(-20px); }
  8%      { opacity: 1; transform: translateX(0); }
  14%     { opacity: 0; transform: translateX(20px); }
  100%    { opacity: 0; transform: translateX(20px); }
}

/* 미니 스파클 */
.header-sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--cr-sparkle-color);
  border-radius: 50%;
  box-shadow: var(--cr-sparkle-glow);
  pointer-events: none;
  z-index: 3;
}

.header-sparkle:nth-child(1) {
  top: -2px; right: -1px;
  animation: hSparkle 6s 0.5s ease-in-out infinite;
}
.header-sparkle:nth-child(2) {
  bottom: 2px; left: -3px;
  animation: hSparkle 6s 1s ease-in-out infinite;
}

@keyframes hSparkle {
  0%, 6%, 18%, 100% { opacity: 0; transform: scale(0); }
  10% { opacity: 1; transform: scale(1.5); }
  14% { opacity: 0; transform: scale(0.5); }
}


/* ============================================================
   3-② 이벤트 카드 + 3D Flip (52×52px, JS 트리거 1회)
   ============================================================ */

.event-card {
  background: linear-gradient(135deg, rgba(25,22,15,0.95), rgba(35,30,18,0.95));
  border: 1px solid rgba(247,208,107,0.15);
  border-radius: 20px;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  backdrop-filter: blur(20px);
  box-shadow:
    0 10px 40px rgba(0,0,0,0.5),
    0 0 0 1px rgba(247,208,107,0.05),
    inset 0 1px 0 rgba(255,255,255,0.03);
  opacity: 0;
  transform: translateY(40px) scale(0.95);
  animation: cardEnter 4.5s ease-out forwards;
}

@keyframes cardEnter {
  0%   { opacity: 0; transform: translateY(40px) scale(0.95); }
  8%   { opacity: 1; transform: translateY(0) scale(1); }
  80%  { opacity: 1; transform: translateY(0) scale(1); }
  92%  { opacity: 0; transform: translateY(-12px) scale(0.98); }
  100% { opacity: 0; transform: translateY(-12px) scale(0.98); }
}

.event-coin-wrap {
  width: 52px;
  height: 52px;
  perspective: 600px;
  flex-shrink: 0;
  position: relative;
}

.event-coin {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  animation: eventFlip 4.5s ease-in-out forwards;
}

.event-coin-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.4) 0%, transparent 50%),
    var(--cr-coin-gradient);
  box-shadow:
    0 0 0 2px #c4942a,
    0 0 0 4px #a37920,
    inset 0 2px 3px rgba(255,255,255,0.5),
    inset 0 -2px 4px rgba(0,0,0,0.2),
    0 4px 20px var(--cr-glow);
}

.event-coin-face::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.5px solid rgba(196,148,42,0.4);
}

.event-coin-face .cr-sym {
  font-family: var(--cr-font);
  font-size: 18px;
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

.event-coin-back {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 70% 80%, rgba(255,255,255,0.3) 0%, transparent 50%),
    var(--cr-coin-back-gradient);
  box-shadow:
    0 0 0 2px #c4942a,
    0 0 0 4px #a37920,
    inset 0 2px 3px rgba(255,255,255,0.4),
    inset 0 -2px 4px rgba(0,0,0,0.2);
}

.event-coin-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1.5px solid rgba(196,148,42,0.4);
}

.event-coin-back .m-mark {
  font-family: var(--cr-font);
  font-size: 16px;
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

@keyframes eventFlip {
  0%, 10%  { transform: rotateY(0deg) scale(1); }
  18%      { transform: rotateY(0deg) scale(1.08); }
  35%      { transform: rotateY(540deg) scale(1); }
  42%      { transform: rotateY(720deg) scale(1); }
  100%     { transform: rotateY(720deg) scale(1); }
}

/* 이벤트 카드 텍스트 */
.event-text {
  flex: 1;
  min-width: 0;
}

.event-title {
  font-size: 14px;
  font-weight: 700;
  color: #f0e6d3;
}

.event-amount {
  font-family: var(--cr-font);
  color: var(--cr-gold-primary);
  font-weight: 700;
}

.event-sub {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

.event-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--cr-gold-primary);
  background: rgba(247,208,107,0.1);
  padding: 3px 8px;
  border-radius: 6px;
  flex-shrink: 0;
  align-self: flex-start;
}

/* Flip Particles */
.flip-particle {
  position: absolute;
  width: 5px;
  height: 5px;
  background: var(--cr-sparkle-color);
  border-radius: 50%;
  box-shadow: var(--cr-sparkle-glow);
  pointer-events: none;
  opacity: 0;
}

.flip-particle:nth-child(1) { --tx: -20px; --ty: -25px; animation: particleBurst 4.5s 0.8s ease-out forwards; }
.flip-particle:nth-child(2) { --tx: 22px;  --ty: -18px; animation: particleBurst 4.5s 0.9s ease-out forwards; }
.flip-particle:nth-child(3) { --tx: -15px; --ty: 20px;  animation: particleBurst 4.5s 0.85s ease-out forwards; }
.flip-particle:nth-child(4) { --tx: 18px;  --ty: 22px;  animation: particleBurst 4.5s 0.95s ease-out forwards; }
.flip-particle:nth-child(5) { --tx: 0px;   --ty: -28px; animation: particleBurst 4.5s 1s ease-out forwards; }

@keyframes particleBurst {
  0%, 15% { opacity: 0; transform: translate(0, 0) scale(0); }
  22%     { opacity: 1; transform: translate(calc(var(--tx)*0.5), calc(var(--ty)*0.5)) scale(1.2); }
  35%     { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0); }
  100%    { opacity: 0; }
}

/* Glow Ring */
.event-glow-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  animation: eventGlow 4.5s ease-in-out forwards;
  pointer-events: none;
}

@keyframes eventGlow {
  0%, 12% { border-color: transparent; transform: scale(1); }
  22%     { border-color: var(--cr-glow-strong); transform: scale(1.15); }
  35%     { border-color: transparent; transform: scale(1.2); }
  100%    { border-color: transparent; }
}


/* ============================================================
   3-③ 라이브 피드 — 연속 카드 스택 (38×38px)
   ============================================================ */

.feed-widget {
  position: fixed;
  bottom: 20px;
  right: 16px;
  width: 320px;
  max-width: calc(100vw - 32px);
  height: 74px;
  z-index: 9990;
}

.feed-card {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, rgba(25,22,15,0.95), rgba(35,30,18,0.95));
  border: 1px solid rgba(247,208,107,0.12);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  opacity: 0;
}

.feed-coin {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.35) 0%, transparent 50%),
    var(--cr-coin-gradient);
  box-shadow: var(--cr-shadow-sm), 0 3px 12px rgba(247,208,107,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.feed-coin-inner {
  font-family: var(--cr-font);
  font-size: 13px;
  font-weight: 700;
  color: var(--cr-gold-text);
  display: inline-block;
}

.feed-title { font-size: 14px; font-weight: 700; color: #eee; }
.feed-amount { font-family: var(--cr-font); color: var(--cr-gold-primary); }
.feed-sub { font-size: 12px; color: #666; }
.feed-time { margin-left: auto; font-size: 11px; color: #555; flex-shrink: 0; }

.feed-card:nth-child(1) { animation: feedSlide 12s 0s ease-out infinite; }
.feed-card:nth-child(2) { animation: feedSlide 12s 4s ease-out infinite; }
.feed-card:nth-child(3) { animation: feedSlide 12s 8s ease-out infinite; }

.feed-card:nth-child(1) .feed-coin-inner { animation: miniFlip 12s 0.4s ease-in-out infinite; }
.feed-card:nth-child(2) .feed-coin-inner { animation: miniFlip 12s 4.4s ease-in-out infinite; }
.feed-card:nth-child(3) .feed-coin-inner { animation: miniFlip 12s 8.4s ease-in-out infinite; }

@keyframes feedSlide {
  0%   { opacity: 0; transform: translateY(30px) scale(0.96); }
  2%   { opacity: 1; transform: translateY(0) scale(1); }
  5%   { transform: translateY(0) scale(1); }
  25%  { opacity: 1; transform: translateY(-74px) scale(0.97); }
  30%  { opacity: 0.4; transform: translateY(-74px) scale(0.97); }
  33%  { opacity: 0; transform: translateY(-74px) scale(0.95); }
  100% { opacity: 0; }
}

@keyframes miniFlip {
  0%, 2% { transform: rotateY(0); }
  5%     { transform: rotateY(720deg); }
  8%, 100% { transform: rotateY(720deg); }
}


/* ============================================================
   3-④ Thank You — Big Flip + Burst (100×100px, JS 트리거 1회)
   ============================================================ */

.thankyou-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.thankyou-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.thankyou-coin-area {
  position: relative;
  width: 100px;
  height: 100px;
  perspective: 800px;
}

.thankyou-coin {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  animation: thankFlip 5s ease-in-out forwards;
}

.thankyou-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.45) 0%, transparent 50%),
    var(--cr-coin-gradient);
  box-shadow:
    var(--cr-shadow),
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -3px 6px rgba(0,0,0,0.2),
    0 8px 40px rgba(247,208,107,0.4);
}

.thankyou-face::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2px solid rgba(196,148,42,0.4);
}

.thankyou-face .cr-big {
  font-family: var(--cr-font);
  font-size: 32px;
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

.thankyou-back {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  transform: rotateY(180deg);
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 70% 80%, rgba(255,255,255,0.3) 0%, transparent 50%),
    var(--cr-coin-back-gradient);
  box-shadow: var(--cr-shadow),
    inset 0 2px 4px rgba(255,255,255,0.4);
}

.thankyou-back::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 2px solid rgba(196,148,42,0.4);
}

.thankyou-back .m-big {
  font-family: var(--cr-font);
  font-size: 28px;
  font-weight: 700;
  color: var(--cr-gold-text);
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

@keyframes thankFlip {
  0%, 5%   { transform: rotateY(0deg) scale(1); }
  10%      { transform: rotateY(0deg) scale(1.1); }
  30%      { transform: rotateY(720deg) scale(1); }
  35%, 100% { transform: rotateY(720deg) scale(1); }
}

/* Burst Rays (8방향) */
.burst-ring {
  position: absolute;
  inset: -30px;
  border-radius: 50%;
  pointer-events: none;
}

.burst-ray {
  position: absolute;
  top: 50%; left: 50%;
  width: 2px;
  height: 20px;
  background: linear-gradient(to top, transparent, var(--cr-sparkle-color));
  transform-origin: bottom center;
  opacity: 0;
  border-radius: 1px;
}

.burst-ray:nth-child(1) { transform: rotate(0deg) translateY(-40px);   animation: rayBurst 5s 0.4s ease-out forwards; }
.burst-ray:nth-child(2) { transform: rotate(45deg) translateY(-40px);  animation: rayBurst 5s 0.45s ease-out forwards; }
.burst-ray:nth-child(3) { transform: rotate(90deg) translateY(-40px);  animation: rayBurst 5s 0.5s ease-out forwards; }
.burst-ray:nth-child(4) { transform: rotate(135deg) translateY(-40px); animation: rayBurst 5s 0.55s ease-out forwards; }
.burst-ray:nth-child(5) { transform: rotate(180deg) translateY(-40px); animation: rayBurst 5s 0.6s ease-out forwards; }
.burst-ray:nth-child(6) { transform: rotate(225deg) translateY(-40px); animation: rayBurst 5s 0.65s ease-out forwards; }
.burst-ray:nth-child(7) { transform: rotate(270deg) translateY(-40px); animation: rayBurst 5s 0.7s ease-out forwards; }
.burst-ray:nth-child(8) { transform: rotate(315deg) translateY(-40px); animation: rayBurst 5s 0.75s ease-out forwards; }

@keyframes rayBurst {
  0%, 8%  { opacity: 0; height: 0; }
  15%     { opacity: 1; height: 24px; }
  25%     { opacity: 0; height: 30px; }
  100%    { opacity: 0; }
}

/* Background Glow */
.thankyou-glow {
  position: absolute;
  width: 200px; height: 200px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(247,208,107,0.15) 0%, transparent 70%);
  animation: bigGlow 5s ease-in-out forwards;
  pointer-events: none;
}

@keyframes bigGlow {
  0%, 5%  { opacity: 0; transform: translate(-50%,-50%) scale(0.5); }
  15%     { opacity: 1; transform: translate(-50%,-50%) scale(1.2); }
  40%     { opacity: 0.6; transform: translate(-50%,-50%) scale(1); }
  100%    { opacity: 0; }
}

/* Thank You Text */
.thankyou-text {
  text-align: center;
  animation: thankTextFade 5s ease-in-out forwards;
}

.thankyou-text .big {
  font-size: 22px;
  font-weight: 800;
  color: #fceabb;
}

.thankyou-text .amount {
  font-family: var(--cr-font);
  font-size: 28px;
  font-weight: 700;
  color: var(--cr-gold-primary);
  display: block;
  margin: 4px 0;
}

.thankyou-text .sub {
  font-size: 13px;
  color: #777;
}

@keyframes thankTextFade {
  0%, 8%    { opacity: 0; transform: translateY(8px); }
  15%       { opacity: 1; transform: translateY(0); }
  85%       { opacity: 1; }
  95%, 100% { opacity: 0; }
}


/* ============================================================
   4. UI 배지 (보조 요소)
   ============================================================ */

.cr-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-family: var(--cr-font);
  font-weight: 700;
  font-size: 14px;
}

.cr-badge.gold {
  background: linear-gradient(135deg, #f7d06b, #e8b730);
  color: #5a3e00;
  box-shadow: 0 2px 12px rgba(247,208,107,0.4);
}

.cr-badge.dark {
  background: rgba(247,208,107,0.1);
  color: var(--cr-gold-primary);
  border: 1px solid rgba(247,208,107,0.3);
}

.cr-badge.glass {
  background: rgba(255,255,255,0.08);
  color: #fceabb;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
}

.cr-badge .mini-coin {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--cr-coin-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  color: var(--cr-gold-text);
  box-shadow: var(--cr-shadow-sm);
  flex-shrink: 0;
}


/* ============================================================
   5. 접근성 — prefers-reduced-motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
