/* ==========================================================================
   NIRA INTERACTIVE GAME-LIKE TUTORIAL STYLESHEET
   ========================================================================== */

/* 1. Cinematic Backdrop Blur & Grayscale */
#nira-tour-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(8, 15, 30, 0.72);
  backdrop-filter: blur(6px) grayscale(45%);
  -webkit-backdrop-filter: blur(6px) grayscale(45%);
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  opacity: 0;
}

#nira-tour-backdrop.active {
  opacity: 1;
}

/* 2. Floating Mascot & Glassmorphism Speech Bubble Container */
#nira-mascot-container {
  position: fixed;
  left: 236px; /* Default for expanded rail (220px) when detail panel is closed */
  bottom: 32px;
  z-index: 100002;
  display: flex;
  align-items: flex-end;
  gap: 16px;
  pointer-events: none;
  font-family: 'Plus Jakarta Sans', sans-serif;
  opacity: 0;
  transform: translateY(60px);
  transition: 
    left 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
    bottom 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
    transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.6s ease;
}

#nira-mascot-container.active {
  opacity: 1;
  transform: translateY(0);
}

/* Shift right animation for Tier 3 Panels (Desktop >= 1200px) */
@media (min-width: 1200px) {
  #nira-mascot-container.nira-tour-shifted {
    left: 608px !important; /* Right of the open 360px detail panel (232px + 360px + 16px) */
  }
}

/* Shift right animation for Tier 3 Panels (Tablet 768px - 1199px) */
@media (min-width: 768px) and (max-width: 1199px) {
  #nira-mascot-container.nira-tour-shifted {
    left: 568px !important; /* Right of the open 320px detail panel (232px + 320px + 16px) */
  }
}

/* Shift far left for Centered Modal on Tablet/Desktop (Step 9) */
@media (min-width: 768px) {
  #nira-mascot-container.nira-tour-modal-open {
    left: 16px !important;
  }
}

/* Floating Animation for Mascot Image and Container */
@keyframes mascot-float {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  50% {
    transform: translateY(-8px) rotate(1.5deg);
  }
}

.nira-mascot-wrapper {
  position: relative;
  width: 180px; /* Premium compact mascot width */
  height: 180px; /* Premium compact mascot height */
  pointer-events: auto;
  animation: mascot-float 4s ease-in-out infinite;
  filter: drop-shadow(0 8px 24px rgba(0, 104, 87, 0.25));
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.nira-mascot-wrapper:hover {
  transform: scale(1.05);
}

#nira-mascot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 3. Luxury Glassmorphism Speech Bubble */
.nira-speech-bubble {
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: 
    0 16px 40px rgba(0, 70, 58, 0.18), 
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: 20px;
  width: 290px; /* Compact dialog width for minimal overlap */
  pointer-events: auto;
  position: relative;
  transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: #1e293b;
}

/* Dark Mode Adaptation */
.dark .nira-speech-bubble {
  background: rgba(15, 23, 42, 0.88);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 
    0 16px 40px rgba(0, 0, 0, 0.45), 
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
}

/* Speech Bubble Left Pointy Arrow */
.nira-speech-bubble::before {
  content: '';
  position: absolute;
  bottom: 28px;
  left: -8px;
  width: 16px;
  height: 16px;
  background: inherit;
  transform: rotate(45deg);
  border-left: 1px solid rgba(255, 255, 255, 0.45);
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: -4px 4px 8px rgba(0, 70, 58, 0.04);
}

.dark .nira-speech-bubble::before {
  border-left-color: rgba(255, 255, 255, 0.1);
  border-bottom-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

/* Bubble Header (Nira Assistant) */
.nira-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(0, 104, 87, 0.1);
  padding-bottom: 8px;
  margin-bottom: 4px;
}

.dark .nira-bubble-header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.nira-mascot-title {
  font-weight: 800;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #006857;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dark .nira-mascot-title {
  color: #5ddbbe;
}

.nira-step-badge {
  font-size: 10px;
  font-weight: 700;
  background: rgba(11, 143, 114, 0.12);
  color: #0b8f72;
  padding: 3px 8px;
  border-radius: 99px;
  letter-spacing: 0.5px;
}

.dark .nira-step-badge {
  background: rgba(93, 219, 190, 0.15);
  color: #5ddbbe;
}

/* Bubble Body Text (With game dialogue flow and absolute word wrapping safety) */
.nira-bubble-body {
  font-size: 12.5px;
  line-height: 1.6;
  font-weight: 500;
  margin-bottom: 8px;
  min-height: 50px;
  width: 100% !important;
  max-width: 100% !important;
  word-wrap: break-word !important;
  word-break: break-word !important;
  white-space: normal !important;
}

.nira-bubble-body strong {
  color: #006857;
  font-weight: 700;
}

.dark .nira-bubble-body strong {
  color: #5ddbbe;
}

/* Bubble Footer Action Buttons */
.nira-bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: auto;
}

