/* ==========================================================================
   Three in a Row — a gender reveal board

   A nursery, not a game room: warm paper, butter and sage. Both accents are
   deliberately gender-neutral, so nothing on the page hints at the answer.
   Rose appears for the first time only when the third square lands.
   ========================================================================== */

:root {
  --paper:      #fdfbf7;
  --paper-warm: #f7f1e6;
  --butter:     #f3d999;
  --butter-dp:  #d9b25e;
  --sage:       #a8bfa8;
  --sage-deep:  #6b8a71;
  --ink:        #4a4038;
  --ink-soft:   #8a7e72;
  --white:      #ffffff;

  --rose:       #e8608f;
  --rose-deep:  #b23a6b;
  --rose-pale:  #ffd7e4;
  --rose-ink:   #7c1f42;

  /* Baloo 2 for display: a chunky rounded face with real bounce — the fun is
     in the type, so the layout can stay calm. Nunito carries everything else;
     its rounded terminals match Baloo without competing with it. Both are
     embedded in fonts.css, so nothing depends on the network. */
  --display: "Baloo 2", Candara, "Trebuchet MS", sans-serif;
  --label:   "Nunito", "Segoe UI", "Trebuchet MS", sans-serif;
  --body:    "Nunito", "Segoe UI", "Trebuchet MS", sans-serif;

  --board-size: min(68vmin, 30rem);
  --ease: cubic-bezier(.2, .8, .25, 1);

  color-scheme: light;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  /* min-height, not height: the background must grow with the content rather
     than tile when a short viewport pushes the page past 100%. */
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;

  background-color: var(--paper);
  background-image:
    /* nursery polka dots */
    radial-gradient(rgba(168, 191, 168, .22) 1.5px, transparent 1.6px),
    /* soft corner washes */
    radial-gradient(70% 55% at 8% 4%, rgba(243, 217, 153, .4), transparent 70%),
    radial-gradient(65% 50% at 96% 96%, rgba(168, 191, 168, .32), transparent 72%),
    linear-gradient(180deg, var(--white), var(--paper-warm));
  background-size: 26px 26px, auto, auto, auto;
  background-position: 0 0, 0 0, 0 0, 0 0;
  background-attachment: fixed;
}

/* Faint paper tooth, inlined so nothing loads from the network. */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .14;
  mix-blend-mode: multiply;
  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='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

/* ---------- layout ------------------------------------------------------- */

.stage {
  position: relative;
  z-index: 2;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.75rem, 4vh, 3rem);
  padding: clamp(2rem, 6vh, 4.5rem) 1.25rem clamp(3.5rem, 8vh, 5rem);
  text-align: center;
}

.masthead {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .85rem;
  max-width: 34rem;
  animation: rise .9s var(--ease) both;
}

.marquee {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.9rem, 6vw, 3.3rem);
  /* Baloo has deep descenders; a tighter leading would crop them on wrap. */
  line-height: 1.18;
  letter-spacing: 0;
  text-wrap: balance;
  color: var(--ink);
}

/* Keeps the surname whole instead of breaking at its hyphen. */
.nowrap { white-space: nowrap; }

/* Butter flourish under the title — a stitched-ribbon rule. */
.marquee-rule {
  width: clamp(2.5rem, 9vw, 4rem);
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--butter-dp), transparent);
}

.lede {
  margin: 0;
  max-width: 29rem;
  font-size: clamp(.98rem, 1.6vw, 1.06rem);
  line-height: 1.7;
  color: var(--ink-soft);
  text-wrap: pretty;
}

.table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.15rem;
}

/* ---------- the board --------------------------------------------------- */

.frame {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: clamp(.7rem, 1.9vmin, 1.15rem);
  border-radius: 24px;
  background: var(--white);
  box-shadow:
    0 0 0 1px rgba(168, 191, 168, .55),
    0 1px 0 1px rgba(255, 255, 255, .9),
    0 26px 50px -24px rgba(74, 64, 56, .3),
    0 8px 18px -12px rgba(74, 64, 56, .16);
  animation: settle 1.1s var(--ease) .15s both;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(.45rem, 1.3vmin, .75rem);
  width: 100%;
  height: 100%;
}

