/* ============================================================
   Gender Reveal Scratch Off — mobile-first
   ============================================================ */

:root {
  --kraft:        #c9a077;
  --kraft-dark:   #b98d63;
  --kraft-deep:   #a97d55;
  --pink:         #d4386d;
  --pink-soft:    #e8709a;
  --blue:         #6f95d6;
  --blue-soft:    #94b2e4;
  --ink:          #43301f;
  --white:        #ffffff;
  --silver-1:     #d8dade;
  --silver-2:     #b9bdc4;
  --silver-3:     #eceef1;

  --radius:       18px;
  --grid-line:    #ffffff;

  --font-script:  'Dancing Script', 'Snell Roundhand', 'Brush Script MT', cursive;
  --font-sans:    'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  /* Must be on the root as well as the body — on its own, body doesn't stop
     Chrome's pull-to-refresh. */
  overscroll-behavior: none;
}

body {
  font-family: var(--font-sans);
  background: #6d5a45;
  background-image:
    radial-gradient(circle at 20% 10%, #7d6950 0%, transparent 55%),
    radial-gradient(circle at 85% 90%, #5d4c39 0%, transparent 60%);
  color: #43301f;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ---------- Stage + card flip ---------- */

.stage {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(12px + env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
  perspective: 1600px;
}

/* The card halves are swapped at the midpoint of the flip rather than being
   two sides of a rotated box. That keeps the live game face at
   `transform: none`, so hit-testing and getBoundingClientRect stay exact —
   a 3D-rotated face reports mirrored geometry and breaks scratch input. */
/* Height comes from the padded stage box rather than a viewport unit, so the
   card can never total more than the screen once padding is added back on. */
.flipper {
  position: relative;
  width: 100%;
  max-width: 460px;
  /* The card is a fixed play surface — nothing inside it scrolls. Without
     this, a thumb that lands between the circles and drags down is read as a
     scroll gesture and fires pull-to-refresh, wiping a game in progress.
     Taps and the scratch pointer events are unaffected. */
  touch-action: none;
  height: min(780px, calc(
    100dvh - 24px
    - env(safe-area-inset-top, 0px)
    - env(safe-area-inset-bottom, 0px)
  ));
}

.face {
  position: absolute;
  inset: 0;
}

.face[hidden] { display: none; }

.flipper.flip-out { animation: flipOut 300ms ease-in forwards; }
.flipper.flip-in  { animation: flipIn 380ms cubic-bezier(.2, .8, .3, 1); }

/* While the card is mid-rotation its geometry is transformed, so a touch
   would map to the wrong spot on the foil. Ignore input until it settles. */
.flipper.flip-out,
.flipper.flip-in { pointer-events: none; }

@keyframes flipOut {
  from { transform: rotateY(0deg);   }
  to   { transform: rotateY(90deg);  }
}

@keyframes flipIn {
  from { transform: rotateY(-90deg); }
  to   { transform: rotateY(0deg);   }
}

/* ---------- The kraft paper card ---------- */

.card {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background-color: var(--kraft);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.42'/%3E%3C/svg%3E"),
    linear-gradient(160deg, #d3ad86 0%, var(--kraft) 42%, var(--kraft-dark) 100%);
  background-blend-mode: soft-light, normal;
  box-shadow:
    0 22px 50px -12px rgba(0, 0, 0, .55),
    0 2px 0 rgba(255, 255, 255, .18) inset,
    0 -2px 0 rgba(0, 0, 0, .10) inset;
}

/* ---------- Star garland (left edge) ----------
   The moon is a true crescent: one arc of the outer circle (R=19) and one of
   the inner circle (r=16, centre offset d=5.5), meeting at the two points
   where the circles cross. Drawing it as two stacked circles instead only
   works while the inner one stays fully inside the outer one — once it pokes
   out, whichever fill rule you pick paints the escaping sliver and the
   crescent turns into a ring.

   To reshape it, recompute the meeting points rather than nudging the numbers:
     x = (d² - r² + R²) / 2d,  y = ±√(R² - x²)
   then  M x,-y  A R,R 0 1,0  x,y  A r,r 0 1,1  x,-y  Z
   Bigger r or d = thinner crescent with more open horns. */

.garland {
  position: absolute;
  top: 0;
  left: 0;
  width: 30%;
  max-width: 130px;
  height: 100%;
  pointer-events: none;
  opacity: .95;
  background-repeat: no-repeat;
  background-position: left top;
  background-size: auto 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 70 500' preserveAspectRatio='xMinYMin meet'%3E%3Cg fill='%23ffffff'%3E%3Crect x='0' y='73' width='30' height='2.4' rx='1.2'/%3E%3Crect x='0' y='121' width='20' height='2.4' rx='1.2'/%3E%3Crect x='0' y='163' width='27' height='2.4' rx='1.2'/%3E%3Crect x='0' y='209' width='16' height='2.4' rx='1.2'/%3E%3Crect x='0' y='255' width='29' height='2.4' rx='1.2'/%3E%3Crect x='0' y='301' width='19' height='2.4' rx='1.2'/%3E%3Crect x='0' y='347' width='26' height='2.4' rx='1.2'/%3E%3Crect x='0' y='393' width='15' height='2.4' rx='1.2'/%3E%3Crect x='0' y='441' width='30' height='2.4' rx='1.2'/%3E%3Crect x='0' y='485' width='21' height='2.4' rx='1.2'/%3E%3Cpath transform='translate(36,74) scale(11)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(26,122) scale(7)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(34,164) scale(9.5)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(22,210) scale(6)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(36,256) scale(10.5)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(25,302) scale(6.5)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(33,348) scale(9)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(21,394) scale(6)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(37,442) scale(11)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(27,486) scale(7.5)' d='M0-1C.12-.34.34-.12 1 0 .34.12.12.34 0 1-.12.34-.34.12-1 0-.34-.12-.12-.34 0-1Z'/%3E%3Cpath transform='translate(30,33) rotate(-28)' d='M12.3,-14.49A19,19 0 1,0 12.3,14.49A16,16 0 1,1 12.3,-14.49Z'/%3E%3C/g%3E%3C/svg%3E");
}

/* On the game side the garland is cropped to the header band so it never
   crowds the title or bleeds into the grid. */
.garland--small {
  width: 62px;
  max-width: 22%;
  height: 30%;
  background-size: auto 620px;
  opacity: .85;
}

/* ---------- FRONT ---------- */

.card--front { padding: 24px 20px 20px; }

.front-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 3vh, 26px);
  padding-left: 14%;
  text-align: center;
}

.script-title {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--white);
  font-family: var(--font-script);
  font-weight: 700;
  line-height: 1.02;
  font-size: clamp(2.6rem, 12vw, 4rem);
  text-shadow: 0 2px 10px rgba(90, 60, 30, .28);
}

.script-title__small { font-size: .86em; }

.footprint {
  width: clamp(140px, 44vw, 210px);
  filter: drop-shadow(0 6px 14px rgba(90, 55, 25, .3));
}

.footprint svg { width: 100%; height: auto; display: block; }

.foot-top    { fill: var(--pink); }
.foot-bottom { fill: var(--blue); }
.toe         { fill: var(--pink); }
.foot-outline,
.toe {
  stroke: var(--white);
  stroke-width: 4;
  stroke-dasharray: 9 9;
  stroke-linecap: round;
}
.foot-outline { fill: none; }

.hearts { display: flex; gap: 12px; }

.hearts span {
  width: 15px;
  height: 15px;
  background: var(--white);
  clip-path: path("M7.5 14.5C3 11 0 8.6 0 5.6 0 3.1 1.9 1.2 4.3 1.2c1.3 0 2.5.6 3.2 1.6.7-1 1.9-1.6 3.2-1.6C13.1 1.2 15 3.1 15 5.6c0 3-3 5.4-7.5 8.9z");
  opacity: .95;
}

.begin-btn {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 14px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--white);
  color: #8a5b3c;
  font-family: var(--font-sans);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 8px 20px -6px rgba(60, 35, 15, .5);
  transition: transform 160ms ease, box-shadow 160ms ease;
  animation: nudge 2.6s ease-in-out infinite;
}

.begin-btn svg { width: 18px; height: 18px; }
.begin-btn:active { transform: scale(.96); box-shadow: 0 4px 12px -6px rgba(60, 35, 15, .5); }

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

/* ---------- BACK / GAME ---------- */

.card--back {
  padding: clamp(16px, 3.4vh, 26px) clamp(14px, 4vw, 22px) clamp(14px, 2.6vh, 22px);
  gap: clamp(10px, 2vh, 18px);
}

.game-head {
  position: relative;
  z-index: 1;
  padding-left: 20%;
}

.boy-girl {
  margin: 0 0 8px;
  font-size: clamp(1.7rem, 8vw, 2.5rem);
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1;
}

.boy-girl .boy  { color: var(--blue);  }
.boy-girl .girl { color: var(--pink);  }
.boy-girl .or   { color: var(--white); font-weight: 400; font-size: .62em; letter-spacing: .18em; vertical-align: middle; }

.instructions {
  margin: 0;
  max-width: 34ch;
  color: var(--white);
  font-size: clamp(.62rem, 2.8vw, .74rem);
  font-weight: 300;
  letter-spacing: .13em;
  line-height: 1.75;
  text-transform: uppercase;
  opacity: .95;
}

.grid-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  width: min(100%, 52vh);
  max-height: 100%;
  aspect-ratio: 1;
  padding: 5px;
  background: var(--grid-line);
  border-radius: 10px;
  box-shadow: 0 10px 26px -14px rgba(50, 30, 12, .8);
}

