:root {
  --uza-safe-top: env(safe-area-inset-top, 0px);
  --uza-safe-right: env(safe-area-inset-right, 0px);
  --uza-safe-bottom: env(safe-area-inset-bottom, 0px);
  --uza-safe-left: env(safe-area-inset-left, 0px);
  --uza-viewport-height: 100dvh;
}

/*
 * iOS uses a translucent status bar and reports a second bottom inset in
 * standalone mode. Keep one viewport authority and let each surface own its
 * safe area instead of moving the complete interface twice.
 */
html.uza-ios {
  width: 100%;
  height: var(--uza-viewport-height, 100dvh);
  min-height: var(--uza-viewport-height, 100dvh);
  max-height: var(--uza-viewport-height, 100dvh);
  overflow: hidden;
  background: #09090b;
}

html.uza-ios body,
html.uza-ios #root,
html.uza-ios .uza-web-root,
html.uza-ios .uza-web-shell {
  box-sizing: border-box;
  height: var(--uza-viewport-height, 100dvh) !important;
  min-height: var(--uza-viewport-height, 100dvh) !important;
  max-height: var(--uza-viewport-height, 100dvh) !important;
}

html.uza-ios body,
html.uza-ios #root {
  width: 100%;
  overflow: hidden;
  background: #09090b;
}

/* Standalone Safari may restore document scroll even when the chat owns its
   own scroller. Pinning the document keeps the header inside the safe area. */
html.uza-ios.uza-ios-pwa body:has(.uza-web-shell.chat-open) {
  position: fixed !important;
  inset: 0 !important;
}