.cell {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: none;
  cursor: pointer;
  perspective: 900px;
  animation: drop .55s var(--ease) both;
  animation-delay: calc(.45s + var(--i) * .045s);
}

.cell:disabled { cursor: default; }

.cell-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .72s var(--ease);
  border-radius: 16px;
}

.cell.turned .cell-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 16px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Face down: a butter-and-sage checkerboard, like a nursery quilt. Tokens are
   swapped by parity so one set of rules paints both squares. Parity is
   independent of what is under the tile, so the pattern gives nothing away. */
.cell {
  --tile-1: #fbeed2;
  --tile-2: var(--butter);
  --tile-3: #eac884;
  --tile-edge: 214, 174, 90;
  --tile-cast: 122, 96, 44;
  --tile-num: #9a7b35;
}

.cell:nth-child(even) {
  --tile-1: #ebf3e7;
  --tile-2: #c6dac2;
  --tile-3: #aec9ab;
  --tile-edge: 122, 152, 128;
  --tile-cast: 62, 86, 66;
  --tile-num: #587a5f;
}

.face-back {
  background: linear-gradient(165deg, var(--tile-1), var(--tile-2) 62%, var(--tile-3));
  box-shadow:
    inset 0 0 0 1px rgba(var(--tile-edge), .55),
    inset 0 2px 0 rgba(255, 255, 255, .7),
    0 4px 10px -6px rgba(var(--tile-cast), .45);
  transition: box-shadow .3s ease, transform .3s var(--ease);
}

.numeral {
  font-family: var(--label);
  font-weight: 700;
  font-size: clamp(.72rem, 2vmin, .95rem);
  letter-spacing: .06em;
  color: var(--tile-num);
  opacity: .6;
  transition: opacity .3s ease;
}

.cell:not(.turned):hover .face-back,
.cell:not(.turned):focus-visible .face-back {
  box-shadow:
    inset 0 0 0 1px rgba(var(--tile-edge), .9),
    inset 0 2px 0 rgba(255, 255, 255, .85),
    0 10px 18px -8px rgba(var(--tile-cast), .55);
  transform: translateY(-3px);
}

.cell:not(.turned):hover .numeral { opacity: .9; }

.cell:focus-visible { outline: 3px solid var(--sage-deep); outline-offset: 4px; }

/* Face up: a clean white card holding the keepsake. */
.face-front {
  transform: rotateY(180deg);
  background: linear-gradient(165deg, var(--white), #f9f4ec);
  box-shadow:
    inset 0 0 0 1px rgba(168, 191, 168, .5),
    inset 0 -3px 8px rgba(74, 64, 56, .06);
}

.mark {
  opacity: 0;
  transform: scale(1.25);
}

/* Sized so the two read at the same optical weight: the bear is wide and the
   bottle is tall, so matching their heights matters more than their boxes. */
.mark-bear   { width: 70%; height: 70%; }
.mark-bottle { width: 66%; height: 66%; }

/* Stamped in only once the tile has finished turning. */
.cell.turned .mark { animation: stamp .42s cubic-bezier(.2, .9, .3, 1.35) .32s forwards; }

/* The three that made the line give a little hop. Must come after the stamp
   rule (equal specificity) and must hold opacity, or the mark would drop back
   to its hidden base state when the animation ends. */
.cell.win .mark { animation: cheer .95s ease .12s forwards; }

.cell.win .face-front {
  background: linear-gradient(165deg, var(--white), var(--rose-pale));
  box-shadow:
    inset 0 0 0 1px rgba(178, 58, 107, .35),
    0 0 26px -2px rgba(232, 96, 143, .55);
}

/* Hidden until the win: the line's endpoints start at 0,0, and a zero-length
   round-cap stroke paints as a rose dot in the corner — which gives the game
   away before anyone has turned a square. */
.strike {
  position: absolute;
  inset: clamp(.7rem, 1.9vmin, 1.15rem);
  pointer-events: none;
  overflow: visible;
  visibility: hidden;
}

.strike.drawn { visibility: visible; }

/* Stroke and dashes both stay in viewBox units — a non-scaling-stroke would
   put the dash pattern in screen px and tear the line into gaps. */
.strike line {
  stroke: var(--rose);
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 0 2px rgba(232, 96, 143, .55));
  stroke-dasharray: 160;
  stroke-dashoffset: 160;
}

