:root {
  --bg-deep: #1a120e;
  --bg-mid: #2a1c14;
  --bg-warm: #3d2820;
  --card-bg: #f5ebd6;
  --card-bg-2: #ead9bc;
  --card-shadow: rgba(0,0,0,0.45);
  --accent: #ff8a5c;
  --accent-soft: #ffb4a2;
  --gold: #ffd166;
  --rose: #ef476f;
  --sage: #88c5a4;
  --ink: #2d1810;
  --muted: #a89580;
  --border-warm: rgba(255, 180, 162, 0.18);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-deep);
  color: var(--card-bg);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.display-font { font-family: 'Fraunces', serif; }

/* Layered atmospheric background */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.bg-gradient {
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(255, 138, 92, 0.18), transparent 60%),
    radial-gradient(ellipse 60% 80% at 100% 100%, rgba(239, 71, 111, 0.12), transparent 60%),
    radial-gradient(ellipse 100% 60% at 50% 50%, rgba(255, 209, 102, 0.05), transparent 70%),
    linear-gradient(180deg, #1a120e 0%, #251812 50%, #1a120e 100%);
}

.bg-noise {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.9 0 0 0 0 0.6 0 0 0 0 0.4 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
  opacity: 0.12;
  mix-blend-mode: overlay;
}

/* Floating paw prints */
.paw {
  position: absolute;
  color: rgba(255, 180, 162, 0.07);
  animation: float-paw 22s linear infinite;
  will-change: transform;
}

@keyframes float-paw {
  0% { transform: translateY(110vh) rotate(0deg); opacity: 0; }
  8% { opacity: 1; }
  92% { opacity: 1; }
  100% { transform: translateY(-20vh) rotate(380deg); opacity: 0; }
}

/* Glowing orbs */
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(8px);
  pointer-events: none;
  animation: drift 18s ease-in-out infinite;
}

@keyframes drift {
  0%, 100% { transform: translate(0, 0); opacity: 0.3; }
  33% { transform: translate(30px, -40px); opacity: 0.7; }
  66% { transform: translate(-20px, 30px); opacity: 0.4; }
}

/* ============ CARD 3D ============ */
.card-container {
  perspective: 1200px;
  aspect-ratio: 3/4;
  cursor: pointer;
  position: relative;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 8px 24px var(--card-shadow),
    0 2px 4px rgba(0,0,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.05);
}

.card-back {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 138, 92, 0.08), transparent 70%),
    linear-gradient(135deg, #3d2820 0%, #2a1c14 100%);
  border: 1.5px solid rgba(255, 138, 92, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(255, 180, 162, 0.18);
  border-radius: 10px;
  }

.card-back::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255, 209, 102, 0.06), transparent 60%);
  pointer-events: none;
}

.card-back-silhouette {
  width: 85%;
  height: 85%;
  color: var(--accent-soft);
  opacity: 0.75;
  filter: drop-shadow(0 0 12px rgba(255, 138, 92, 0.3));
  position: relative;
  z-index: 1;
  }

.card-back-mark {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-style: italic;
  font-size: 0.65rem;
  color: rgba(255, 180, 162, 0.4);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  }

