/* ====================================================================
   REVSTRIX HOME PROFILE & POKÉMON COMPANION STYLING
   ==================================================================== */

.home-profile-controls,
.home-pokemon-companion {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.home-profile-controls {
  z-index: 100001;
}

.home-profile-controls[hidden],
.home-pokemon-companion[hidden],
.home-profile-backdrop[hidden],
.home-pokemon-greeting[hidden],
.home-pokemon-ball[hidden] {
  display: none !important;
}

/* ====================================================================
   1. TRAINER PROFILE BUTTON (Non-overlapping, Luxury Glass Aesthetic)
   ==================================================================== */
.home-profile-button {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 0px));
  right: max(20px, env(safe-area-inset-right, 0px));
  z-index: 100001;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 2px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(18, 18, 18, 0.78);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: pointer;
  pointer-events: auto;
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1), border-color 180ms ease, box-shadow 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.home-profile-button img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  pointer-events: none;
}

.home-profile-button:hover {
  transform: scale(1.06);
  border-color: rgba(255, 255, 255, 0.45);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.home-profile-button:active {
  transform: scale(0.96);
}

/* ====================================================================
   2. TRAINER PROFILE MODAL DIALOG
   ==================================================================== */
.home-profile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100002;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: max(72px, calc(env(safe-area-inset-top, 0px) + 64px)) max(20px, env(safe-area-inset-right, 0px)) 24px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 220ms cubic-bezier(0.2, 0.8, 0.2, 1), visibility 220ms ease;
}

.home-profile-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.home-profile-dialog {
  position: relative;
  width: min(100%, 340px);
  padding: 28px 24px 24px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  color: #ffffff;
  background: rgba(16, 17, 22, 0.95);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 0 0 1px rgba(0, 0, 0, 0.4);
  text-align: center;
  transform: translateY(-8px) scale(0.97);
  transition: opacity 220ms ease, transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
  opacity: 0;
  pointer-events: auto;
  font-family: "PP Neue Montreal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.home-profile-backdrop.is-open .home-profile-dialog {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.home-profile-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.06);
  font: 300 22px/1 Arial, sans-serif;
  cursor: pointer;
  pointer-events: auto;
  transition: color 150ms ease, background-color 150ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.home-profile-close:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.14);
  transform: scale(1.05);
}

.home-profile-eyebrow {
  margin: 0 0 16px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.home-profile-portrait-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 130px;
  height: 130px;
  margin: 0 auto 16px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.home-profile-portrait {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  object-fit: cover;
}

.home-profile-label {
  margin: 6px 0 2px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  font-weight: 500;
}

.home-profile-name {
  margin: 0 0 18px;
  color: #ffffff;
  font-size: clamp(24px, 6vw, 30px);
  font-weight: 600;
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}

.home-profile-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: #000000;
  background: #ffffff;
  font-family: "PP Neue Montreal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 150ms ease, transform 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

.home-profile-logout:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

.home-profile-logout:active {
  transform: scale(0.98);
}

.home-profile-logout:disabled {
  cursor: wait;
  opacity: 0.6;
}

.home-profile-status {
  min-height: 16px;
  margin: 8px 0 0;
  color: #ff6b7b;
  font-size: 12px;
  font-weight: 500;
}

/* ====================================================================
   3. FLOATING POKÉMON BUDDY CONTAINER & ENTRANCE ANIMATION
   ==================================================================== */
.home-pokemon-companion {
  z-index: 100000;
  right: auto;
  bottom: auto;
  width: clamp(76px, 13vw, 100px);
  height: clamp(76px, 13vw, 100px);
  overflow: visible;
  transform: translate(-50%, -50%);
  transition: left 5.8s cubic-bezier(0.22, 0.75, 0.24, 1), top 5.8s cubic-bezier(0.22, 0.75, 0.24, 1);
  will-change: left, top;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

/* Poké Ball Animation Element (Uses Uploaded Asset) */
.home-pokemon-ball {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -50%);
  background-image: url("/images/pokeball-clean.png");
  background-repeat: no-repeat;
  background-size: 225px 225px;
  /* Frame 0: Closed Poké Ball */
  background-position: -3px -79px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
  transition: opacity 280ms ease, transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
  pointer-events: none;
  z-index: 2;
}

/* Subtle anticipatory wobble while buddy is hidden inside the Poké Ball */
.home-pokemon-companion.is-inside-ball .home-pokemon-ball {
  animation: pokeball-wobble-wait 1.1s ease-in-out infinite alternate;
}

/* Frame 1: Cracked Open */
.home-pokemon-companion.ball-opening-1 .home-pokemon-ball {
  width: 58px;
  height: 63px;
  background-position: -81px -79px;
  transform: translate(-50%, -50%) scale(1.08);
}

/* Frame 2: Fully Open */
.home-pokemon-companion.ball-opening-2 .home-pokemon-ball {
  width: 59px;
  height: 78px;
  background-position: -164px -74px;
  transform: translate(-50%, -50%) scale(1.12);
}

/* Ball Dissolved / Hidden After Entrance */
.home-pokemon-companion.is-revealed .home-pokemon-ball {
  opacity: 0;
  transform: translate(-50%, -30%) scale(0.7);
  pointer-events: none;
}

/* Radial energy flash radiating from opening ball */
.home-pokemon-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 15%, #5ee2ff 55%, rgba(255, 255, 255, 0) 75%);
  box-shadow: 0 0 28px #5ee2ff, 0 0 56px #12a8ff;
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.home-pokemon-companion.is-flashing .home-pokemon-flash {
  animation: pokeball-flash-burst 450ms ease-out forwards;
}

@keyframes pokeball-wobble-wait {
  0% { transform: translate(-50%, -50%) rotate(-4deg); }
  50% { transform: translate(-50%, -52%) rotate(4deg) scale(1.03); }
  100% { transform: translate(-50%, -50%) rotate(-4deg); }
}

@keyframes pokeball-flash-burst {
  0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0.95; }
  50% { transform: translate(-50%, -50%) scale(8.5); opacity: 0.85; }
  100% { transform: translate(-50%, -50%) scale(15); opacity: 0; }
}

