*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --void: #050308;
  --deep: #0c0618;
  --surface: rgba(14, 8, 28, 0.82);
  --surface-glass: rgba(20, 12, 38, 0.65);
  --border: rgba(200, 168, 90, 0.22);
  --border-glow: rgba(232, 200, 120, 0.5);
  --gold: #c4a035;
  --gold-bright: #f0d890;
  --gold-dim: #8a7020;
  --moon: #e8edf5;
  --purple: #6b3fa0;
  --purple-bright: #9b6fd4;
  --text: #ede8f5;
  --muted: #8a7da8;
  --glow-gold: rgba(212, 175, 55, 0.4);
  --glow-purple: rgba(120, 60, 200, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--void);
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: rgba(196, 160, 53, 0.35);
  color: var(--gold-bright);
  text-shadow: 0 0 8px var(--glow-gold);
}

body.ritual-active {
  overflow: hidden;
}

/* ══════════════════════════════════════
   COSMOS BACKGROUND
══════════════════════════════════════ */
.cosmos {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--void);
  overflow: hidden;
}

.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.55;
}

.nebula-1 {
  width: 70vw;
  height: 70vw;
  max-width: 600px;
  max-height: 600px;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(90, 40, 160, 0.55) 0%, rgba(40, 15, 80, 0.2) 50%, transparent 70%);
  animation: drift 20s ease-in-out infinite;
}

.nebula-2 {
  width: 50vw;
  height: 50vw;
  max-width: 400px;
  max-height: 400px;
  bottom: -10%;
  right: -15%;
  background: radial-gradient(circle, rgba(60, 20, 100, 0.4) 0%, transparent 65%);
  animation: drift 16s ease-in-out infinite reverse;
}

.moon {
  position: absolute;
  top: 8%;
  right: 12%;
  width: clamp(48px, 12vw, 80px);
  height: clamp(48px, 12vw, 80px);
  border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #f8f4ff 0%, #c8d0e8 40%, #8090b0 100%);
  box-shadow:
    0 0 40px rgba(200, 210, 240, 0.3),
    0 0 80px rgba(150, 170, 220, 0.15),
    inset -8px -4px 12px rgba(60, 70, 100, 0.3);
  animation: moon-pulse 6s ease-in-out infinite;
}

.moon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 65% 55%, transparent 30%, rgba(40, 50, 80, 0.15) 100%);
}

.stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 5% 10%, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 18% 35%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1.5px 1.5px at 32% 8%, rgba(240,220,160,0.7), transparent),
    radial-gradient(1px 1px at 48% 22%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 62% 45%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1.5px 1.5px at 78% 12%, rgba(240,220,160,0.6), transparent),
    radial-gradient(1px 1px at 90% 38%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 12% 68%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1.5px 1.5px at 28% 82%, rgba(240,220,160,0.5), transparent),
    radial-gradient(1px 1px at 55% 75%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 72% 88%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1.5px 1.5px at 88% 72%, rgba(240,220,160,0.45), transparent),
    radial-gradient(1px 1px at 42% 55%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 95% 55%, rgba(255,255,255,0.35), transparent);
  animation: twinkle 10s ease-in-out infinite alternate;
}

.mist {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(to top, rgba(8, 4, 16, 0.9) 0%, rgba(20, 10, 40, 0.3) 50%, transparent 100%);
  pointer-events: none;
}

.particles span {
  position: absolute;
  bottom: -10px;
  border-radius: 50%;
  background: rgba(240, 210, 140, 0.5);
  box-shadow: 0 0 6px rgba(240, 210, 140, 0.4);
  animation: rise linear infinite;
  opacity: 0;
}

@keyframes drift {
  0%, 100% { transform: translateX(-50%) translateY(0) scale(1); }
  50% { transform: translateX(-48%) translateY(25px) scale(1.05); }
}

@keyframes moon-pulse {
  0%, 100% { box-shadow: 0 0 40px rgba(200,210,240,0.3), 0 0 80px rgba(150,170,220,0.15), inset -8px -4px 12px rgba(60,70,100,0.3); }
  50% { box-shadow: 0 0 55px rgba(200,210,240,0.45), 0 0 100px rgba(150,170,220,0.25), inset -8px -4px 12px rgba(60,70,100,0.3); }
}