.card-front {
  background: radial-gradient(ellipse at 50% 30%, #faf2e0 0%, #ead9bc 100%);
  transform: rotateY(180deg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1.5px solid rgba(45, 24, 16, 0.1);
  }

.card-front-svg {
  width: 90%;
  height: 78%;
}

.card-name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-style: italic;
  font-size: 0.7rem;
  color: var(--ink);
  letter-spacing: 0.08em;
  margin-top: 4px;
  opacity: 0.85;
}

/* Hover state */
.card-container:hover:not(.flipped):not(.matched) .card-inner {
  transform: translateY(-6px);
}

.card-container:hover:not(.flipped):not(.matched) .card-back {
  box-shadow:
    0 16px 36px rgba(255, 138, 92, 0.3),
    0 4px 8px rgba(0,0,0,0.3),
    inset 0 1px 0 rgba(255,255,255,0.1);
  border-color: var(--accent);
}

.card-container:hover:not(.flipped):not(.matched) .card-back-silhouette {
  opacity: 0.95;
  transform: scale(1.05);
  transition: all 0.3s;
}

/* Match - float fade */
@keyframes float-fade {
  0% { transform: rotateY(180deg) translateY(0) scale(1); opacity: 1; }
  15% { transform: rotateY(180deg) translateY(-8px) scale(1.06); opacity: 1; }
  100% { transform: rotateY(180deg) translateY(-110px) scale(0.6) rotate(-8deg); opacity: 0; }
}

.card-container.matched .card-inner {
  animation: float-fade 1.3s cubic-bezier(0.4, 0, 0.6, 1) forwards;
  pointer-events: none;
}

.card-container.matched .card-front {
  box-shadow:
    0 0 30px rgba(255, 209, 102, 0.6),
    0 0 60px rgba(255, 138, 92, 0.4);
}

/* Shake on miss */
@keyframes shake-miss {
  0%, 100% { transform: rotateY(180deg) translateX(0) rotateZ(0); }
  12% { transform: rotateY(180deg) translateX(-9px) rotateZ(-2deg); }
  24% { transform: rotateY(180deg) translateX(9px) rotateZ(2deg); }
  36% { transform: rotateY(180deg) translateX(-7px) rotateZ(-2deg); }
  48% { transform: rotateY(180deg) translateX(7px) rotateZ(2deg); }
  60% { transform: rotateY(180deg) translateX(-5px) rotateZ(-1deg); }
  72% { transform: rotateY(180deg) translateX(5px) rotateZ(1deg); }
  84% { transform: rotateY(180deg) translateX(-2px) rotateZ(0); }
}

.card-container.shake .card-inner {
  animation: shake-miss 0.65s ease-in-out;
}

.card-container.shake .card-front {
  box-shadow:
    0 0 24px rgba(239, 71, 111, 0.5),
    0 8px 24px var(--card-shadow);
  border-color: rgba(239, 71, 111, 0.4);
}

/* Ripple on match */
@keyframes ripple {
  0% { transform: scale(0); opacity: 0.7; }
  100% { transform: scale(4); opacity: 0; }
}

.ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  margin-left: -15px;
  border-radius: 50%;
  border: 2.5px solid var(--gold);
  pointer-events: none;
  animation: ripple 0.9s ease-out forwards;
  z-index: 5;
}

/* Sparkle on match */
@keyframes sparkle-out {
  0% { transform: translate(0, 0) scale(0); opacity: 0; }
  20% { transform: translate(var(--tx), var(--ty)) scale(1.2); opacity: 1; }
  100% { transform: translate(calc(var(--tx) * 2.5), calc(var(--ty) * 2.5)) scale(0); opacity: 0; }
}

.sparkle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  margin-left: -4px;
  pointer-events: none;
  animation: sparkle-out 0.9s ease-out forwards;
  z-index: 6;
}

/* ============ STREAK BANNER ============ */
.streak-banner {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 100;
  text-align: center;
  opacity: 0;
}

@keyframes streak-pop {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.25) rotate(2deg); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1.05) rotate(-1deg); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -65%) scale(1.4) rotate(0); opacity: 0; }
}

.streak-banner.show {
  animation: streak-pop 1.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.streak-text {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  font-style: italic;
  font-size: clamp(3rem, 9vw, 6rem);
  line-height: 1;
  background: linear-gradient(135deg, var(--gold) 0%, var(--accent) 50%, var(--rose) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 30px rgba(255, 138, 92, 0.5));
}

.streak-sub {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 8px;
}

/* ============ STATS ============ */
.stat-card {
  background: linear-gradient(135deg, rgba(245, 235, 214, 0.06), rgba(245, 235, 214, 0.02));
  border: 1px solid var(--border-warm);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.4s;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 138, 92, 0.1), transparent);
  transition: left 0.6s;
}

.stat-card:hover::before { left: 100%; }

.stat-card:hover {
  border-color: rgba(255, 138, 92, 0.4);
  transform: translateY(-2px);
}

.stat-value {
  font-family: 'Fraunces', serif;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.25em;
  color: var(--muted);
  font-weight: 500;
}

.streak-flame {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255, 138, 92, 0.3), rgba(239, 71, 111, 0.2));
  border: 1px solid rgba(255, 138, 92, 0.5);
  color: var(--gold);
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-left: 4px;
}