/* Pokémon Buddy Image Motion */
.home-pokemon-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 9px rgba(50, 212, 255, 0.72));
  transform-origin: 50% 86%;
  animation: home-pokemon-idle 3.2s ease-in-out infinite;
  transition: opacity 350ms ease, transform 450ms cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

/* Hidden while inside Poké Ball */
.home-pokemon-companion.is-inside-ball .home-pokemon-image {
  opacity: 0;
  transform: scale(0) translateY(24px);
  pointer-events: none;
  animation: none;
}

/* Revealed after Poké Ball opens with fluid motion */
.home-pokemon-companion.is-revealed .home-pokemon-image {
  opacity: 1;
  transform: scale(1) translateY(0);
}

.home-pokemon-companion.is-cheery .home-pokemon-image {
  animation:
    home-pokemon-cheer 850ms ease-out 1,
    home-pokemon-idle 3.2s ease-in-out 850ms infinite;
}

.home-pokemon-companion.is-still .home-pokemon-image {
  animation: none;
}

/* ====================================================================
   4. RESTYLED COMPANION DIALOGUE BOX (Matching Website's UI System)
   ==================================================================== */
.home-pokemon-greeting {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  z-index: 10;
  width: max-content;
  max-width: min(260px, calc(100vw - 32px));
  padding: 9px 15px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  color: #ffffff;
  background: rgba(14, 16, 22, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  font-family: "PP Neue Montreal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 220ms;
}

.home-pokemon-greeting.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition-delay: 0s;
}

/* Speech bubble pointer tail pointing down to buddy */
.home-pokemon-greeting::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid rgba(14, 16, 22, 0.94);
}

@keyframes home-pokemon-idle {
  0%, 100% { transform: rotate(-2.5deg) translateY(0); }
  50% { transform: rotate(2.5deg) translateY(-3px); }
}

@keyframes home-pokemon-cheer {
  0%, 100% { transform: rotate(0) translateY(0); }
  35% { transform: rotate(-5deg) translateY(-8px) scale(1.05); }
  68% { transform: rotate(4deg) translateY(-3px) scale(1.02); }
}

/* ====================================================================
   5. RESPONSIVE MOBILE ADJUSTMENTS
   ==================================================================== */
@media (max-width: 768px) {
  .home-profile-button {
    top: max(11px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: 38px;
    height: 38px;
  }

  .home-profile-backdrop {
    padding-top: max(56px, calc(env(safe-area-inset-top, 0px) + 50px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
  }

  .home-profile-dialog {
    width: 100%;
    padding: 22px 18px 20px;
  }

  .home-profile-portrait-frame {
    width: 110px;
    height: 110px;
  }

  .home-profile-name {
    font-size: 22px;
    margin-bottom: 14px;
  }

  .home-pokemon-greeting {
    font-size: 12px;
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .home-profile-button,
  .home-profile-backdrop,
  .home-profile-dialog,
  .home-pokemon-companion,
  .home-pokemon-greeting,
  .home-pokemon-ball,
  .home-pokemon-image {
    transition-duration: 1ms !important;
    animation: none !important;
  }
}
