/* web_chrome.css — Standalone website & installed PWA chrome adjustments.
   Every rule is strictly scoped to html.impito-web-site (and
   html.impito-web-site.impito-pwa-standalone for installed PWA bottom insets)
   so Telegram Mini App and MAX Mini App remain 100% untouched. */

/* ── 1. Hide Telegram-style top blurred veil & fixed centered title on web ── */
html.impito-web-site body::before {
  display: none !important;
  height: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* Keep screen headings visually removed on standalone web while preserving
   semantic role="heading" nodes for screen readers. */
html.impito-web-site .impito-profile-heading {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

html.impito-web-site[data-impito-nav] body::before,
html.impito-web-site[data-impito-nav] .impito-profile-heading {
  view-transition-name: none;
}

/* ── 2. Reclaim top spacing & honor real OS safe-area-inset-top ──────────────
   Screens call syncTelegramInsets() which writes --ui-safe-top: 0px inline on
   <html>. !important ensures real env(safe-area-inset-top) wins in iOS PWA
   standalone (Dynamic Island / notch) while keeping Safari tabs clean. */
html.impito-web-site {
  --ui-safe-top: env(safe-area-inset-top, 0px) !important;
  --ui-veil-base: var(--ui-safe-top) !important;
  --ui-veil-height: var(--ui-safe-top) !important;
  --ui-page-top: calc(var(--ui-safe-top) + 16px) !important;
}

/* Reserve top clearance whenever the floating circular Back button is shown. */
html.impito-web-site.impito-web-back-visible {
  --ui-veil-base: calc(var(--ui-safe-top) + 56px) !important;
  --ui-veil-height: calc(var(--ui-safe-top) + 56px) !important;
  --ui-page-top: calc(var(--ui-safe-top) + 64px) !important;
}

/* Home mobile: replace Telegram's hardcoded 56px + 12px top offset so the
   greeting and devil mascot sit cleanly below the status bar / top edge. */
html.impito-web-site body.impito-home-active .impito-home-page:not([data-desk]) {
  padding-top: calc(var(--ui-safe-top) + 12px) !important;
}

/* Overlays that previously added 56px–76px for Telegram's native close bar. */
html.impito-web-site .impito-viewer__top {
  padding-top: calc(var(--ui-safe-top) + 12px);
}

html.impito-web-site .impito-gate--consent {
  padding-top: calc(var(--ui-safe-top) + 20px);
}

html.impito-web-site .impito-legal__head {
  margin-top: calc(var(--ui-safe-top) + 12px);
}

/* Desktop & unfolded wide layouts (>= 760px): keep sidebar and split panes
   balanced with no phantom top header gap. */
@media (min-width: 760px) {
  html.impito-web-site:not(.impito-web-back-visible) {
    --ui-page-top: calc(var(--ui-safe-top) + 24px) !important;
  }

  html.impito-web-site .impito-desk-work > .impito-desk-insp {
    top: 0;
    margin-top: 0;
    height: 100vh;
    height: 100dvh;
  }

  html.impito-web-site .impito-home-side {
    top: calc(var(--ui-safe-top) + 20px);
  }
}

/* ── 3. Lift floating tabbar & fixed bottom controls ONLY in mobile PWA ────
   Never applied in regular Safari browser tabs, Telegram, MAX, desktop PWA
   windows (no data-impito-mobile), wide layouts >= 760px, or foldable
   side-rail mode (html.impito-rail).
   FaceID iPhones report env(safe-area-inset-bottom) = 34px in standalone PWA,
   which pushes a floating pill too high (38px); clamp to 14px so .impito-tabbar
   sits snugly at bottom: 18px right above the iOS home indicator (~13px). */
@media (max-width: 759.98px) {
  html.impito-web-site.impito-pwa-standalone[data-impito-mobile="true"]:not(.impito-rail) {
    --impito-pwa-safe-bottom: min(max(env(safe-area-inset-bottom, 0px), 12px), 14px);
    --ui-safe-bottom: var(--impito-pwa-safe-bottom) !important;
  }

  html.impito-web-site.impito-pwa-standalone[data-impito-mobile="true"]:not(.impito-rail) .impito-tabbar {
    bottom: calc(4px + var(--impito-pwa-safe-bottom)) !important;
  }
}

html.impito-web-site.impito-pwa-standalone.impito-rail {
  --ui-safe-bottom: env(safe-area-inset-bottom, 0px) !important;
}

/* ── 4. Circular Liquid-Glass Back Button (#impito-web-back) ──────────────── */
html.impito-web-site #impito-web-back {
  position: fixed;
  top: calc(var(--ui-safe-top) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 14px);
  z-index: 85;
  isolation: isolate;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--lg-glass-fill, var(--lg-tabbar-fill, rgba(229, 229, 231, 0.8)));
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  color: var(--ui-text);
  cursor: pointer;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition:
    transform 0.2s var(--ui-ease, ease),
    opacity 0.18s var(--ui-ease, ease);
}