@keyframes twinkle {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

@keyframes rise {
  0% { opacity: 0; transform: translateY(0) translateX(0); }
  10% { opacity: 0.7; }
  90% { opacity: 0.3; }
  100% { opacity: 0; transform: translateY(-100vh) translateX(20px); }
}

/* ── Floating runes ── */
.runes span {
  position: absolute;
  font-family: "Philosopher", serif;
  color: rgba(240, 210, 140, 0.12);
  text-shadow: 0 0 20px rgba(196, 160, 53, 0.2);
  animation: rune-float linear infinite;
  pointer-events: none;
  user-select: none;
}

@keyframes rune-float {
  0% { opacity: 0; transform: translateY(20px) rotate(0deg); }
  15% { opacity: 0.5; }
  85% { opacity: 0.2; }
  100% { opacity: 0; transform: translateY(-120px) rotate(15deg); }
}

/* ── Shooting stars ── */
.shooting-stars span {
  position: absolute;
  width: 80px;
  height: 1px;
  background: linear-gradient(90deg, rgba(240, 220, 160, 0.8), transparent);
  border-radius: 50%;
  opacity: 0;
  animation: shoot linear infinite;
  pointer-events: none;
}

@keyframes shoot {
  0% { opacity: 0; transform: translate(0, 0) rotate(-35deg); }
  5% { opacity: 1; }
  15% { opacity: 0; transform: translate(-200px, 120px) rotate(-35deg); }
  100% { opacity: 0; }
}

/* ── Music toggle ── */
.music-btn {
  position: fixed;
  top: calc(0.75rem + var(--safe-top));
  right: calc(0.75rem + var(--safe-right));
  z-index: 50;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  touch-action: manipulation;
}

.music-btn:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 24px var(--glow-gold);
}

.music-btn.playing {
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 30px var(--glow-gold), inset 0 0 12px rgba(196, 160, 53, 0.1);
}

.music-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.music-waves {
  display: none;
  gap: 2px;
  align-items: flex-end;
  height: 14px;
}

.music-btn.playing .music-icon { display: none; }
.music-btn.playing .music-waves { display: flex; }

.music-waves i {
  display: block;
  width: 3px;
  background: var(--gold-bright);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}

.music-waves i:nth-child(1) { height: 6px; animation-delay: 0s; }
.music-waves i:nth-child(2) { height: 12px; animation-delay: 0.15s; }
.music-waves i:nth-child(3) { height: 8px; animation-delay: 0.3s; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* ── Magic title shimmer ── */
.magic-title {
  font-family: "Cormorant Garamond", "Philosopher", "Be Vietnam Pro", serif;
  font-weight: 700;
  text-transform: none;
  font-variant: normal;
  background: linear-gradient(
    120deg,
    var(--gold-dim) 0%,
    var(--gold-bright) 25%,
    #fff8e0 45%,
    var(--gold-bright) 55%,
    var(--gold) 75%,
    var(--gold-dim) 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: title-shimmer 6s ease-in-out infinite;
}

.magic-title-sm {
  background-size: 180% auto;
  animation-duration: 5s;
}

@keyframes title-shimmer {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

/* ══════════════════════════════════════
   RITUAL OVERLAY
══════════════════════════════════════ */
.ritual {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: rgba(5, 3, 8, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: ritual-in 0.4s ease both;
}

.ritual::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, rgba(120, 60, 200, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 30% 70%, rgba(196, 160, 53, 0.08) 0%, transparent 40%);
  animation: ritual-aura 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ritual-aura {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.05); }
}

@keyframes ritual-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ritual-sigil {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.ritual-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid var(--border-glow);
}

.ring-outer {
  inset: 0;
  border-style: dashed;
  animation: spin 12s linear infinite;
  box-shadow: 0 0 30px var(--glow-gold), inset 0 0 20px var(--glow-purple);
}

.ring-inner {
  inset: 18px;
  border-color: rgba(155, 111, 212, 0.4);
  animation: spin 8s linear infinite reverse;
}

.ritual-moon {
  font-size: 2.5rem;
  color: var(--gold-bright);
  text-shadow: 0 0 30px var(--glow-gold);
  animation: ritual-pulse 1.5s ease-in-out infinite;
}

.ritual-text {
  font-family: "Cormorant Garamond", "Be Vietnam Pro", serif;
  font-size: 1.25rem;
  font-style: italic;
  font-weight: 500;
  color: var(--gold-bright);
  letter-spacing: 0.04em;
  text-shadow:
    0 0 20px var(--glow-gold),
    0 0 40px rgba(120, 60, 200, 0.3);
  animation: ritual-text 2s ease-in-out infinite;
  position: relative;
  z-index: 1;
  transition: opacity 0.4s ease;
}

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

@keyframes ritual-pulse {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.12); opacity: 1; }
}

