@import "tailwindcss";

/* ===== Base Styles (in @layer base so utilities can override) ===== */
@layer base {
  :root {
    --bg-cream: #f5f0e8;
    --bg-paper: #ece5d8;
    --bg-dark: #1a1a2e;
    --bg-dark-deep: #10101e;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4553;
    --text-muted: #8a8494;
    --text-inverted: #f5f0e8;
    --gold: #d4a574;
    --gold-light: #e8c9a0;
    --gold-hover: #c49464;
    --terracotta: #c75b39;
    --terracotta-hover: #b04d2f;
    --jade: #2d6a4f;
    --jade-light: #40916c;
    --border-default: #d4cfc5;
    --border-muted: #e8e3d9;
    --shadow-sm: 0 1px 3px rgba(26, 26, 46, 0.08);
    --shadow-md: 0 4px 12px rgba(26, 26, 46, 0.12);
    --shadow-lg: 0 8px 24px rgba(26, 26, 46, 0.16);
    --overlay: rgba(26, 26, 46, 0.5);
  }

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

  body {
    font-family: "Noto Sans SC", sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
  }

  h1, h2, h3, h4 {
    font-family: "Playfair Display", serif;
  }
}

/* ===== Keyframes ===== */
@keyframes stamp-press {
  0% { transform: scale(1.3) rotate(-5deg); opacity: 0; }
  40% { transform: scale(0.95) rotate(2deg); opacity: 1; }
  60% { transform: scale(1.05) rotate(-1deg); }
  80% { transform: scale(0.98) rotate(0.5deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse-soft {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(199, 91, 57, 0.3); }
  50% { transform: scale(1.03); box-shadow: 0 6px 20px rgba(199, 91, 57, 0.45); }
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(212, 165, 116, 0.15), 0 8px 32px rgba(199, 91, 57, 0.3); }
  50% { box-shadow: 0 0 40px rgba(212, 165, 116, 0.25), 0 8px 40px rgba(199, 91, 57, 0.45); }
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes overlay-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes rotate-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes music-ripple {
  0%   { transform: scale(0.9); opacity: 0.5; }
  100% { transform: scale(2.0); opacity: 0; }
}

@keyframes music-disc-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes admin-row-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== Component Classes (in @layer components) ===== */
@layer components {
  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .animate-stamp-press { animation: stamp-press 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
  .animate-fade-in-up { opacity: 0; animation: fade-in-up 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
  .animate-fade-in { opacity: 0; animation: fade-in 0.8s ease-out both; }
  .animate-pulse-soft { animation: pulse-soft 2s ease-in-out infinite; }
  .animate-pulse-glow { animation: pulse-glow 3s ease-in-out infinite; }
  .animate-slide-up { animation: slide-up 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }
  .animate-overlay-fade { animation: overlay-fade 0.25s ease-out both; }
  .animate-float { animation: float 4s ease-in-out infinite; }
  .animate-scale-in { opacity: 0; animation: scale-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
  .animate-music-ripple { animation: music-ripple 2.4s cubic-bezier(0.22, 1, 0.36, 1) infinite; }
  .animate-music-spin { animation: music-disc-spin 18s linear infinite; }
  .animate-toast-in { animation: toast-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both; }
  .animate-admin-row { animation: admin-row-in 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }

  .music-progress {
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    background: transparent;
    cursor: pointer;
  }
  .music-progress::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 999px;
    background: linear-gradient(to right,
      var(--gold) 0%,
      var(--gold) var(--progress, 0%),
      rgba(212, 165, 116, 0.2) var(--progress, 0%),
      rgba(212, 165, 116, 0.2) 100%);
  }
  .music-progress::-moz-range-track {
    height: 3px;
    border-radius: 999px;
    background: rgba(212, 165, 116, 0.2);
  }
  .music-progress::-moz-range-progress {
    height: 3px;
    border-radius: 999px;
    background: var(--gold);
  }
  .music-progress::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gold-light);
    border: 1px solid rgba(255, 255, 255, 0.3);
    margin-top: -4.5px;
    box-shadow: 0 0 8px rgba(212, 165, 116, 0.5);
  }
  .music-progress::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--gold-light);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 8px rgba(212, 165, 116, 0.5);
  }

  /* Stagger children */
  .stagger-children > * {
    opacity: 0;
    animation: fade-in-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .stagger-children > *:nth-child(1)  { animation-delay: 0.04s; }
  .stagger-children > *:nth-child(2)  { animation-delay: 0.08s; }
  .stagger-children > *:nth-child(3)  { animation-delay: 0.12s; }
  .stagger-children > *:nth-child(4)  { animation-delay: 0.16s; }
  .stagger-children > *:nth-child(5)  { animation-delay: 0.20s; }
  .stagger-children > *:nth-child(6)  { animation-delay: 0.24s; }
  .stagger-children > *:nth-child(7)  { animation-delay: 0.28s; }
  .stagger-children > *:nth-child(8)  { animation-delay: 0.32s; }
  .stagger-children > *:nth-child(9)  { animation-delay: 0.36s; }
  .stagger-children > *:nth-child(10) { animation-delay: 0.40s; }
  .stagger-children > *:nth-child(11) { animation-delay: 0.44s; }
  .stagger-children > *:nth-child(12) { animation-delay: 0.48s; }
  .stagger-children > *:nth-child(13) { animation-delay: 0.52s; }
  .stagger-children > *:nth-child(14) { animation-delay: 0.56s; }
  .stagger-children > *:nth-child(15) { animation-delay: 0.60s; }
  .stagger-children > *:nth-child(16) { animation-delay: 0.64s; }
  /* 超过 16 的子元素统一立即显示（不错乱） */
  .stagger-children > *:nth-child(n+17) { animation-delay: 0.68s; }

  /* Stamp Card Effects */
  .stamp-border {
    background-image: radial-gradient(circle, var(--bg-cream) 4px, transparent 4px);
    background-size: 12px 12px;
    background-position: -6px -6px;
  }

  /* Grain / Noise Texture */
  .grain-overlay::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 256px 256px;
  }

  /* Paper Texture */
  .paper-texture {
    position: relative;
    background-color: var(--bg-cream);
    background-image:
      radial-gradient(ellipse at 20% 0%, rgba(212, 165, 116, 0.08) 0%, transparent 60%),
      radial-gradient(ellipse at 80% 100%, rgba(199, 91, 57, 0.05) 0%, transparent 60%);
  }

  /* Decorative Elements */
  .ornament-line {
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--gold) 20%, var(--gold) 80%, transparent 100%);
    opacity: 0.3;
  }

  .stamp-seal {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .stamp-seal::before {
    content: "";
    position: absolute;
    inset: -8px;
    border: 2px dashed;
    border-color: rgba(212, 165, 116, 0.25);
    border-radius: 50%;
    animation: rotate-slow 30s linear infinite;
  }

  .stamp-seal::after {
    content: "";
    position: absolute;
    inset: -20px;
    border: 1px solid;
    border-color: rgba(212, 165, 116, 0.1);
    border-radius: 50%;
    animation: rotate-slow 45s linear infinite reverse;
  }
}