/* Pre-upgrade fallback glass ring before boot_body.js attaches .impito-lg-btn. */
html.impito-web-site #impito-web-back:not(.impito-lg-btn) {
  box-shadow:
    0 0 0 0.5px rgba(var(--ui-shadow-rgb, 60, 60, 67), 0.22),
    inset 0 1px 1px rgba(255, 255, 255, 0.55),
    inset 0 -1px 1px rgba(255, 255, 255, 0.2);
}

html.impito-web-site[data-theme="dark"] #impito-web-back:not(.impito-lg-btn) {
  box-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.16),
    inset 0 1px 1px rgba(255, 255, 255, 0.18),
    inset 0 -1px 1px rgba(0, 0, 0, 0.3);
}

/* Authentic Impito Liquid-Glass rim & hairline layers (populated by boot_body.js). */
html.impito-web-site #impito-web-back.impito-lg-btn {
  box-shadow: none;
}

html.impito-web-site #impito-web-back::before,
html.impito-web-site #impito-web-back::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

html.impito-web-site #impito-web-back::before {
  background: var(--lg-rim, none) -2px -2px / calc(100% + 4px) calc(100% + 4px) no-repeat;
}

html.impito-web-site #impito-web-back::after {
  background: rgba(var(--ui-shadow-rgb, 60, 60, 67), 0.22);
  -webkit-mask: var(--lg-hair, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
  mask: var(--lg-hair, linear-gradient(transparent, transparent)) center / 100% 100% no-repeat;
}

html.impito-web-site[data-theme="dark"] #impito-web-back::after {
  background: rgba(0, 0, 0, 0.35);
}

html.impito-web-site #impito-web-back[hidden] {
  display: none !important;
}

html.impito-web-site #impito-web-back svg {
  display: block;
  width: 22px;
  height: 22px;
  pointer-events: none;
}

html.impito-web-site #impito-web-back:active {
  transform: scale(var(--ui-press-scale, 0.94));
  transition-duration: var(--ui-dur-press, 0.08s);
}

html.impito-web-site #impito-web-back:focus {
  outline: none;
}

html.impito-web-site #impito-web-back:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  html.impito-web-site #impito-web-back:hover {
    background: color-mix(in srgb, var(--ui-text) 8%, var(--lg-glass-fill, var(--lg-tabbar-fill, rgba(229, 229, 231, 0.8))));
  }
}

@media (prefers-reduced-motion: reduce) {
  html.impito-web-site #impito-web-back {
    transition: none;
  }
}

/* Keep the floating Back button pinned smoothly during iOS push/pop transitions. */
html.impito-web-site[data-impito-nav] #impito-web-back:not([hidden]) {
  view-transition-name: impito-web-back;
}

/* Desktop with left sidebar: shift Back button past .impito-sidebar. */
@media (min-width: 760px) {
  html.impito-web-site:not(.impito-rail) #impito-web-back {
    top: calc(var(--ui-safe-top) + 14px);
    left: calc(var(--impito-sidebar-w, 236px) + 16px);
  }
}

