/* needleBaseStyles.css — Cratoora Needle
   Flat shell architecture — no stereo-shell wrapper.

   SIDEBAR EXPAND / OVERLAY ARCHITECTURE
   ──────────────────────────────────────
   The sidebar expands ON TOP of the main content (Spotify-style overlay).
   The content panel left offset NEVER changes. Only the sidebar width grows.

   Default:   cratoora-needle-sidebar  width: --needle-sidebar-w (320px)
              #needleContent           left: var(--needle-sidebar-w) = 320px

   Expanded:  cratoora-needle-sidebar  width: --needle-sidebar-expanded (560px)
                                       z-index: 150 (above content)
              #needleContent           left: 320px  ← UNCHANGED
              #sidebarExpandBackdrop   visible over content area

   Expand button is AUTH-GATED — only shown when cr_auth_token exists.
   Guests get inner scroll only (Spotify pattern for logged-out state).

   MOBILE LAYOUT STRATEGY (dvh-based)
   ────────────────────────────────────
   body has NO padding-top. Top clearance handled by margin-top on
   #needleContent. dvh units absorb Android Chrome URL bar animation.
*/

/* ═══════════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════════ */
* {
  margin: 0;
  padding: 0;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

:root {
  position: relative;
  font-size: 62.5%; /* 1rem = 10px */

  /* ── Layout tokens ── */
  --needle-nav-h: 56px;
  --needle-tab-h: 64px;

  /* ── Sidebar widths ──
     --needle-sidebar-w:        default width (content offset stays here always)
     --needle-sidebar-expanded: overlay width when expanded (content doesn't move) */
  --needle-sidebar-w: 320px;
  --needle-sidebar-expanded: 560px;

  /* ── Shell gap — space between sidebar and header/content (Spotify-style) ──
     Header + content move in unison by this amount.
     Body is #000 on desktop so the gap reads as clean dark negative
     space matching the sidebar — not a stub artifact. */
  --needle-shell-gap: 8px;

  /* ── Shared sidebar transition ── */
  --sidebar-ease:     cubic-bezier(0.23, 1, 0.32, 1);
  --sidebar-duration: 0.3s;
}

img { max-width: 100%; height: auto; }

body.stereo-layout {
  background: #0a0a0a;
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  color: #fff;
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   ANTI-FLASH SLIDEBAR
═══════════════════════════════════════════════════════════════ */
cratoora-needle-mobile-slidebar-view:not(.open) {
  -webkit-transform: translateX(-100%) !important;
  transform: translateX(-100%) !important;
}
cratoora-needle-mobile-slidebar-view:not(:defined) {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   PLAYER BAR
═══════════════════════════════════════════════════════════════ */
.player-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 300;
  background: #181818;
  border-top: 1px solid #2a2a2a;
  height: 90px;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  padding: 0 1.5rem; gap: 1rem;
  -webkit-transform: translateY(100%); transform: translateY(100%);
  -webkit-transition: -webkit-transform 0.4s cubic-bezier(0.23,1,0.32,1);
  transition: transform 0.4s cubic-bezier(0.23,1,0.32,1);
}
.player-bar.visible { -webkit-transform: translateY(0); transform: translateY(0); }
body.player-active  { padding-bottom: 90px; }

.player-progress {
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px; background: rgba(255,255,255,0.08); cursor: pointer;
}
.player-progress-fill {
  height: 100%; width: 0%; background: #8B5CF6;
  -webkit-transition: width 0.5s linear; transition: width 0.5s linear;
  pointer-events: none;
}
.player-thumb {
  width: 52px; height: 52px; border-radius: 6px;
  background: linear-gradient(135deg, #8B5CF6, #D97706);
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  font-size: 1.4rem; -webkit-flex-shrink: 0; flex-shrink: 0;
}
.player-info { -webkit-flex: 1; flex: 1; min-width: 0; }
.player-title {
  font-size: 0.88rem; font-weight: 700; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.player-artist {
  font-size: 0.72rem; color: rgba(255,255,255,0.5); margin-top: 2px;
}
.player-controls {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 0.35rem; -webkit-flex-shrink: 0; flex-shrink: 0;
}
.player-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: none; color: rgba(255,255,255,0.65);
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  cursor: pointer;
  -webkit-transition: color 0.15s, background 0.15s;
  transition: color 0.15s, background 0.15s;
}
.player-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.player-btn.play-pause { width: 42px; height: 42px; background: #fff; color: #080808; }
.player-btn.play-pause:hover { background: rgba(255,255,255,0.88); }

/* ═══════════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════════ */
.create-crate-overlay,
.crate-auth-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 800;
  background: rgba(0,0,0,0.75);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  padding: 1.25rem; opacity: 0; pointer-events: none;
  -webkit-transition: opacity 0.22s ease; transition: opacity 0.22s ease;
}
.create-crate-overlay.open,
.crate-auth-overlay.open { opacity: 1; pointer-events: auto; }
.create-crate-modal, .crate-auth-modal {
  background: #282828; border-radius: 16px; padding: 1.5rem; width: min(360px, 100%);
  -webkit-transform: scale(0.95); transform: scale(0.95);
  -webkit-transition: -webkit-transform 0.25s cubic-bezier(0.23,1,0.32,1);
  transition: transform 0.25s cubic-bezier(0.23,1,0.32,1);
}
.create-crate-overlay.open .create-crate-modal,
.crate-auth-overlay.open .crate-auth-modal {
  -webkit-transform: scale(1); transform: scale(1);
}

/* ═══════════════════════════════════════════════════════════════
   PREVIEW BANNER
═══════════════════════════════════════════════════════════════ */
.cr-preview-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 250;
  background: #1d1d1d; border-top: 1px solid rgba(255,255,255,0.1);
  padding: 0.85rem 1.5rem;
  padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: space-between; justify-content: space-between;
  gap: 1rem;
  -webkit-transform: translateY(100%); transform: translateY(100%);
  -webkit-transition: -webkit-transform 0.45s cubic-bezier(0.23,1,0.32,1);
  transition: transform 0.45s cubic-bezier(0.23,1,0.32,1);
}
.cr-preview-banner.visible { -webkit-transform: translateY(0); transform: translateY(0); }

/* ═══════════════════════════════════════════════════════════════
   UPDATE BANNER
═══════════════════════════════════════════════════════════════ */
.update-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: #8B5CF6; color: #fff; padding: 0.75rem; text-align: center;
  -webkit-transform: translateY(-100%); transform: translateY(-100%);
  -webkit-transition: -webkit-transform 0.3s ease; transition: transform 0.3s ease;
}
.update-banner.visible { -webkit-transform: translateY(0); transform: translateY(0); }

/* ═══════════════════════════════════════════════════════════════
   PWA INSTALL PROMPT
═══════════════════════════════════════════════════════════════ */
.pwa-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 9999;
  background: rgba(0,0,0,0.55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  -webkit-transition: opacity 0.25s ease; transition: opacity 0.25s ease;
}
.pwa-overlay.visible { opacity: 1; pointer-events: auto; }
.pwa-install-popup {
  width: min(360px, 90%); background: #111; border-radius: 18px;
  padding: 1.75rem 1.5rem 1.5rem;
  -webkit-box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  -webkit-transform: translateY(20px); transform: translateY(20px);
  -webkit-transition: -webkit-transform 0.28s cubic-bezier(0.25,1,0.5,1);
  transition: transform 0.28s cubic-bezier(0.25,1,0.5,1);
}
.pwa-overlay.visible .pwa-install-popup { -webkit-transform: translateY(0); transform: translateY(0); }
.pwa-install-header {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 1rem; margin-bottom: 1.25rem;
}
.pwa-install-icon  { width: 52px; height: 52px; border-radius: 12px; }
.pwa-install-title { font-size: 1.1rem; font-weight: 800; font-family: 'Syne', sans-serif; color: #fff; }
.pwa-install-sub   { font-size: 0.85rem; color: rgba(255,255,255,0.55); margin-top: 2px; }
.pwa-install-body  { font-size: 0.85rem; color: rgba(255,255,255,0.65); line-height: 1.55; margin-bottom: 1.5rem; }
.pwa-install-actions {
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  gap: 0.65rem;
}
.pwa-btn-install {
  padding: 0.75rem; background: #8B5CF6; color: #fff;
  font-size: 0.9rem; font-weight: 700; border-radius: 999px;
  border: none; cursor: pointer; font-family: inherit;
  -webkit-transition: background 0.15s; transition: background 0.15s;
}
.pwa-btn-install:hover { background: #7C3AED; }
.pwa-btn-later {
  padding: 0.75rem; background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.75);
  font-size: 0.9rem; font-weight: 600; border-radius: 999px;
  border: none; cursor: pointer; font-family: inherit;
  -webkit-transition: background 0.15s; transition: background 0.15s;
}
.pwa-btn-later:hover { background: rgba(255,255,255,0.14); }

/* ═══════════════════════════════════════════════════════════════
   MOBILE SHELL  ≤ 768px
═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  body.stereo-layout {
    overflow-y: auto;
    overflow-x: hidden;
    height: auto !important;
    min-height: 100dvh;
    padding-bottom: calc(var(--needle-tab-h) + env(safe-area-inset-bottom, 0px));
    width: 100%;
    max-width: 100vw;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
  }

  cratoora-needle-mobile-navbar-view {
    display: block;
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    height: var(--needle-nav-h);
  }

  cratoora-needle-mobile-slidebar-view {
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 1200;
    -webkit-transform: translateX(-100%);
    transform: translateX(-100%);
    -webkit-transition: -webkit-transform 0.32s cubic-bezier(0.23,1,0.32,1);
    transition: transform 0.32s cubic-bezier(0.23,1,0.32,1);
    pointer-events: none;
  }
  cratoora-needle-mobile-slidebar-view.open {
    -webkit-transform: translateX(0);
    transform: translateX(0);
    pointer-events: auto;
  }

  cratoora-needle-mobile-tabbar-view {
    display: block;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1000;
    height: calc(var(--needle-tab-h) + env(safe-area-inset-bottom, 0px));
  }

  cratoora-needle-mobile-footer { display: block; width: 100%; }

  #needleContent {
    display: block !important;
    -webkit-flex: none !important;
    flex: none !important;
    overflow-y: visible !important;
    width: 100%;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    background: #0a0a0a;
    margin-top: calc(var(--needle-nav-h) + 1.5dvh);
    min-height: calc(
      100dvh - var(--needle-nav-h) - var(--needle-tab-h)
      - env(safe-area-inset-bottom, 0px)
    );
  }

  #sidebarBackdrop {
    display: block;
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1190;
    background: rgba(0,0,0,0.6);
    -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
    opacity: 0; pointer-events: none;
    -webkit-transition: opacity 0.3s ease; transition: opacity 0.3s ease;
  }
  #sidebarBackdrop.visible { opacity: 1; pointer-events: auto; }

  cratoora-needle-header,
  cratoora-needle-sidebar,
  cratoora-needle-tabdesk-footer { display: none !important; }

  #crPreviewBanner { display: none !important; }

  .player-bar {
    bottom: calc(var(--needle-tab-h) + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 400 !important;
  }
  body.player-active {
    padding-bottom: calc(
      var(--needle-tab-h) + 90px + env(safe-area-inset-bottom, 0px)
    );
  }
}

/* ═══════════════════════════════════════════════════════════════
   DESKTOP / TABLET  ≥ 769px
   Sidebar overlays content — #needleContent left NEVER changes.

   GAP STRATEGY (Spotify-style):
   Header and content are offset by --needle-shell-gap from the sidebar.
   The body background is #000 inside this block so the gap reads as
   clean dark negative space — matching the sidebar's right edge exactly.
   No border-radius anywhere — all edges straight.
═══════════════════════════════════════════════════════════════ */
@media (min-width: 769px) {

  body.stereo-layout {
    overflow: hidden;
    height: 100dvh;
    /* #000 fills the gap between sidebar and content with the same
       color as the sidebar — eliminates the grayish stub artifact. */
    background: #000;
  }

  cratoora-needle-mobile-navbar-view,
  cratoora-needle-mobile-slidebar-view,
  cratoora-needle-mobile-tabbar-view,
  cratoora-needle-mobile-footer { display: none !important; }

  /* ─────────────────────────────────────────────────────────────
     DESKTOP SIDEBAR
     Default width: --needle-sidebar-w (320px)
     Expanded width: --needle-sidebar-expanded (560px)
     No border-radius — straight edges both sides.
  ──────────────────────────────────────────────────────────────*/
  cratoora-needle-sidebar {
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--needle-sidebar-w);
    z-index: 100;
    background: #000;
    overflow: hidden;
    -webkit-transition:
      width var(--sidebar-duration) var(--sidebar-ease);
    transition:
      width var(--sidebar-duration) var(--sidebar-ease);
  }

  /* Expanded — grows over content, higher z-index */
  cratoora-needle-sidebar.expanded {
    width: var(--needle-sidebar-expanded);
    z-index: 150;
  }

  /* ─────────────────────────────────────────────────────────────
     SIDEBAR EXPAND BACKDROP
     Left offset matches header + content — moves in unison with them.
  ──────────────────────────────────────────────────────────────*/
  #sidebarExpandBackdrop {
    display: block;
    position: fixed;
    top: var(--needle-nav-h);
    left: calc(var(--needle-sidebar-w) + var(--needle-shell-gap));
    right: 0;
    bottom: 0;
    z-index: 140;
    background: rgba(0,0,0,0.45);
    opacity: 0;
    pointer-events: none;
    -webkit-transition: opacity 0.25s ease;
    transition: opacity 0.25s ease;
  }
  #sidebarExpandBackdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* ─────────────────────────────────────────────────────────────
     DESKTOP HEADER
     Offset by --needle-shell-gap from the sidebar — moves in unison
     with #needleContent. Straight edges, no border-radius.

     Visual styling (background, backdrop-filter, border-bottom) is
     intentionally NOT set here. The component's shadow DOM ::before
     pseudo-element handles all of it. Keeping those rules here caused
     a double compositing layer — Chromium rendered a 1px bright edge
     artifact at the element's left boundary (the gap made it visible).
     overflow: hidden clips any residual compositing bleed.
  ──────────────────────────────────────────────────────────────*/
  cratoora-needle-header {
    display: block;
    position: fixed;
    top: 0;
    left: calc(var(--needle-sidebar-w) + var(--needle-shell-gap));
    right: 0;
    z-index: 100;
    height: var(--needle-nav-h);
    overflow: hidden;
  }

  /* ─────────────────────────────────────────────────────────────
     CONTENT OUTLET
     Same left offset as the header — they move in unison.
     No border-radius — both sides scroll with straight flush edges.
     outline: none — NeedleRouter's AccessibilityFilter calls
     needleContent.focus() on every navigation for screen reader
     announcement. Without this, the browser renders its default
     focus ring (white outline) around the entire outlet.
     overflow-y: scroll (not auto) for touch-scroll ownership on tablet.
  ──────────────────────────────────────────────────────────────*/
  #needleContent {
    display: block;
    position: fixed;
    top: var(--needle-nav-h);  
    left: calc(var(--needle-sidebar-w) + var(--needle-shell-gap));
    right: 0;
    bottom: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior-y: contain;
    background: #121212;
    outline: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #needleContent::-webkit-scrollbar { display: none; }

  #sidebarBackdrop { display: none !important; }

  #crPreviewBanner { display: -webkit-flex; display: flex; }
}