/*
 * Liquid Glass Tab Bar — Daily Grid Games
 * Inspired by Apple's iOS 26 Liquid Glass design language (WWDC 2025).
 *
 * Key design properties:
 *  1. Floats above the home indicator with a visible gap (not wall-attached).
 *  2. Horizontal insets — does NOT span the full screen width.
 *  3. All four corners rounded (full pill-oid shape).
 *  4. Visible glass border on all sides — the defining iOS 26 trait.
 *  5. Downward-facing floating shadow (ambient depth).
 *  6. Strong blur + saturation boost — background content shows through clearly.
 *  7. Specular caustic line on the top arc (light refracting off curved glass).
 *  8. Active tab pill — a double-depth inner glass layer.
 *  9. Safe-area inset top applied to body to prevent status-bar overlap.
 */


/* ─── Safe-area top — applied unconditionally so content never shifts ─────── */
/*
 * viewport-fit=cover extends the viewport edge-to-edge behind the status bar.
 * Previously this was gated on the JS-added .dg-tab-bar-active class, which
 * caused a visible layout shift (~44px) after the module loaded.
 * Applying it unconditionally at mobile widths eliminates the jump entirely.
 * (tab-bar.css is only loaded on hub pages, not game pages — safe to do here.)
 */
@media (max-width: 899px) {
  body {
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* ─── Pre-JS bottom padding ─────────────────────────────────────────────────── */
/*
 * Reserve the tab-bar clearance before JS loads and injects the bar or adds
 * the .dg-tab-bar-page-padding class. Without this the page layout shifts
 * downward when JS runs, causing the visible "jump" on navigation.
 * Applies to any <main> on a hub page at mobile widths.
 */
@media (max-width: 899px) {
  main {
    padding-bottom: var(--dg-bottom-clear, calc(80px + env(safe-area-inset-bottom, 0px)));
  }
}

/* Utility class: pad for status bar on a child element (use when body padding is insufficient) */
.pt-safe {
  padding-top: env(safe-area-inset-top, 0px);
}

/* ─── Bar shell ─────────────────────────────────────────────────────────────── */
.dg-tab-bar {
  position: fixed;

  /* Float above the home indicator with a visible gap */
  bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);

  /* Horizontal insets — not edge-to-edge */
  left: 12px;
  right: 12px;

  z-index: 200;

  /* Liquid Glass material — minimal tint, let content show through */
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);

  /* All-rounded pill — the key iOS 26 floating shape */
  border-radius: 26px;

  /* Visible glass border on every side (iOS 26 signature) */
  border: 0.5px solid rgba(255, 255, 255, 0.18);

  /* Floating shadow downward + inner specular glow */
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.2),
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.06),
    0 14px 44px rgba(0, 0, 0, 0.42),
    0 3px 10px rgba(0, 0, 0, 0.24);

  padding-top: 8px;
}

/* Specular caustic — bright gradient rim along the convex top arc */
.dg-tab-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.32) 20%,
    rgba(255, 255, 255, 0.62) 50%,
    rgba(255, 255, 255, 0.32) 80%,
    transparent 100%
  );
  border-radius: 999px;
  pointer-events: none;
}

/* Subtle inner bloom from the top edge downward — convex lens depth */
.dg-tab-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(to bottom,
    rgba(255, 255, 255, 0.055) 0%,
    transparent 100%
  );
  border-radius: 26px;
  pointer-events: none;
}

/* ─── Tab list ───────────────────────────────────────────────────────────────── */
.dg-tab-bar__list {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px 8px;
  margin: 0;
  list-style: none;
}

/* ─── Individual tab ─────────────────────────────────────────────────────────── */
.dg-tab-bar__tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.dg-tab-bar__tab a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  padding: 6px 4px 4px;
  text-decoration: none;
  position: relative;
  border-radius: 16px;
  transition: opacity 0.15s ease;
}

.dg-tab-bar__tab a:active {
  opacity: 0.7;
}

/* ─── Active pill ────────────────────────────────────────────────────────────── */
/*
 * A second inner glass layer — lighter tint, own specular, brighter border.
 * Creates the "double-depth" look characteristic of iOS 26 Liquid Glass.
 */
.dg-tab-bar__tab.active a {
  background: rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -0.5px 0 rgba(0, 0, 0, 0.1),
    0 1px 6px rgba(0, 0, 0, 0.2);
  border: 0.5px solid rgba(255, 255, 255, 0.18);
}

/* ─── Icon ──────────────────────────────────────────────────────────────────── */
.dg-tab-bar__icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  transition: color 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dg-tab-bar__tab a:active .dg-tab-bar__icon {
  transform: scale(0.88);
}

.dg-tab-bar__tab .dg-tab-bar__icon {
  color: rgba(200, 210, 230, 0.45);
}

.dg-tab-bar__tab.active .dg-tab-bar__icon {
  color: rgba(255, 255, 255, 0.95);
  transform: scale(1.05);
}


/* ─── Label ──────────────────────────────────────────────────────────────────── */
.dg-tab-bar__label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  transition: color 0.2s ease;
  /* Use the shared UI font stack (Space Grotesk loads on all game pages) */
  font-family: var(--dg-font-ui, 'Space Grotesk', 'Inter', -apple-system, sans-serif);
  color: rgba(200, 210, 230, 0.45);
}

.dg-tab-bar__tab.active .dg-tab-bar__label {
  color: rgba(255, 255, 255, 0.9);
}

/* ─── Badge (unread count) ───────────────────────────────────────────────────── */
.dg-tab-bar__badge {
  position: absolute;
  top: 2px;
  right: 50%;
  transform: translateX(10px);
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 1.5px solid rgba(8, 12, 26, 0.8);
  pointer-events: none;
}

/* ─── Page padding (content clears the floating bar) ────────────────────────── */
/*
 * Uses --dg-bottom-clear from design-tokens.css.
 * Also aliased as .tab-bar-clear in design-tokens.css — use either.
 * Equivalent to: calc(64px + env(safe-area-inset-bottom, 0px) + 0.75rem)
 */
.dg-tab-bar-page-padding {
  padding-bottom: var(--dg-bottom-clear, calc(80px + env(safe-area-inset-bottom, 0px))) !important;
}

/* ─── Desktop: hide tab bar (≥ 900px matches games-base.css nav breakpoint) ─── */
@media (min-width: 900px) {
  .dg-tab-bar {
    display: none !important;
  }
  html.dg-tab-bar-active body {
    padding-top: 0;
  }
  .dg-tab-bar-page-padding {
    padding-bottom: 2rem !important;
  }
}

/* ─── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .dg-tab-bar__icon,
  .dg-tab-bar__label {
    transition: none;
  }
}