/* ---------- A single scratch cell ---------- */

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background:
    linear-gradient(150deg, #d3ad86, var(--kraft) 60%, var(--kraft-dark));
  border-radius: 4px;
  overflow: hidden;
  isolation: isolate;
}

.cell:focus-visible {
  outline: 3px solid #fff8;
  outline-offset: -3px;
}

/* The symbol sits under the foil at full strength so scratching uncovers it
   progressively, the way a real card does. The pop only celebrates the
   moment the last of the foil comes off. */
.symbol {
  width: 56%;
  height: 56%;
  display: block;
}

.cell.is-revealed .symbol {
  animation: symbolPop 440ms cubic-bezier(.2, 1.4, .4, 1);
}

@keyframes symbolPop {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.16); }
  100% { transform: scale(1);    }
}

.symbol.is-pink { fill: var(--pink); filter: drop-shadow(0 2px 4px rgba(150, 30, 70, .28)); }
.symbol.is-blue { fill: var(--blue); filter: drop-shadow(0 2px 4px rgba(30, 60, 140, .25)); }

.scratch {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  border-radius: 50%;
  touch-action: none;
  cursor: grab;
  opacity: 1;
  transition: opacity 420ms ease;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, .28),
    inset 0 1px 1px rgba(255, 255, 255, .6);
}

