/* 오늘의 행운 보석 — 밝은 민트·크림 바탕에 금빛 반짝임, 돌을 깨면 나오는 보석 */

:root {
  --bg-1: #a9dcc3; /* 가장자리 */
  --bg-2: #f3fbe9; /* 가운데 */
  --cream: #1e3b31; /* 본문 글자 */
  --cream-2: #4b6a5e; /* 보조 글자 */
  --gold: #c48b10; /* 밝은 바탕에서 읽히는 금색 글자 */
  --gold-bright: #f3d27a; /* 버튼·테두리 */
  --gold-deep: #d9a93a;
  --ink: #1e3b31;
  --paper: #fffaf0;
  --dust: #8f8477;
  --tap-ms: 420ms;
  --split-ms: 700ms;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  color: var(--cream);
  background: radial-gradient(90% 70% at 50% 30%, var(--bg-2) 0%, #cfeedb 45%, var(--bg-1) 100%);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* 배경 그림: img/bg.png 또는 img/bg.jpg 가 있으면 전체 화면에 깔고, 글자가 읽히도록 밝은 막을 살짝 덮습니다 */
body.has-bg::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.28)),
    var(--bg-image) center / cover no-repeat;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--gold-deep);
  outline-offset: 4px;
}

/* ── 배경 장식 ──────────────────────────── */

.deco {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.deco svg {
  position: absolute;
  color: #e0b23c;
  animation: drift var(--dur, 9s) ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
  opacity: var(--alpha, 0.3);
}

.deco .clover {
  color: #4fb384;
}

@keyframes drift {
  from {
    transform: translateY(0) rotate(-6deg);
  }
  to {
    transform: translateY(-22px) rotate(8deg);
  }
}

/* ── 틀 ─────────────────────────────────── */

.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(28px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

/* 본문은 남는 공간 가운데에, add-on 자리는 맨 아래에 */
.content {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ── 하단 add-on(광고) 자리 ────────────── */

.ad-slot {
  position: relative;
  flex: none;
  width: min(100%, 320px);
  min-height: 100px;
  margin-top: 24px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 0 0 1px #cfe5d8,
    0 8px 20px rgba(20, 60, 45, 0.1);
}

@media (min-width: 760px) {
  .ad-slot {
    width: min(100%, 728px);
    min-height: 90px;
  }
}

.ad-slot-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: inherit;
}

.ad-slot-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--cream-2);
  pointer-events: none;
}

/* 광고 코드가 들어오면 "광고표시판" 글자와 카드 배경을 숨깁니다. */
.ad-slot:has(.ad-slot-inner > *) {
  background: none;
  box-shadow: none;
}

.ad-slot:has(.ad-slot-inner > *) .ad-slot-label {
  display: none;
}

.head {
  text-align: center;
  margin-bottom: 4px;
}

.mascot {
  display: block;
  width: 88px;
  height: 88px;
  margin: 0 auto 10px;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.3));
}

.mascot[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: clamp(15px, 4vw, 18px);
  color: var(--cream-2);
}

.head h1 {
  margin: 0;
  font-size: clamp(36px, 9.5vw, 50px);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--gold);
  text-shadow: 0 2px 16px rgba(243, 210, 122, 0.6);
}

.hint {
  min-height: 1.5em;
  margin: 12px 0 0;
  font-size: clamp(17px, 4.6vw, 21px);
  color: var(--cream-2);
  transition: opacity 0.25s;
}

.hint.swap {
  opacity: 0;
}

/* ── 무대 ───────────────────────────────── */

.stage {
  position: relative;
  width: 100%;
  max-width: 640px;
  height: 420px;
  margin-top: 12px;
}

/* 보석이 나오면 그 색으로 은은하게 빛나는 바닥 */
.glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow, transparent) 0%, transparent 65%);
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.9s;
  pointer-events: none;
}

.stage[data-state='open'] .glow {
  opacity: 0.6;
}

.stones {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(2px, 1.5vw, 14px);
}

.stone {
  position: relative;
  width: 32.5%;
  max-width: 210px;
  padding: 0;
  border: 0;
  background: none;
  transition:
    transform var(--split-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 0.45s ease,
    width var(--split-ms) cubic-bezier(0.2, 0.8, 0.2, 1);
  filter: drop-shadow(0 10px 12px rgba(20, 60, 45, 0.18));
}

/* 돌이 깨지면 바닥 그림자는 조금 옅어집니다 */
.stone.open .ground {
  opacity: 0.2;
}

.stone svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* 고르기 전: 살짝 둥실둥실 */
.stage[data-state='pick'] .stone {
  animation: float 3.2s ease-in-out infinite;
}

.stage[data-state='pick'] .stone:nth-child(2) {
  animation-delay: -1.1s;
}

.stage[data-state='pick'] .stone:nth-child(3) {
  animation-delay: -2.2s;
}

.stage[data-state='pick'] .stone:hover,
.stage[data-state='pick'] .stone:focus-visible {
  animation-play-state: paused;
  transform: translateY(-10px) scale(1.06);
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-9px);
  }
}