@keyframes ritual-text {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
.container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding:
    calc(1.25rem + var(--safe-top))
    calc(1rem + var(--safe-right))
    calc(2.5rem + var(--safe-bottom))
    calc(1rem + var(--safe-left));
}

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header-sigil {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 1rem;
}

.sigil-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(200, 168, 90, 0.3);
  animation: spin 20s linear infinite;
}

.sigil-ring-2 {
  inset: 10px;
  border-style: dashed;
  border-color: rgba(155, 111, 212, 0.25);
  animation-direction: reverse;
  animation-duration: 14s;
}

.sigil-moon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: var(--gold-bright);
  text-shadow: 0 0 20px var(--glow-gold);
}

.header-ornament {
  font-size: 0.7rem;
  letter-spacing: 0.5em;
  color: var(--gold);
  opacity: 0.55;
  margin-bottom: 0.5rem;
}

h1 {
  font-size: clamp(1.75rem, 6.5vw, 3rem);
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-shadow:
    0 0 50px var(--glow-gold),
    0 0 100px rgba(120, 60, 200, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.8);
  filter: drop-shadow(0 0 30px rgba(196, 160, 53, 0.3));
}

.subtitle {
  margin-top: 0.6rem;
  color: var(--muted);
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  font-style: italic;
  letter-spacing: 0.04em;
}

.header-line {
  width: min(240px, 60vw);
  height: 1px;
  margin: 1.25rem auto 0;
  background: linear-gradient(90deg, transparent 0%, var(--gold-dim) 20%, var(--gold-bright) 50%, var(--gold-dim) 80%, transparent 100%);
  box-shadow: 0 0 12px var(--glow-gold);
}

/* ══════════════════════════════════════
   CONTROLS
══════════════════════════════════════ */
.controls {
  position: relative;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.25rem 1.25rem 1.5rem;
  max-width: 400px;
  margin: 0 auto 2rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.5),
    0 0 60px rgba(120, 60, 200, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.controls::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 21px;
  padding: 1px;
  background: conic-gradient(from 180deg, rgba(200,168,90,0.4), transparent 30%, rgba(120,60,200,0.3) 60%, transparent 80%, rgba(200,168,90,0.3));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  animation: border-rotate 8s linear infinite;
}

@keyframes border-rotate {
  to { filter: hue-rotate(360deg); }
}

.controls-label {
  text-align: center;
  font-family: "Cormorant Garamond", serif;
  font-size: 0.95rem;
  font-style: italic;
  color: var(--muted);
  letter-spacing: 0.1em;
  margin-bottom: 0.9rem;
}

.presets {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.preset {
  flex: 1;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  font-family: "Cormorant Garamond", serif;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
}

.preset span {
  position: relative;
  z-index: 1;
}

.preset.active {
  border-color: var(--gold);
  color: var(--gold-bright);
  background: linear-gradient(135deg, rgba(196,160,53,0.2), rgba(120,60,200,0.1));
  box-shadow: 0 0 20px var(--glow-gold), inset 0 0 12px rgba(196,160,53,0.1);
}

.control-row {
  display: flex;
  gap: 0.65rem;
}

input[type="number"] {
  flex: 1;
  min-width: 0;
  min-height: 50px;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
  color: var(--gold-bright);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  touch-action: manipulation;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(196, 160, 53, 0.12), 0 0 20px var(--glow-gold);
}

#draw-btn {
  position: relative;
  overflow: hidden;
  min-height: 50px;
  padding: 0.75rem 1.4rem;
  border: 1px solid rgba(240, 210, 140, 0.3);
  border-radius: 12px;
  background: linear-gradient(160deg, #f0d878 0%, #c4a035 40%, #7a6018 100%);
  color: #0a0612;
  font-family: "Cormorant Garamond", "Be Vietnam Pro", serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: none;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
  box-shadow:
    0 4px 24px rgba(196, 160, 53, 0.4),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-glow {
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255,255,255,0.25) 50%, transparent 60%);
  animation: btn-shimmer 3s ease-in-out infinite;
}

