/* Unays Guide v3: vector character with jointed limbs and state-driven animation. */
.ug-root {
  --ug-ink: #16302d;
  --ug-paper: #fffaf2;
  --ug-mint: #e1f1e9;
  --ug-border: #c4d9cf;
  --ug-teal: #17594f;
  --ug-coral: #e8705a;
  --ug-ease: cubic-bezier(.22, 1, .36, 1);
  --ug-spring: cubic-bezier(.34, 1.45, .55, 1);
  position: fixed;
  inset: auto max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) auto;
  z-index: 1400;
  display: grid;
  justify-items: end;
  color: var(--ug-ink);
  font: 500 14px/1.45 'DM Sans', system-ui, sans-serif;
  text-align: start;
}
.ug-root * { box-sizing: border-box; }
body[data-theme="dark"] .ug-root {
  --ug-ink: #eaf5ec;
  --ug-paper: #172724;
  --ug-mint: #203b35;
  --ug-border: #44695d;
  --ug-teal: #2a7a68;
}
body[data-theme="dark"] .ug-root :is(.ug-bubble,.ug-form input,.ug-head-controls select,.ug-head-controls button,.ug-actions button,.ug-preview button) {
  background: #1f3531;
  border-color: var(--ug-border);
}
body[data-theme="dark"] .ug-root :is(.ug-link,.ug-help) { color: #aee4d1; }
.ug-root [hidden] { display: none !important; }
.ug-root button, .ug-root input, .ug-root select {
  color: var(--ug-ink);
  font: inherit;
  box-shadow: none;
  letter-spacing: normal;
  text-transform: none;
}
.ug-root :where(button, select, input, a):focus-visible { outline: 3px solid #2f8a74; outline-offset: 3px; }
.ug-root button { cursor: pointer; }

/* Launcher: a pill with the guide's face. */
.ug-launch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 52px;
  padding: 5px 18px 5px 5px;
  border: 0;
  border-radius: 999px;
  background: var(--ug-teal);
  color: #fff !important;
  font-weight: 750 !important;
  box-shadow: 0 14px 30px -10px #0d3a3299, 0 3px 8px #0d3a3226;
  transition: transform .35s var(--ug-spring), box-shadow .3s ease;
  animation: ug-arrive .7s .4s var(--ug-spring) both;
}
.ug-launch:hover { transform: translateY(-3px); box-shadow: 0 18px 34px -10px #0d3a32aa, 0 4px 10px #0d3a322e; }
.ug-launch-face {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ddf0e6);
  overflow: hidden;
}
.ug-avatar { width: 38px; height: 42px; margin-top: 6px; overflow: visible; }
.ug-launch:hover .ug-avatar, .ug-hello .ug-launch .ug-avatar { animation: ug-peek 1.1s var(--ug-ease) both; }
@keyframes ug-arrive { from { opacity: 0; transform: translateY(18px) scale(.9); } }
@keyframes ug-peek { 0%,100% { rotate: 0deg; } 25% { rotate: -12deg; } 55% { rotate: 9deg; } 80% { rotate: -4deg; } }

/* Compact launcher: face only, label slides out on hover or focus. */
.ug-launch > span:last-child { display: inline-block; max-width: 160px; overflow: hidden; white-space: nowrap; transition: max-width .4s var(--ug-ease), opacity .3s ease; }
.ug-compact .ug-launch:not(:hover, :focus-visible) { padding-right: 5px; gap: 0; }
.ug-compact .ug-launch:not(:hover, :focus-visible) > span:last-child { max-width: 0; opacity: 0; }

/* One-time greeting bubble above the launcher. */
.ug-nudge {
  position: relative;
  margin: 0 4px 12px 0;
  max-width: 230px;
  padding: 11px 15px;
  border-radius: 18px 18px 4px 18px;
  background: #fff;
  color: #16302d;
  font-weight: 650;
  box-shadow: 0 14px 34px -12px #0d3a3270, 0 0 0 1px #0d3a3212;
  cursor: pointer;
  transform-origin: 100% 100%;
  animation: ug-bubble-in .5s var(--ug-spring) both;
}
@keyframes ug-bubble-in { from { opacity: 0; transform: translateY(10px) scale(.85); } }

/* Panel. */
.ug-form button, .ug-send {
  background: var(--ug-teal);
  color: #fff !important;
  border: 1px solid var(--ug-teal);
  border-radius: 999px;
  font-weight: 750 !important;
  min-height: 44px;
  padding: 8px 17px;
  transition: background .2s ease, transform .2s ease;
}
.ug-form button:hover, .ug-send:hover { background: #0f463e; transform: translateY(-1px); }
.ug-panel {
  width: min(380px, calc(100vw - 36px));
  max-height: min(590px, calc(100vh - 36px));
  max-height: min(590px, calc(100dvh - 36px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  border: 1px solid var(--ug-border);
  border-radius: 26px;
  background: var(--ug-paper);
  box-shadow: 0 30px 70px -24px #0d3a3266, 0 8px 20px #0d3a321a;
  overflow: hidden;
  transform-origin: 100% 100%;
  animation: ug-panel-in .48s var(--ug-spring) both;
}
@keyframes ug-panel-in { from { opacity: 0; transform: translateY(18px) scale(.9); } }
.ug-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px 12px 12px;
  background: linear-gradient(120deg, #d9efe4, #eef7ef 60%, #fbe7dc);
}
body[data-theme="dark"] .ug-head { background: linear-gradient(120deg, #1f3d36, #1b302c); }
.ug-head > div:first-of-type { flex: 1; min-width: 0; }
.ug-head-face {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px #ffffff80;
  overflow: hidden;
}
.ug-head-face .ug-avatar { width: 36px; height: 40px; margin-top: 6px; }
.ug-head h2 { margin: 0; color: var(--ug-ink); font: 750 18px/1.2 'DM Sans', system-ui, sans-serif; letter-spacing: -.02em; }
.ug-head p { margin: 1px 0 0; font-size: 12px; opacity: .8; }
.ug-head h2::after {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 7px;
  border-radius: 50%;
  background: #2fb57f;
  vertical-align: 2px;
  box-shadow: 0 0 0 3px #2fb57f33;
}
.ug-head-controls, .ug-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ug-head-controls :is(select,button), .ug-actions button {
  background: #fffaf2;
  border: 1px solid var(--ug-border);
  border-radius: 999px;
  padding: 6px 11px;
  min-height: 36px;
  min-width: 36px;
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}
.ug-actions button:hover { background: var(--ug-mint); border-color: #8fbfae; transform: translateY(-1px); }
.ug-close { font-size: 22px !important; line-height: 1 !important; transition: rotate .3s var(--ug-ease); }
.ug-close:hover { rotate: 90deg; }
.ug-scroll { overflow: auto; min-height: 0; padding: 14px 14px 0; }
.ug-bubble {
  position: relative;
  background: #fff;
  border: 1px solid #e7e0d3;
  border-radius: 6px 18px 18px 18px;
  padding: 13px 14px;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 16px -10px #2a3a3640;
}
.ug-bubble.ug-fresh > :not(.ug-typing) { animation: ug-rise .45s var(--ug-ease) both; }
.ug-bubble.ug-fresh > p { animation-delay: .06s; }
.ug-bubble.ug-fresh > a { animation-delay: .12s; }
@keyframes ug-rise { from { opacity: 0; transform: translateY(6px); } }
.ug-typing { display: none; gap: 5px; padding: 4px 0 8px; }
.ug-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ug-teal); animation: ug-dot 1s ease-in-out infinite; }
.ug-typing i:nth-child(2) { animation-delay: .15s; }
.ug-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ug-dot { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
.ug-busy .ug-typing { display: flex; }
.ug-busy .ug-bubble > :not(.ug-typing) { opacity: .4; transition: opacity .2s ease; }
.ug-discovery { margin-top: 9px; }
.ug-discovery button { min-height: 32px; font-size: 12px; }
.ug-bubble strong { display: block; font-weight: 800; }
.ug-bubble p { margin: 5px 0 0; white-space: pre-wrap; }
.ug-link { display: inline-block; color: var(--ug-teal); margin-top: 6px; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.ug-status { margin: 7px 0; font-size: 12px; }
.ug-status:empty { display: none; }
.ug-form { margin: 11px 14px 8px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px; }
.ug-form input {
  min-width: 0;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--ug-border);
  border-radius: 999px;
  padding: 9px 15px;
  background: #fff;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.ug-form input:focus { outline: 0; border-color: var(--ug-teal); box-shadow: 0 0 0 4px #17594f1f; }
.ug-tools { padding: 0 14px; }
.ug-tools button { font-size: 12px; }
.ug-tools button[aria-pressed="true"] { background: var(--ug-mint); border-color: var(--ug-teal); }
.ug-help { font-size: 11px; padding: 8px 14px 13px; margin: 0; color: #3e5852; }
.ug-preview { padding: 6px 0; }
.ug-preview p { margin: 0 0 5px; font-size: 12px; }
.ug-preview img { width: 100%; max-height: 140px; object-fit: contain; background: #edf2ef; border-radius: 10px; }
.ug-preview .ug-actions { margin-top: 6px; }

/* Character: only on stage while the panel is open. */
.ug-root .ug-character {
  display: none;
  position: absolute;
  right: calc(100% - 6px);
  bottom: -4px;
  width: 116px;
  aspect-ratio: 120 / 188;
  padding: 0;
  background: transparent;
  border: 0;
  touch-action: manipulation;
  user-select: none;
  cursor: grab;
}
.ug-root.ug-open .ug-character { display: block; animation: ug-hop-in .6s var(--ug-spring) both; }
@keyframes ug-hop-in { from { opacity: 0; transform: translateY(24px) scale(.8); } }
.ug-figure { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 6px 6px #12302c26); transition: transform .25s ease; }
.ug-left .ug-figure { transform: scaleX(-1); }
.ug-figure *, .ug-avatar * { transform-box: view-box; }
.ug-shadow { fill: #12302c; opacity: .14; transform-origin: 60px 180px; }
.ug-hoodie, .ug-sleeve { fill: #1f5f58; }
.ug-trim { fill: none; stroke: #e8775c; stroke-width: 2.6; stroke-linejoin: round; }
.ug-hood, .ug-cuff { fill: #e8775c; }
.ug-strings { stroke: #f3b9a4; stroke-width: 2; stroke-linecap: round; }
.ug-logo { fill: none; stroke: #a9d3c6; stroke-width: 2; stroke-linecap: round; }
.ug-pants { fill: #1a4a46; }
.ug-shoe { fill: #e8735a; }
.ug-sole { fill: #f7ead9; }
.ug-skin { fill: #f6cfae; }
.ug-hair { fill: #1f4b4a; }
.ug-eyes { fill: #1b2a28; transform-origin: 60px 46px; }
.ug-cheeks { fill: #f0907a; opacity: .45; }
.ug-smile { fill: none; stroke: #8a3f33; stroke-width: 1.8; stroke-linecap: round; }
.ug-mouth { fill: #8a3f33; transform-origin: 60px 55px; scale: 1 0; }
.ug-think { fill: #fff; stroke: #9fc2b5; stroke-width: 1; opacity: 0; transition: opacity .3s ease; }

/* Joints. CSS translate places each limb; rotate swings it about that joint. */
.ug-body { transform-origin: 60px 178px; }
.ug-leg-back .ug-pants { fill: #133b37; }
.ug-leg-back .ug-shoe { fill: #d4614a; }
.ug-torso { transform-origin: 60px 126px; }
.ug-head { transform-origin: 60px 64px; }
.ug-leg, .ug-arm, .ug-forearm { transform-origin: 0 0; }
.ug-leg-back { translate: 52px 121px; }
.ug-leg-front { translate: 68px 121px; }
.ug-arm-back { translate: 43px 77px; rotate: 9deg; }
.ug-arm-front { translate: 77px 77px; rotate: -9deg; }
.ug-forearm { translate: 0 23px; }
.ug-leg, .ug-arm, .ug-forearm, .ug-head { transition: rotate .45s var(--ug-ease); }

/* Idle: breathe, sway and blink. */
.ug-figure .ug-torso { animation: ug-breathe 3.6s ease-in-out infinite; }
.ug-figure .ug-head { animation: ug-sway 6s ease-in-out infinite; }
.ug-eyes { animation: ug-blink 5.2s infinite; }
@keyframes ug-breathe { 50% { scale: 1 1.025; } }
@keyframes ug-sway { 0%,100% { rotate: -2deg; } 50% { rotate: 2.5deg; } }
@keyframes ug-blink { 0%,93%,100% { scale: 1 1; } 95% { scale: 1 .1; } 97% { scale: 1 1; } }

/* Greeting: big wave with a small hop. */
.ug-root[data-state="greeting"] .ug-arm-front { rotate: -128deg; }
.ug-root[data-state="greeting"] .ug-arm-front .ug-forearm { animation: ug-wave .42s ease-in-out infinite alternate; }
.ug-root[data-state="greeting"] .ug-body { animation: ug-hop .9s var(--ug-ease) 1; }
.ug-root[data-state="greeting"] .ug-figure .ug-head { animation: none; rotate: 7deg; }
@keyframes ug-wave { from { rotate: -70deg; } to { rotate: -20deg; } }
@keyframes ug-hop { 30% { translate: 0 -10px; } 60% { translate: 0 0; } 75% { translate: 0 -3px; } }

/* Walking: alternating legs and arms with a bob. */
.ug-root[data-state="walking"] .ug-body { animation: ug-bob .3s ease-in-out infinite alternate; }
.ug-root[data-state="walking"] .ug-leg-back { animation: ug-step .6s ease-in-out infinite alternate; }
.ug-root[data-state="walking"] .ug-leg-front { animation: ug-step .6s ease-in-out infinite alternate-reverse; }
.ug-root[data-state="walking"] .ug-arm-back { animation: ug-swing .6s ease-in-out infinite alternate-reverse; }
.ug-root[data-state="walking"] .ug-arm-front { animation: ug-swing .6s ease-in-out infinite alternate; }
.ug-root[data-state="walking"] .ug-forearm { rotate: -25deg; }
.ug-root[data-state="walking"] .ug-shadow { animation: ug-shadow .3s ease-in-out infinite alternate; }
@keyframes ug-bob { from { translate: 0 0; } to { translate: 0 -4px; } }
@keyframes ug-step { from { rotate: -22deg; } to { rotate: 22deg; } }
@keyframes ug-swing { from { rotate: -24deg; } to { rotate: 24deg; } }
@keyframes ug-shadow { to { scale: .85 1; } }

/* Pointing at the item that was explained. */
.ug-root[data-state="pointing"] .ug-arm-front { rotate: -82deg; }
.ug-root[data-state="pointing"] .ug-arm-front .ug-forearm { rotate: -6deg; animation: ug-poke .7s ease-in-out infinite alternate; }
.ug-root[data-state="pointing"] .ug-figure .ug-head { animation: none; rotate: 6deg; }
@keyframes ug-poke { to { translate: 2px 23px; } }

/* Thinking while an answer loads. */
.ug-root[data-state="thinking"] .ug-arm-front { rotate: 26deg; }
.ug-root[data-state="thinking"] .ug-arm-front .ug-forearm { rotate: 150deg; }
.ug-root[data-state="thinking"] .ug-figure .ug-head { animation: none; rotate: -8deg; }
.ug-root[data-state="thinking"] .ug-figure .ug-eyes { translate: 1.5px -1.5px; }
.ug-root[data-state="thinking"] .ug-think { opacity: 1; }
.ug-root[data-state="thinking"] .ug-think circle { animation: ug-dot 1.2s ease-in-out infinite; }
.ug-root[data-state="thinking"] .ug-think circle:nth-child(2) { animation-delay: .2s; }
.ug-root[data-state="thinking"] .ug-think circle:nth-child(3) { animation-delay: .4s; }

/* Answer arrived: open arms and a happy bounce. */
.ug-root[data-state="answering"] .ug-arm-front { rotate: -60deg; }
.ug-root[data-state="answering"] .ug-arm-back { rotate: 60deg; }
.ug-root[data-state="answering"] .ug-forearm { rotate: -20deg; }
.ug-root[data-state="answering"] .ug-arm-back .ug-forearm { rotate: 20deg; }
.ug-root[data-state="answering"] .ug-body { animation: ug-hop .8s var(--ug-ease) 1; }

/* Speaking: animated mouth, nodding head and a talking hand. */
.ug-root[data-state="speaking"] .ug-smile { opacity: 0; }
.ug-root[data-state="speaking"] .ug-mouth { animation: ug-talk .26s ease-in-out infinite alternate; }
.ug-root[data-state="speaking"] .ug-figure .ug-head { animation: ug-nod 1.4s ease-in-out infinite; }
.ug-root[data-state="speaking"] .ug-arm-front { rotate: -38deg; }
.ug-root[data-state="speaking"] .ug-arm-front .ug-forearm { animation: ug-gesture 1.6s ease-in-out infinite; }
@keyframes ug-talk { from { scale: 1 .25; } to { scale: 1 1; } }
@keyframes ug-nod { 0%,100% { rotate: -2deg; } 50% { rotate: 3deg; } }
@keyframes ug-gesture { 0%,100% { rotate: -60deg; } 50% { rotate: -25deg; } }

/* Picking an item: looking around. */
.ug-root[data-state="looking"] .ug-figure .ug-head { animation: ug-look 2.4s ease-in-out infinite; }
.ug-root[data-state="looking"] .ug-figure .ug-eyes { animation: ug-scan 2.4s ease-in-out infinite; }
.ug-root[data-state="looking"] .ug-arm-front { rotate: -100deg; }
.ug-root[data-state="looking"] .ug-arm-front .ug-forearm { rotate: -70deg; }
@keyframes ug-look { 0%,100% { rotate: -9deg; } 50% { rotate: 9deg; } }
@keyframes ug-scan { 0%,100% { translate: -1.6px 0; } 50% { translate: 1.6px 0; } }

.ug-move-status { display: none; }
.ug-driving .ug-character { cursor: move; }
.ug-driving .ug-figure { filter: drop-shadow(0 8px 10px #12302c40); }
.ug-driving .ug-move-status {
  display: block;
  position: fixed;
  z-index: 1;
  inset: max(8px, env(safe-area-inset-top)) auto auto 50%;
  translate: -50% 0;
  width: max-content;
  max-width: calc(100vw - 16px);
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--ug-teal);
  color: #fff;
  pointer-events: none;
}
.ug-picking, .ug-picking body *:not(.ug-root *) { cursor: crosshair !important; }
.ug-root.ug-selecting { inset: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) auto auto; }
.ug-selecting :is(.ug-character,.ug-form,.ug-bubble,.ug-discovery,.ug-preview,.ug-tools button:not(.ug-pick),.ug-help) { display: none !important; }
.ug-selecting .ug-tools { padding-bottom: 9px; }

/* Narrow screens: the character peeks over the top of the panel. */
@media (max-width: 600px), (max-height: 600px) {
  .ug-root { inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto; }
  .ug-panel { width: min(380px, calc(100vw - 24px)); max-height: calc(100dvh - 110px); }
  .ug-root .ug-character { right: auto; left: 14px; bottom: calc(100% - 30px); width: 62px; z-index: -1; }
  .ug-form input { font-size: 16px; }
  .ug-launch { min-height: 48px; padding-right: 15px; }
  .ug-launch-face { width: 38px; height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  .ug-root *, .ug-root *::before, .ug-root *::after { animation: none !important; transition: none !important; }
}
