@font-face {
  font-family: 'Jua';
  src: url('../fonts/Jua-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}

:root {
  --pink: #f3056e;
  --pink-2: #ff3d8b;
  --pink-deep: #a50b57;
  --purple: #b22bd6;
  --purple-deep: #4b0a63;
  --gold: #ffe066;
  --cyan: #9bf6ff;
  --ink: #2a0526;
  --glass: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  color: #fff;
  background: #8b0752;
  background-image:
    radial-gradient(120% 70% at 50% -10%, #d64be0 0%, #b71ba8 28%, #f3056e 62%, #a30a57 100%);
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* 배경 장식 */
.bg-deco { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.orb { position: absolute; border-radius: 50%; filter: blur(34px); opacity: 0.55; }
.o1 { width: 260px; height: 260px; left: -90px; top: -60px; background: #ff67c9; }
.o2 { width: 320px; height: 320px; right: -120px; top: 22%; background: #8a2be2; opacity: 0.45; }
.o3 { width: 280px; height: 280px; left: 10%; bottom: -130px; background: #ff2e88; opacity: 0.4; }
.spark {
  position: absolute; color: #fff; opacity: 0.5; font-size: 14px;
  animation: twinkle 3.2s ease-in-out infinite;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.9);
}
.s1 { left: 12%; top: 16%; animation-delay: 0.2s; }
.s2 { right: 14%; top: 9%; animation-delay: 1.1s; font-size: 10px; }
.s3 { left: 20%; bottom: 22%; animation-delay: 2.1s; font-size: 11px; }
.s4 { right: 10%; bottom: 30%; animation-delay: 0.7s; font-size: 16px; }
.s5 { left: 46%; top: 6%; animation-delay: 1.7s; font-size: 9px; }
@keyframes twinkle {
  0%, 100% { opacity: 0.18; transform: scale(0.85); }
  50% { opacity: 0.75; transform: scale(1.15); }
}

/* ── 앱 프레임 ── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px calc(env(safe-area-inset-bottom, 0px) + 6px);
}

.topbar {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 0;
}

.icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08));
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(90, 0, 50, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(90, 0, 50, 0.3); }
.icon-btn .ic-off { display: none; }
.icon-btn[aria-pressed="false"] .ic-on { display: none; }
.icon-btn[aria-pressed="false"] .ic-off { display: inline; }
.icon-btn[aria-pressed="false"] { opacity: 0.72; }

.meter {
  text-align: center;
  line-height: 1;
}
.meter-label {
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
  opacity: 0.9;
  text-shadow: 0 0 8px rgba(255, 200, 60, 0.8);
}
.meter-value {
  font-family: 'Jua', sans-serif;
  font-size: clamp(26px, 8vw, 34px);
  line-height: 1.12;
  color: #fff;
  letter-spacing: 1px;
  text-shadow:
    0 0 6px rgba(255, 255, 255, 0.7),
    0 0 16px rgba(255, 120, 220, 0.6),
    0 2px 0 rgba(140, 0, 80, 0.55);
  transition: transform 0.1s ease;
}
.meter-value.pop { transform: scale(1.16); }
.meter-best {
  margin-top: 7px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
}
.meter-best b { color: var(--gold); font-weight: 700; }

/* ── 릴 ── */
.reelbar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  background: linear-gradient(180deg, rgba(58, 4, 76, 0.55), rgba(30, 2, 44, 0.45));
  box-shadow: inset 0 0 18px rgba(255, 110, 210, 0.28), 0 2px 0 rgba(90, 0, 50, 0.28);
}
.reel-cap {
  font-family: 'Jua', sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--gold);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  opacity: 0.95;
  text-shadow: 0 0 8px rgba(255, 200, 60, 0.8);
}
.reels {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(90% 90% at 50% 20%, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.02) 70%),
    linear-gradient(180deg, rgba(24, 2, 36, 0.72), rgba(60, 6, 74, 0.55));
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45);
}
.cell.first {
  border-color: rgba(255, 224, 102, 0.9);
  box-shadow: 0 0 12px rgba(255, 200, 60, 0.55), inset 0 0 14px rgba(255, 190, 60, 0.25);
}
.reels.win .cell {
  border-color: rgba(255, 224, 102, 0.95);
  box-shadow: 0 0 14px rgba(255, 200, 60, 0.6), inset 0 0 14px rgba(255, 190, 60, 0.3);
}
.cell, .reels .cell { transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.cell::after {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}
.strip {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  will-change: transform;
}
.strip canvas {
  width: 100%;
  height: 100%;
  display: block;
  flex: 0 0 100%;
}

/* ── 게임판 ── */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#game {
  display: block;
  border-radius: 18px;
  touch-action: none;
  cursor: pointer;
  box-shadow:
    0 10px 30px rgba(60, 0, 40, 0.38),
    0 0 0 1px rgba(255, 255, 255, 0.12);
}

.jackpot {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
  opacity: 0;
  pointer-events: none;
  font-family: 'Jua', sans-serif;
  font-size: clamp(34px, 13vw, 54px);
  letter-spacing: 2px;
  color: #fff;
  -webkit-text-stroke: 2px rgba(120, 0, 70, 0.55);
  text-shadow:
    0 0 10px rgba(255, 255, 255, 0.95),
    0 0 26px rgba(255, 214, 64, 0.95),
    0 0 46px rgba(255, 90, 190, 0.85);
  white-space: nowrap;
  z-index: 3;
}
.jackpot.show { animation: jackpotPop 1.15s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
@keyframes jackpotPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-10deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(2deg); }
  30% { transform: translate(-50%, -50%) scale(0.98) rotate(-2deg); }
  45% { transform: translate(-50%, -50%) scale(1.04) rotate(1deg); opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(1.06); }
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  border-radius: 18px;
  z-index: 2;
}
.flash.on { animation: flashOut 0.42s ease-out; }

.danger {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -6px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(228, 16, 74, 0.96);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 18px rgba(255, 40, 100, 0.9);
  font-family: 'Jua', sans-serif;
  font-size: 16px;
  letter-spacing: 1px;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.danger.show { opacity: 1; transform: translate(-50%, 0); animation: dangerPulse 0.7s ease-in-out infinite; }
.danger i {
  display: block;
  width: 58px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.35);
  overflow: hidden;
}
.danger b {
  display: block;
  height: 100%;
  width: 100%;
  background: #ffe066;
  transform-origin: left center;
  transition: width 0.1s linear;
}
@keyframes dangerPulse {
  0%, 100% { box-shadow: 0 0 12px rgba(255, 40, 100, 0.7); }
  50% { box-shadow: 0 0 26px rgba(255, 60, 120, 1); }
}
@keyframes flashOut {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

.hint {
  margin: 4px 0 0;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
  transition: opacity 0.5s ease;
  height: 18px;
}
.hint b { color: var(--gold); }
.hint.hide { opacity: 0; }

/* ── 화면들 ── */
.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background-color: #5e0850;
  background-image:
    radial-gradient(85% 55% at 50% 0%, rgba(226, 90, 236, 0.55) 0%, rgba(150, 12, 108, 0.72) 45%, rgba(72, 3, 62, 0.94) 100%),
    linear-gradient(180deg, #6f0a5e 0%, #3d0336 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.screen.show { display: flex; animation: fadeIn 0.28s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.start-inner { text-align: center; width: 100%; max-width: 380px; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.logo {
  position: relative;
  margin: 14px 0 4px;
  font-family: 'Jua', sans-serif;
  font-size: clamp(52px, 17vw, 76px);
  font-weight: 400;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.logo-text {
  color: #fff;
  letter-spacing: 2px;
  text-shadow:
    0 2px 0 rgba(120, 0, 70, 0.55),
    0 0 18px rgba(255, 130, 205, 0.75);
  animation: logoGlow 3.4s ease-in-out infinite;
}
@keyframes logoGlow {
  0%, 100% { text-shadow: 0 2px 0 rgba(120, 0, 70, 0.55), 0 0 16px rgba(255, 130, 205, 0.7); }
  50% { text-shadow: 0 2px 0 rgba(120, 0, 70, 0.55), 0 0 30px rgba(255, 200, 90, 0.85); }
}
.logo-char { width: 62px; height: 62px; display: inline-block; transform: rotate(-8deg); }
.logo-char canvas { width: 100%; height: 100%; }

.tagline {
  margin: 6px 0 16px;
  font-size: 15px;
  color: rgba(255, 255, 255, 0.95);
}
.tagline b { color: var(--gold); }

.chain {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 8px;
  margin-bottom: 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(40, 2, 52, 0.42), rgba(40, 2, 52, 0.24));
  border: 1.5px solid rgba(255, 255, 255, 0.22);
}
.chain .cf { width: 34px; height: 34px; flex: 0 0 auto; }
.chain .arrow { color: rgba(255, 255, 255, 0.45); font-size: 9px; flex: 0 0 auto; }

.cta {
  width: 100%;
  max-width: 300px;
  padding: 16px 20px;
  border: none;
  border-radius: 18px;
  font-family: 'Jua', sans-serif;
  font-size: 22px;
  letter-spacing: 1px;
  color: var(--pink-deep);
  background: linear-gradient(180deg, #fff7c9 0%, #ffe066 42%, #ffb52e 100%);
  box-shadow:
    0 6px 0 #b8620a,
    0 10px 22px rgba(80, 0, 40, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.9);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8620a, 0 6px 14px rgba(80, 0, 40, 0.35); }
.cta.small { max-width: 240px; font-size: 19px; padding: 13px 18px; margin-top: 6px; }

.start-best { margin: 16px 0 0; font-size: 14px; color: rgba(255, 255, 255, 0.85); }
.start-best b { font-family: 'Jua', sans-serif; font-size: 19px; color: var(--gold); margin-left: 4px; }
.start-note { margin: 8px 0 0; font-size: 11px; color: rgba(255, 255, 255, 0.6); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(48, 2, 40, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.overlay.show { display: flex; animation: fadeIn 0.2s ease; }

.card {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px 20px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(122, 10, 96, 0.96), rgba(70, 4, 70, 0.98));
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 18px 40px rgba(40, 0, 30, 0.5), inset 0 0 30px rgba(255, 120, 220, 0.18);
  position: relative;
}
.card-title {
  margin: 0 0 4px;
  font-family: 'Jua', sans-serif;
  font-size: 26px;
  font-weight: 400;
  color: #fff;
  text-shadow: 0 0 14px rgba(255, 140, 220, 0.9);
}
.card-sub { margin: 0 0 16px; font-size: 13px; color: rgba(255, 255, 255, 0.75); }
.card-row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }

.ghost {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  cursor: pointer;
}
.ghost:active { background: rgba(255, 255, 255, 0.2); }

.record-badge {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%) rotate(-4deg);
  padding: 5px 14px;
  border-radius: 999px;
  font-family: 'Jua', sans-serif;
  font-size: 13px;
  letter-spacing: 1px;
  color: #7a3500;
  background: linear-gradient(180deg, #fff8cc, #ffd23f);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  animation: badgePop 0.6s ease 0.25s both;
}
@keyframes badgePop {
  0% { transform: translateX(-50%) rotate(-4deg) scale(0); }
  70% { transform: translateX(-50%) rotate(-4deg) scale(1.15); }
  100% { transform: translateX(-50%) rotate(-4deg) scale(1); }
}

.result-score { margin: 14px 0 2px; }
.rs-label { display: block; font-size: 11px; letter-spacing: 2px; color: var(--gold); opacity: 0.9; }
.result-score strong {
  display: block;
  font-family: 'Jua', sans-serif;
  font-size: 46px;
  font-weight: 400;
  line-height: 1.1;
  text-shadow: 0 0 16px rgba(255, 255, 255, 0.8), 0 0 34px rgba(255, 200, 60, 0.8);
}
.result-best { font-size: 13px; color: rgba(255, 255, 255, 0.8); margin-bottom: 8px; }
.result-best b { color: var(--gold); }
.result-fruit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
}
.result-fruit canvas { width: 44px; height: 44px; }

.installbar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 16px;
  font-size: 12.5px;
  background: rgba(38, 2, 50, 0.94);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  max-width: 480px;
  margin: 0 auto;
}
.installbar span { flex: 1; }
.installbar button {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 13px;
  color: #7a0a4e;
  background: linear-gradient(180deg, #fff7c9, #ffd23f);
  cursor: pointer;
}
.installbar .x {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  padding: 6px 8px;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(30, 2, 40, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 40;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 700px) {
  .logo { font-size: 48px; margin: 8px 0 2px; }
  .logo-char { width: 50px; height: 50px; }
  .tagline { margin: 4px 0 10px; font-size: 14px; }
  .chain { padding: 8px 6px; margin-bottom: 14px; }
  .chain .cf { width: 28px; height: 28px; }
  .cta { padding: 13px 18px; font-size: 20px; }
  .start-best { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .spark, .logo-text, .record-badge { animation: none; }
}