@keyframes btn-shimmer {
  0%, 100% { transform: translateX(-100%); }
  50% { transform: translateX(100%); }
}

.btn-text {
  position: relative;
  z-index: 1;
}

#draw-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(196, 160, 53, 0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}

#draw-btn:active { transform: scale(0.97); }

#draw-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ══════════════════════════════════════
   RESULT
══════════════════════════════════════ */
.result {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  scroll-margin-top: calc(1rem + var(--safe-top));
  animation: result-in 0.8s ease both;
}

.result .sparkles {
  position: absolute;
  inset: -2rem;
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-aura {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(600px, 90vw);
  height: min(400px, 60vh);
  background: radial-gradient(ellipse, rgba(120, 60, 200, 0.12) 0%, rgba(196, 160, 53, 0.06) 40%, transparent 70%);
  pointer-events: none;
  animation: aura-pulse 4s ease-in-out infinite;
}

@keyframes aura-pulse {
  0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
}

.result-title {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  position: relative;
  z-index: 1;
}

.ornament-line {
  display: block;
  width: clamp(40px, 12vw, 80px);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  box-shadow: 0 0 8px var(--glow-gold);
}

.result h2 {
  font-size: clamp(1.2rem, 4.5vw, 1.6rem);
  letter-spacing: 0.04em;
  text-shadow: 0 0 30px var(--glow-gold);
  white-space: nowrap;
  filter: drop-shadow(0 0 20px rgba(196, 160, 53, 0.4));
}

.oracle-msg {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-size: clamp(0.9rem, 3.2vw, 1.05rem);
  color: var(--muted);
  text-align: center;
  margin-bottom: 1.5rem;
  letter-spacing: 0.03em;
  position: relative;
  z-index: 1;
  animation: oracle-in 1s ease 0.3s both;
}

@keyframes oracle-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Card names list ── */
.card-names {
  list-style: none;
  width: 100%;
  max-width: 460px;
  margin: 1.75rem auto 0;
  padding: 1.25rem 1.5rem;
  background: var(--surface-glass);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 40px rgba(120, 60, 200, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  position: relative;
  z-index: 1;
  overflow: hidden;
}

.card-names::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(120, 60, 200, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(196, 160, 53, 0.08) 0%, transparent 50%);
  pointer-events: none;
}

.card-names::after {
  content: "✦";
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.55rem;
  color: var(--gold);
  opacity: 0.4;
  letter-spacing: 0;
}

.card-name-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid rgba(200, 168, 90, 0.12);
  opacity: 0;
  filter: blur(6px);
  transform: translateY(8px);
}