.cell.is-revealed .scratch {
  opacity: 0;
  pointer-events: none;
}

/* Winning line highlight */
.cell.is-win::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 4px;
  box-shadow: inset 0 0 0 3px var(--pink), 0 0 18px rgba(212, 56, 109, .55);
  animation: winPulse 1.1s ease-in-out 3;
}

@keyframes winPulse {
  0%, 100% { opacity: .35; }
  50%      { opacity: 1; }
}

/* ---------- Game footer ---------- */

.game-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-left: 2px;
}

.hint {
  margin: 0;
  color: rgba(255, 255, 255, .92);
  font-size: .64rem;
  font-weight: 400;
  letter-spacing: .1em;
  text-transform: uppercase;
  transition: opacity 300ms ease;
}

.reset-btn {
  flex: none;
  padding: 9px 16px;
  border: 1.5px solid rgba(255, 255, 255, .7);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-family: var(--font-sans);
  font-size: .6rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 180ms ease, transform 140ms ease;
}

.reset-btn:active { transform: scale(.95); background: rgba(255, 255, 255, .18); }

/* ---------- Reveal overlay ---------- */

.reveal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 236, 243, .97), rgba(244, 194, 214, .97));
  animation: fadeIn 420ms ease both;
}

.reveal[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.reveal-inner {
  position: relative;
  text-align: center;
  animation: popIn 620ms cubic-bezier(.2, 1.3, .35, 1) both 120ms;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(.8) translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.reveal-kicker {
  margin: 0;
  color: var(--pink);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .34em;
  text-transform: uppercase;
  opacity: .8;
}

.reveal-title {
  margin: 0;
  color: var(--pink);
  font-family: var(--font-script);
  font-weight: 700;
  font-size: clamp(4.4rem, 26vw, 8rem);
  line-height: .96;
  text-shadow: 0 6px 24px rgba(212, 56, 109, .3);
}

.reveal-hearts {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 14px;
}

.reveal-hearts svg {
  width: 22px;
  height: 22px;
  fill: var(--pink-soft);
  animation: beat 1.6s ease-in-out infinite;
}

.reveal-hearts svg:nth-child(2) { animation-delay: .2s; }
.reveal-hearts svg:nth-child(3) { animation-delay: .4s; }

@keyframes beat {
  0%, 100% { transform: scale(1); }
  35%      { transform: scale(1.22); }
}

.reveal-sub {
  margin: 0 auto 26px;
  max-width: 26ch;
  color: #9c4468;
  font-size: .82rem;
  font-weight: 400;
  line-height: 1.6;
}

.reveal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn {
  padding: 13px 22px;
  border-radius: 999px;
  border: 1.5px solid var(--pink);
  font-family: var(--font-sans);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease;
}

.btn:active { transform: scale(.95); }
.btn--solid { background: var(--pink); color: #fff; }
.btn--ghost { background: transparent; color: var(--pink); }

/* ---------- Motion / small screens ---------- */

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

@media (max-height: 640px) {
  .instructions { display: none; }
}

@media (min-width: 620px) and (min-height: 700px) {
  .flipper { max-width: 520px; }
}
