/* Floating Perxona avatar companion — additive layer on top of the quiz UI.
   Kept isolated under .avatar-panel so it never touches the quiz's own
   selectors (see index.html's original <style> block). */

.avatar-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  width: 200px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", YuGothic, "Noto Sans JP", Meiryo, sans-serif;
}

.avatar-stage {
  position: relative;
  width: 200px;
  height: 200px;
  background: #11131a;
  border: 1px solid #171a22;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.avatar-presenter {
  display: block;
  width: 100%;
  height: 100%;
  visibility: hidden;
}

.avatar-panel.ready .avatar-presenter {
  visibility: visible;
}

.avatar-status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.4;
  color: #d8dbe4;
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
}

.avatar-panel.ready .avatar-status:empty {
  display: none;
}

.avatar-scene-select {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 6px 8px;
  background: #ffffff;
  border: 1px solid #c9ceda;
  border-radius: 8px;
  font-size: 11px;
  color: #444b5c;
}

.avatar-bubble {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid #c9ceda;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.65;
  color: #171a22;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
  /* say()/formatQA() put a blank line between the learner's own question
     and the avatar's reply — preserve it instead of collapsing to a space
     like a plain <p> normally would. */
  white-space: pre-line;
}

.avatar-ask-form {
  display: flex;
  gap: 6px;
  margin: 8px 0 0;
}

.avatar-ask-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  background: #ffffff;
  border: 1px solid #c9ceda;
  border-radius: 8px;
  font-size: 11px;
  color: #171a22;
}

.avatar-ask-input:disabled {
  background: #eef0f4;
  color: #8a90a0;
}

.avatar-ask-mic {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  border: 1px solid #c9ceda;
  border-radius: 50%;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.avatar-ask-mic:disabled {
  background: #eef0f4;
  color: #8a90a0;
  cursor: default;
}

.avatar-ask-mic.listening {
  background: #d64545;
  border-color: #d64545;
  animation: avatar-ask-mic-pulse 1.2s ease-in-out infinite;
}

@keyframes avatar-ask-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(214, 69, 69, 0); }
}

.avatar-ask-submit {
  flex: none;
  padding: 6px 10px;
  background: #171a22;
  border: 1px solid #171a22;
  border-radius: 8px;
  font-size: 11px;
  color: #ffffff;
  cursor: pointer;
}

.avatar-ask-submit:disabled {
  background: #8a90a0;
  border-color: #8a90a0;
  cursor: default;
}

/* Mobile (incl. Android): the desktop corner box doesn't work on a narrow,
   short viewport — it either overlaps quiz content or gets squeezed
   illegibly. Below 640px the avatar becomes a full-width bar pinned to the
   window's bottom edge, always painted above the page (z-index above
   .wrap's 41 — see index.html): the avatar block (.avatar-visual — the
   presenter plus its scene picker, stacked) on the left, and everything the
   learner reads/types ("communication": bubble/ask-form, .avatar-comm) on
   the right. The comm column scrolls internally so the bar never exceeds
   --avatar-bar-max-h; index.html pads .wrap's bottom by that same amount so
   page content and the toast never sit under it. */
@media (max-width: 640px) {
  .avatar-panel {
    --avatar-bar-max-h: 280px;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 45;
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-height: var(--avatar-bar-max-h);
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(17, 19, 26, 0.96);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.3);
  }
  .avatar-visual {
    flex: 0 0 88px;
    width: 88px;
  }
  .avatar-stage {
    width: 88px;
    height: 88px;
  }
  .avatar-scene-select {
    font-size: 10px;
    padding: 4px 6px;
  }
  .avatar-comm {
    flex: 1;
    min-width: 0;
    max-height: calc(var(--avatar-bar-max-h) - 20px);
    overflow-y: auto;
  }
  .avatar-comm > :first-child {
    margin-top: 0;
  }
  .avatar-bubble {
    max-height: 96px;
    font-size: 11.5px;
  }
  .avatar-ask-form {
    flex-wrap: wrap;
  }
  .avatar-ask-input {
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .avatar-panel * {
    transition: none !important;
  }
}
