/* ==========================================================
   AP AI Website Narrator — v2.0.0
   Namespaced: apnar-* prefix prevents theme conflicts.
   ========================================================== */

/* ---- Reset for widget scope ---- */
#ap-ai-guide-root *,
#ap-ai-guide-root *::before,
#ap-ai-guide-root *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---- Custom Properties ---- */
:root {
  --ap-orange:    #FF8C42;
  --ap-orange-dk: #e57420;
  --ap-blue:      #2C6EAB;
  --ap-blue-dk:   #1A4E7A;
  --ap-blue-lt:   #E8F4FF;
  --ap-white:     #FFFFFF;
  --ap-shadow:    0 8px 32px rgba(0,0,0,0.18);
  --ap-radius:    18px;
  --ap-panel-w:   340px;
  --ap-panel-h:   530px;
}

/* ================================================================
   MASCOT BUTTON (floating)
================================================================ */
.apnar-btn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  border: 3px solid var(--ap-orange);
  background: var(--ap-white);
  cursor: pointer;
  box-shadow: var(--ap-shadow);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  outline: none;
  overflow: visible;
  /* Smooth left↔right repositioning */
  transition: transform 0.28s ease, border-color 0.25s ease,
              right 0.55s cubic-bezier(0.34,1.56,0.64,1),
              left  0.55s cubic-bezier(0.34,1.56,0.64,1),
              bottom 0.3s ease;
}

.apnar-btn:hover { transform: scale(1.11) translateY(-3px); border-color: var(--ap-blue); }
.apnar-btn.apnar-open { transform: scale(0.88); border-color: var(--ap-blue); }

/* Ripple ring */
.apnar-ripple {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--ap-orange);
  animation: apnar-ripple 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes apnar-ripple {
  0%   { transform: scale(1);   opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* Image wrapper — needed for mouth overlay */
.apnar-img-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apnar-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 50%;
  pointer-events: none;
}

/* ── Simulated mouth / lip-sync overlay ─────────────────────── */
.apnar-mouth {
  position: absolute;
  bottom: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 8px;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Three equalizer bars */
.apnar-mouth::before,
.apnar-mouth::after,
.apnar-mouth span {
  content: '';
  display: block;
  width: 7px;
  background: var(--ap-orange);
  border-radius: 3px 3px 0 0;
  height: 4px;
  transition: height 0.12s ease;
}

/* Speaking — bars animate */
.apnar-mouth.apnar-mouth-on {
  opacity: 1;
}
.apnar-mouth.apnar-mouth-on::before {
  animation: apnar-bar1 0.42s ease-in-out infinite alternate;
}
.apnar-mouth.apnar-mouth-on span {
  animation: apnar-bar2 0.31s ease-in-out infinite alternate;
  animation-delay: 0.09s;
}
.apnar-mouth.apnar-mouth-on::after {
  animation: apnar-bar3 0.38s ease-in-out infinite alternate;
  animation-delay: 0.18s;
}
/* Beat pulse (onboundary) */
.apnar-mouth.apnar-mouth-beat::before { height: 14px !important; }
.apnar-mouth.apnar-mouth-beat span   { height: 10px !important; }
.apnar-mouth.apnar-mouth-beat::after  { height: 12px !important; }

@keyframes apnar-bar1 { from { height: 3px; } to { height: 14px; } }
@keyframes apnar-bar2 { from { height: 5px; } to { height: 18px; } }
@keyframes apnar-bar3 { from { height: 3px; } to { height: 11px; } }

/* ── Wake word indicator ─────────────────────────────────── */
.apnar-wake-ind {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 22px;
  height: 22px;
  background: var(--ap-blue);
  border: 2px solid var(--ap-white);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #fff;
  z-index: 100002;
  animation: apnar-wake-pulse 1.8s ease-in-out infinite;
  pointer-events: none;
}
@keyframes apnar-wake-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(44,110,171,0.5); }
  50%       { box-shadow: 0 0 0 6px rgba(44,110,171,0); }
}

/* ── Speech bubble tease ─────────────────────────────────── */
.apnar-bubble-tease {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  background: var(--ap-blue);
  color: var(--ap-white);
  padding: 9px 14px;
  border-radius: 14px 14px 2px 14px;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
  z-index: 100000;
  max-width: 220px;
  white-space: normal;
  text-align: center;
}
.apnar-bubble-show { opacity: 1; transform: translateY(0); }

/* ── Mascot state animations ─────────────────────────────── */
.apnar-state-idle .apnar-img-wrap img {
  animation: apnar-float 3.2s ease-in-out infinite;
}
@keyframes apnar-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-7px); }
}

.apnar-state-thinking .apnar-img-wrap img {
  animation: apnar-think 0.55s ease-in-out infinite alternate;
}
@keyframes apnar-think {
  from { transform: rotate(-5deg) scale(0.95); }
  to   { transform: rotate(5deg) scale(1.06); }
}