/* 하나를 고르면: 나머지는 사라지고, 고른 것은 가운데로 커짐 */
.stage[data-state='chosen'] .stone:not(.chosen),
.stage[data-state='open'] .stone:not(.chosen) {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

.stone.chosen {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(78%, 360px);
  max-width: none;
  transform: translate(-50%, -50%);
}

.stone.tap {
  animation: tap var(--tap-ms) cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes tap {
  10% {
    transform: translate(-50%, -50%) rotate(-5deg) scale(0.96);
  }
  35% {
    transform: translate(-50%, -50%) rotate(5deg) scale(1.03);
  }
  60% {
    transform: translate(-50%, -50%) rotate(-3deg);
  }
  100% {
    transform: translate(-50%, -50%);
  }
}

/* 돌: 두드릴 때마다 그림이 바뀌고, 깨지면(.open) 사라지면서 아래의 보석이 드러납니다 */
.rock {
  transform-origin: 100px 100px;
  transition:
    opacity 0.4s ease,
    transform var(--split-ms) cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stone.open .rock {
  opacity: 0;
  transform: scale(1.2);
}

.gem {
  opacity: 0;
  transform: scale(0.3);
  transform-origin: 100px 108px;
  filter: drop-shadow(0 0 10px var(--gem)) drop-shadow(0 8px 6px rgba(0, 0, 0, 0.22));
}

.stone.open .gem {
  opacity: 1;
  animation: pop 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.3) 0.15s forwards;
}

/* 돌 사이에서 보일 만한 크기로 커집니다. */
@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.2);
  }
  to {
    opacity: 1;
    transform: scale(0.66);
  }
}

/* 보석 위 반짝임 */
.spark {
  fill: #fff;
  transform-box: fill-box;
  transform-origin: center;
  animation: twinkle 2.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.15;
    transform: scale(0.6);
  }
  50% {
    opacity: 1;
    transform: scale(1.1);
  }
}

/* 튀는 조각: 돌가루 / 보석 조각 / 금빛 가루 */
.shard {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  animation: shard 0.9s ease-out forwards;
}

.shard.dust {
  border-radius: 40%;
  background: var(--dust);
}

.shard.gem {
  background: var(--shard, #fff);
  box-shadow: 0 0 6px var(--shard, #fff);
}

.shard.gold {
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 6px var(--gold-bright);
}

@keyframes shard {
  0% {
    transform: translate(-50%, -50%) rotate(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(260deg) scale(0.5);
    opacity: 0;
  }
}

/* 운세 카드: 보석 위로 솟아오름 */
.slip {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  width: min(88%, 340px);
  padding: 18px 22px 18px;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow:
    inset 0 0 0 2px var(--gold-deep),
    inset 0 0 0 5px var(--paper),
    0 18px 36px rgba(20, 60, 45, 0.22);
  transform: translate(-50%, -40%) scale(0.5);
  opacity: 0;
  pointer-events: none;
  /* 다시 뽑기를 누르면 바로 사라집니다. 천천히 올라오는 움직임은 나타날 때만. */
  transition: opacity 0.12s;
}

.stage[data-state='open'] .slip {
  transform: translate(-50%, -156%) scale(1);
  opacity: 1;
  pointer-events: auto;
  transition:
    transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) 0.55s,
    opacity 0.5s ease 0.55s;
}

.slip-gem {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  color: var(--gold);
}

.slip-text {
  margin: 0;
  font-size: 17px;
  line-height: 1.6;
  font-weight: 600;
  text-align: center;
  word-break: keep-all;
}

/* ── 결과 ───────────────────────────────── */

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  text-align: center;
  animation: rise 0.6s ease-out both;
}

.result[hidden] {
  display: none;
}

@keyframes rise {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.gem-line,
.lucky {
  margin: 0;
  font-size: 14px;
  color: var(--cream-2);
}

.gem-line b,
.lucky b {
  color: var(--gold);
}

.dot {
  opacity: 0.5;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.btn {
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.btn-primary {
  background: var(--gold-bright);
  color: var(--ink);
}

.btn-primary:hover {
  background: #ffe08f;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px #b9d6c7;
}

.btn-ghost:hover {
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  z-index: 3;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(30, 59, 49, 0.94);
  color: #fff8e6;
  font-size: 13px;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

/* 모바일: 돌 크기는 그대로 두고, 돌끼리 살짝 겹치게 붙여 양옆에 빈 공간을 만듭니다 */
@media (max-width: 480px) {
  .stage {
    height: 360px;
  }

  .stones {
    gap: 0;
  }

  .stage[data-state='pick'] .stone + .stone {
    margin-left: -4%;
  }

  /* 운세 카드 글씨를 조금 줄입니다 */
  .slip {
    width: min(84%, 300px);
    padding: 14px 16px;
  }

  .slip-gem {
    font-size: 11px;
  }

  .slip-text {
    font-size: 14px;
    line-height: 1.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage[data-state='pick'] .stone,
  .stone.tap,
  .result,
  .spark,
  .deco svg {
    animation: none;
  }

  .stone.open .gem {
    animation: none;
    transform: scale(0.66);
  }

  .stone,
  .rock,
  .slip {
    transition-duration: 0.01ms;
    transition-delay: 0s;
  }
}
