/* Bed Time (tricky letters): a bedroom at night. The bed spells "bed" along the bottom; the animal stands
   on the middle of the bed holding up its pillow; the left half of the screen is the head end (b), the
   right half the foot end (d). The room is a size container: everything is placed from the bed's width
   (--bw), so it fits any screen. */
.game.bedtime { background: #2a2050; }
.bedtime button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.bedtime .game-top { padding-top: 5px; padding-bottom: 5px; }
.bedtime .bt-back { min-height: 56px; white-space: nowrap; }
.bedtime .bt-room {
  flex: 1; min-height: 0; position: relative; overflow: hidden; container-type: size; user-select: none; -webkit-user-select: none;
  --bw: min(94cqw, 118cqh);                        /* the bed */
  --bh: calc(var(--bw) * .44);
  --bb: 2cqh;                                      /* how high its feet are */
  --mt: calc(var(--bb) + var(--bh) * .4864);       /* the mattress top, from the bottom */
  --gw: calc(var(--bw) * .19);                     /* the animal on the bed */
  --pw: clamp(140px, calc(var(--bw) * .3), 240px); /* its pillow */
  --pb: calc(var(--mt) + var(--gw) * .9);          /* the pillow's bottom edge */
}


/* ---------- the room ---------- */
.bedtime .bt-wall {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20px 20px, rgba(255, 255, 255, .07) 0 3px, transparent 4px) 0 0 / 60px 60px,
    radial-gradient(circle at 50px 50px, rgba(255, 255, 255, .05) 0 2px, transparent 3px) 0 0 / 60px 60px,
    linear-gradient(#3a2d78, #5b3f92 75%);
}
.bedtime .bt-floor {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--bb) + var(--bh) * .3); z-index: 0;
  background: radial-gradient(ellipse 46% 40% at 50% 62%, #e3a24f 0 70%, #c9873a 71% 76%, transparent 77%),
    repeating-linear-gradient(90deg, #7a4d2c 0 90px, #6a4226 90px 93px, #84552f 93px 180px);
  border-top: 5px solid var(--ink);
}
.bedtime .bt-lights { position: absolute; left: 2%; right: 2%; top: 0; height: 34px; display: flex; justify-content: space-between; pointer-events: none; }
.bedtime .bt-lights::before { content: ''; position: absolute; left: -2%; right: -2%; top: -14px; height: 34px; border-bottom: 3px solid #241845; border-radius: 0 0 50% 50% / 0 0 100% 100%; }
.bedtime .bt-lights i { position: relative; width: 12px; height: 16px; margin-top: 14px; border-radius: 50% 50% 45% 45%; background: var(--c); box-shadow: 0 0 10px var(--c), 0 0 2px #fff inset; animation: bt-bulb 2.4s ease-in-out var(--d) infinite alternate; }
.bedtime .bt-lights i:nth-child(odd) { margin-top: 20px; }
.bedtime .bt-lights i:nth-child(4n + 2) { margin-top: 24px; }
@keyframes bt-bulb { to { opacity: .55; box-shadow: 0 0 4px var(--c); } }
.bedtime .bt-frame { position: absolute; right: 6%; top: 10%; width: clamp(70px, 12cqw, 140px); border: 8px solid #c99258; border-radius: 6px; box-shadow: 0 0 0 3px var(--ink), 0 5px 0 rgba(0, 0, 0, .25); line-height: 0; transform: rotate(3deg); }
.bedtime .bt-frame svg { display: block; width: 100%; height: auto; }

/* the window: the moon rises and a star comes out for each one tucked in (gold if right the first time) */
.bedtime .bt-window {
  position: absolute; z-index: 1; left: 5%; top: 8%; width: clamp(120px, 21cqw, 230px); aspect-ratio: 1.2; box-sizing: border-box;
  border: 10px solid #c99258; border-radius: 14px; box-shadow: 0 0 0 4px var(--ink), 0 6px 0 rgba(0, 0, 0, .25); overflow: hidden; --p: 0;
}
.bedtime .bt-sky { position: absolute; inset: 0; background: linear-gradient(#0d143c, #26357f); }
.bedtime .bt-moon {
  position: absolute; width: 24%; aspect-ratio: 1; border-radius: 50%; background: #fff2bf; box-shadow: 0 0 18px rgba(255, 240, 180, .85), inset -6px -4px 0 rgba(220, 200, 140, .5);
  left: calc(10% + var(--p) * 56%); top: calc(58% - var(--p) * 46%); transition: left 1s ease, top 1s ease;
}
.bedtime .bt-star { position: absolute; font-style: normal; line-height: 1; color: #ffd23f; font-size: clamp(14px, 2.4cqw, 26px); text-shadow: 0 0 8px #ffd23f; transform: translate(-50%, -50%) scale(0); transition: transform .5s cubic-bezier(.2, 1.6, .4, 1); }
.bedtime .bt-star.on { transform: translate(-50%, -50%) scale(1); animation: bt-twinkle 2.2s ease-in-out .5s infinite alternate; }
.bedtime .bt-star.dim { color: #dfe3ff; text-shadow: 0 0 5px #fff; font-size: clamp(10px, 1.6cqw, 18px); }
@keyframes bt-twinkle { to { opacity: .6; } }
.bedtime .bt-pane { position: absolute; background: #c99258; }
.bedtime .bt-pane.v { left: 50%; top: 0; bottom: 0; width: 6px; margin-left: -3px; }
.bedtime .bt-pane.h { top: 50%; left: 0; right: 0; height: 6px; margin-top: -3px; }
.bedtime .bt-curtain { position: absolute; top: 0; bottom: 0; width: 15%; background: repeating-linear-gradient(90deg, #d0588a 0 6px, #b6436f 6px 12px); }
.bedtime .bt-curtain.l { left: 0; border-right: 3px solid var(--ink); }
.bedtime .bt-curtain.r { right: 0; border-left: 3px solid var(--ink); }

/* ---------- the bed ---------- */
.bedtime .bt-bed { position: absolute; z-index: 2; left: calc(50% - var(--bw) / 2); bottom: var(--bb); width: var(--bw); height: var(--bh); }
.bedtime .bt-bed-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.bedtime .bt-bed-back { z-index: 0; }
.bedtime .bt-sleepers { position: absolute; inset: 0; z-index: 1; }
.bedtime .bt-bed-front { z-index: 2; }
/* its b and its d light up when they're named (a glow behind, the letter above) */
.bedtime .bt-glow { position: absolute; z-index: 0; top: -18%; bottom: -8%; width: 40%; border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 214, 80, .8), rgba(255, 214, 80, 0)); opacity: 0; transition: opacity .3s; }
.bedtime .bt-glow.b { left: -10%; } .bedtime .bt-glow.d { right: -10%; }
.bedtime .bt-tag { position: absolute; z-index: 3; top: -28%; font-size: max(36px, calc(var(--bw) * .085)); font-weight: 700; line-height: 1; color: #ffd23f; -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); opacity: 0; transform: scale(.4); transition: opacity .25s, transform .3s cubic-bezier(.2, 1.6, .4, 1); pointer-events: none; }
.bedtime .bt-tag.b { left: 3.5%; } .bedtime .bt-tag.d { right: 3.5%; }
.bedtime .bt-bed.glow-b .bt-glow.b, .bedtime .bt-bed.glow-d .bt-glow.d { opacity: 1; }
.bedtime .bt-bed.glow-b .bt-tag.b, .bedtime .bt-bed.glow-d .bt-tag.d { opacity: 1; transform: none; }

/* the sleepers: heads on their pillows, eyes shut, breathing */
.bedtime .bt-sleeper { position: absolute; bottom: 35%; width: 17%; aspect-ratio: 1; transform: translateX(-50%); transition: left .45s ease; }
.bedtime .bt-spill { position: absolute; left: 4%; right: 4%; top: 49%; height: 30%; display: grid; place-items: center; background: #fffdf6; border: 3px solid var(--ink); border-radius: 40% / 50%; font-size: calc(var(--bw) * .03); font-weight: 700; color: #8a7fa0; }
.bedtime .bt-scrit { position: absolute; inset: 0; font-size: calc(var(--bw) * .17); line-height: 1; transform-origin: 50% 100%; animation: bt-breathe 3.2s ease-in-out infinite; }
.bedtime .bt-scrit .critter-svg { display: block; width: 100%; height: 100%; }
.bedtime .bt-sleeper.snuggle .bt-scrit { animation: bt-snuggle .7s ease-out, bt-breathe 3.2s ease-in-out .7s infinite; }
.bedtime .bt-sleeper .critter .cr-blink { animation: none; transform: scaleY(.12); }
.bedtime .bt-sleeper:nth-child(even) .bt-scrit { animation-delay: -1.4s; }
.bedtime .bt-z { position: absolute; right: 4%; top: -4%; font-style: normal; font-weight: 800; font-size: calc(var(--bw) * .03); color: #fff; text-shadow: 0 2px 0 var(--ink); opacity: 0; animation: bt-z 4s ease-in-out infinite; pointer-events: none; }
.bedtime .bt-sleeper.foot .bt-z { right: auto; left: 4%; }
.bedtime .bt-sleeper:nth-child(3n) .bt-z { animation-delay: 1.3s; } .bedtime .bt-sleeper:nth-child(3n + 1) .bt-z { animation-delay: 2.6s; }
@keyframes bt-breathe { 50% { transform: scale(1.03, .97); } }
@keyframes bt-snuggle { 0% { transform: translateY(-14%) scale(1.06); } 50% { transform: translateY(4%) scale(1.04, .92); } 100% { transform: none; } }
@keyframes bt-z { 0%, 60% { opacity: 0; transform: none; } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(10px, -26px) scale(1.5); } }

/* ---------- the animal on the bed, with its pillow ---------- */
.bedtime .bt-guest { position: absolute; z-index: 4; left: calc(50% - var(--gw) / 2); bottom: calc(var(--mt) - var(--gw) * .05); width: var(--gw); height: var(--gw); pointer-events: none; opacity: 0; }
.bedtime .bt-guest.show { opacity: 1; }
.bedtime .bt-animal { position: absolute; inset: 0; font-size: var(--gw); line-height: 1; transform-origin: 50% 100%; }
.bedtime .bt-animal .critter-svg { display: block; width: 100%; height: 100%; }
.bedtime .bt-guest.yawn .bt-animal { animation: bt-yawn 1.4s ease-in-out; }
@keyframes bt-yawn { 20% { transform: scale(1.04, .94); } 45% { transform: scale(.97, 1.07) rotate(-4deg); } 70% { transform: scale(1.02, .98) rotate(2deg); } }
.bedtime .bt-pillow, .bedtime .bt-lesson {
  background: radial-gradient(ellipse at 40% 35%, #fff 0 50%, #f4eedf); border: 5px solid var(--ink); border-radius: 36% / 44%;
  box-shadow: inset 0 -10px 0 rgba(107, 75, 209, .1), 0 6px 0 rgba(0, 0, 0, .28); box-sizing: border-box;
}
.bedtime .bt-pillow { position: absolute; left: 50%; bottom: 88%; width: var(--pw); height: calc(var(--pw) * .78); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2%; }
.bedtime .bt-glyph { display: block; height: 80%; aspect-ratio: 100 / 160; }
.bedtime .bt-glyph.sm { height: 56%; }
.bedtime .bt-word { display: block; font-size: calc(var(--pw) * .26); font-weight: 700; line-height: 1.1; color: var(--ink); white-space: nowrap; }
.bedtime .bt-word.sm { font-size: calc(var(--pw) * .16); }
.bedtime .bt-key { font-weight: 700; background: #ffe98a; border-radius: .16em; padding: 0 .05em; }

/* the two ends: each half of the screen is a button */
.bedtime .bt-end { position: absolute; top: 0; bottom: 0; width: 50%; z-index: 5; margin: 0; padding: 0; border: 0; background: transparent; cursor: pointer; transition: background .25s; }
.bedtime .bt-end.head { left: 0; }
.bedtime .bt-end.foot { right: 0; }
.bedtime .bt-end:active { background: rgba(255, 230, 150, .1); transition: none; }
.bedtime .bt-end.pick-me { animation: bt-pick .7s ease-in-out infinite alternate; }
.bedtime .bt-end.head.pick-me { background: linear-gradient(90deg, rgba(255, 210, 63, .5), rgba(255, 210, 63, .12) 45%, transparent 85%); box-shadow: inset 10px 0 0 #ffd23f; }
.bedtime .bt-end.foot.pick-me { background: linear-gradient(270deg, rgba(255, 210, 63, .5), rgba(255, 210, 63, .12) 45%, transparent 85%); box-shadow: inset -10px 0 0 #ffd23f; }
.bedtime .bt-end.nope { background: rgba(255, 90, 95, .16); transition: none; }
@keyframes bt-pick { from { opacity: .55; } to { opacity: 1; } }

/* grow the B, by the pillow */
.bedtime .bt-hint {
  position: absolute; z-index: 6; left: calc(50% + var(--pw) / 2 + 14px); bottom: calc(var(--pb) + var(--pw) * .39 - 44px);
  width: 88px; height: 88px; padding: 0; border-radius: 50%; border: 4px solid var(--ink); background: #ffd23f; color: var(--ink); font: inherit; font-weight: 800; cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, .3); opacity: 0; transform: scale(.6); pointer-events: none; transition: opacity .2s, transform .25s cubic-bezier(.2, 1.5, .4, 1);
}
.bedtime .bt-hint.show { opacity: 1; transform: none; pointer-events: auto; }
.bedtime .bt-hint:active { transform: scale(.92); }
.bedtime .bt-hint-b { font-size: 50px; line-height: 1; font-family: 'Andika', var(--font); }
.bedtime .bt-hint-q { position: absolute; right: 10px; top: 4px; font-size: 22px; }

/* after a miss: the letter flips to the other one and back; the hands show the trick */
.bedtime .bt-lesson {
  position: absolute; z-index: 7; left: 50%; bottom: calc(var(--pb) - var(--pw) * .12); width: calc(var(--pw) * 1.1); height: calc(var(--pw) * .96);
  transform: translateX(-50%) scale(.5); opacity: 0; pointer-events: none; transition: opacity .2s, transform .3s cubic-bezier(.2, 1.4, .4, 1);
  box-shadow: 0 0 0 9px #ffd23f, 0 0 60px rgba(255, 210, 63, .7), 0 6px 0 rgba(0, 0, 0, .28);
}
.bedtime .bt-lesson.show { opacity: 1; transform: translateX(-50%); }
.bedtime .bt-lesson.other { background: radial-gradient(ellipse at 40% 35%, #fff 0 50%, #ece4ff); }
.bedtime .bt-flip { position: absolute; inset: 6%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2%; }
.bedtime .bt-lesson.is-word .bt-glyph { height: 66%; }
.bedtime .bt-lesson .bt-word.sm { font-size: calc(var(--pw) * .19); }
.bedtime .bt-hands {
  position: absolute; z-index: 7; right: 3%; top: 3%; width: clamp(150px, 24cqw, 250px); padding: 6px 8px 2px; box-sizing: border-box;
  background: rgba(255, 253, 246, .96); border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 rgba(0, 0, 0, .28);
  opacity: 0; transform: scale(.4) rotate(-6deg); transform-origin: 80% 0; pointer-events: none; transition: opacity .25s, transform .35s cubic-bezier(.2, 1.5, .4, 1);
}
.bedtime .bt-hands.show { opacity: 1; transform: none; }
.bedtime .bt-hands-svg { display: block; width: 100%; height: auto; }

/* ---------- banner, start, lights out ---------- */
.bedtime .bt-banner {
  position: absolute; left: 50%; top: 28%; z-index: 9; transform: translate(-50%, -50%); opacity: 0; pointer-events: none; white-space: nowrap;
  font-size: clamp(32px, 6cqw, 62px); font-weight: 800; color: #ffd23f; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink);
}
.bedtime .bt-banner.show { animation: bt-banner 1.6s ease-out forwards; }
@keyframes bt-banner { 0% { transform: translate(-50%, -50%) scale(.4); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; } 25%, 80% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { transform: translate(-50%, -60%); opacity: 0; } }
.bedtime .bt-start { position: absolute; inset: 0; z-index: 12; display: none; justify-items: center; align-content: start; padding: 2cqh 12px 0; background: rgba(20, 12, 50, .25); }
.bedtime .bt-start.show { display: grid; }
.bedtime .bt-card { background: #fffdf6; border: 4px solid var(--ink); border-radius: 26px; padding: 10px 18px 14px; box-shadow: var(--shadow); text-align: center; width: min(420px, 100%); box-sizing: border-box; }
.bedtime .bt-card-hands { width: min(300px, 100%, calc((100cqh - var(--bh) - var(--bb) - 150px) * 1.36)); min-width: 160px; margin: 0 auto; }
.bedtime .bt-go { font-size: 30px; padding: 8px 46px; min-height: 80px; margin-top: 4px; }
.bedtime .bt-off { font-weight: 700; color: var(--coral-dark); margin: 6px 0; }
.bedtime .bt-dark {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity 1.8s ease;
  background:
    radial-gradient(circle at 12% 18%, #fff 0 1.5px, transparent 2.5px), radial-gradient(circle at 36% 9%, #fff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 62% 16%, #fff 0 2px, transparent 3px), radial-gradient(circle at 84% 8%, #fff 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 74% 30%, #fff 0 1.5px, transparent 2.5px), radial-gradient(circle at 46% 28%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 92% 24%, #fff 0 2px, transparent 3px), radial-gradient(circle at 26% 34%, #fff 0 1px, transparent 2px),
    radial-gradient(ellipse 60% 70% at 16% 22%, rgba(10, 8, 34, .05), rgba(10, 8, 34, .35) 45%, rgba(10, 8, 34, .6) 80%);
}
.bedtime .bt-room.night .bt-dark { opacity: 1; }
.bedtime .bt-room.night .bt-window { z-index: 4; }
.bedtime .bt-room.night .bt-z { animation-duration: 2.6s; }
.bedtime .bt-room.night .bt-end { pointer-events: none; }

@media (max-width: 600px) {
  .bedtime .game-top h2 { font-size: 22px; }
  .bedtime .bt-hint { width: 80px; height: 80px; left: calc(50% + var(--pw) / 2 + 8px); }
  .bedtime .bt-hint-b { font-size: 44px; }
}
@media (max-width: 420px) { .bedtime .game-top h2 { display: none; } .bedtime .game-top { grid-template-columns: auto 1fr; } }
@media (prefers-reduced-motion: reduce) {
  .bedtime .bt-scrit, .bedtime .bt-z, .bedtime .bt-lights i, .bedtime .bt-star.on { animation: none !important; }
}
/* tall screens: the bed is as wide as it gets, so it goes up a little and the pillow gets bigger */
@media (max-aspect-ratio: 4/5) {
  .bedtime .bt-room { --bb: 17cqh; --gw: calc(var(--bw) * .21); --pw: clamp(150px, 42cqw, 260px); }
  .bedtime .bt-window { width: 36cqw; top: 7%; }
  .bedtime .bt-frame { width: 24cqw; top: 9%; }
}
/* phones held up: the bed goes up more, so it isn't all wall up top */
@media (max-aspect-ratio: 3/5) {
  .bedtime .bt-room { --bb: 24cqh; --gw: calc(var(--bw) * .24); }
  .bedtime .bt-window { width: 44cqw; top: 6%; }
  .bedtime .bt-frame { width: 28cqw; top: 9%; }
}
