/* =========================================================
   PUZZLE OF US — candlelit corkboard edition
   Palette: wine #3b0f1a, blush #ffd9de, gold #d4af37, paper #fffaf5
   ========================================================= */

:root{
  --wine: #3b0f1a;
  --wine-deep: #2a0a12;
  --blush: #ffd9de;
  --blush-soft: #fff0f2;
  --gold: #d4af37;
  --gold-bright: #f1c95e;
  --paper: #fffaf5;
  --ink: #4a2530;
  --shadow-wine: rgba(59, 15, 26, 0.45);
  --radius-lg: 22px;
  --radius-md: 14px;
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

*{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html{ height: 100%; }

.puzzle-body{
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Cormorant Garamond', serif;
  color: var(--ink);
  /* solid fallback only — the gradient lives on a fixed ambient layer
     below so mobile Safari never has to repaint a fixed body background
     while the page scrolls (the old background-attachment:fixed jank) */
  background: var(--wine-deep);
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* === AMBIENT LAYERS === */
.ambient-wash{
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 15% 0%, rgba(212,175,55,0.15), transparent 55%),
    radial-gradient(ellipse at 85% 100%, rgba(255,217,222,0.18), transparent 55%),
    linear-gradient(160deg, var(--wine) 0%, var(--wine-deep) 100%);
}
.bokeh-bg{
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.bokeh-bg::before, .bokeh-bg::after{
  content:""; position:absolute; inset:-10%;
  background:
    radial-gradient(circle at 20% 30%, rgba(255,217,222,0.10) 0%, transparent 9%),
    radial-gradient(circle at 75% 15%, rgba(212,175,55,0.14) 0%, transparent 7%),
    radial-gradient(circle at 60% 70%, rgba(255,217,222,0.08) 0%, transparent 10%),
    radial-gradient(circle at 10% 85%, rgba(212,175,55,0.10) 0%, transparent 8%);
  background-size: 600px 600px;
  animation: drift 30s ease-in-out infinite alternate;
  filter: blur(1px);
}
.bokeh-bg::after{ animation-duration: 42s; animation-direction: alternate-reverse; opacity: 0.6; }
@keyframes drift{ 0%{ transform: translate(0,0); } 100%{ transform: translate(-3%, 4%); } }

.cork-texture{
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 6px 6px;
  mix-blend-mode: overlay;
}

/* Soft hearts drifting up through the candlelight — kept sparse and slow
   so it reads as ambience, not decoration. Off entirely on very small/
   reduced-motion screens (see media queries below). */
.floating-hearts{
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.floating-hearts .fh{
  position: absolute;
  bottom: -8%;
  left: var(--fh-x, 10%);
  font-size: var(--fh-size, 16px);
  color: rgba(255, 217, 222, var(--fh-op, 0.28));
  filter: drop-shadow(0 0 8px rgba(212,175,55,0.18));
  animation: fh-rise var(--fh-dur, 16s) ease-in infinite;
  animation-delay: var(--fh-delay, 0s);
}
@keyframes fh-rise{
  0%{ transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  10%{ opacity: 1; }
  50%{ transform: translateY(-55vh) translateX(var(--fh-drift, 14px)) rotate(10deg); }
  90%{ opacity: 0.4; }
  100%{ transform: translateY(-105vh) translateX(calc(var(--fh-drift, 14px) * -1)) rotate(-8deg); opacity: 0; }
}
@media (max-width: 480px){
  .floating-hearts .fh:nth-child(n+4){ display: none; } /* keep it light on small phones */
}

/* === LAYOUT === */
.puzzle-container{ position: relative; z-index: 2; padding: 2.5rem 1.25rem 6rem; max-width: 1200px; margin: 0 auto; }

.puzzle-header{ text-align: center; margin-bottom: 2rem; animation: riseIn 0.9s var(--ease-soft) both; }
.eyebrow{
  font-family: 'Jost', sans-serif; text-transform: uppercase; letter-spacing: 0.28em;
  font-size: 0.72rem; color: var(--gold-bright); margin: 0 0 0.6rem;
}
.puzzle-title{
  font-family: 'Dancing Script', cursive; font-weight: 700;
  font-size: clamp(2.6rem, 8vw, 4.4rem);
  color: var(--blush); margin: 0 0 0.4rem;
  text-shadow: 0 2px 24px rgba(212,175,55,0.35);
}
.puzzle-subtitle{
  font-style: italic; font-size: clamp(1rem, 2.4vw, 1.25rem);
  color: rgba(255,240,242,0.78); margin: 0; max-width: 40ch; margin-inline: auto;
}

@keyframes riseIn{ from{ opacity:0; transform: translateY(14px); } to{ opacity:1; transform: translateY(0); } }

/* === PROGRESS === */
.progress-board{ display:flex; flex-direction:column; align-items:center; gap:0.4rem; margin-bottom: 2.4rem; animation: riseIn 0.9s var(--ease-soft) 0.1s both; }
.progress-hearts{ display:flex; gap:0.5rem; font-size: 1.6rem; }
.progress-heart{ color: rgba(255,217,222,0.35); transition: color 0.5s var(--ease-soft), transform 0.5s var(--ease-soft); }
.progress-heart.filled{ color: var(--gold-bright); transform: scale(1.15); text-shadow: 0 0 14px rgba(241,201,94,0.7); }
.progress-label{ font-family:'Jost', sans-serif; font-size: 0.85rem; letter-spacing: 0.05em; color: rgba(255,240,242,0.65); margin:0; }

/* === WRAPPER === */
.puzzles-wrapper{
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2.4rem 1.8rem; align-items: start;
}

/* === PUZZLE SECTION (polaroid pinned to a corkboard) === */
.puzzle-section{
  position: relative;
  background: var(--paper);
  border-radius: 4px;
  padding: 1rem 1rem 1.6rem;
  box-shadow: 0 18px 40px var(--shadow-wine), 0 2px 0 rgba(0,0,0,0.05);
  transform: rotate(var(--pin-rotate, 0deg));
  transition: transform 0.4s var(--ease-soft), box-shadow 0.4s var(--ease-soft);
  opacity: 0;
  animation: pinDrop 0.8s var(--ease-soft) forwards;
}
.puzzle-section:nth-of-type(1){ animation-delay: 0.15s; }
.puzzle-section:nth-of-type(2){ animation-delay: 0.3s; }
.puzzle-section:nth-of-type(3){ animation-delay: 0.45s; }

@keyframes pinDrop{
  from{ opacity:0; transform: translateY(-30px) rotate(var(--pin-rotate,0deg)) scale(0.94); }
  to{ opacity:1; transform: translateY(0) rotate(var(--pin-rotate,0deg)) scale(1); }
}

.puzzle-section:hover{ transform: rotate(0deg) translateY(-4px); box-shadow: 0 26px 55px var(--shadow-wine); }

.pin{
  position:absolute; top: -12px; left: 50%; transform: translateX(-50%);
  width: 22px; height: 20px;
  z-index: 3;
  filter: drop-shadow(0 3px 5px rgba(0,0,0,0.4));
}
.pin::before{
  content: "♥";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
  background: linear-gradient(160deg, var(--gold-bright), var(--gold) 65%, #8a6a1a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.puzzle-name{
  font-family: 'Dancing Script', cursive; font-weight: 700;
  font-size: 1.7rem; color: var(--wine); text-align: center; margin: 0.4rem 0 0.9rem;
}

/* === GRID / FRAME === */
.puzzle-frame{
  background: #f2ece2; border-radius: 6px; padding: 0.5rem;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}
.puzzle-grid{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  touch-action: none;
  background: var(--wine-deep);
}

/* === PIECES === */
.puzzle-piece{
  width: 100%; height: 100%;
  background-size: 300% 300%;
  cursor: grab;
  border-radius: 3px;
  transition: background-position 0.4s var(--ease-soft), box-shadow 0.25s ease, filter 0.25s ease, transform 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  outline-offset: 2px;
}
.puzzle-piece:active{ cursor: grabbing; }

.puzzle-piece.selected{
  box-shadow: inset 0 0 0 3px var(--gold-bright), 0 0 14px rgba(241,201,94,0.6);
  transform: scale(0.96);
  z-index: 4;
}
.puzzle-piece.dragging{
  opacity: 0.5;
}
.puzzle-piece.correct{
  filter: saturate(1.05);
  animation: settle 0.5s var(--ease-soft);
}
@keyframes settle{
  0%{ transform: scale(1.06); }
  100%{ transform: scale(1); }
}

/* Drag ghost that follows the pointer */
.drag-ghost{
  position: fixed;
  pointer-events: none;
  z-index: 999;
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  opacity: 0.92;
  transform: translate(-50%, -50%) scale(1.08) rotate(-2deg);
  background-size: 300% 300%;
}

/* Completed photo reveal */
.completed-full-image{
  position:absolute; inset:0; width:100%; height:100%; object-fit:cover;
  opacity:0; transition: opacity 1.1s var(--ease-soft);
  border-radius: 4px;
}
.completed-full-image.show{ opacity: 1; }

.moves{
  font-family: 'Jost', sans-serif; font-size: 0.8rem; letter-spacing: 0.04em;
  color: #8d7568; text-align:center; margin: 0.7rem 0 0;
}

.hint-text{
  text-align:center; font-style: italic; color: rgba(255,240,242,0.55);
  font-size: 0.92rem; margin-top: 2.4rem;
}

/* === SOUND TOGGLE === */
.icon-btn{
  position: fixed; top: calc(var(--safe-t) + 18px); right: calc(var(--safe-r) + 18px); z-index: 60;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,217,222,0.35);
  background: rgba(59,15,26,0.55); backdrop-filter: blur(6px);
  color: var(--blush); display:flex; align-items:center; justify-content:center;
  cursor:pointer; transition: transform 0.2s ease, background 0.2s ease;
  touch-action: manipulation;
}
.icon-btn:hover{ transform: scale(1.08); background: rgba(59,15,26,0.75); }

/* === WIN OVERLAY === */
.win-message{
  position: fixed; inset: 0; z-index: 200;
  display:flex; align-items:center; justify-content:center;
  background: radial-gradient(circle at center, rgba(59,15,26,0.88), rgba(20,5,9,0.96));
  backdrop-filter: blur(8px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.7s ease, visibility 0.7s;
  padding: calc(var(--safe-t) + 1.5rem) calc(var(--safe-r) + 1.5rem) calc(var(--safe-b) + 1.5rem) calc(var(--safe-l) + 1.5rem);
  overflow-y: auto;
}
.win-message:not(.hidden){ opacity: 1; visibility: visible; }

.win-card{
  text-align:center; max-width: 480px;
  animation: winPop 0.7s var(--ease-soft);
}
@keyframes winPop{ from{ opacity:0; transform: scale(0.85) translateY(20px);} to{ opacity:1; transform: scale(1) translateY(0);} }

.win-text{
  font-family: 'Dancing Script', cursive; font-weight: 700;
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  background: linear-gradient(45deg, var(--blush), var(--gold-bright), var(--blush));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin-bottom: 0.6rem;
  animation: heartBeat 2.4s ease-in-out infinite;
}
@keyframes heartBeat{ 0%,100%{ transform: scale(1);} 50%{ transform: scale(1.06);} }

.win-sub{ font-size: 1.15rem; font-style: italic; color: rgba(255,240,242,0.85); margin: 0 0 1.6rem; }
.win-buttons{ display:flex; gap: 0.8rem; justify-content:center; flex-wrap: wrap; }

/* === BUTTONS === */
.golden-btn{
  font-family: 'Jost', sans-serif; font-weight: 600; letter-spacing: 0.03em;
  padding: 0.85rem 1.8rem; border: none; border-radius: 50px;
  color: var(--wine-deep);
  background: linear-gradient(135deg, var(--gold-bright), var(--gold));
  box-shadow: 0 10px 24px rgba(212,175,55,0.35);
  cursor: pointer; transition: transform 0.25s var(--ease-soft), box-shadow 0.25s ease;
  display: inline-flex; align-items:center; gap: 0.4rem;
}
.golden-btn:hover{ transform: translateY(-2px); box-shadow: 0 16px 34px rgba(212,175,55,0.45); }
.golden-btn:active{ transform: translateY(0); }

/* === MUSIC HINT (first visit only) === */
.music-hint{
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + 26px);
  transform: translateX(-50%);
  z-index: 59;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  background: rgba(59,15,26,0.72);
  border: 1px solid rgba(255,217,222,0.3);
  backdrop-filter: blur(6px);
  color: var(--blush);
  font-family: 'Jost', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.music-hint.show{ opacity: 1; animation: hint-bob 1.8s ease-in-out infinite; }
@keyframes hint-bob{ 0%,100%{ transform: translateX(-50%) translateY(0); } 50%{ transform: translateX(-50%) translateY(-6px); } }

.ghost-btn{
  background: transparent; color: var(--blush);
  box-shadow: inset 0 0 0 1.5px rgba(255,217,222,0.5);
}
.ghost-btn:hover{ box-shadow: inset 0 0 0 1.5px var(--blush); }

.back-btn{
  position: fixed; bottom: calc(var(--safe-b) + 24px); right: calc(var(--safe-r) + 24px); z-index: 60;
  padding: 0.75rem 1.4rem; font-size: 0.95rem;
  touch-action: manipulation;
}

/* === FLOATING PARTICLES (hearts / sparks injected via JS) === */
.fx-heart, .fx-spark{
  position: fixed; pointer-events: none; z-index: 500; will-change: transform, opacity;
}

/* === RESPONSIVE === */
@media (max-width: 900px){
  .puzzles-wrapper{ grid-template-columns: 1fr; max-width: 380px; margin-inline: auto; gap: 2rem; }
}

@media (max-width: 480px){
  .puzzle-container{ padding: 1.4rem 0.85rem 6rem; }
  .puzzle-header{ margin-bottom: 1.4rem; }
  .progress-board{ margin-bottom: 1.6rem; }
  .icon-btn{ width: 40px; height: 40px; top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 12px); }
  .back-btn{ bottom: calc(var(--safe-b) + 16px); right: calc(var(--safe-r) + 16px); padding: 0.65rem 1.1rem; font-size: 0.88rem; }
  .win-buttons{ flex-direction: column; }
  .golden-btn{ width: 100%; justify-content:center; }
  .puzzle-frame{ padding: 0.4rem; }
  .puzzle-name{ font-size: 1.45rem; margin: 0.3rem 0 0.7rem; }
  .music-hint{ font-size: 0.74rem; padding: 0.5rem 0.9rem; }
}

@media (max-width: 360px){
  .puzzle-subtitle{ font-size: 0.95rem; }
  .progress-hearts{ font-size: 1.35rem; }
}

/* Focus visibility for keyboard users */
.puzzle-piece:focus-visible, .golden-btn:focus-visible, .icon-btn:focus-visible{
  outline: 2px solid var(--gold-bright);
}