.card-name-item.visible {
  animation: name-emerge 1.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.card-name-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.card-name-item:first-child {
  padding-top: 0.25rem;
}

.card-name-num {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Cinzel Decorative", serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--gold);
  border: 1px solid rgba(196, 160, 53, 0.3);
  border-radius: 50%;
  background: rgba(196, 160, 53, 0.08);
  box-shadow: 0 0 12px rgba(196, 160, 53, 0.15);
}

.card-name-text {
  font-family: "Cinzel Decorative", "Cormorant Garamond", serif;
  font-size: clamp(0.85rem, 3.2vw, 1.05rem);
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.05em;
  text-transform: capitalize;
  background: linear-gradient(
    135deg,
    var(--gold-dim) 0%,
    var(--gold-bright) 40%,
    #fff6d8 55%,
    var(--gold-bright) 70%,
    var(--gold) 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 8px rgba(196, 160, 53, 0.35));
  animation: name-shimmer 5s ease-in-out infinite;
}

@keyframes name-shimmer {
  0%, 100% { background-position: 0% center; }
  50% { background-position: 100% center; }
}

@keyframes name-emerge {
  0% {
    opacity: 0;
    filter: blur(10px);
    transform: translateY(12px);
  }
  40% {
    opacity: 0.3;
    filter: blur(6px);
  }
  100% {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

/* ══════════════════════════════════════
   CARDS GRID
══════════════════════════════════════ */
.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(0.65rem, 2.5vw, 1.25rem);
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  padding: 2.5rem 0.25rem 1.5rem;
  position: relative;
  z-index: 1;
  overflow: visible;
}

.cards::before {
  content: "";
  position: absolute;
  inset: -1rem -2rem;
  background:
    radial-gradient(ellipse at 30% 60%, rgba(100, 70, 160, 0.08) 0%, transparent 55%),
    radial-gradient(ellipse at 70% 40%, rgba(196, 160, 53, 0.05) 0%, transparent 50%);
  filter: blur(20px);
  pointer-events: none;
  animation: cards-mist 8s ease-in-out infinite alternate;
}

@keyframes cards-mist {
  from { opacity: 0.5; transform: scale(1); }
  to { opacity: 0.9; transform: scale(1.03); }
}

.cards[data-count="1"] {
  grid-template-columns: minmax(0, 175px);
  max-width: 175px;
}

.cards[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 380px;
}

.cards[data-count="4"],
.cards[data-count="5"],
.cards[data-count="6"] { max-width: 480px; }

.cards[data-count="7"],
.cards[data-count="8"],
.cards[data-count="9"],
.cards[data-count="10"] { max-width: 540px; }

/* ══════════════════════════════════════
   CARD FLIP
══════════════════════════════════════ */
.card {
  width: 100%;
  min-width: 0;
  perspective: 1200px;
  position: relative;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.6s ease, transform 0.6s ease;
  overflow: visible;
}

.card.slot-ready {
  opacity: 1;
  transform: translateY(0);
}

.card-smoke {
  position: absolute;
  left: -25%;
  right: -25%;
  bottom: -5%;
  height: 220%;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  overflow: visible;
}

.card.smoking .card-smoke {
  opacity: 1;
}

.card.emerging .card-smoke,
.card.flipped .card-smoke {
  animation: smoke-dissipate 2.8s ease forwards;
}

/* Tall rising plumes from bottom */
.smoke-plume {
  position: absolute;
  bottom: 0;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  filter: blur(14px);
  opacity: 0;
  transform-origin: bottom center;
  animation: plume-rise ease-out infinite;
}

.card.smoking .smoke-plume {
  opacity: 1;
}

.smoke-plume:nth-child(1) {
  left: 10%;
  width: 45%;
  height: 55%;
  background: radial-gradient(ellipse at bottom, rgba(190, 170, 230, 0.65) 0%, rgba(100, 70, 160, 0.35) 35%, transparent 70%);
  animation-duration: 3.2s;
  animation-delay: 0s;
}

.smoke-plume:nth-child(2) {
  left: 30%;
  width: 38%;
  height: 50%;
  background: radial-gradient(ellipse at bottom, rgba(210, 195, 240, 0.55) 0%, rgba(120, 90, 170, 0.25) 40%, transparent 75%);
  animation-duration: 3.8s;
  animation-delay: 0.5s;
}

.smoke-plume:nth-child(3) {
  left: 50%;
  width: 42%;
  height: 58%;
  background: radial-gradient(ellipse at bottom, rgba(180, 155, 220, 0.6) 0%, rgba(80, 55, 140, 0.3) 38%, transparent 72%);
  animation-duration: 3.5s;
  animation-delay: 0.3s;
}

.smoke-plume:nth-child(4) {
  left: 5%;
  width: 30%;
  height: 45%;
  background: radial-gradient(ellipse at bottom, rgba(220, 200, 170, 0.4) 0%, rgba(140, 110, 90, 0.15) 45%, transparent 80%);
  animation-duration: 4s;
  animation-delay: 0.8s;
}

.smoke-plume:nth-child(5) {
  right: 5%;
  left: auto;
  width: 35%;
  height: 48%;
  background: radial-gradient(ellipse at bottom, rgba(200, 180, 240, 0.5) 0%, rgba(90, 65, 150, 0.2) 42%, transparent 78%);
  animation-duration: 3.6s;
  animation-delay: 0.6s;
}

/* Small puff particles rising */
.smoke-puff {
  position: absolute;
  bottom: 5%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  filter: blur(6px);
  background: rgba(200, 185, 235, 0.55);
  opacity: 0;
  animation: puff-rise linear infinite;
}

.card.smoking .smoke-puff {
  opacity: 0.8;
}

.smoke-puff:nth-child(6)  { left: 20%; animation-duration: 2.8s; animation-delay: 0.1s; }
.smoke-puff:nth-child(7)  { left: 40%; animation-duration: 3.2s; animation-delay: 0.6s; width: 14px; height: 14px; }
.smoke-puff:nth-child(8)  { left: 60%; animation-duration: 2.5s; animation-delay: 0.3s; }
.smoke-puff:nth-child(9)  { left: 75%; animation-duration: 3.5s; animation-delay: 0.9s; width: 22px; height: 22px; }
.smoke-puff:nth-child(10) { left: 35%; animation-duration: 3s;   animation-delay: 1.2s; width: 12px; height: 12px; }
.smoke-puff:nth-child(11) { left: 55%; animation-duration: 2.6s; animation-delay: 0.4s; }
.smoke-puff:nth-child(12) { left: 85%; animation-duration: 3.3s; animation-delay: 0.7s; width: 16px; height: 16px; }

@keyframes plume-rise {
  0% {
    transform: translateY(0) scaleX(0.7) scaleY(0.5);
    opacity: 0.85;
  }
  25% {
    transform: translateY(-40%) scaleX(1) scaleY(0.9);
    opacity: 0.7;
  }
  55% {
    transform: translateY(-90%) scaleX(1.4) scaleY(1.3);
    opacity: 0.45;
  }
  80% {
    transform: translateY(-140%) scaleX(1.8) scaleY(1.6);
    opacity: 0.2;
  }
  100% {
    transform: translateY(-200%) scaleX(2.2) scaleY(1.8);
    opacity: 0;
  }
}

@keyframes puff-rise {
  0% {
    transform: translateY(0) translateX(0) scale(0.6);
    opacity: 0.7;
  }
  30% {
    opacity: 0.6;
  }
  100% {
    transform: translateY(-220px) translateX(var(--drift, 15px)) scale(2.2);
    opacity: 0;
  }
}

@keyframes smoke-dissipate {
  0% { opacity: 1; }
  40% { opacity: 0.7; }
  100% { opacity: 0; visibility: hidden; }
}

.card-flip {
  position: relative;
  z-index: 2;
  width: 100%;
  opacity: 0;
  filter: blur(12px);
  transform: scale(0.82);
  transition:
    opacity 1.4s cubic-bezier(0.22, 0.61, 0.36, 1),
    filter 1.6s cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 1.4s cubic-bezier(0.22, 0.61, 0.36, 1);
}

.card.emerging .card-flip {
  opacity: 1;
  filter: blur(0);
  transform: scale(1);
}

.card-flip-inner {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 1.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transition-delay: var(--flip-delay, 0s);
}

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

.card.revealed .card-front {
  animation: card-reveal-glow 1.2s ease both;
}

@keyframes card-reveal-glow {
  0% { box-shadow: 0 0 60px rgba(240, 210, 140, 0.6), 0 0 100px rgba(120, 60, 200, 0.3); }
  100% { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 30px rgba(120, 60, 200, 0.1); }
}

/* ── Sparkles on reveal ── */
.sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: hidden;
}

.sparkle {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 8px var(--gold-bright), 0 0 16px var(--glow-gold);
  animation: sparkle-burst 1s ease forwards;
}

@keyframes sparkle-burst {
  0% { opacity: 1; transform: scale(1) translate(0, 0); }
  100% { opacity: 0; transform: scale(0) translate(var(--sx), var(--sy)); }
}

.card-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  position: relative;
}

