/**
 * Fluid Glass Menu - Morphing Glass Capsule
 * Single-object morph navigation inspired by fluid.glass
 */

:root {
  --fg-capsule-closed-w: 236px;
  --fg-capsule-closed-h: 48px;
  --fg-capsule-open-w: 284px;
  --fg-capsule-open-h: 366px;
  --fg-bg: rgba(18, 18, 22, 0.82);
  --fg-bg-open: rgba(14, 14, 18, 0.92);
  --fg-border: rgba(255, 255, 255, 0.12);
  --fg-border-open: rgba(255, 255, 255, 0.18);
  --fg-orange: #ff6400;
  --fg-text: #f4f4f6;
  --fg-text-dim: #9ca3af;
}

/* Base floating container pinned at bottom center */
.fg-menu {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 36px);
  opacity: 0;
  pointer-events: none;
  z-index: 99999;
  display: block !important;
  transition: transform 0.55s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.45s ease;
  will-change: transform, opacity;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.fg-menu.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.fg-menu.is-hidden-footer {
  opacity: 0;
  transform: translate(-50%, 28px);
  pointer-events: none;
}

/* The Morphing Capsule: expands upward */
.fg-capsule {
  position: relative;
  width: var(--fg-capsule-closed-w);
  height: var(--fg-capsule-closed-h);
  max-height: calc(100vh - 40px);
  border-radius: 12px;
  background: var(--fg-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--fg-border);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3), 
              0 0 0 1px rgba(255, 255, 255, 0.06) inset;
  display: flex;
  flex-direction: column-reverse; /* Bar pinned at bottom, body expands upward */
  overflow: hidden;
  transform-origin: bottom center;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              height 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              border-radius 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              background-color 0.4s ease,
              border-color 0.4s ease,
              box-shadow 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              backdrop-filter 0.4s ease;
}

/* Specular top reflection */
.fg-capsule::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  pointer-events: none;
}

/* Expanded state of the capsule */
.fg-menu.is-open .fg-capsule {
  width: var(--fg-capsule-open-w);
  height: var(--fg-capsule-open-h);
  border-radius: 18px;
  background: var(--fg-bg-open);
  border-color: var(--fg-border-open);
  backdrop-filter: blur(34px) saturate(190%);
  -webkit-backdrop-filter: blur(34px) saturate(190%);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45), 
              0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

/* Bottom Bar: HOME + Toggle */
.fg-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: var(--fg-capsule-closed-h);
  min-height: var(--fg-capsule-closed-h);
  padding: 0 12px 0 16px;
  flex-shrink: 0;
  box-sizing: border-box;
  z-index: 2;
}

.fg-home {
  color: var(--fg-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  border-radius: 6px;
  transition: color 0.2s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.fg-menu.is-open .fg-home {
  transform: translateX(8px);
}

.fg-home:hover {
  color: #ffffff;
}

/* Hamburger to X Morph */
.fg-toggle {
  background: transparent;
  border: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-text);
  outline: none;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.fg-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

.fg-burger {
  position: relative;
  display: block;
  width: 18px;
  height: 14px;
}

.fg-line {
  position: absolute;
  left: 0;
  width: 18px;
  height: 2px;
  background: #ffffff;
  border-radius: 1px;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.35s ease;
  transform-origin: center;
}

.fg-line--1 { top: 0; }
.fg-line--2 { top: 6px; }
.fg-line--3 { bottom: 0; }

/* Morphing hamburger to X */
.fg-menu.is-open .fg-line--1 {
  transform: translateY(6px) rotate(45deg);
}

.fg-menu.is-open .fg-line--2 {
  opacity: 0;
  transform: scaleX(0);
}

.fg-menu.is-open .fg-line--3 {
  transform: translateY(-6px) rotate(-45deg);
}

/* Expandable Links Body */
.fg-body {
  display: flex;
  flex-direction: column;
  padding: 12px 14px 4px;
  width: 100%;
  box-sizing: border-box;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.fg-body::-webkit-scrollbar {
  width: 4px;
}
.fg-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.fg-menu.is-open .fg-body {
  opacity: 1;
  pointer-events: auto;
}

.fg-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fg-item {
  margin: 0;
  padding: 0;
  min-height: 44px;
  transform: translateY(8px);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.35s ease;
}

/* Stagger reveals for links */
.fg-menu.is-open .fg-item:nth-child(1) { transition-delay: 0.08s; transform: translateY(0); opacity: 1; }
.fg-menu.is-open .fg-item:nth-child(2) { transition-delay: 0.12s; transform: translateY(0); opacity: 1; }
.fg-menu.is-open .fg-item:nth-child(3) { transition-delay: 0.16s; transform: translateY(0); opacity: 1; }
.fg-menu.is-open .fg-item:nth-child(4) { transition-delay: 0.20s; transform: translateY(0); opacity: 1; }
.fg-menu.is-open .fg-item:nth-child(5) { transition-delay: 0.24s; transform: translateY(0); opacity: 1; }
.fg-menu.is-open .fg-item:nth-child(6) { transition-delay: 0.28s; transform: translateY(0); opacity: 1; }

.fg-link {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  padding: 8px 14px;
  color: var(--fg-text-dim);
  text-decoration: none;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
}

.fg-link:focus-visible,
.fg-home:focus-visible,
.fg-toggle:focus-visible {
  outline: 2px solid var(--fg-orange);
  outline-offset: 2px;
}

.fg-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(4px);
}

.fg-link.is-active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 600;
}

.fg-link.is-active::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-orange);
  margin-left: auto;
}

.fg-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 8px 0 4px;
  width: 100%;
  flex-shrink: 0;
}

/* Zapobieganie kolizji z przyciskiem powrotu na górę: gdy dolne menu jest otwarte, back-to-top znika */
body.has-fg-open .back-to-top {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.85) !important;
  transition: opacity 0.2s ease, transform 0.2s ease !important;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .fg-menu,
  .fg-capsule,
  .fg-line,
  .fg-item,
  .fg-link,
  .fg-home,
  .fg-toggle,
  body.has-fg-open .back-to-top {
    transition: none !important;
    animation: none !important;
    transform: none !important;
  }
  .fg-menu.is-visible {
    transform: translate(-50%, 0) !important;
  }
}

/* Mobile adjustments */
@media (max-width: 600px) {
  :root {
    --fg-capsule-closed-w: 176px;
    --fg-capsule-closed-h: 48px;
    --fg-capsule-open-w: min(calc(100vw - 32px), 284px);
    --fg-capsule-open-h: 366px;
  }
  .fg-menu {
    bottom: max(16px, env(safe-area-inset-bottom));
  }
  .fg-bar {
    height: 48px;
    min-height: 48px;
    padding: 0 8px 0 12px;
  }
  .fg-body {
    padding: 10px 10px 4px;
  }
  .fg-home {
    font-size: 13.5px;
  }
  .fg-link {
    padding: 8px 12px;
    font-size: 17px;
    min-height: 44px;
  }
}