.streak-flame.active {
  opacity: 1;
  transform: scale(1);
  animation: flame-pulse 1.5s ease-in-out infinite;
}

@keyframes flame-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(255, 138, 92, 0.4); }
  50% { box-shadow: 0 0 16px rgba(255, 138, 92, 0.8); }
}

/* ============ BUTTONS ============ */
.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--rose) 100%);
  color: white;
  border: none;
  padding: 14px 36px;
  border-radius: 999px;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 6px 24px rgba(255, 138, 92, 0.4);
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.6s;
}

.btn-primary:hover::before { left: 100%; }

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(255, 138, 92, 0.55);
}

.btn-primary:active { transform: translateY(0); }

.btn-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(245, 235, 214, 0.06);
  border: 1px solid var(--border-warm);
  color: var(--card-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.btn-icon:hover {
  background: rgba(255, 138, 92, 0.15);
  border-color: var(--accent);
  transform: translateY(-2px);
}

/* ============ TITLE ============ */
.title-letter {
  display: inline-block;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: linear-gradient(180deg, #fff5e8 0%, var(--gold) 50%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 4px 20px rgba(255, 138, 92, 0.3));
}

.title-letter:hover {
  transform: translateY(-8px) rotate(-3deg) scale(1.1);
  filter: drop-shadow(0 12px 28px rgba(255, 138, 92, 0.5));
}

/* ============ CARD GRID ============ */
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  max-width: 580px;
  width: 100%;
}

@media (max-width: 540px) {
  .card-grid { gap: 9px; }
}

/* ============ WIN MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 18, 14, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
  padding: 20px;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background:
    radial-gradient(circle at 30% 0%, rgba(255, 138, 92, 0.15), transparent 60%),
    linear-gradient(160deg, #3d2820 0%, #2a1c14 100%);
  border: 1px solid rgba(255, 138, 92, 0.3);
  border-radius: 24px;
  padding: 40px 32px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  transform: scale(0.85) translateY(20px);
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  position: relative;
  overflow: hidden;
}

.modal::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 209, 102, 0.05), transparent, rgba(255, 138, 92, 0.05), transparent);
  animation: rotate-bg 20s linear infinite;
  pointer-events: none;
}

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

.modal > * { position: relative; z-index: 1; }

.modal-overlay.show .modal {
  transform: scale(1) translateY(0);
}

/* Star rating */
.star {
  display: inline-block;
  width: 48px;
  height: 48px;
  margin: 0 4px;
  opacity: 0;
  transform: scale(0) rotate(-180deg);
  transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.star.show {
  opacity: 1;
  transform: scale(1) rotate(0);
}

.star.filled {
  color: var(--gold);
  filter: drop-shadow(0 0 14px rgba(255, 209, 102, 0.7));
}

.star.empty {
  color: rgba(255, 209, 102, 0.15);
}

/* Confetti canvas */
#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
}

/* Decorative dividers */
.divider-line {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 180, 162, 0.4), transparent);
  width: 48px;
}

/* ============ RESPONSIVE — MOBILE (< 540px) ============ */
@media (max-width: 540px) {
  /* Title scales down so 8 letters fit comfortably on narrow screens */
  .display-font.title {
    font-size: clamp(2.75rem, 14vw, 3.75rem);
    letter-spacing: -0.02em;
  }

  /* Eyebrow text: tighten letter-spacing so it fits on one line */
  .header-row .eyebrow {
    letter-spacing: 0.2em;
    font-size: 0.55rem;
  }

  /* Hide the decorative dividers on the header row to reclaim space */
  .header-row .divider-line {
    display: none;
  }

  /* Stats become a 2×2 grid instead of a cramped 4-across row */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Trim modal padding so the win dialog fits small screens */
  .modal {
    padding: 28px 20px;
  }

  .modal .star {
    width: 40px;
    height: 40px;
    margin: 0 2px;
  }
}

/* How to play */
details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::after {
  content: '▾';
  display: inline-block;
  margin-left: 6px;
  transition: transform 0.3s;
  font-size: 0.7em;
}
details[open] summary::after { transform: rotate(180deg); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Subtle vignette */
.vignette {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  box-shadow: inset 0 0 200px rgba(0,0,0,0.5);
}