.strike.drawn line { animation: strike .6s var(--ease) forwards; }

/* ---------- status ------------------------------------------------------ */

.tally {
  margin: 0;
  font-family: var(--label);
  font-weight: 700;
  font-size: .74rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--sage-deep);
}

.hint {
  margin: 0;
  font-size: .92rem;
  font-style: italic;
  color: var(--ink-soft);
  opacity: .8;
}

/* ---------- the reveal -------------------------------------------------- */

.reveal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 2rem 1.5rem;
  text-align: center;
  background:
    /* nursery dots, echoing the board page */
    radial-gradient(rgba(255, 255, 255, .5) 2px, transparent 2.2px),
    radial-gradient(90% 70% at var(--origin-x, 50%) var(--origin-y, 50%),
      rgba(255, 250, 252, .97) 0%,
      var(--rose-pale) 38%,
      var(--rose) 78%,
      var(--rose-deep) 100%);
  background-size: 30px 30px, auto;
  clip-path: circle(0% at var(--origin-x, 50%) var(--origin-y, 50%));
  /* Stays visible for the full shrink on the way out, then hides. */
  transition: clip-path 1.15s var(--ease), visibility 0s linear 1.15s;
  visibility: hidden;
}

.reveal.open {
  visibility: visible;
  clip-path: circle(150% at var(--origin-x, 50%) var(--origin-y, 50%));
  transition: clip-path 1.15s var(--ease), visibility 0s linear 0s;
}

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

/* A white card with a blanket-stitch outline, the bear peeking over the top. */
.reveal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .95rem;
  max-width: 33rem;
  padding: clamp(1.5rem, 4vw, 2.4rem) clamp(1.5rem, 5vw, 3rem) clamp(1.75rem, 4vw, 2.5rem);
  border-radius: 34px;
  background: rgba(255, 253, 254, .93);
  box-shadow:
    0 0 0 1px rgba(178, 58, 107, .14),
    0 26px 60px -26px rgba(124, 31, 66, .5);
}

/* The stitch is an inset dashed ring rather than a border, so it never
   fights the card's own radius or padding. */
.reveal-card::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 2.5px dashed rgba(232, 96, 143, .55);
  border-radius: 26px;
  pointer-events: none;
}

.reveal-badge {
  position: relative;
  z-index: 1; /* the absolutely-positioned stitch would otherwise paint over it */
  display: grid;
  place-items: center;
  width: clamp(6.5rem, 22vw, 8.5rem);
  aspect-ratio: 1;
  margin-top: calc(-1 * clamp(4.5rem, 15vw, 6rem));
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, var(--white), var(--rose-pale));
  box-shadow:
    0 0 0 5px rgba(255, 253, 254, .95),
    0 0 0 7px rgba(232, 96, 143, .3),
    0 14px 26px -14px rgba(124, 31, 66, .5);
}

.reveal-badge .mark {
  width: 74%;
  height: 74%;
  opacity: 1;
  transform: none;
  animation: bob 2.6s ease-in-out infinite alternate;
}

.reveal-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  /* Capped so "It's a Girl" stays on one line inside the card. */
  font-size: clamp(2.6rem, 9.5vw, 5.3rem);
  line-height: 1.1;
  letter-spacing: 0;
  color: var(--rose-ink);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 .26em;
  text-shadow: 0 2px 0 rgba(255, 255, 255, .45);
}

.reveal-title:focus-visible { outline: 3px solid var(--rose-ink); outline-offset: 12px; }

.reveal-title span {
  display: inline-block;
  transform: translateY(115%);
  opacity: 0;
}

.replay {
  margin-top: .9rem;
  padding: .85rem 1.7rem;
  font-family: var(--label);
  font-weight: 700;
  font-size: .72rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: #fff8fa;
  background: var(--rose-ink);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  opacity: 0;
  transition: background .25s ease, transform .25s var(--ease);
}