.nira-btn-tour {
  font-size: 11px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.nira-btn-tour-secondary {
  background: transparent;
  color: #64748b;
}

.nira-btn-tour-secondary:hover {
  background: rgba(0, 0, 0, 0.04);
  color: #334155;
}

.dark .nira-btn-tour-secondary {
  color: #94a3b8;
}

.dark .nira-btn-tour-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #e2e8f0;
}

.nira-btn-tour-primary {
  background: linear-gradient(135deg, #0b8f72, #006857);
  color: white;
  box-shadow: 0 4px 12px rgba(0, 104, 87, 0.25);
}

.nira-btn-tour-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 104, 87, 0.35);
}

.nira-btn-tour-primary:active {
  transform: translateY(0);
}

/* 4. Game-like Glowing Zoom Highlight */
@keyframes glow-pulse {
  0% {
    box-shadow: 
      0 0 0 0px rgba(11, 143, 114, 0.6), 
      0 0 10px rgba(11, 143, 114, 0.4),
      0 8px 24px rgba(0, 0, 0, 0.15) !important;
  }
  50% {
    box-shadow: 
      0 0 0 12px rgba(11, 143, 114, 0), 
      0 0 25px rgba(11, 143, 114, 0.8),
      0 8px 24px rgba(0, 0, 0, 0.15) !important;
  }
  100% {
    box-shadow: 
      0 0 0 0px rgba(11, 143, 114, 0), 
      0 0 10px rgba(11, 143, 114, 0.4),
      0 8px 24px rgba(0, 0, 0, 0.15) !important;
  }
}

/* Desktop highlight – scale transform is safe here */
@media (min-width: 768px) {
  .nira-tour-active-highlight {
    z-index: 100000 !important;
    pointer-events: auto !important;
    transform: scale(1.08) !important;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease !important;
    animation: glow-pulse 1.6s infinite !important;
    border-color: #0b8f72 !important;
  }
}

/* Report-form modal is a large card — don't scale it, just glow */
#report-form-modal.nira-tour-active-highlight {
  transform: none !important;
  box-shadow:
    0 0 0 4px rgba(11, 143, 114, 0.55),
    0 0 28px rgba(11, 143, 114, 0.35),
    0 20px 60px rgba(0,0,0,0.25) !important;
  animation: glow-pulse 1.6s infinite !important;
}

/* 5. Precise Dimming rules inside boosted parents (Avoids dimming parent containers) */
.nira-tour-parent-highlight {
  z-index: 99999 !important;
}

/* Report-form overlay needs higher z-index to sit above the tutorial backdrop */
#report-form-overlay.nira-tour-parent-highlight {
  z-index: 100001 !important;
  opacity: 1 !important;
  pointer-events: all !important;
}

.nira-tour-parent-highlight .rail-nav-btn:not(.nira-tour-active-highlight),
.nira-tour-parent-highlight .rail-action-btn,
.nira-tour-parent-highlight .rail-avatar,
.nira-tour-parent-highlight .rail-expand-btn,
.nira-tour-parent-highlight .menu-row:not(.nira-tour-active-highlight) {
  opacity: 0.22 !important;
  pointer-events: none !important;
  transition: opacity 0.3s ease !important;
}

