/* Gan Champions 43: Nori and friends (buddy43.js).
   Nori is the original illustration in layers. He rises from the bottom edge for a moment;
   he takes taps only while he says hello, offers help or celebrates (is-touchable). */
.buddy43 {
  position: fixed;
  bottom: 0;
  left: 50%;
  translate: -50% 0;
  z-index: 9997;
  pointer-events: none;
  direction: ltr;
}
.buddy43-nori {
  position: relative;
  width: clamp(116px, 31vw, 156px);
  transform: translateY(108%);
}
.nr-rig {
  position: relative;
  aspect-ratio: 1;
  transform-origin: 50% 97%;
  filter: drop-shadow(0 8px 10px #0b1f4d47);
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.buddy43-nori.is-touchable .nr-rig { pointer-events: auto; cursor: pointer; }
.nr-rig img, .nr-head {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
.nr-head { transform-origin: 48.7% 53.7%; animation: buddy43-bob 3.2s ease-in-out infinite; }
.nr-antenna { position: absolute; inset: 0; transform-origin: 55.6% 13.2%; }

/* Robot touches: a pulsing light in the antenna ball and a light sweep across the face screen. */
.nr-light {
  position: absolute;
  left: 55.3%;
  top: 6.4%;
  width: 8.5%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #fffbe0 0 18%, #ffe27acc 38%, #ffd23f00 70%);
  mix-blend-mode: screen;
  animation: buddy43-light 1.8s ease-in-out infinite;
}
.is-happy .nr-light { animation-duration: .5s; }
@keyframes buddy43-light { 0%, 100% { opacity: .25; scale: .85; } 50% { opacity: 1; scale: 1.15; } }
.nr-visor {
  position: absolute;
  left: 33.1%;
  top: 24.3%;
  width: 38.8%;
  height: 27%;
  border-radius: 42% / 48%;
  overflow: hidden;
  pointer-events: none;
}
.nr-shine {
  position: absolute;
  inset: -10% auto -10% 0;
  width: 34%;
  background: linear-gradient(90deg, #fff0, #ffffff59 45%, #e8ffff80 55%, #fff0);
  mix-blend-mode: screen;
  opacity: 0;
}

/* Breathing: the whole body rises and falls a little, and the head follows half a beat later. */
.nr-rig { animation: buddy43-breathe 3.2s ease-in-out infinite; }
@keyframes buddy43-breathe { 0%, 100% { scale: 1 1; } 50% { scale: 1.012 1.022; } }
@keyframes buddy43-bob { 0%, 100% { translate: 0 0; } 60% { translate: 0 -.7%; } }

/* Faces: the base face, with painted expressions layered on top. */
.nr-happy, .nr-think, .nr-blink { opacity: 0; }
.is-happy .nr-happy { opacity: 1; }
.is-think .nr-think { opacity: 1; }
.nr-blink { animation: buddy43-blink 3.4s infinite; }
.is-happy .nr-blink, .is-think .nr-blink { animation: none; opacity: 0; }
@keyframes buddy43-blink {
  0%, 90%, 96%, 100% { opacity: 0; }
  91.5%, 94.5% { opacity: 1; }
}

/* Speech bubble, in the site's style: white card, gold border, navy text. */
.buddy43-bubble {
  position: absolute;
  bottom: 116%;
  left: 50%;
  transform: translateX(-50%);
  transform-origin: 50% 100%;
  width: max-content;
  max-width: min(230px, 76vw);
  padding: 8px 16px;
  border-radius: 18px;
  background: #fff;
  border: 3px solid #f2cf6b;
  box-shadow: 0 4px 0 #e3b23c55, 0 8px 18px #0b1f4d26;
  color: #16285f;
  font: 800 clamp(15px, 4.2vw, 18px)/1.25 system-ui, "Segoe UI", Arial, sans-serif;
  white-space: normal;
  text-wrap: balance;
  direction: rtl;
  text-align: center;
  opacity: 0;
}
.buddy43-bubble:empty { display: none; }
.buddy43-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 14px;
  height: 14px;
  margin: -6px 0 0 -7px;
  background: #fff;
  border-right: 3px solid #f2cf6b;
  border-bottom: 3px solid #f2cf6b;
  transform: rotate(45deg);
}

/* The bubble's picture: big, on top of the words, for children who cannot read yet. */
.buddy43-icon {
  display: block;
  width: max-content;
  margin: -2px auto 3px;
  font: clamp(34px, 9vw, 46px)/1.1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", system-ui, sans-serif;
  letter-spacing: -.06em;
}
.buddy43-words { display: block; }

.buddy43-sparks {
  position: absolute;
  left: 50%;
  top: 30%;
  width: 0;
  height: 0;
  pointer-events: none;
}
.buddy43-sparks span {
  position: absolute;
  left: 0;
  top: 0;
  font: 22px/1 system-ui, "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
}

/* Friends (chick, owl, bunny). */
.buddy43-friend {
  position: absolute;
  bottom: 0;
  width: clamp(54px, 15vw, 78px);
  transform: translateY(110%);
  filter: drop-shadow(0 4px 6px #0b1f4d33);
}
.buddy43-chick { right: calc(100% - 6px); }
.buddy43-owl { right: calc(100% - 6px + clamp(58px, 16vw, 82px)); }
.buddy43-bunny { left: calc(100% - 4px); }
.buddy43-svg { display: block; width: 100%; height: auto; overflow: visible; }
.buddy43 svg g { transform-box: view-box; }
.buddy43 .f-all { transform-origin: 40px 84px; }
.buddy43 .f-wing-l { transform-origin: 22px 44px; }
.buddy43 .f-wing-r { transform-origin: 58px 44px; }
.buddy43 .f-ear-l { transform-origin: 30px 42px; }
.buddy43 .f-ear-r { transform-origin: 50px 42px; }

@media (prefers-reduced-motion: reduce) {
  .nr-blink, .nr-rig, .nr-head, .nr-light { animation: none; }
}
html.no-motion .nr-blink, html.no-motion .nr-rig, html.no-motion .nr-head, html.no-motion .nr-light { animation: none; }

/* Home screen: Nori greets the child, a little bigger next to the large picture. */
.royal-home .buddy43-nori { width: clamp(130px, 13vw, 210px); }

/* Talking: his mouth follows the recording (buddy43.js lipSync). Closed, open smile (the base face) and wide open. */
.nr-talk0, .nr-talk2 { opacity: 0; }
.buddy43-nori.is-talking .nr-happy, .buddy43-nori.is-talking .nr-think, .buddy43-nori.is-talking .nr-blink { opacity: 0; animation: none; }
.buddy43-nori[data-mouth="0"] .nr-talk0, .buddy43-nori[data-mouth="2"] .nr-talk2 { opacity: 1; }

/* Things Nori wears (a trophy gives the next one; the child chooses on the home screen). */
.nr-rig { container-type: inline-size; }
.nr-wear {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  font: 40px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  pointer-events: none;
  filter: drop-shadow(0 2px 2px #0b1f4d40);
}
.nr-wear:empty { display: none; }
.wear-crown { left: 40%; top: 13%; font-size: 30cqw; rotate: -10deg; }
.wear-tophat { left: 40%; top: 9%; font-size: 32cqw; rotate: -12deg; }
.wear-cap { left: 41%; top: 15%; font-size: 33cqw; rotate: -14deg; }
.wear-bow { left: 73%; top: 18%; font-size: 21cqw; rotate: 16deg; }
.wear-flower { left: 24%; top: 24%; font-size: 19cqw; rotate: -12deg; }
.wear-glasses { left: 52%; top: 35%; font-size: 36cqw; }
.wear-sparkle { left: 71%; top: 11%; font-size: 19cqw; rotate: 12deg; }
.wear-medal { left: 56%; top: 71%; font-size: 18cqw; }

/* Nori's closet on the home screen. */
.buddy43-closet {
  position: absolute;
  bottom: 104%;
  left: 50%;
  translate: -50% 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: max-content;
  max-width: min(300px, 86vw);
  padding: 8px 10px;
  border-radius: 20px;
  background: #fff;
  border: 3px solid #f2cf6b;
  box-shadow: 0 4px 0 #e3b23c55, 0 8px 18px #0b1f4d26;
  pointer-events: auto;
  z-index: 2;
}
.buddy43-closet button {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 2px solid #e8eefc;
  background: #f7f9ff;
  font: 28px/1 "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  cursor: pointer;
}
.buddy43-closet button[aria-pressed="true"] { border-color: #f2cf6b; background: #fff4cc; }

/* The family turned Nori off in the accessibility panel. */
html.nori-off43 .buddy43 { display: none !important; }