.replay:hover { background: #5f1633; transform: translateY(-2px); }
.replay:focus-visible { outline: 3px solid #fff8fa; outline-offset: 3px; }

/* Staged entrance once the bloom has spread: the three words rise in turn,
   then the reset button. */
.reveal.open .reveal-title span { animation: lift .85s var(--ease) forwards; }
.reveal.open .reveal-title span:nth-child(1) { animation-delay: .55s; }
.reveal.open .reveal-title span:nth-child(2) { animation-delay: .65s; }
.reveal.open .reveal-title span:nth-child(3) { animation-delay: .75s; }
.reveal.open .replay { animation: fade .8s ease 1.35s forwards; }

/* Board softens and pulls back behind the bloom. */
.stage { transition: filter .8s ease, transform .8s var(--ease), opacity .8s ease; }
body.revealed .stage { filter: blur(3px) saturate(.75); transform: scale(.96); opacity: .45; }

/* ---------- sound toggle ----------------------------------------------- */

.sound {
  position: fixed;
  z-index: 50;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .85rem;
  background: rgba(255, 255, 255, .82);
  border: 1px solid rgba(168, 191, 168, .7);
  border-radius: 999px;
  color: var(--sage-deep);
  font-family: var(--label);
  font-weight: 700;
  font-size: .64rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 6px 14px -10px rgba(74, 64, 56, .5);
  transition: border-color .25s ease, color .25s ease, opacity .5s ease;
}

/* Nothing sage belongs on top of the reveal. */
body.revealed .sound { opacity: 0; pointer-events: none; }

.sound:hover { border-color: var(--sage-deep); color: var(--ink); }
.sound:focus-visible { outline: 3px solid var(--sage-deep); outline-offset: 3px; }

.sound-icon {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.sound[aria-pressed="false"] .sound-icon {
  background: none;
  border: 1.5px solid currentColor;
}

/* ---------- motion ----------------------------------------------------- */

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

@keyframes settle {
  from { opacity: 0; transform: translateY(22px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

@keyframes drop {
  from { opacity: 0; transform: translateY(-10px) scale(.94); }
  to   { opacity: 1; transform: none; }
}

/* Pressed in like a rubber stamp, with a little overshoot. */
@keyframes stamp {
  0%   { opacity: 0; transform: scale(1.3) rotate(-5deg); }
  55%  { opacity: 1; transform: scale(.94) rotate(1.5deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes cheer {
  0%   { opacity: 1; transform: none; }
  22%  { opacity: 1; transform: translateY(-11%) scale(1.09) rotate(-3deg); }
  48%  { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
  70%  { opacity: 1; transform: translateY(-5%) scale(1.04) rotate(2deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes bob {
  from { transform: translateY(0) rotate(-2deg); }
  to   { transform: translateY(-7%) rotate(2deg); }
}

@keyframes strike {
  to { stroke-dashoffset: 0; }
}

@keyframes fade {
  to { opacity: 1; }
}

@keyframes lift {
  from { transform: translateY(115%); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .masthead,
  .frame,
  .cell { animation: none; opacity: 1; transform: none; }

  .cell-inner { transition: none; }
  .cell.turned .cell-inner { transform: none; }
  .face-back { opacity: 1; }
  .cell.turned .face-back { opacity: 0; }
  .face-front { transform: none; }
  .cell:not(.turned) .face-front { opacity: 0; }

  .mark { opacity: 1; transform: none; }
  .cell.turned .mark,
  .cell.win .mark,
  .reveal-badge .mark { animation: none; }

  .strike line { stroke-dashoffset: 0; }
  .strike.drawn line { animation: none; }

  .reveal { transition: none; }
  .stage { transition: none; }

  .reveal.open .replay { animation: none; opacity: 1; }
  .reveal.open .reveal-title span { animation: none; opacity: 1; transform: none; }
}

/* Short viewports: shrink the board rather than scrolling the page. */
@media (max-height: 720px) {
  :root { --board-size: min(58vmin, 24rem); }
  .lede { display: none; }
}