/* 6. Dynamic Arrow Pointer (COMPLETELY OFF) */
#nira-tour-pointer {
  display: none !important;
}

/* 7. Dialogue Text Typing Transition */
.nira-bubble-text-fade {
  animation: text-reveal-anim 0.35s ease-out forwards;
}

@keyframes text-reveal-anim {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
   8. MOBILE TUTORIAL — Complete Visual Spotlight System
   ============================================================ */
@media (max-width: 767px) {

  /* ── Mascot container base positioning ── */
  #nira-mascot-container {
    display: flex !important;
    flex-direction: column !important;    /* bubble on top, mascot below */
    align-items: flex-start !important;
    left: 12px !important;
    right: 12px !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 108px) !important;
    gap: 8px !important;
    pointer-events: none !important;
    transform: translateY(60px);
  }

  #nira-mascot-container.active {
    transform: translateY(0) !important;
  }

  /* When step targets a HEADER element — push container down to the bottom of the screen to avoid covering the header */
  #nira-mascot-container.nira-tour-target-header {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px) !important;
  }

  /* When step targets NAV — keep container mid-screen */
  #nira-mascot-container.nira-tour-target-nav {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 108px) !important;
  }

  /* Disable desktop shifts on mobile */
  #nira-mascot-container.nira-tour-shifted,
  #nira-mascot-container.nira-tour-modal-open {
    left: 12px !important;
  }

  /* ── Mascot image (row: mascot left, nothing right) ── */
  .nira-mascot-wrapper {
    width: 120px !important;
    height: 120px !important;
    align-self: flex-start !important;
    margin-left: 0 !important;
    filter: drop-shadow(0 6px 16px rgba(0, 104, 87, 0.22));
    animation: mascot-float 4s ease-in-out infinite;
    flex-shrink: 0 !important;
  }

  /* ── Speech bubble — full width card sitting above mascot ── */
  .nira-speech-bubble {
    width: calc(100vw - 24px) !important;
    max-width: 420px !important;
    border-radius: 20px !important;
    padding: 14px 16px !important;
    order: -1;  /* bubble first (top), mascot second (bottom) */
    /* Clean left-aligned arrow at bottom-left pointing down to mascot */
    position: relative;
  }

  /* Arrow at BOTTOM pointing to mascot below the bubble */
  .nira-speech-bubble::before {
    bottom: -8px !important;
    left: 28px !important;
    top: auto !important;
    border-left: none !important;
    border-top: none !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.45) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.45) !important;
    transform: rotate(45deg) !important;
    box-shadow: 4px 4px 8px rgba(0, 70, 58, 0.04) !important;
  }

  .dark .nira-speech-bubble::before {
    border-bottom-color: rgba(255, 255, 255, 0.1) !important;
    border-right-color: rgba(255, 255, 255, 0.1) !important;
  }

  /* ── Backdrop: heavier blur on mobile, rest of screen blurred ── */
  #nira-tour-backdrop {
    display: block !important;
    background: rgba(8, 15, 30, 0.68) !important;
    backdrop-filter: blur(6px) !important;
    -webkit-backdrop-filter: blur(6px) !important;
  }

  /* ── PARENT HIGHLIGHT on mobile: lift whole container ABOVE backdrop ── */
  /* The key insight: fixed elements' z-index is absolute, so we set it very high */
  .nira-tour-parent-highlight {
    z-index: 100001 !important;
    position: fixed !important;   /* ensure it participates in the fixed stack */
  }

  /* Dim and blur non-highlighted siblings inside boosted parent */
  .nira-tour-parent-highlight > *:not(.nira-tour-active-highlight) {
    opacity: 0.22 !important;
    filter: blur(2px) !important;
    transition: opacity 0.3s ease, filter 0.3s ease !important;
    pointer-events: none !important;
  }

  /* Prevent dimming and blurring of nav wrapper div itself */
  nav.mobile-only.nira-tour-parent-highlight > div {
    opacity: 1 !important;
    filter: none !important;
    pointer-events: auto !important;
  }

  /* ── ACTIVE HIGHLIGHT on mobile: NO transform scale (it resets stacking) ── */
  /* Use outline + box-shadow glow ring instead */
  .nira-tour-active-highlight {
    z-index: 100002 !important;
    pointer-events: auto !important;
    transform: none !important;
    outline: 3px solid rgba(11, 143, 114, 0.8) !important;
    outline-offset: 4px !important;
    border-radius: 12px !important;
    animation: mobile-glow-pulse 1.6s infinite !important;
  }

  @keyframes mobile-glow-pulse {
    0%, 100% {
      box-shadow: 0 0 0 0px rgba(11, 143, 114, 0.5), 0 0 12px rgba(11, 143, 114, 0.4) !important;
      outline-color: rgba(11, 143, 114, 0.8) !important;
    }
    50% {
      box-shadow: 0 0 0 8px rgba(11, 143, 114, 0), 0 0 24px rgba(11, 143, 114, 0.7) !important;
      outline-color: rgba(11, 143, 114, 1.0) !important;
    }
  }

  /* Prevent opacity dimming of siblings from interfering inside highlighted parents */
  .nira-tour-parent-highlight .nira-tour-active-highlight {
    opacity: 1 !important;
  }

  /* Nav-specific: dim and blur inactive tab items inside nav */
  nav.mobile-only.nira-tour-parent-highlight > div > *:not(.nira-tour-active-highlight):not(:has(.nira-tour-active-highlight)),
  nav.mobile-only.nira-tour-parent-highlight > *:not(.nira-tour-active-highlight):not(:has(.nira-tour-active-highlight)) {
    opacity: 0.22 !important;
    filter: blur(2px) !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease, filter 0.3s ease !important;
  }
  /* Keep both direct and wrapper-enclosed highlighted elements fully visible and unblurred */
  nav.mobile-only.nira-tour-parent-highlight > div > .nira-tour-active-highlight,
  nav.mobile-only.nira-tour-parent-highlight > div > *:has(.nira-tour-active-highlight),
  nav.mobile-only.nira-tour-parent-highlight > .nira-tour-active-highlight {
    opacity: 1 !important;
    filter: none !important;
  }
  /* The highlighted element inside the wrapper is also full opacity and unblurred */
  nav.mobile-only.nira-tour-parent-highlight .nira-tour-active-highlight {
    opacity: 1 !important;
    filter: none !important;
  }

  /* For the central floating button (#btn-quick-report) inside its wrapper div */
  .nira-tour-active-highlight#btn-quick-report {
    outline-offset: 6px !important;
    border-radius: 50% !important;
  }

  /* Search pill target */
  #search-mobile-pill.nira-tour-active-highlight {
    outline-offset: 4px !important;
    border-radius: 9999px !important;
  }

  /* Header-specific dimming: dim and blur icons but keep search highlighted and clear */
  header.mobile-only.nira-tour-parent-highlight > *:not(#search-wrapper-mobile) {
    opacity: 0.22 !important;
    filter: blur(2px) !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease, filter 0.3s ease !important;
  }
  header.mobile-only.nira-tour-parent-highlight #search-wrapper-mobile {
    opacity: 1 !important;
    filter: none !important;
  }

  /* Boost mobile overlays above backdrop when tutorial is active so they are fully visible and interactive when opened */
  .nira-tutorial-active #staysafe-overlay,
  .nira-tutorial-active #community-overlay,
  .nira-tutorial-active #quick-report-sheet,
  .nira-tutorial-active #report-form-overlay {
    z-index: 100001 !important;
  }

  /* Shift mascot and speech bubble to the left when targeting right-side elements */
  #nira-mascot-container.nira-tour-target-right {
    right: auto !important;
    left: 12px !important;
    width: 250px !important;
  }
  #nira-mascot-container.nira-tour-target-right .nira-speech-bubble {
    width: 250px !important;
    max-width: 250px !important;
  }

  /* Circular button targets */
  #mobile-layers-toggle.nira-tour-active-highlight,
  #nira-mobile-btn.nira-tour-active-highlight,
  #btn-quick-report.nira-tour-active-highlight {
    outline-offset: 6px !important;
    border-radius: 50% !important;
  }
}