.apnar-state-speaking .apnar-img-wrap img {
  animation: apnar-speak 0.32s ease-in-out infinite alternate;
}
@keyframes apnar-speak {
  from { transform: scaleY(1); }
  to   { transform: scaleY(1.07); }
}

.apnar-state-listening .apnar-img-wrap img {
  animation: apnar-listen 1s ease-in-out infinite;
  filter: drop-shadow(0 0 10px var(--ap-orange));
}
@keyframes apnar-listen {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.09); }
}

/* ── Pointer gesture emoji ───────────────────────────────── */
@keyframes apnar-ptr {
  from { transform: translateY(0) rotate(-5deg); }
  to   { transform: translateY(-8px) rotate(5deg); }
}

/* ================================================================
   CHAT PANEL
================================================================ */
.apnar-panel {
  position: fixed;
  bottom: 114px;
  right: 28px;
  width: var(--ap-panel-w);
  max-height: var(--ap-panel-h);
  background: var(--ap-white);
  border-radius: var(--ap-radius);
  box-shadow: var(--ap-shadow);
  z-index: 99998;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.86) translateY(22px);
  transform-origin: bottom right;
  transition: opacity 0.3s ease, transform 0.3s ease,
              right 0.55s cubic-bezier(0.34,1.56,0.64,1),
              left  0.55s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: none;
}
.apnar-panel[hidden] { display: flex !important; }
.apnar-panel-open {
  opacity: 1 !important;
  transform: scale(1) translateY(0) !important;
  pointer-events: all !important;
}

/* ── Header ─────────────────────────────────────────────── */
.apnar-header {
  background: linear-gradient(135deg, var(--ap-blue), var(--ap-blue-dk));
  color: var(--ap-white);
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.apnar-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.apnar-header-img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--ap-orange);
  background: var(--ap-white);
  padding: 2px;
  object-fit: contain;
  animation: apnar-float 3.2s ease-in-out infinite;
  flex-shrink: 0;
}
.apnar-header-title {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.apnar-header-sub {
  font-size: 10.5px;
  opacity: 0.82;
  margin-top: 2px;
}
.apnar-header-acts {
  display: flex;
  gap: 5px;
}
.apnar-icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 7px;
  color: var(--ap-white);
  cursor: pointer;
  font-size: 14px;
  padding: 5px 7px;
  transition: background 0.2s;
  line-height: 1;
}
.apnar-icon-btn:hover { background: rgba(255,255,255,0.28); }

/* ── Messages area ───────────────────────────────────────── */
.apnar-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 13px 11px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  scroll-behavior: smooth;
  min-height: 0;
}
.apnar-msgs::-webkit-scrollbar { width: 5px; }
.apnar-msgs::-webkit-scrollbar-track { background: #f0f0f0; }
.apnar-msgs::-webkit-scrollbar-thumb { background: #c8c8c8; border-radius: 4px; }

.apnar-msg {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  animation: apnar-msg-in 0.22s ease;
}
@keyframes apnar-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.apnar-avatar {
  font-size: 17px;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.apnar-bubble {
  background: var(--ap-blue-lt);
  color: #1a1a2e;
  border-radius: 14px 14px 14px 2px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.55;
  max-width: 86%;
  word-break: break-word;
}
.apnar-bubble a { color: var(--ap-blue); font-weight: 600; text-decoration: underline; }
.apnar-bubble-user {
  background: var(--ap-orange);
  color: var(--ap-white);
  border-radius: 14px 14px 2px 14px;
  margin-left: auto;
}
.apnar-user { justify-content: flex-end; }

/* Thinking dots */
.apnar-dots span {
  animation: apnar-dot-bounce 1.2s infinite ease-in-out;
  display: inline-block;
  font-size: 18px;
  color: var(--ap-blue);
}
.apnar-dots span:nth-child(2) { animation-delay: 0.2s; }
.apnar-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes apnar-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-7px); }
}

/* Tour badge */
.apnar-badge {
  background: var(--ap-orange);
  color: var(--ap-white);
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 8px;
  margin-right: 4px;
  display: inline-block;
  vertical-align: middle;
}

