/* ============================================================
   MILLER THE FARMER — Baby Barn (css/babybarn.css)
   Seedlings (ages 0–2) lap-time mode, built by js/babybarn.js.
   Calm and high-contrast: one huge friend on a cream moon over a
   deep night-blue barnyard; slow, soft motion; no text needed.
   z-index 62: above the 3D overlays (58) and confetti (60).
   ============================================================ */

.bb-overlay {
  --bb-night: #142a4a;
  --bb-night-2: #0d1d36;
  --bb-moon: var(--cream);
  --bb-ring: var(--tractor-yellow);
  position: fixed; inset: 0; z-index: 62;
  display: flex; flex-direction: column;
  background: radial-gradient(120% 80% at 50% 30%, var(--bb-night) 0%, var(--bb-night-2) 100%);
  color: var(--bb-moon);
  font-family: var(--font-display);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.bb-overlay[hidden] { display: none; }
body.bb-lock { overflow: hidden !important; }

/* soft twinkling stars (decoration only) + the book's rolling hills at night */
.bb-sky { position: absolute; inset: 0; pointer-events: none; }
.bb-overlay::before {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 30%; pointer-events: none;
  background: linear-gradient(180deg, var(--hill-shadow), #24451f);
  -webkit-mask: var(--mask-hills-back) top / 100% 90px no-repeat, linear-gradient(#000, #000) 0 89px / 100% 100% no-repeat;
  mask: var(--mask-hills-back) top / 100% 90px no-repeat, linear-gradient(#000, #000) 0 89px / 100% 100% no-repeat;
  opacity: .85;
}
.bb-sky i { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--bb-ring); opacity: .55; animation: bbTwinkle 6s ease-in-out infinite; }
.bb-sky i:nth-child(1) { top: 9%; left: 12%; }
.bb-sky i:nth-child(2) { top: 16%; left: 82%; animation-delay: 1.5s; }
.bb-sky i:nth-child(3) { top: 30%; left: 6%; animation-delay: 3s; width: 6px; height: 6px; }
.bb-sky i:nth-child(4) { top: 6%; left: 52%; animation-delay: 2.2s; }
.bb-sky i:nth-child(5) { top: 38%; left: 92%; animation-delay: 4s; width: 6px; height: 6px; }
.bb-sky i:nth-child(6) { top: 70%; left: 4%; animation-delay: .8s; width: 5px; height: 5px; }
.bb-sky i:nth-child(7) { top: 64%; left: 95%; animation-delay: 2.8s; width: 5px; height: 5px; }
@keyframes bbTwinkle { 0%, 100% { opacity: .25; } 50% { opacity: .75; } }

/* grown-up exit — top corner, big, press-and-hold */
.bb-exit {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right)); z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 84px; height: 84px; border: 3px solid rgba(248, 242, 214, .5); border-radius: 50%;
  background: rgba(248, 242, 214, .14); color: var(--bb-moon); cursor: pointer;
  font-family: var(--font-body); font-weight: 800; font-size: 11px;
  justify-content: center;
}
.bb-exit svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 5; stroke-linecap: round; }
.bb-exit-label { line-height: 1; opacity: .9; }
.bb-exit-ring { position: absolute; inset: 0; border-radius: 50%; border: 4px solid transparent; }
.bb-exit.holding .bb-exit-ring { border-color: var(--bb-ring); animation: bbHold .9s linear forwards; }
@keyframes bbHold { from { clip-path: inset(100% 0 0 0); } to { clip-path: inset(0 0 0 0); } }
.bb-exit:focus-visible, .bb-round:focus-visible, .bb-friend:focus-visible, .bb-barn:focus-visible {
  outline: 5px solid var(--bb-ring); outline-offset: 6px;
}

/* stage — the friend fills it */
.bb-stage {
  flex: 1; min-height: 0; position: relative;
  display: grid; place-items: center; padding: 96px 16px 8px;
}

.bb-friend {
  border: 0; padding: 0; background: none; cursor: pointer;
  width: min(86vw, 62vh, 560px); aspect-ratio: 1;
  border-radius: 50%;
  transition: transform .5s ease, opacity .5s ease;
}
.bb-disc {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: var(--bb-moon);
  box-shadow: 0 0 0 10px rgba(255, 226, 122, .9), 0 0 0 22px rgba(255, 226, 122, .18), 0 24px 60px rgba(0, 0, 0, .45);
  overflow: hidden; display: grid; place-items: center;
}
.bb-disc img { width: 88%; height: 88%; object-fit: contain; pointer-events: none; }

