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

:root {
  --bg-deep: #0a0612;
  --bg-mid: #140e24;
  --gold: #d4a847;
  --gold-light: #f0d078;
  --gold-dim: #8a6d2b;
  --cauldron-bg: #1a0f2e;
  --cauldron-rim: #c8952e;
  --card-bg: #1e1535;
  --card-border: #2e2248;
  --text-primary: #e8dcc8;
  --text-dim: #8a7e6b;
  --success-glow: #4aff8855;
  --fail-red: #ff4a4a;
}

body {
  background: var(--bg-deep);
  font-family: 'Crimson Pro', serif;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated background stars */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 20% 50%, #1a0f3a 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, #0f1a2e 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, #1a0a2a 0%, transparent 60%),
    var(--bg-deep);
  z-index: -2;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

.star {
  position: fixed;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: twinkle var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
  z-index: -1;
  pointer-events: none;
}

/* Title glow */
.title-glow {
  font-family: 'Cinzel', serif;
  background: linear-gradient(135deg, #d4a847 0%, #f0d078 40%, #d4a847 60%, #8a6d2b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(212, 168, 71, 0.4));
  text-shadow: none;
}

/* Element cards */
.element-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 10px 8px;
  cursor: grab;
  transition: all 0.2s ease;
  user-select: none;
  text-align: center;
  min-width: 80px;
  position: relative;
  overflow: hidden;
}

.element-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.element-card:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.element-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--element-color, var(--gold));
  border-radius: 12px 12px 0 0;
}

/* Cauldron */
.cauldron-container {
  position: relative;
}

.cauldron {
  background: radial-gradient(ellipse at center bottom, #2a1845 0%, #1a0f2e 60%, #0f0a1e 100%);
  border: 3px solid var(--cauldron-rim);
  border-radius: 50%;
  width: 280px;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow:
    0 0 40px rgba(200, 149, 46, 0.15),
    inset 0 -20px 40px rgba(200, 149, 46, 0.08),
    inset 0 0 60px rgba(0,0,0,0.5);
}

@keyframes bubbleFloat {
  0% { transform: translateY(0) scale(1); opacity: 0.6; }
  50% { opacity: 0.3; }
  100% { transform: translateY(-60px) scale(0.3); opacity: 0; }
}

.bubble {
  position: absolute;
  border-radius: 50%;
  background: rgba(200, 149, 46, 0.2);
  animation: bubbleFloat 3s ease-in infinite;
  pointer-events: none;
}

/* Merge slots */
.merge-slot {
  width: 72px;
  height: 72px;
  border: 2px dashed rgba(200, 149, 46, 0.4);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(26, 15, 46, 0.8);
  transition: all 0.2s ease;
  position: relative;
}

.merge-slot.filled {
  border-color: var(--gold);
  background: rgba(212, 168, 71, 0.1);
  border-style: solid;
}

.merge-slot.drag-over {
  border-color: var(--gold-light);
  background: rgba(212, 168, 71, 0.2);
  box-shadow: 0 0 20px rgba(212, 168, 71, 0.3);
}

/* Buttons */
.btn-merge {
  font-family: 'Cinzel', serif;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dim) 100%);
  color: #0a0612;
  border: none;
  padding: 12px 36px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 2px;
}

.btn-merge:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(212, 168, 71, 0.4);
}

.btn-merge:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-clear {
  font-family: 'Cinzel', serif;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid rgba(138, 126, 107, 0.3);
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-clear:hover {
  border-color: var(--text-dim);
  color: var(--text-primary);
}

/* Discovery animation */
@keyframes discoveryPulse {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes discoveryGlow {
  0% { box-shadow: 0 0 0 0 rgba(212, 168, 71, 0.8); }
  100% { box-shadow: 0 0 60px 30px rgba(212, 168, 71, 0); }
}

.discovery-anim {
  animation: discoveryPulse 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.discovery-glow {
  animation: discoveryGlow 1s ease-out forwards;
}

/* Shake animation for failed merge */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

/* Scroll area */
.scroll-log {
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.scroll-log::-webkit-scrollbar {
  width: 6px;
}

.scroll-log::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 3px;
}

.scroll-log::-webkit-scrollbar-track {
  background: transparent;
}

/* Sparkle particles */
@keyframes sparkle {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

.sparkle-particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold-light);
  border-radius: 50%;
  pointer-events: none;
  animation: sparkle 0.8s ease-out forwards;
}

/* Win modal */
@keyframes modalIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-modal {
  animation: modalIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Confetti */
@keyframes confettiFall {
  0% { transform: translateY(-100vh) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

.confetti-piece {
  position: fixed;
  width: 10px;
  height: 10px;
  top: 0;
  animation: confettiFall var(--dur) linear forwards;
  animation-delay: var(--delay);
  z-index: 100;
  pointer-events: none;
}

/* Log entry */
.log-entry {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(46, 34, 72, 0.5);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Discovery panel on mobile */
@media (max-width: 768px) {
  .cauldron {
    width: 220px;
    height: 220px;
  }
  .merge-slot {
    width: 58px;
    height: 58px;
  }
  .element-card {
    min-width: 70px;
    padding: 8px 6px;
  }
}

/* Footer */
.alchemy-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 13px;
  border-top: 1px solid rgba(46, 34, 72, 0.4);
  margin-top: 20px;
}

.alchemy-footer a {
  color: var(--gold-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.alchemy-footer a:hover {
  color: var(--gold);
}

/* Hint button */
.hint-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(212, 168, 71, 0.15);
  border: 1px solid rgba(212, 168, 71, 0.3);
  color: var(--gold);
  font-family: 'Cinzel', serif;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hint-btn:hover {
  background: rgba(212, 168, 71, 0.25);
  border-color: var(--gold);
}

/* Floating message */
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

.float-msg {
  animation: floatUp 2s ease-out forwards;
  pointer-events: none;
}

/* Plus sign between slots */
.slot-plus {
  color: var(--gold-dim);
  font-family: 'Cinzel', serif;
  font-size: 24px;
  font-weight: 700;
  user-select: none;
}