/* Sources */
.apnar-sources {
  font-size: 11px;
  color: #555;
  padding: 5px 2px 2px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.apnar-src {
  color: var(--ap-blue) !important;
  text-decoration: none !important;
  background: #f0f7ff;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 600;
  border: 1px solid #c9dffa;
  transition: background 0.15s;
}
.apnar-src:hover { background: var(--ap-blue-lt); }

/* Nav button */
.apnar-nav-btn, .apnar-tour-cta {
  background: var(--ap-orange);
  color: var(--ap-white);
  border: none;
  border-radius: 8px;
  padding: 6px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 5px;
  display: inline-block;
  transition: background 0.2s, transform 0.15s;
}
.apnar-nav-btn:hover, .apnar-tour-cta:hover {
  background: var(--ap-orange-dk);
  transform: scale(1.03);
}

/* User type picker */
.apnar-type-label { font-size: 11.5px; font-weight: 600; color: #555; margin-bottom: 7px; }
.apnar-type-btns { display: flex; flex-wrap: wrap; gap: 5px; }
.apnar-type-btns button {
  background: #fff3e8;
  border: 1.5px solid var(--ap-orange);
  border-radius: 20px;
  color: #a0410a;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.apnar-type-btns button:hover { background: var(--ap-orange); color: #fff; }

/* ── Tour controls ───────────────────────────────────────── */
.apnar-tour-ctrls {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  background: #f7fbff;
  border-top: 1px solid #dceaf8;
  gap: 6px;
  flex-shrink: 0;
}
.apnar-tbtn {
  background: var(--ap-blue);
  color: var(--ap-white);
  border: none;
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, background 0.2s;
}
.apnar-tbtn:disabled { opacity: 0.38; cursor: default; }
.apnar-tbtn:not(:disabled):hover { background: var(--ap-blue-dk); }
.apnar-tbtn-stop { background: #e8e8e8; color: #555; }
.apnar-tbtn-stop:hover { background: #d5d5d5 !important; }
#apnar-tour-prog { font-size: 11.5px; color: #666; flex: 1; text-align: center; }

/* ── Wake word row ───────────────────────────────────────── */
.apnar-wake-row {
  padding: 6px 13px;
  background: #f9fbff;
  border-top: 1px solid #e5edf7;
  flex-shrink: 0;
}
.apnar-wake-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #555;
  cursor: pointer;
}
.apnar-wake-label input[type="checkbox"] {
  accent-color: var(--ap-blue);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ── Input row ───────────────────────────────────────────── */
.apnar-input-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 9px 11px;
  border-top: 1px solid #e4eef8;
  background: #fff;
  flex-shrink: 0;
}
.apnar-input {
  flex: 1;
  border: 1.5px solid #c9dffa;
  border-radius: 22px;
  padding: 8px 14px;
  font-size: 13px;
  outline: none;
  color: #1a1a2e;
  background: #f8fbff;
  transition: border-color 0.2s;
}
.apnar-input:focus { border-color: var(--ap-blue); background: #fff; }

.apnar-mic-btn {
  background: #f0f7ff;
  border: 1.5px solid #c9dffa;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}
.apnar-mic-btn:hover { background: var(--ap-blue-lt); border-color: var(--ap-blue); }
.apnar-mic-on {
  background: #ffe5e5 !important;
  border-color: #e74c3c !important;
  animation: apnar-pulse 1s ease-in-out infinite;
}
@keyframes apnar-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231,76,60,0.4); }
  50%       { box-shadow: 0 0 0 8px rgba(231,76,60,0); }
}

.apnar-send-btn {
  background: var(--ap-blue);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  color: var(--ap-white);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
.apnar-send-btn:hover { background: var(--ap-blue-dk); transform: scale(1.08); }

/* ── Footer ─────────────────────────────────────────────── */
.apnar-footer {
  font-size: 10px;
  color: #aaa;
  text-align: center;
  padding: 4px 0 6px;
  background: #fff;
  flex-shrink: 0;
}
.apnar-footer a { color: var(--ap-blue); text-decoration: none; font-weight: 600; }

/* ================================================================
   ELEMENT HIGHLIGHT (on page content)
================================================================ */
.apnar-hl {
  outline: 3px solid var(--ap-orange) !important;
  outline-offset: 5px !important;
  box-shadow: 0 0 0 6px rgba(255,140,66,0.2) !important;
  scroll-margin-top: 80px;
}

/* ================================================================
   MOBILE RESPONSIVE
================================================================ */
@media (max-width: 420px) {
  :root {
    --ap-panel-w: calc(100vw - 20px);
    --ap-panel-h: 72vh;
  }
  .apnar-panel { right: 10px; bottom: 98px; }
  .apnar-btn   { right: 16px; bottom: 20px; }
}

/* ================================================================
   REDUCED MOTION
================================================================ */
@media (prefers-reduced-motion: reduce) {
  .apnar-btn,
  .apnar-state-idle .apnar-img-wrap img,
  .apnar-state-speaking .apnar-img-wrap img,
  .apnar-state-thinking .apnar-img-wrap img,
  .apnar-state-listening .apnar-img-wrap img,
  .apnar-header-img,
  .apnar-ripple,
  .apnar-mouth.apnar-mouth-on::before,
  .apnar-mouth.apnar-mouth-on span,
  .apnar-mouth.apnar-mouth-on::after {
    animation: none !important;
  }
}