/* slow soft bounce on hello */
.bb-bounce { animation: bbBounce 1.1s cubic-bezier(.34, 1.4, .64, 1); }
@keyframes bbBounce {
  0% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-5%) scale(1.06, .97); }
  60% { transform: translateY(0) scale(.98, 1.02); }
  100% { transform: translateY(0) scale(1); }
}
/* gentle slide between friends */
.bb-friend.bb-out-l { transform: translateX(-30%) scale(.85); opacity: 0; }
.bb-friend.bb-out-r { transform: translateX(30%) scale(.85); opacity: 0; }
.bb-friend.bb-in-r { transform: translateX(30%) scale(.85); opacity: 0; transition: none; }
.bb-friend.bb-in-l { transform: translateX(-30%) scale(.85); opacity: 0; transition: none; }

/* peekaboo barn */
.bb-barn {
  border: 0; padding: 0; background: none; cursor: pointer;
  width: min(84vw, 58vh, 520px);
  display: flex; flex-direction: column; align-items: center;
}
.bb-barn-roof {
  width: 100%; aspect-ratio: 2.4; background: var(--barn-dark);
  filter: drop-shadow(0 -4px 0 #fff);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  margin-bottom: -2px;
}
.bb-barn-body {
  position: relative; width: 84%; aspect-ratio: 1.05;
  background: repeating-linear-gradient(180deg, var(--barn-red) 0 22px, #b3241f 22px 25px); border-radius: 0 0 14px 14px;
  border: 6px solid #fff; border-top: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  display: grid; place-items: center;
  perspective: 900px;
}
.bb-barn-inside {
  position: relative; width: 74%; height: 80%; margin-top: 12%;
  background: var(--bb-moon); border-radius: 10px 10px 0 0; overflow: hidden;
  display: grid; place-items: center;
}
.bb-barn-inside img { width: 96%; height: 96%; object-fit: contain; pointer-events: none; }
.bb-door {
  position: absolute; top: calc(12% + 10%); bottom: 0; width: 37%;
  background: #b3241f; /* the book's barn doors: red with a white X brace */
  background-image:
    linear-gradient(to top right, transparent calc(50% - 6px), #fff calc(50% - 6px), #fff calc(50% + 6px), transparent calc(50% + 6px)),
    linear-gradient(to top left, transparent calc(50% - 6px), #fff calc(50% - 6px), #fff calc(50% + 6px), transparent calc(50% + 6px));
  border: 10px solid #fff; box-sizing: border-box;
  transition: transform 1s ease-in-out;
  backface-visibility: hidden;
}
.bb-door-l { left: 13%; transform-origin: left center; border-radius: 10px 0 0 0; }
.bb-door-r { right: 13%; transform-origin: right center; border-radius: 0 10px 0 0; }
.bb-barn.open .bb-door-l { transform: rotateY(-105deg); }
.bb-barn.open .bb-door-r { transform: rotateY(105deg); }

/* bottom bar — three big round buttons */
.bb-bar {
  display: flex; justify-content: center; align-items: center; gap: clamp(18px, 7vw, 56px);
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
  position: relative; z-index: 2;
}
.bb-round {
  width: 88px; height: 88px; border-radius: 50%; border: 4px solid var(--outline); cursor: pointer;
  background: var(--bb-ring); color: var(--bb-night-2);
  display: grid; place-items: center;
  box-shadow: 0 6px 0 var(--outline);
}
.bb-round:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0, 0, 0, .3); }
.bb-round svg { width: 50px; height: 50px; fill: none; stroke: currentColor; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.bb-round .bb-ic-fill { fill: var(--barn-red); stroke: var(--bb-night-2); stroke-width: 3; }
.bb-round .bb-ic-door { fill: var(--bb-moon); stroke: var(--bb-night-2); stroke-width: 3; }
.bb-round .bb-ic-x { stroke: var(--barn-red); stroke-width: 2.5; }
.bb-round .bb-ic-img { width: 78%; height: 78%; object-fit: contain; pointer-events: none; }
.bb-mode { background: var(--bb-moon); }
.bb-hide { visibility: hidden; }
.bb-overlay .hidden { display: none !important; }

.bb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 480px) {
  .bb-stage { padding-top: 92px; }
  .bb-round { width: 76px; height: 76px; }
  .bb-round svg { width: 42px; height: 42px; }
  .bb-exit { width: 72px; height: 72px; }
}
@media (max-height: 560px) {
  .bb-stage { padding-top: 12px; }
  .bb-round { width: 68px; height: 68px; }
}

@media (prefers-reduced-motion: reduce) {
  .bb-sky i { animation: none; }
  .bb-bounce { animation: bbPulse .6s ease; }
  @keyframes bbPulse { 50% { filter: brightness(1.08); } }
  .bb-friend, .bb-door { transition: none; }
  .bb-exit.holding .bb-exit-ring { animation: none; clip-path: none; }
}