.card-front {
  position: absolute;
  inset: 0;
  transform: rotateY(180deg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  text-align: center;
  box-shadow:
    0 12px 32px rgba(0, 0, 0, 0.55),
    0 0 30px rgba(120, 60, 200, 0.1);
}

.card-back .card-frame {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.card-frame {
  position: relative;
  padding: 5px;
  background: linear-gradient(145deg, rgba(196,160,53,0.25), rgba(80,40,120,0.2));
}

.card-frame-glow::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(240,210,140,0.1), transparent 50%, rgba(155,111,212,0.1));
  pointer-events: none;
  z-index: 1;
}

.corner {
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: var(--gold-bright);
  border-style: solid;
  z-index: 2;
  opacity: 0.7;
}

.corner-tl { top: 8px; left: 8px; border-width: 1px 0 0 1px; }
.corner-tr { top: 8px; right: 8px; border-width: 1px 1px 0 0; }
.corner-bl { bottom: 8px; left: 8px; border-width: 0 0 1px 1px; }
.corner-br { bottom: 8px; right: 8px; border-width: 0 1px 1px 0; }

.card img {
  width: 100%;
  aspect-ratio: 2 / 3.5;
  object-fit: cover;
  display: block;
  border-radius: 8px;
  background: #0a0612;
}