/* Yield cleanly to fullscreen overlays and open modal sheets that own their
   own close/backdrop controls. */
html.impito-web-site.impito-gate-open #impito-web-back,
html.impito-web-site:has(.impito-sheet.is-open) #impito-web-back,
html.impito-web-site:has(.impito-viewer.is-open) #impito-web-back,
html.impito-web-site:has(.impito-camera:not([hidden])) #impito-web-back {
  opacity: 0;
  pointer-events: none;
}

/* ── 5. Home Pull-to-Refresh Indicator (.impito-ptr) ──────────────────────── */
html.impito-web-site .impito-ptr {
  position: fixed;
  top: calc(var(--ui-safe-top) - 46px);
  left: 0;
  right: 0;
  z-index: 80;
  display: grid;
  width: 38px;
  height: 38px;
  margin-inline: auto;
  border-radius: 50%;
  background: var(--lg-glass-fill, var(--lg-tabbar-fill, rgba(229, 229, 231, 0.85)));
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  box-shadow:
    0 0 0 0.5px rgba(var(--ui-shadow-rgb, 60, 60, 67), 0.2),
    0 4px 14px rgba(var(--ui-shadow-rgb, 60, 60, 67), 0.12),
    inset 0 1px 1px rgba(255, 255, 255, 0.55);
  color: var(--ui-text);
  opacity: 0;
  pointer-events: none;
  place-items: center;
  will-change: transform, opacity;
}

html.impito-web-site[data-theme="dark"] .impito-ptr {
  box-shadow:
    0 0 0 0.5px rgba(255, 255, 255, 0.16),
    0 4px 16px rgba(0, 0, 0, 0.42),
    inset 0 1px 1px rgba(255, 255, 255, 0.18);
}

html.impito-web-site .impito-ptr.is-settling,
html.impito-web-site .impito-ptr.is-refreshing {
  transition:
    transform 0.28s var(--ui-ease-ios, cubic-bezier(0.32, 0.72, 0, 1)),
    opacity 0.22s var(--ui-ease, ease);
}

html.impito-web-site .impito-home-page.impito-ptr-settling {
  transition: transform 0.28s var(--ui-ease-ios, cubic-bezier(0.32, 0.72, 0, 1));
}

html.impito-web-site .impito-ptr__icon {
  position: relative;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
}

html.impito-web-site .impito-ptr__arrow,
html.impito-web-site .impito-ptr__spin {
  grid-area: 1 / 1;
  display: block;
  width: 18px;
  height: 18px;
}

html.impito-web-site .impito-ptr__arrow {
  transition:
    transform 0.2s var(--ui-ease-ios, cubic-bezier(0.32, 0.72, 0, 1)),
    opacity 0.15s ease;
}

html.impito-web-site .impito-ptr.is-ready .impito-ptr__arrow {
  transform: rotate(180deg);
}

html.impito-web-site .impito-ptr__spin {
  opacity: 0;
}

html.impito-web-site .impito-ptr.is-refreshing {
  opacity: 1;
}

html.impito-web-site .impito-ptr.is-refreshing .impito-ptr__arrow {
  opacity: 0;
}

html.impito-web-site .impito-ptr.is-refreshing .impito-ptr__spin {
  opacity: 1;
  animation: impito-ptr-spin 0.75s linear infinite;
}

@keyframes impito-ptr-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 760px) {
  html.impito-web-site:not(.impito-rail) .impito-ptr {
    left: var(--impito-sidebar-w, 236px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html.impito-web-site .impito-ptr.is-settling,
  html.impito-web-site .impito-ptr.is-refreshing,
  html.impito-web-site .impito-home-page.impito-ptr-settling,
  html.impito-web-site .impito-ptr__arrow {
    transition: none;
  }

  html.impito-web-site .impito-ptr.is-refreshing .impito-ptr__spin {
    animation-duration: 1.4s;
  }
}