@media (width <= 820px) {
  html.uza-ios body.uza-ios-install-open #root {
    position: relative !important;
    z-index: 1200 !important;
  }

  html.uza-ios .uza-ios-install-overlay {
    z-index: 1300 !important;
    background: rgba(5, 5, 8, 0.72) !important;
    -webkit-backdrop-filter: blur(10px) saturate(0.78) !important;
    backdrop-filter: blur(10px) saturate(0.78) !important;
  }

  html.uza-ios .uza-ios-install-sheet {
    box-sizing: border-box !important;
    gap: 13px !important;
    padding: 10px 20px max(22px, calc(var(--uza-safe-bottom) + 12px)) !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
    border-radius: 30px 30px 0 0 !important;
    background:
      radial-gradient(
        circle at 14% 0%,
        rgba(183, 180, 205, 0.15),
        transparent 36%
      ),
      linear-gradient(180deg, #23222a 0%, #17171c 42%, #0e0e11 100%) !important;
    box-shadow:
      inset 0 1px rgba(255, 255, 255, 0.06),
      0 -22px 70px rgba(0, 0, 0, 0.48) !important;
  }

  html.uza-ios .uza-ios-install-handle {
    width: 44px !important;
    height: 4px !important;
    background: rgba(244, 244, 245, 0.34) !important;
  }

  html.uza-ios .uza-ios-install-hero > :first-child {
    border-color: rgba(255, 255, 255, 0.14) !important;
    background: rgba(255, 255, 255, 0.055) !important;
    color: #f4f4f5 !important;
  }

  html.uza-ios .uza-ios-install-hero > :last-child > :first-child {
    color: #9bea12 !important;
    letter-spacing: 0.16em !important;
  }

  html.uza-ios .uza-ios-install-hero > :last-child > :last-child {
    color: #f7f7f8 !important;
    letter-spacing: -0.025em !important;
  }

  html.uza-ios .uza-ios-install-body {
    color: #aaa9af !important;
  }

  html.uza-ios .uza-ios-install-steps {
    gap: 7px !important;
  }

  html.uza-ios .uza-ios-install-steps > * {
    border-color: rgba(255, 255, 255, 0.105) !important;
    background: rgba(255, 255, 255, 0.035) !important;
  }

  html.uza-ios .uza-ios-install-steps > * > :first-child {
    background: #9bea12 !important;
    color: #101105 !important;
  }

  html.uza-ios .uza-ios-install-steps > * > :nth-child(2) {
    color: #e4e4e7 !important;
  }

  html.uza-ios .uza-ios-install-steps > * > :last-child {
    color: #dedee2 !important;
  }

  html.uza-ios .uza-ios-install-note {
    color: #85848b !important;
  }

  html.uza-ios .uza-ios-install-actions > button:first-child {
    border: 1px solid rgba(255, 255, 255, 0.72) !important;
    background: #f0f0f2 !important;
    color: #141418 !important;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2) !important;
  }

  html.uza-ios .uza-ios-install-actions > button:first-child * {
    color: #141418 !important;
  }

  html.uza-ios .uza-ios-install-actions > button:last-child {
    border-color: rgba(255, 255, 255, 0.14) !important;
    background: rgba(255, 255, 255, 0.045) !important;
  }

  html.uza-ios .uza-ios-install-actions > button:last-child * {
    color: #d2d1d6 !important;
  }

  html.uza-ios .uza-ios-install-never,
  html.uza-ios .uza-ios-install-never * {
    color: #85848b !important;
  }

  /* Conversations: the brand begins below the iPhone status indicators. */
  html.uza-ios body.uza-conversations-approved .uza-left-brand-header {
    height: calc(88px + var(--uza-safe-top)) !important;
    padding: calc(8px + var(--uza-safe-top)) 14px 8px !important;
  }

  html.uza-ios body.uza-conversations-approved .uza-left-brand-header > img {
    top: calc(-24px + var(--uza-safe-top)) !important;
  }

  html.uza-ios body.uza-conversations-approved .uza-conversation-rail {
    top: calc(88px + var(--uza-safe-top)) !important;
    bottom: 84px !important;
  }

  html.uza-ios body.uza-conversations-approved .uza-quick-actions {
    top: calc(82px + var(--uza-safe-top)) !important;
  }

  /*
   * The dock remains at the same visual anchor as Android. The 68px surface
   * itself keeps every icon well above the home indicator, so adding the full
   * iOS inset here only creates the large black strip reported by users.
   */
  html.uza-ios .uza-approved-bottom-nav.uza-shared-bottom-nav:not(.uza-member-inline-nav),
  html.uza-ios .uza-member-back-dock,
  html.uza-ios body.uza-conversations-approved
    .uza-web-shell
    > .uza-sidebar.under-brand {
    bottom: 9px !important;
  }

  /* Chat uses the same visible viewport and reserves only the real top inset. */
  html.uza-ios .uza-web-shell.chat-open .uza-chat-header {
    min-height: calc(82px + var(--uza-safe-top)) !important;
    padding: max(12px, var(--uza-safe-top)) 13px 10px !important;
  }

  html.uza-ios .uza-web-shell.chat-open .uza-chat-loading-layer {
    padding-top: max(14px, var(--uza-safe-top)) !important;
    padding-bottom: max(15px, var(--uza-safe-bottom)) !important;
  }

  /*
   * Standalone chat: reserve the physical cutout and then keep the same
   * breathing room used by the Android/browser layout.  Using max() here
   * replaced that breathing room on notched iPhones and left the header too
   * close to the status indicators.
   */
  html.uza-ios .uza-web-shell.chat-open .uza-chat-header {
    padding-top: calc(var(--uza-safe-top) + 10px) !important;
    position: relative !important;
    z-index: 25 !important;
    flex: 0 0 auto !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
  }

  /* The active audio stays below the safe header without resizing the history. */
  html.uza-ios .uza-web-shell.chat-open .uza-pinned-audio {
    top: calc(82px + var(--uza-safe-top)) !important;
  }

  html.uza-ios .uza-web-shell.chat-open .uza-chat-loading-layer {
    padding-top: calc(var(--uza-safe-top) + 12px) !important;
  }

  html.uza-ios .uza-web-shell.chat-open .uza-composer-area {
    padding-bottom: calc(var(--uza-safe-bottom) + 9px) !important;
  }

  /*
   * The bundled app still marks installed iPhones with .uza-iphone-pwa and
   * carries an older, more specific 64px/66px chat rule. Override that exact
   * state so the installed PWA uses the same viewport as Conversations.
   */
  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    > .uza-web-center,
  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-chat-pane {
    box-sizing: border-box !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: var(--uza-viewport-height, 100dvh) !important;
    min-height: var(--uza-viewport-height, 100dvh) !important;
    max-height: var(--uza-viewport-height, 100dvh) !important;
    overflow: hidden !important;
  }

  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-chat-pane {
    z-index: 1 !important;
    isolation: isolate !important;
  }

  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-chat-header,
  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .telegram-channel-mode
    .uza-chat-header {
    box-sizing: border-box !important;
    min-height: calc(82px + var(--uza-safe-top)) !important;
    padding: calc(var(--uza-safe-top) + 10px) 13px 10px !important;
    flex: 0 0 auto !important;
    position: relative !important;
    z-index: 25 !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
  }

  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-message-stage {
    min-height: 0 !important;
    flex: 1 1 auto !important;
  }

  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-composer-area,
  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .telegram-channel-mode
    .uza-composer-area {
    box-sizing: border-box !important;
    min-height: 66px !important;
    padding-bottom: 9px !important;
    flex: 0 0 auto !important;
    position: relative !important;
    z-index: 25 !important;
  }

  html.uza-ios.uza-ios-pwa
    .uza-web-root.uza-iphone-pwa
    .uza-web-shell.chat-open
    .uza-pinned-audio {
    top: calc(82px + var(--uza-safe-top)) !important;
  }

  /* Do not leave the Conversations surface composited behind the transparent
     chat layers. It is restored as soon as chat-open is removed. */
  html.uza-ios.uza-ios-pwa
    body:has(.uza-web-shell.chat-open)
    .uza-web-shell
    > .uza-left-brand-header,
  html.uza-ios.uza-ios-pwa
    body:has(.uza-web-shell.chat-open)
    .uza-web-shell
    > .uza-conversation-rail {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }

  /*
   * Canal+ Bronze is the same mobile surface used on Android. On iPhone only
   * the physical status and home-indicator cutouts are reserved; the artwork,
   * scale and internal spacing remain untouched.
   */
  html.uza-ios
    .uza-web-shell.canal-plus-member-detail-open
    > .uza-left-brand-header.canal-plus-bronze {
    box-sizing: border-box !important;
    height: calc(112px + var(--uza-safe-top)) !important;
    min-height: calc(112px + var(--uza-safe-top)) !important;
    padding: 0 !important;
    background: #050a10 !important;
  }

  html.uza-ios
    .uza-web-shell.canal-plus-member-detail-open
    > .uza-left-brand-header.canal-plus-bronze
    > img {
    position: absolute !important;
    top: var(--uza-safe-top) !important;
    right: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 112px !important;
    max-height: 112px !important;
    object-fit: cover !important;
  }

  html.uza-ios
    .uza-web-shell.canal-plus-member-detail-open
    > .uza-web-center {
    top: calc(112px + var(--uza-safe-top)) !important;
    bottom: 0 !important;
  }

  html.uza-ios
    .uza-web-shell.canal-plus-member-detail-open
    .uza-canal-plus-scroll {
    box-sizing: border-box !important;
    padding-bottom: var(--uza-safe-bottom) !important;
    scroll-padding-bottom: var(--uza-safe-bottom) !important;
  }
}