.card .name {
  padding: 0.55rem 0.4rem 0.2rem;
  font-family: "Cinzel Decorative", "Cormorant Garamond", serif;
  font-size: clamp(0.62rem, 2.5vw, 0.8rem);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.04em;
  text-transform: capitalize;
  color: var(--gold-bright);
  text-shadow: 0 0 12px var(--glow-gold);
  word-break: break-word;
  opacity: 0;
  transition: opacity 1s ease 0.6s;
}

.card.flipped .name {
  opacity: 1;
}

.card .index {
  font-size: 0.6rem;
  color: var(--muted);
  padding-bottom: 0.5rem;
  letter-spacing: 0.15em;
  opacity: 0;
  transition: opacity 1s ease 0.8s;
}

.card.flipped .index {
  opacity: 1;
}

.hidden { display: none !important; }

.error {
  text-align: center;
  color: #e08080;
  margin-top: 1rem;
  font-size: 0.9rem;
  padding: 0.75rem 1rem;
  background: rgba(200, 60, 60, 0.1);
  border: 1px solid rgba(200, 60, 60, 0.25);
  border-radius: 10px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* ══════════════════════════════════════
   DESKTOP
══════════════════════════════════════ */
@media (min-width: 600px) {
  .container {
    padding:
      calc(2.5rem + var(--safe-top))
      calc(1.5rem + var(--safe-right))
      calc(4rem + var(--safe-bottom))
      calc(1.5rem + var(--safe-left));
  }

  .header { margin-bottom: 2.5rem; }

  .header-sigil {
    width: 90px;
    height: 90px;
  }

  .sigil-moon { font-size: 2rem; }

  .controls {
    padding: 1.5rem 1.75rem 1.75rem;
    margin-bottom: 2.5rem;
  }

  .cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 940px;
    gap: 1.5rem;
  }

  .cards[data-count] { max-width: 940px; }

  .card {
    width: 172px;
    flex-shrink: 0;
  }

  .card:hover .card-front {
    box-shadow:
      0 20px 48px rgba(0, 0, 0, 0.6),
      0 0 40px var(--glow-gold);
  }

  .oracle-msg { margin-bottom: 2rem; }
}

@media (max-width: 599px) {
  .control-row { flex-direction: column; }
  #draw-btn { width: 100%; }
  .moon { right: 8%; top: 5%; }
}

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

  .card-flip-inner { transition: none; }
  .card.flipped .card-flip-inner { transform: rotateY(180deg); }
  .card { opacity: 1; transform: none; }
  .card.slot-ready { opacity: 1; }
  .card-flip { opacity: 1; filter: none; transform: none; }
  .card-smoke { display: none; }
  .card-name-item { opacity: 1; filter: none; transform: none; }
  .card .name, .card .index { opacity: 1; }
}
