/* Lootly — native-app feel global CSS
   Loaded alongside bottom-nav.js on authenticated pages.
   Applies quick wins that make the mobile web feel native. */

/* Safe area roots for notch + home indicator */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Disable iOS tap highlight + text selection on interactive elements */
a, button, [role="button"], .bn-item, nav *, .nav-links a, .filter-btn, .btn {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* But allow selection in inputs and content */
input, textarea, p, h1, h2, h3, h4, h5, h6, .llb-name, .lb-name, .profile-name, .coins-main {
  -webkit-user-select: auto;
  user-select: auto;
}

/* Avoid iOS auto-zoom on focus (only when font-size < 16px) */
input, select, textarea {
  font-size: max(16px, 1em);
}

/* Prevent rubber-band overscroll bounce on body (feels weird in an app) */
html, body {
  overscroll-behavior-y: contain;
  overflow-x: clip;
}

/* Let flex/grid items shrink below their content width (this is what causes
   the "page is wider than the viewport" symptom when a long word or a table
   lives inside a flex container). */
*, *::before, *::after { min-width: 0; }

@media (max-width: 900px) {
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  img, video, iframe, canvas { max-width: 100%; height: auto; }
  /* Wide data tables should scroll inside their own box, not push the page */
  table { display: block; max-width: 100%; overflow-x: auto; }
  pre, code { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
  /* Common container classes: cap at viewport width on mobile */
  .container, .wrap, .wrapper, main, section, article, header, footer {
    max-width: 100vw;
    box-sizing: border-box;
  }
}

/* Make top nav respect notch */
nav:first-of-type, .lt-nav {
  padding-top: calc(env(safe-area-inset-top, 0px));
  min-height: calc(64px + env(safe-area-inset-top, 0px));
}

/* Smooth momentum scrolling on iOS */
* {
  -webkit-overflow-scrolling: touch;
}

/* Hide the browser scrollbar on webkit (app-like) */
body::-webkit-scrollbar { display: none; }
body { scrollbar-width: none; }

/* Bottom-sheet modal base (used for spin wheel & future modals) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 6000;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
  opacity: 0;
  transition: opacity .3s ease;
  overflow-y: auto;
}
.sheet-overlay.open { display: flex; opacity: 1; }
.sheet {
  width: 100%;
  max-width: 560px;
  background: radial-gradient(ellipse at top, #1a1a26 0%, #0e0e14 60%);
  border: 0.5px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 12px 22px 26px;
  transform: translateY(-30px);
  opacity: 0;
  transition: transform .35s cubic-bezier(.34,1.1,.64,1), opacity .25s ease;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  margin-bottom: 20px;
}
.sheet-overlay.open .sheet { transform: translateY(0); opacity: 1; }
.sheet-handle {
  width: 44px;
  height: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.sheet-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255,255,255,0.06);
  border: none;
  color: rgba(255,255,255,0.55);
  width: 34px;
  height: 34px;
  border-radius: 12px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-close:active { background: rgba(255,255,255,0.12); }

/* Pull to refresh indicator */
.ptr-indicator {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  left: 50%;
  transform: translate(-50%, -120%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #0e0e14;
  border: 1px solid rgba(93,202,165,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: transform .3s ease, opacity .3s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
}
.ptr-indicator.visible { transform: translate(-50%, 0); opacity: 1; }
.ptr-indicator svg {
  width: 20px;
  height: 20px;
  color: #5DCAA5;
  transition: transform .2s ease;
}
.ptr-indicator.spinning svg { animation: ptr-spin 0.9s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* On mobile: hide only the floating launcher buttons, NOT the .lcw-root
   container itself (the chat panel is a child of .lcw-root and needs to
   stay available for programmatic open via window.lootlyOpenChat). */
@media (max-width: 900px) {
  .lcw-bubble,
  .lcw-bell,
  .lcw-super-btn,
  .llb-mobile-btn,
  .ltl-float {
    display: none !important;
  }
  /* Keep the root container visible but empty — its children get hidden above */
  .lcw-root { right: 0 !important; bottom: 0 !important; }
  /* Panels need to open above the bottom tab bar */
  .lcw-panel {
    bottom: calc(var(--bn-height, 62px) + env(safe-area-inset-bottom, 0px) + 12px) !important;
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
    max-width: 480px !important;
    margin: 0 auto !important;
  }
  .lcw-toast {
    bottom: calc(var(--bn-height, 62px) + env(safe-area-inset-bottom, 0px) + 14px) !important;
  }
  .lcw-bell-panel {
    bottom: calc(var(--bn-height, 62px) + env(safe-area-inset-bottom, 0px) + 12px) !important;
    right: 12px !important;
    left: 12px !important;
    margin: 0 auto !important;
  }
  .llb-root {
    bottom: calc(var(--bn-height, 62px) + env(safe-area-inset-bottom, 0px) + 0px) !important;
  }
}

/* Bottom tab bar — inline HTML version, no JS required */
:root { --bn-height: 84px; }
aside.bn-bar { display: none; }
/* Hide bottom-nav entirely on Messages + Super Chat (full-screen chat feel) */
body[data-page="friends"] aside.bn-bar,
body[data-page="super"] aside.bn-bar { display: none !important; }
body[data-page="friends"],
body[data-page="super"] { padding-bottom: 0 !important; }
@media (max-width: 900px) {
  body { padding-bottom: calc(var(--bn-height) + env(safe-area-inset-bottom, 0px) + 10px); }
  aside.bn-bar {
    display: flex;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9500;
    background: rgba(0,0,0,0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 0.5px solid rgba(255,255,255,0.08);
    padding: 12px 4px calc(18px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: stretch;
    font-family: "DM Sans", sans-serif;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.45);
    width: auto;
    height: auto;
    margin: 0;
    border-radius: 0;
    flex-direction: row;
  }
}
.bn-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px 4px;
  text-decoration: none;
  color: rgba(255,255,255,0.5);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.bn-item svg { width: 24px; height: 24px; transition: transform .15s; }
.bn-item:active svg { transform: scale(0.88); }
.bn-item:active { color: rgba(255,255,255,0.75); }
.bn-item.active { color: #5DCAA5; }
.bn-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 30%;
  right: 30%;
  height: 2px;
  background: #5DCAA5;
  border-radius: 0 0 3px 3px;
  box-shadow: 0 0 8px rgba(93,202,165,0.6);
}
.bn-item.active svg { filter: drop-shadow(0 0 6px rgba(93,202,165,0.5)); }

/* Create tab — raised central button, Instagram/TikTok style */
.bn-item[data-tab="tab.create"] {
  color: #f5f5f5;
}
.bn-item[data-tab="tab.create"] svg {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, #1D9E75, #5DCAA5);
  border-radius: 14px;
  padding: 8px;
  color: #fff;
  box-shadow: 0 6px 18px rgba(29,158,117,0.45), inset 0 1px 0 rgba(255,255,255,0.18);
}
.bn-item[data-tab="tab.create"] span { display: none; }
.bn-item[data-tab="tab.create"]::before { display: none !important; }
.bn-item[data-tab="tab.create"]:active svg { transform: scale(0.92); }

/* Utility: app-padded wrapper (for screens that need native edge-to-edge) */
.app-screen {
  padding: calc(env(safe-area-inset-top, 0px) + 12px) calc(env(safe-area-inset-right, 0px) + 16px) calc(env(safe-area-inset-bottom, 0px) + 12px) calc(env(safe-area-inset-left, 0px) + 16px);
}