@media (width <= 540px) {
  /* Canal+: keep its logo on the same safe top baseline as Conversations. */
  html.uza-ios.uza-member-hub-active
    .uza-web-shell.canal-plus-member-shell
    .uza-canal-plus-mobile-chooser.uza-member-hub {
    padding-top: calc(31px + var(--uza-safe-top)) !important;
    padding-bottom: 96px !important;
  }

  html.uza-ios.uza-member-hub-active
    .uza-web-shell.canal-plus-member-shell
    .uza-canal-plus-mobile-chooser.uza-member-hub.uza-member-nav-inline {
    padding-bottom: max(24px, calc(var(--uza-safe-bottom) + 16px)) !important;
  }

  html.uza-ios.uza-member-hub-active.uza-member-hub-entering
    .uza-web-shell.canal-plus-section
    > .uza-left-brand-header,
  html.uza-ios.uza-member-hub-active.uza-member-hub-leaving
    .uza-web-shell.canal-plus-section
    > .uza-left-brand-header {
    height: calc(88px + var(--uza-safe-top)) !important;
    padding: calc(8px + var(--uza-safe-top)) 14px 8px !important;
  }

  html.uza-ios.uza-member-hub-active.uza-member-hub-entering
    .uza-web-shell.canal-plus-section
    > .uza-left-brand-header
    > img,
  html.uza-ios.uza-member-hub-active.uza-member-hub-leaving
    .uza-web-shell.canal-plus-section
    > .uza-left-brand-header
    > img {
    top: calc(-24px + var(--uza-safe-top)) !important;
  }
}

