/* Finish the Word (tricky letters): the word machine on the left (on top on a tall screen), the two big
   letter tiles and the trick button on the right (underneath). Everything he taps is at least 80px.
   The letter flips (.fl-y/.fl-x/.fl-z) at the bottom are shared with Dog or Bog?. */
.game.finishword { background: linear-gradient(160deg, #dff7ef, #fff6df 58%, #e2efff); }
.finishword button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.finishword .game-top { padding-top: 5px; padding-bottom: 5px; }
.finishword .fw-back { min-height: 60px; min-width: 60px; white-space: nowrap; }
.finishword .fw-count { white-space: nowrap; }
.finishword .fw-body {
  flex: 1; min-height: 0; position: relative; display: grid; gap: 14px 24px;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 14px max(16px, env(safe-area-inset-left, 0px));
}

/* ---------- the machine ---------- */
.finishword .fw-machine {
  position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 8px 14px 14px;
  background: linear-gradient(#45c2a8, #2f9e86); border: 4px solid var(--ink); border-radius: 30px; box-shadow: var(--shadow);
}
.finishword .fw-machine.sputter { animation: fw-sputter .6s ease-in-out; }
.finishword .fw-top { flex: none; display: flex; align-items: center; justify-content: center; gap: 14px; height: clamp(38px, 7vh, 62px); }
.finishword .fw-top .fw-face { height: 100%; width: auto; }
.finishword .fw-bulb { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--ink); background: #ffd23f; animation: fw-blink 1.6s ease-in-out infinite; }
.finishword .fw-bulb + .fw-face + .fw-bulb { background: #ff7eb6; animation-delay: .8s; }

/* the face: eyes look about, happy (^ ^) or dizzy (x x) */
.fw-face .fw-joy, .fw-face .fw-x, .fw-face .fw-oh { display: none; }
.fw-face .fw-pupil, .fw-face .fw-glint { animation: fw-look 5s ease-in-out infinite; }
.fw-face.happy .fw-pupil, .fw-face.happy .fw-glint, .fw-face.dizzy .fw-pupil, .fw-face.dizzy .fw-glint { display: none; }
.fw-face.happy .fw-joy { display: inline; }
.fw-face.dizzy .fw-x, .fw-face.dizzy .fw-oh { display: inline; }
.fw-face.dizzy .fw-mouth { display: none; }

/* the screen with the word on it */
.finishword .fw-screen {
  flex: none; position: relative; display: flex; align-items: center; justify-content: center; gap: 12px; min-height: clamp(104px, 20vh, 180px); padding: 6px 12px;
  background: #22303f; border: 4px solid var(--ink); border-radius: 22px; box-shadow: inset 0 0 0 4px #33465a;
}
.finishword .fw-word { display: flex; align-items: baseline; padding-bottom: .12em; font-size: clamp(64px, 7vw + 3vh, 128px); font-weight: 700; line-height: 1.2; color: #fff; letter-spacing: .03em; }
.finishword .fw-ch { display: inline-block; }
.finishword .fw-slot {
  position: relative; display: inline-block; margin: 0 .05em; padding: 0 .1em; border-radius: 16px; line-height: 1.05;
  outline: 5px dashed #ffd23f; outline-offset: -2px; animation: fw-gap 1.4s ease-in-out infinite;
}
.finishword .fw-ghost { visibility: hidden; }
.finishword .fw-slot.full { outline: none; animation: fw-land .35s cubic-bezier(.2, 1.6, .4, 1); }
.finishword .fw-slot.ok { background: #2bb673; }
.finishword .fw-slot.bad { background: #e5484d; }
.finishword .fw-word.yay { animation: fw-yay .6s ease-out; }
.finishword .fw-word.shake { animation: fw-shake .4s; }
.finishword .fw-star { font-size: .8em; animation: fw-yay 1s ease-in-out infinite; }
.finishword .fw-hear {
  flex: none; width: 80px; height: 80px; padding: 0; border-radius: 50%; border: 4px solid var(--ink); background: #fff8d6;
  font-size: 36px; line-height: 1; box-shadow: 0 4px 0 rgba(0, 0, 0, .3); cursor: pointer;
}
.finishword .fw-hear:active:not(:disabled) { transform: scale(.92); }
.finishword .fw-hear:disabled { visibility: hidden; }
.finishword .fw-hear.wiggle { animation: fw-wiggle .5s ease-in-out 2; }

/* the chute where the machine puts what he made */
.finishword .fw-chute {
  position: relative; flex: 1; min-height: 110px; display: grid; place-items: center; overflow: hidden; container-type: size;
  background: radial-gradient(ellipse at 50% 60%, #3c5468, #1a2632 75%); border: 4px solid var(--ink); border-radius: 22px;
}
.finishword .fw-gear { position: absolute; width: min(110px, 34cqh); height: min(110px, 34cqh); }
.finishword .fw-gear.l { left: -4%; bottom: -10%; }
.finishword .fw-gear.r { right: -3%; top: -9%; width: min(90px, 28cqh); height: min(90px, 28cqh); }
.finishword .fw-chute.run .fw-gear.l { animation: fw-spin 1s ease-in-out; }
.finishword .fw-chute.run .fw-gear.r { animation: fw-spin 1s ease-in-out reverse; }
.finishword .fw-wait { position: absolute; font-size: min(50cqh, 160px); font-weight: 800; line-height: 1; color: rgba(255, 255, 255, .07); animation: fw-hop 2.4s ease-in-out infinite; }
.finishword .fw-chute:has(.fw-out:not(:empty)) .fw-wait { display: none; }
.finishword .fw-out { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 2cqh; max-width: 100%; }
.finishword .fw-out.pop { animation: fw-pop .55s cubic-bezier(.2, 1.6, .4, 1) both; }
.finishword .fw-out.gone { animation: fw-out .3s ease-in forwards; }
.finishword .fw-thing { display: grid; place-items: center; font-size: min(60cqh, 46cqw); line-height: 1; }
.finishword .fw-thing > svg { display: block; }
.finishword .fw-wordthing {
  font-size: min(30cqh, 16cqw); font-weight: 700; color: var(--ink); background: #fff; border: 4px solid var(--ink); border-radius: 18px;
  padding: 0 .4em; box-shadow: 0 0 0 6px rgba(255, 210, 63, .5);
}
.finishword .fw-tag { font-size: min(13cqh, 34px); font-weight: 700; line-height: 1.2; color: var(--ink); background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 0 12px; }
.finishword .fw-out.oops .fw-tag, .finishword .fw-out.oops .fw-wordthing { background: #ffe1e3; color: #b33; box-shadow: none; }
.finishword .fw-out.oops .fw-thing { animation: fw-wobble .9s ease-in-out; }

/* the shelf: one spot for each word, filling up */
.finishword .fw-shelf { flex: none; display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; padding: 5px; background: #22303f; border: 4px solid var(--ink); border-radius: 16px; }
.finishword .fw-shelf i { aspect-ratio: 1; max-height: 52px; justify-self: center; width: 100%; display: grid; place-items: center; background: rgba(255, 255, 255, .1); border-radius: 9px; font-style: normal; container-type: inline-size; overflow: hidden; }
.finishword .fw-shelf i.on { background: #fff; line-height: 1; animation: fw-pop .4s cubic-bezier(.2, 1.6, .4, 1); }
.finishword .fw-shelf i.on > * { font-size: 74cqw; }
.finishword .fw-shelf i.on > svg { display: block; }
.finishword .fw-shelf i.w > * { font-size: 30cqw; font-weight: 700; color: var(--ink); }
.finishword .fw-body.party .fw-shelf i.on { animation: fw-hop .7s ease-in-out infinite; }
.finishword .fw-body.party .fw-shelf i:nth-child(2n) { animation-delay: .15s; }
.finishword .fw-body.party .fw-shelf i:nth-child(3n) { animation-delay: .3s; }
.finishword .fw-body.party .fw-gear.l { animation: fw-spin 1.6s linear infinite; }
.finishword .fw-body.party .fw-gear.r { animation: fw-spin 1.6s linear infinite reverse; }
.db-emo, .finishword .db-emo { font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; line-height: 1; }

/* ---------- the letter tiles ---------- */
.finishword .fw-body.waiting .fw-side, .finishword .fw-body.waiting .fw-hear { visibility: hidden; }
.finishword .fw-side { min-width: 0; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; container-type: size; }
.finishword .fw-tiles { display: flex; justify-content: center; gap: clamp(14px, 4cqw, 30px); }
.finishword .fw-tile {
  --w: min(45cqw, calc((100cqh - 120px) * .72), 290px);
  width: var(--w); height: calc(var(--w) / .72); padding: 7% 9%; perspective: 700px;
  background: #fff; border: 5px solid var(--ink); border-radius: 30px; box-shadow: 0 8px 0 rgba(58, 42, 74, .25); cursor: pointer;
  opacity: 0; transform: scale(.7); transition: opacity .2s, transform .25s cubic-bezier(.2, 1.5, .4, 1), background .2s;
}
.finishword .fw-tile.show { opacity: 1; transform: none; }
.finishword .fw-tile.show:active:not(:disabled) { transform: scale(.95); }
.finishword .fw-tile:disabled { cursor: default; }
@media (hover: hover) { .finishword .fw-tile.show:hover:not(:disabled) { background: #fff8d6; } }
.finishword .fw-tile.sent .fw-tface { opacity: .25; }
.finishword .fw-tile.dim { opacity: .3; transform: scale(.9); }
.finishword .fw-tile.pulse { background: #dcf8e3; animation: fw-pulse .9s ease-in-out infinite; }
.finishword .fw-tile.gone { opacity: 0; transform: scale(.8); }
.finishword .fw-tile.flipping .lt-pic { opacity: 0; }
.finishword .fw-tface { display: block; width: 100%; height: 100%; pointer-events: none; transition: opacity .2s; }
.finishword .fw-fly { position: fixed; z-index: 40; pointer-events: none; }
.finishword .fw-fly .lt-svg { width: 100%; height: 100%; }
.fw-arrow { animation: fw-arrow .5s ease-out both; }

.finishword .fw-hint {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 120px; height: 84px; padding: 6px 22px;
  background: #fff8d6; border: 4px solid var(--ink); border-radius: 999px; box-shadow: var(--shadow); cursor: pointer;
}
.finishword .fw-hint .fw-hicon { width: 66px; height: 66px; display: block; }
.finishword .fw-hint:active:not(:disabled) { transform: scale(.94); }
.finishword .fw-hint:disabled { opacity: .45; cursor: default; }
.finishword .fw-hint.used { background: #ffe8b0; }

/* ---------- before the first word ---------- */
.finishword .fw-start { position: absolute; inset: 0; z-index: 12; display: none; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 14px; overflow: auto; background: rgba(20, 50, 50, .35); }
.finishword .fw-start.show { display: grid; }
.finishword .fw-start-card {
  width: min(560px, 100%); display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 14px 20px 20px; text-align: center;
  background: #fff; border: 4px solid var(--ink); border-radius: 28px; box-shadow: var(--shadow);
}
.finishword .fw-hero { display: flex; align-items: center; justify-content: center; gap: 4px; max-width: 100%; height: min(90px, 13vh); }
.finishword .fw-hero > svg { height: 80%; width: auto; animation: fw-spin 6s linear infinite; }
.finishword .fw-hero > svg.b { animation-direction: reverse; }
.finishword .fw-hface { height: 100%; padding: 6px 10px; background: #3fb89f; border: 4px solid var(--ink); border-radius: 20px; }
.finishword .fw-hface svg { height: 100%; width: auto; display: block; }
.finishword .fw-pairs { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 18px; }
.finishword .fw-pair {
  position: relative; display: flex; gap: 6px; padding: 12px 18px; background: #fff; border: 4px solid var(--ink); border-radius: 24px;
  box-shadow: var(--shadow); cursor: pointer;
}
.finishword .fw-pair .fw-pl { display: block; width: 62px; height: 99px; }
.finishword .fw-pair.main { background: #fff8d6; padding: 16px 26px; }
.finishword .fw-pair.main .fw-pl { width: 84px; height: 134px; }
.finishword .fw-pair:active { transform: scale(.95); }
.finishword .fw-play { position: absolute; right: -16px; bottom: -16px; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--coral); color: #fff; border: 4px solid var(--ink); font-size: 24px; padding-left: 4px; }
.finishword .fw-off { margin: 0; font-weight: 700; color: var(--coral-dark); }
.finishword .fw-off .btn { min-height: 48px; }

/* the things he made, on the results card */
.results .fw-res { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; max-width: 340px; margin: 0 auto; }
.results .fw-res > span { display: grid; place-items: center; width: 48px; height: 48px; font-size: 40px; line-height: 1; background: #f3fbf8; border-radius: 10px; }
.results .fw-res > span > svg { display: block; }
.results .fw-res i { font-style: normal; font-size: 17px; font-weight: 700; }

/* ---------- a tall screen (an iPad held up, a phone): the machine on top ---------- */
@media (max-aspect-ratio: 1/1) {
  .finishword .fw-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; gap: 14px; }
  .finishword .fw-side { container-type: normal; gap: 12px; }
  .finishword .fw-tile { --w: min(40vw, 22vh, 230px); }
  .finishword .fw-screen { min-height: clamp(96px, 14vh, 150px); }
  .finishword .fw-word { font-size: clamp(60px, 13vw, 120px); }
}
@media (max-width: 560px) {
  .finishword .game-top h2 { font-size: 20px; }
  .finishword .hud span { font-size: 16px; padding: 0 8px; }
  .finishword .fw-body { padding-top: 8px; padding-bottom: 10px; gap: 10px; }
  .finishword .fw-machine { padding: 6px 10px 10px; gap: 8px; border-radius: 24px; }
  .finishword .fw-screen { min-height: 96px; border-radius: 18px; }
  .finishword .fw-hear { font-size: 32px; }
  .finishword .fw-shelf { gap: 3px; padding: 4px; border-width: 3px; }
  .finishword .fw-tile { border-width: 4px; border-radius: 24px; }
  .finishword .fw-hint { height: 80px; }
  .finishword .fw-hint .fw-hicon { width: 58px; height: 58px; }
  .finishword .fw-pair.main .fw-pl { width: 70px; height: 112px; }
  .finishword .fw-pair .fw-pl { width: 52px; height: 83px; }
  .finishword .fw-hero { height: 64px; }
  .finishword .fw-hero > svg { display: none; }
}
/* short and wide (a phone on its side): smaller screen and tiles */
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .finishword .fw-top { display: none; }
  .finishword .fw-screen { min-height: 80px; }
  .finishword .fw-word { font-size: 60px; }
  .finishword .fw-shelf i { max-height: 30px; }
  .finishword .fw-side { gap: 8px; }
}

@keyframes fw-blink { 50% { filter: brightness(1.35); box-shadow: 0 0 10px 3px rgba(255, 255, 255, .7); } }
@keyframes fw-look { 0%, 30% { transform: translate(0, 0); } 40%, 60% { transform: translate(-5px, 1px); } 70%, 100% { transform: translate(4px, 2px); } }
@keyframes fw-gap { 50% { outline-color: rgba(255, 210, 63, .35); } }
@keyframes fw-land { from { transform: scale(1.5); } }
@keyframes fw-yay { 30% { transform: translateY(-10px) scale(1.06); } 60% { transform: translateY(2px); } }
@keyframes fw-shake { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
@keyframes fw-wiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
@keyframes fw-sputter { 15% { transform: translate(-6px, 2px) rotate(-1deg); } 35% { transform: translate(6px, -2px) rotate(1deg); } 55% { transform: translate(-4px, 0); } 75% { transform: translate(3px, 1px); } }
@keyframes fw-spin { to { transform: rotate(360deg); } }
@keyframes fw-pop { from { transform: scale(0) translateY(40%); opacity: 0; } 60% { opacity: 1; } }
@keyframes fw-out { to { transform: scale(.4); opacity: 0; } }
@keyframes fw-wobble { 20% { transform: rotate(-12deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(4deg); } }
@keyframes fw-hop { 50% { transform: translateY(-8px); } }
@keyframes fw-pulse { 50% { transform: scale(1.06); } }
@keyframes fw-arrow { from { opacity: 0; transform: scaleY(.3); } }

/* ---------- a letter turning into the other one (both letter games) ---------- */
/* sideways (b-d): d flipped over is exactly b; upside down (b-p) and right round (d-p) turn about
   the round part of the letter */
.fl-y { animation: fl-y .7s ease-in-out forwards; }
.fl-x { transform-origin: 50% 60%; animation: fl-x .7s ease-in-out forwards; }
.fl-z { transform-origin: 50% 60%; animation: fl-z .7s ease-in-out forwards; }
@keyframes fl-y { to { transform: rotateY(180deg); } }
@keyframes fl-x { to { transform: rotateX(180deg); } }
@keyframes fl-z { to { transform: rotate(180deg); } }
@media (prefers-reduced-motion: reduce) {
  .fw-face .fw-pupil, .fw-face .fw-glint, .finishword .fw-bulb, .finishword .fw-slot, .finishword .fw-body.party * { animation: none !important; }
}