@media (width <= 370px) {
  html.uza-ios body.uza-conversations-approved .uza-left-brand-header > img {
    top: calc(-21px + var(--uza-safe-top)) !important;
  }
}

@supports (-webkit-touch-callout: none) {
  html.uza-ios body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
  }
}

/*
 * WebKit stability — account/profile surfaces
 *
 * Safari and iOS PWAs can stall the compositor when an animated, full-screen
 * fixed layer combines backdrop-filter with other blurred descendants. Keep
 * the approved appearance, but render these two account surfaces without
 * live background sampling on iPhone/iPad.
 */
@media (width <= 820px) {
  html.uza-ios .uza-profile-fan-layer {
    isolation: auto !important;
    contain: none !important;
    transform: none !important;
  }

  html.uza-ios .uza-profile-fan-backdrop,
  html.uza-ios .uza-account-profile-backdrop {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  html.uza-ios .uza-profile-fan-backdrop {
    background:
      radial-gradient(
        circle at 50% 86%,
        rgba(48, 52, 64, 0.18),
        transparent 44%
      ),
      rgba(5, 5, 8, 0.86) !important;
    animation: none !important;
    transition: none !important;
    will-change: auto !important;
  }

  html.uza-ios .uza-profile-fan-close {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    filter: none !important;
    background: linear-gradient(145deg, #2b2a31, #18181d) !important;
    animation: none !important;
    transition: none !important;
    will-change: auto !important;
  }

  html.uza-ios .uza-profile-fan-options,
  html.uza-ios .uza-profile-fan-option {
    animation: none !important;
    transition: none !important;
    will-change: auto !important;
  }

  html.uza-ios .uza-profile-fan-close::before {
    animation: none !important;
    transition: none !important;
    filter: none !important;
  }

  html.uza-ios body.uza-account-menu-open
    .uza-approved-bottom-nav.uza-shared-bottom-nav:not(.uza-member-inline-nav) {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    filter: none !important;
    transform: translateX(-50%) !important;
    transition: none !important;
  }

  html.uza-ios body.uza-account-menu-open
    .uza-approved-bottom-nav.uza-shared-bottom-nav:not(.uza-member-inline-nav)
    > * {
    opacity: 0 !important;
    transition: none !important;
  }

  html.uza-ios .uza-account-profile-backdrop {
    background:
      radial-gradient(
        circle at 50% 38%,
        rgba(83, 81, 106, 0.16),
        transparent 40%
      ),
      rgba(5, 5, 8, 0.94) !important;
    animation: uza-ios-account-fade-in 160ms ease-out both !important;
  }

  html.uza-ios .uza-account-profile-glow {
    display: none !important;
    filter: none !important;
  }

  html.uza-ios .uza-account-profile-modal {
    animation: uza-ios-account-sheet-in 190ms ease-out both !important;
    box-shadow:
      0 22px 54px rgba(0, 0, 0, 0.58),
      inset 0 1px rgba(255, 255, 255, 0.055) !important;
  }
}

@keyframes uza-ios-account-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes uza-ios-account-close-in {
  from {
    opacity: 0;
    transform: translateX(-50%) rotate(90deg) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) rotate(90deg) scale(1);
  }
}

@keyframes uza-ios-account-sheet-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
