/**
 * Mobile compatibility pass — APK (Capacitor) + mobile web.
 * Layout/CSS only; breakpoints: 320, 360, 390, 414, 480px.
 */

:root {
  --notes-app-height: 100dvh;
  --notes-safe-top: env(safe-area-inset-top, 0px);
  --notes-safe-right: env(safe-area-inset-right, 0px);
  --notes-safe-bottom: env(safe-area-inset-bottom, 0px);
  --notes-safe-left: env(safe-area-inset-left, 0px);
  --notes-pad-inline: clamp(12px, 4.2vw, 18px);
  --notes-modal-pad: clamp(14px, 4vw, 28px);
  /* Bottom layout tokens — single source for main, footer, FAB stack */
  --notes-footer-link-size: 0.6875rem;
  --notes-footer-link-lh: 1.35;
  --notes-footer-row-gap: 8px;
  --notes-footer-col-gap: 10px;
  --notes-footer-block-gap: 6px;
  --notes-footer-pad-top: 8px;
  --notes-footer-pad-bottom: max(8px, var(--notes-safe-bottom));
  --notes-footer-link-rows: 2;
  --notes-footer-content-h: calc(
    var(--notes-footer-pad-top)
    + var(--notes-footer-link-rows) * (var(--notes-footer-link-size) * var(--notes-footer-link-lh))
    + (var(--notes-footer-link-rows) - 1) * var(--notes-footer-row-gap)
    + var(--notes-footer-block-gap)
    + var(--notes-footer-link-size) * var(--notes-footer-link-lh)
  );
  --notes-footer-zone: calc(var(--notes-footer-content-h) + var(--notes-footer-pad-bottom));
  --notes-footer-fab-gutter: 0px;
  --notes-fab-size: 46px;
  --notes-fab-size-chat: var(--notes-fab-size);
  --notes-fab-size-planner: var(--notes-fab-size);
  --notes-fab-stack-gap: clamp(6px, 1.8vw, 8px);
  --notes-fab-planner-offset: 0px;
  --notes-fab-nav-gap: 14px;
  --notes-fab-stack-total: calc(
    var(--notes-fab-size) + var(--notes-fab-stack-gap) + var(--notes-fab-size)
  );
  /* Anchor FABs just above the phone nav / gesture bar — not footer document height */
  --notes-fab-bottom-base: calc(var(--notes-fab-nav-gap) + var(--notes-safe-bottom));
  --notes-main-bottom-pad: var(--notes-footer-block-gap);
  --notes-scroll-bottom-pad: max(
    var(--notes-main-bottom-pad),
    calc(var(--notes-fab-bottom-base) + var(--notes-fab-size) + 8px)
  );
  --notes-fab-clearance: var(--notes-scroll-bottom-pad);
  --notes-toast-gap: 10px;
  --notes-toast-bottom: calc(
    var(--notes-fab-nav-gap) + var(--notes-safe-bottom) + var(--notes-fab-stack-total) + var(--notes-toast-gap)
  );

  /* Cross-device type scale — px caps beat vw + system font scaling drift */
  --notes-type-2xs: 10px;
  --notes-type-xs: 11px;
  --notes-type-sm: 12px;
  --notes-type-base: 13px;
  --notes-type-md: 14px;
  --notes-type-lg: 16px;
  --notes-type-xl: 18px;
  --notes-type-2xl: 20px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html.capacitor-native {
  font-size: 16px;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  /* Modest fallback when WebView reports 0 safe-area (3-button nav / gesture bar) */
  --notes-safe-bottom: max(env(safe-area-inset-bottom, 0px), 20px);
  --notes-footer-pad-bottom: max(8px, var(--notes-safe-bottom));
  --notes-fab-nav-gap: 12px;
  --notes-fab-bottom-base: calc(var(--notes-fab-nav-gap) + var(--notes-safe-bottom));
}

html {
  overflow-x: clip;
  max-width: 100%;
}

html,
body {
  min-height: 100vh;
  min-height: var(--notes-app-height);
}

body {
  overflow-x: clip;
}

.app,
.main,
.page,
.page-shell,
.home-dashboard,
.home-dashboard-primary,
.home-dashboard-top {
  max-width: 100%;
  min-width: 0;
}

.main {
  overflow-x: clip;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

img,
video,
canvas,
svg,
embed,
iframe {
  max-width: 100%;
}

table {
  max-width: 100%;
}

pre,
code,
.note-card pre,
.note-view-body pre {
  max-width: 100%;
  overflow-x: auto;
  word-break: break-word;
}

/* Modals: fit viewport, scroll inside, respect safe areas */
.modal {
  padding:
    max(10px, var(--notes-safe-top))
    max(10px, var(--notes-safe-right))
    max(10px, var(--notes-safe-bottom))
    max(10px, var(--notes-safe-left));
  align-items: center;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  box-sizing: border-box;
  width: 100%;
  max-width: min(560px, calc(100vw - 20px));
  max-height: min(
    calc(var(--notes-app-height) - 20px),
    calc(var(--notes-app-height) - var(--notes-safe-top) - var(--notes-safe-bottom) - 20px)
  );
  margin: auto;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--notes-modal-pad);
}

.note-export-modal,
.note-share-modal,
.scan-cam-share-modal .modal-content,
.scan-cam-upgrade-modal .modal-content,
.auth-shell__card {
  width: 100%;
  max-width: min(420px, calc(100vw - 20px));
}

.modal-header {
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.modal-header h2,
.modal-header h3 {
  min-width: 0;
  flex: 1 1 auto;
  font-size: var(--notes-type-lg);
  line-height: 1.25;
}

/* Forms: no overflow when keyboard opens; avoid WebView zoom jump */
input,
textarea,
select,
.note-rich-editor,
.note-editor-wrap,
.web-chat-composer textarea,
#webChatInput {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

input,
textarea,
select {
  font-size: max(16px, 1rem);
}

.page-header {
  flex-wrap: wrap;
  align-items: flex-start;
  gap: clamp(10px, 3vw, 16px);
}

.page-header h2,
.page-header h1 {
  font-size: var(--notes-type-xl);
  line-height: 1.2;
  min-width: 0;
}

.topbar-heading {
  font-size: var(--notes-type-lg);
}

.eyebrow {
  font-size: var(--notes-type-xs);
}

.home-hero-title {
  font-size: var(--notes-type-lg);
}

.home-copy,
.card-subtitle,
.note-card-text {
  font-size: var(--notes-type-sm);
}

/* Buttons: fluid width, no rigid px columns on narrow screens */
.save-button,
.add-button,
.back-button,
.primaryBtn,
.secondary,
.note-export-option,
.scan-cam-chip-btn,
.scan-cam-preview-bar__convert,
.scan-cam-preview-bar__ghost {
  max-width: 100%;
  box-sizing: border-box;
}

/* Cards / panels */
.note-card,
.premium-plan-card,
.premium-feature-card,
.premium-preview-card,
.bot-connect-panel,
.manual-panel,
.bot-chat-panel,
.scan-cam-tool,
.scan-cam-side-card,
.scan-cam-mini-card,
.settings-section,
.history-toolbar {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Grids → single column on very small phones */
@media (max-width: 480px) {
  .app .main {
    padding-left: var(--notes-pad-inline);
    padding-right: var(--notes-pad-inline);
  }

  .home-dashboard-top,
  .home-stats-grid,
  .hex-grid:not(.home-categories-grid),
  .bot-panel-grid,
  .pricing-lite-grid,
  .pricing-lite-why,
  .scan-cam-info-cards,
  .note-export-theme-seg,
  .settings-grid,
  .home-reminders-fields {
    grid-template-columns: 1fr !important;
  }

  .home-stats-panel {
    width: 100%;
    max-width: 100%;
  }

  .settings-nav-btn:nth-child(5):last-child {
    grid-column: 1 / -1;
    max-width: calc(50% - 3px);
    justify-self: center;
  }

  .page-header .save-button,
  .page-header .add-button,
  .page-header .back-button {
    width: 100%;
    flex: 1 1 100%;
  }

  .note-export-theme-seg {
    flex-direction: column;
  }

  .note-export-theme-btn {
    width: 100%;
  }

  .scan-cam-launch__chips,
  .scan-cam-preview-bar {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .scan-cam-chip-btn,
  .scan-cam-preview-bar__convert,
  .scan-cam-preview-bar__ghost {
    flex: 1 1 calc(50% - 8px);
    min-width: min(100%, 140px);
  }

  .pricing-lite-compare {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .pricing-lite-compare__head,
  .pricing-lite-compare__row {
    min-width: min(100%, 300px);
  }

  .web-chat-page--messenger,
  .web-chat-messenger {
    width: 100%;
    max-width: 100%;
  }

  #webChat.web-chat-drawer .web-chat-messenger {
    min-height: min(62dvh, 520px);
    max-height: min(70dvh, 580px);
  }
}

/* Tighter 320–390px devices */
@media (max-width: 390px) {
  .modal-content {
    padding: clamp(12px, 3.5vw, 18px);
    border-radius: clamp(16px, 4vw, 22px);
  }

  .close-button {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }

  .topbar-logo {
    width: 42px;
    height: 42px;
  }

  .topbar-logo-svg {
    width: 26px;
    height: 26px;
  }

  .mobile-menu-toggle {
    width: 38px;
    height: 38px;
  }

  .scan-cam-chip-btn,
  .scan-cam-preview-bar__convert,
  .scan-cam-preview-bar__ghost {
    flex: 1 1 100%;
    width: 100%;
  }
}

@media (max-width: 360px) {
  .home-bottom-info-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .home-bottom-info-bar__title {
    font-size: clamp(0.88rem, 4vw, 1rem);
  }
}

@media (max-width: 320px) {
  :root {
    --notes-pad-inline: 10px;
    --notes-modal-pad: 12px;
  }

  .modal-content {
    max-width: calc(100vw - 12px);
  }
}

/* Mobile/APK: balanced bottom — no giant void, footer clear of FABs */
@media (max-width: 840px) {
  body {
    display: flex;
    flex-direction: column;
    min-height: var(--notes-app-height);
  }

  .app {
    flex: 0 0 auto;
    min-height: auto !important;
    width: 100%;
  }

  .main {
    min-height: auto !important;
    padding-bottom: var(--notes-main-bottom-pad) !important;
    scroll-padding-bottom: var(--notes-scroll-bottom-pad) !important;
  }

  .site-footer {
    flex-shrink: 0;
    width: 100%;
    margin-top: 0;
    position: relative;
    z-index: 1;
  }

  /* Body-level FABs must stack above the footer (chat FAB was inside .app before). */
  .web-chat-fab,
  #webChatFab,
  .web-chat-fab-tip,
  #webChatFabTip,
  .daily-planner-fab,
  #dailyPlannerFab {
    z-index: 1302 !important;
  }

  .site-footer-inner {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin-inline: auto;
    padding-top: var(--notes-footer-pad-top);
    padding-bottom: var(--notes-footer-pad-bottom);
    padding-left: max(12px, var(--notes-safe-left));
    padding-right: max(12px, var(--notes-safe-right));
    gap: var(--notes-footer-block-gap);
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .site-footer-links {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  .site-footer-links-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--notes-footer-row-gap) var(--notes-footer-col-gap);
    width: min(100%, 288px);
    max-width: calc(100vw - 24px - var(--notes-safe-left) - var(--notes-safe-right));
    margin-inline: auto;
    justify-items: center;
    align-items: center;
  }

  .site-footer-links-grid a {
    font-size: var(--notes-footer-link-size);
    line-height: var(--notes-footer-link-lh);
    padding: 2px 4px;
    text-align: center;
    width: 100%;
    white-space: nowrap;
  }

  .site-footer-copy {
    font-size: var(--notes-footer-link-size);
    line-height: var(--notes-footer-link-lh);
    margin: 0;
    width: 100%;
    text-align: center;
    opacity: 0.88;
  }

  html.capacitor-native .main {
    padding-bottom: var(--notes-main-bottom-pad) !important;
    scroll-padding-bottom: var(--notes-scroll-bottom-pad) !important;
  }

  html.capacitor-native .modal {
    padding-bottom: max(12px, var(--notes-safe-bottom));
  }

  /* Very narrow phones: 2 balanced columns (3 rows × 2 cols) */
  @media (max-width: 360px) {
    :root {
      --notes-footer-link-rows: 3;
      --notes-footer-col-gap: 8px;
    }

    .site-footer-links-grid {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      width: min(100%, 236px);
    }
  }
}

/* Coarse pointer / touch: reduce overlap risk for floating controls */
@media (max-width: 480px), (pointer: coarse) {
  .web-chat-fab,
  #webChatFab,
  .daily-planner-fab,
  .discord-fab {
    contain: layout;
  }

  body:has(#webChat:not(.hidden)) .app .main,
  body:has(.daily-planner-modal:not(.hidden)) .app .main {
    scroll-padding-bottom: max(96px, var(--notes-scroll-bottom-pad));
  }
}

/**
 * FAB stack — mobile / touch / APK only.
 * Anchored above footer zone; clear vertical gap between planner + chat.
 */
@media (max-width: 840px), (pointer: coarse) {
  html.capacitor-native {
    --notes-fab-stack-gap: clamp(6px, 1.8vw, 8px);
  }

  @media (max-height: 640px) {
    :root {
      --notes-footer-pad-top: 6px;
      --notes-footer-row-gap: 6px;
      --notes-footer-block-gap: 4px;
      --notes-fab-nav-gap: 10px;
      --notes-fab-stack-gap: 6px;
      --notes-fab-planner-offset: 0px;
    }
  }

  .web-chat-fab,
  #webChatFab,
  .daily-planner-fab,
  #dailyPlannerFab {
    position: fixed !important;
    top: auto !important;
    right: max(14px, calc(var(--notes-safe-right) + 10px)) !important;
    width: var(--notes-fab-size) !important;
    height: var(--notes-fab-size) !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  .web-chat-fab,
  #webChatFab {
    bottom: calc(var(--notes-fab-nav-gap) + var(--notes-safe-bottom)) !important;
    z-index: 1301;
  }

  .daily-planner-fab,
  #dailyPlannerFab {
    bottom: calc(
      var(--notes-fab-nav-gap) + var(--notes-safe-bottom) + var(--notes-fab-size) + var(--notes-fab-stack-gap)
    ) !important;
    z-index: 1300;
  }

  .web-chat-fab-tip,
  #webChatFabTip {
    position: fixed !important;
    top: auto !important;
    right: max(72px, calc(var(--notes-safe-right) + 66px)) !important;
    bottom: calc(
      var(--notes-fab-nav-gap) + var(--notes-safe-bottom) + var(--notes-fab-size) + 6px
    ) !important;
    z-index: 1301;
  }

  .discord-fab {
    left: max(14px, calc(var(--notes-safe-left) + 10px));
    bottom: calc(var(--notes-fab-nav-gap) + var(--notes-safe-bottom));
  }

  body:has(#webChat:not(.hidden)) .web-chat-fab,
  body:has(#webChat:not(.hidden)) #webChatFab {
    bottom: calc(var(--notes-fab-nav-gap) + var(--notes-safe-bottom)) !important;
  }

  body:has(#webChat:not(.hidden)) .daily-planner-fab,
  body:has(#webChat:not(.hidden)) #dailyPlannerFab {
    bottom: calc(
      var(--notes-fab-nav-gap) + var(--notes-safe-bottom) + var(--notes-fab-size) + var(--notes-fab-stack-gap)
    ) !important;
  }
}

/* Home / Work / School — 3 cards side-by-side on all phone widths */
@media (max-width: 840px) {
  #home .home-categories-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: clamp(6px, 2vw, 10px) !important;
    max-width: 100%;
    width: 100%;
  }

  #home .home-categories-grid .hex-card {
    min-height: 152px !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 12px !important;
  }

  #home .home-categories-grid .hex-card-main {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: center !important;
    grid-template-columns: unset !important;
    padding: 8px 6px 6px !important;
    gap: 4px !important;
  }

  #home .home-categories-grid .category-icon,
  #home .home-categories-grid .hex-icon {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    font-size: 18px !important;
    border-radius: 10px !important;
    margin: 0 !important;
    flex-shrink: 0;
  }

  #home .home-categories-grid .hex-card-main strong {
    font-size: var(--notes-type-sm) !important;
    line-height: 1.15 !important;
  }

  #home .home-categories-grid .card-subtitle {
    font-size: var(--notes-type-2xs) !important;
    line-height: 1.3 !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  #home .home-categories-grid .hex-card-add {
    min-height: 28px !important;
    padding: 5px 6px !important;
    font-size: var(--notes-type-2xs) !important;
    margin-top: auto;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
}

@media (max-width: 360px) {
  #home .home-categories-grid {
    gap: 6px !important;
  }

  #home .home-categories-grid .hex-card {
    min-height: 158px !important;
  }
}

/* Auto-hide app topbar on scroll down (mobile + APK) */
@media (max-width: 840px) {
  body .topbar {
    transform: translate3d(0, 0, 0);
    transition:
      transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
      opacity 0.28s ease,
      min-height 0.28s cubic-bezier(0.22, 1, 0.36, 1),
      padding 0.28s cubic-bezier(0.22, 1, 0.36, 1),
      background 0.28s ease,
      border-color 0.28s ease,
      box-shadow 0.28s ease !important;
  }

  body.topbar-auto-hidden .topbar {
    transform: translate3d(0, calc(-100% - env(safe-area-inset-top, 0px)), 0);
    opacity: 0;
    pointer-events: none;
  }

  body.topbar-auto-hidden .notes-toolbar {
    top: max(6px, env(safe-area-inset-top, 0px)) !important;
  }

  body.topbar-auto-hidden.mobile-scrolled .notes-toolbar {
    top: max(6px, env(safe-area-inset-top, 0px)) !important;
  }
}

html.capacitor-native body.topbar-auto-hidden .notes-toolbar {
  top: max(8px, env(safe-area-inset-top, 0px)) !important;
}

@media (prefers-reduced-motion: reduce) {
  body.topbar-auto-hidden .topbar {
    transition: none !important;
  }
}

/* Web Chat drawer — floating overlay on current page (mobile/APK) */
@media (max-width: 840px) {
  #webChat.web-chat-drawer {
    z-index: 10050 !important;
    align-items: flex-end !important;
    justify-content: center !important;
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      max(12px, env(safe-area-inset-right, 0px))
      max(12px, env(safe-area-inset-bottom, 0px))
      max(12px, env(safe-area-inset-left, 0px)) !important;
    background: rgba(0, 0, 0, 0.25) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
  }

  #webChat.web-chat-drawer .web-chat-messenger {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    min-height: min(62dvh, 520px) !important;
    max-height: min(78dvh, 580px) !important;
    border-radius: 20px 20px 12px 12px !important;
  }

  #webChat.web-chat-drawer.web-chat-drawer--active .web-chat-messenger {
    transform: translateY(0) scale(1) !important;
  }

  #webChat .web-chat-sheet-handle {
    display: none !important;
  }

  #webChat .web-chat-messenger::after,
  #webChat .web-chat-messenger.chat-container.chat-bot-mode::after,
  #webChat .web-chat-messenger.chat-container.openai-mode::before {
    animation: none !important;
    transform: none !important;
    filter: none !important;
    will-change: auto !important;
  }

  #webChat .web-chat-messenger__body {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  #webChat .web-chat-messages {
    padding-bottom: 96px !important;
  }

  #webChat .web-chat-messenger__footer {
    left: 10px !important;
    right: 10px !important;
    bottom: 10px !important;
    border-radius: 14px !important;
  }

  body.web-chat-drawer-open .site-footer {
    visibility: hidden;
    pointer-events: none;
    user-select: none;
  }

  #webChat .web-chat-messenger__header {
    position: sticky;
    top: 0;
    z-index: 4;
    flex-shrink: 0;
  }

  #webChat .web-chat-messenger__back {
    display: grid !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  #webChat .web-chat-quick-actions,
  #webChatQuickActions {
    display: none !important;
  }
}

/* Lighter mobile/APK paint: cut Recalculate style + Paint cost */
@media (max-width: 840px), (pointer: coarse) {
  :root {
    --depth-glass-blur: 0px;
    --depth-elev-1: 0 3px 10px rgba(0, 0, 0, 0.14);
    --depth-elev-2: 0 6px 14px rgba(0, 0, 0, 0.18);
    --ds-shadow-soft: 0 4px 12px rgba(2, 8, 22, 0.18);
    --mobile-panel-bg: rgba(15, 23, 42, 0.94);
    --mobile-modal-bg: rgba(15, 23, 42, 0.96);
  }

  .background-canvas {
    transform: none !important;
    will-change: auto !important;
  }

  .depth-blob {
    filter: none !important;
    opacity: 0.18 !important;
    animation: none !important;
  }

  .brand-mark {
    animation: none !important;
  }

  .site-footer {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(15, 23, 42, 0.92) !important;
  }

  .sidebar {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(10, 18, 36, 0.96)) !important;
  }

  body.mobile-nav-open .sidebar {
    box-shadow: 8px 0 24px rgba(2, 8, 20, 0.4) !important;
  }

  .toast,
  #toast,
  .reminder-foreground-toast {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(15, 23, 42, 0.96) !important;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28) !important;
  }

  .notes-search-input,
  .notes-select-input,
  .history-search-input,
  .history-sort-select,
  .field-group input,
  .field-group textarea,
  .field-group select,
  #webChatInput,
  .web-chat-composer,
  .web-chat-composer textarea,
  .daily-planner-item,
  .home-reminders-shell::before,
  .scan-cam-fake-doc,
  .scan-cam-zone,
  .scan-cam-camera-glow,
  .web-chat-fab-tip,
  #webChatFabTip,
  .web-chat-premium-tab-tooltip,
  .note-rich-editor-glass,
  .pricing-lite-card,
  .premium-plan-card,
  .settings-section,
  .home-stats-cta,
  .coins-dash-shell,
  .bot-connect-panel,
  .manual-panel {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    filter: none !important;
  }

  .scan-cam-fake-doc {
    animation: none !important;
  }

  .scan-cam-camera-glow {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.2), 0 6px 16px rgba(2, 8, 20, 0.22) !important;
  }

  #webChat .web-chat-messenger__header,
  #webChat .web-chat-messenger__back,
  #webChat .web-chat-composer,
  #webChat .web-chat-messenger__footer,
  #webChat .web-chat-mode-pill,
  #webChat .web-chat-bubble,
  #webChat .web-chat-model-lock-banner--slim,
  #webChat .web-chat-soft-lock,
  .web-chat-messenger__footer {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  #webChat .web-chat-messenger::after,
  #webChat .web-chat-messenger::before,
  #webChat .web-chat-messenger.chat-container.chat-bot-mode::after,
  #webChat .web-chat-messenger.chat-container.auto-mode::after,
  #webChat .web-chat-messenger.chat-container.openai-mode::after,
  #webChat .web-chat-messenger.chat-container.openai-mode::before {
    display: none !important;
    animation: none !important;
    filter: none !important;
  }

  #webChat.web-chat-drawer {
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
  }

  .note-card,
  .hex-card,
  .home-stats-panel,
  .home-reminders-shell,
  .home-stats-cta,
  .reminder-card,
  .settings-card,
  .glass-panel,
  .topbar,
  .notes-toolbar,
  .sidebar .menu-item,
  .admin-stat-card,
  .admin-card,
  .admin-user-card,
  .admin-subs-card,
  .admin-dash-user-card,
  .admin-dash-note-card,
  body.theme-advanced .note-card,
  body.theme-advanced .settings-section,
  body.theme-normal .note-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: var(--mobile-panel-bg) !important;
    box-shadow: var(--depth-elev-1) !important;
    transition: transform 0.18s ease, opacity 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease !important;
  }

  .modal-content,
  #webChat.web-chat-drawer .web-chat-messenger,
  .note-view-modal .modal-content,
  .note-export-modal,
  .note-share-modal {
    backdrop-filter: blur(6px) saturate(112%) !important;
    -webkit-backdrop-filter: blur(6px) saturate(112%) !important;
    background: var(--mobile-modal-bg) !important;
    box-shadow: 0 14px 32px rgba(2, 8, 20, 0.34) !important;
  }

  #webChat.web-chat-drawer .web-chat-messenger {
    background: rgba(15, 23, 42, 0.97) !important;
  }

  .admin-drawer-backdrop.is-open,
  .admin-drawer-backdrop:not([hidden]) {
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
  }

  body.mobile-scrolled .topbar,
  body.mobile-scrolled .main,
  body.mobile-scrolled .notes-toolbar,
  body.mobile-scrolled .topbar-inner {
    transition: none !important;
  }

  #notesList,
  #remindersList,
  #allNotesList,
  .admin-subs-cards,
  .admin-user-cards {
    content-visibility: auto;
    contain-intrinsic-size: 480px;
  }

  .web-chat-fab,
  #webChatFab,
  .daily-planner-fab,
  #dailyPlannerFab,
  .discord-fab {
    will-change: auto;
    transform: translate3d(0, 0, 0);
    contain: layout style paint;
    transition: opacity 0.2s ease, transform 0.2s ease !important;
  }

  .web-chat-fab,
  #webChatFab {
    animation: none !important;
  }

  .web-chat-fab::before,
  .web-chat-fab__active-dot::after {
    animation: none !important;
  }

  .web-chat-fab__active-dot {
    animation: none !important;
  }

  .scan-cam-camera-glow {
    animation: none !important;
  }

  .scan-cam-camera-glow::after,
  .scan-cam-camera-glow::before {
    animation: none !important;
  }

  .daily-planner-item {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(15, 23, 42, 0.88) !important;
    box-shadow: 0 3px 10px rgba(2, 6, 23, 0.22) !important;
  }

  body.floating-scrolled .web-chat-fab,
  body.floating-scrolled #webChatFab,
  body.floating-scrolled .daily-planner-fab,
  body.floating-scrolled #dailyPlannerFab,
  body.floating-scrolled .discord-fab {
    opacity: 0.84;
    transform: translate3d(0, 0, 0);
  }

  .tilt-target.is-tilting,
  .tilt-target {
    transform: none !important;
  }

  .note-card:hover,
  .hex-card:hover,
  .home-stats-panel:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16) !important;
  }

  body.web-chat-drawer-open #webChat,
  body.web-chat-drawer-open #webChatMessages {
    content-visibility: visible !important;
  }

  .main,
  .page,
  #home,
  #notes-all,
  #category,
  #bot,
  #settings,
  #reminder-history,
  #coins-hub,
  .settings-section-pane,
  #dailyPlannerList,
  #activeReminders,
  #pastReminders,
  #webChatMessages {
    content-visibility: auto;
    contain-intrinsic-size: 1px 480px;
  }

  .list-load-sentinel {
    display: block;
    width: 100%;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
    pointer-events: none;
    visibility: hidden;
  }

  .note-card,
  .hex-card,
  .reminder-card,
  .save-button,
  .primaryBtn,
  .menu-item {
    transition: transform 0.22s ease, opacity 0.22s ease, border-color 0.22s ease !important;
  }

  .note-card:hover,
  .hex-card:hover {
    box-shadow: var(--depth-elev-1) !important;
  }
}

/* Theme overrides: mobile uses solid panels, blur only on modals/chat shell */
@media (max-width: 840px), (pointer: coarse) {
  body.theme-advanced .note-card,
  body.theme-advanced .settings-section,
  body.theme-advanced .bot-connect-panel,
  body.theme-classic .settings-section,
  body.theme-normal .note-card,
  body.theme-normal .settings-section {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: var(--depth-elev-1) !important;
  }

  body.theme-advanced .workspace-item.sticky,
  body.theme-advanced .workspace-item.note-1,
  body.theme-advanced .workspace-item.note-2 {
    animation: none !important;
    will-change: auto !important;
    filter: none !important;
  }
}

html.capacitor-native {
  --depth-glass-blur: 0px;
}

html.capacitor-native .depth-blob {
  filter: none !important;
  opacity: 0.16 !important;
  animation: none !important;
}

html.capacitor-native .note-card,
html.capacitor-native .hex-card,
html.capacitor-native .home-stats-panel,
html.capacitor-native .reminder-card,
html.capacitor-native .site-footer,
html.capacitor-native .sidebar {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14) !important;
}

html.capacitor-native .modal-content,
html.capacitor-native #webChat.web-chat-drawer .web-chat-messenger {
  backdrop-filter: blur(6px) saturate(108%) !important;
  -webkit-backdrop-filter: blur(6px) saturate(108%) !important;
  background: rgba(15, 23, 42, 0.97) !important;
  box-shadow: 0 12px 28px rgba(2, 8, 20, 0.32) !important;
}

/* APK: always pin FAB stack just above system nav — immune to style.css mobile overrides */
html.capacitor-native #webChatFab,
html.capacitor-native .web-chat-fab,
html.capacitor-native #dailyPlannerFab,
html.capacitor-native .daily-planner-fab {
  position: fixed !important;
  top: auto !important;
  margin: 0 !important;
}

html.capacitor-native #webChatFab,
html.capacitor-native .web-chat-fab {
  bottom: calc(12px + max(env(safe-area-inset-bottom, 0px), 20px)) !important;
}

html.capacitor-native #dailyPlannerFab,
html.capacitor-native .daily-planner-fab {
  bottom: calc(12px + max(env(safe-area-inset-bottom, 0px), 20px) + var(--notes-fab-size) + var(--notes-fab-stack-gap)) !important;
}

html.capacitor-native #webChatFabTip,
html.capacitor-native .web-chat-fab-tip {
  bottom: calc(12px + max(env(safe-area-inset-bottom, 0px), 20px) + var(--notes-fab-size) + 6px) !important;
}

html.capacitor-native .toast,
html.capacitor-native #toast {
  contain: layout style paint;
  bottom: calc(
    12px + max(env(safe-area-inset-bottom, 0px), 20px) + var(--notes-fab-stack-total) + 10px
  ) !important;
}

/* APK: static FABs + lighter infinite motion — main-thread scroll budget */
html.capacitor-native .web-chat-fab,
html.capacitor-native #webChatFab,
html.capacitor-native .daily-planner-fab,
html.capacitor-native #dailyPlannerFab {
  animation: none !important;
  will-change: auto !important;
}

html.capacitor-native .web-chat-fab::before,
html.capacitor-native .web-chat-fab__active-dot,
html.capacitor-native .web-chat-fab__active-dot::after {
  animation: none !important;
}

html.capacitor-native .scan-cam-camera-glow,
html.capacitor-native .scan-cam-camera-glow::before,
html.capacitor-native .scan-cam-camera-glow::after {
  animation: none !important;
}

html.capacitor-native .background-canvas {
  transform: none !important;
  will-change: auto !important;
}

html.capacitor-native #allNotesList,
html.capacitor-native #notesList,
html.capacitor-native #remindersList {
  content-visibility: auto;
  contain-intrinsic-size: 420px;
}

/* ========== Cross-device UI scale (modals, home, stats) ========== */
@media (max-width: 840px), (pointer: coarse) {
  #home .home-hero-title {
    font-size: var(--notes-type-lg) !important;
    line-height: 1.15 !important;
    max-width: none !important;
  }

  #home .home-welcome-line {
    font-size: var(--notes-type-base) !important;
  }

  #home .home-stats-eyebrow,
  #home .home-intro .eyebrow {
    font-size: var(--notes-type-2xs) !important;
  }

  #home .home-stat-value {
    font-size: var(--notes-type-lg) !important;
  }

  #home .home-stat-label {
    font-size: var(--notes-type-2xs) !important;
  }

  #home .home-stats-cta {
    font-size: var(--notes-type-sm) !important;
    min-height: 36px !important;
  }

  #home .home-bottom-info-bar__title {
    font-size: var(--notes-type-md) !important;
  }

  #home .home-bottom-info-bar__sub {
    font-size: var(--notes-type-sm) !important;
  }

  .welcome-sheet {
    width: min(100%, calc(100vw - 24px - var(--notes-safe-left) - var(--notes-safe-right))) !important;
    max-height: calc(100dvh - var(--notes-safe-top) - var(--notes-safe-bottom) - 20px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 12px 14px 10px !important;
  }

  .welcome-sheet__title {
    font-size: var(--notes-type-md) !important;
    line-height: 1.25 !important;
  }

  .welcome-sheet__subtitle {
    font-size: var(--notes-type-2xs) !important;
    margin-bottom: 8px !important;
  }

  .welcome-sheet__bullets {
    font-size: var(--notes-type-sm) !important;
    line-height: 1.45 !important;
    padding-left: 1rem !important;
  }

  .welcome-sheet__trial {
    padding: 8px 10px !important;
    margin-bottom: 10px !important;
  }

  .welcome-sheet__trial-heading {
    font-size: var(--notes-type-base) !important;
  }

  .welcome-sheet__trial-lead,
  .welcome-sheet__trial-bullets {
    font-size: var(--notes-type-xs) !important;
    line-height: 1.42 !important;
  }

  .welcome-sheet__trial-note {
    font-size: var(--notes-type-xs) !important;
  }

  .welcome-sheet__cta.save-button {
    min-height: 40px !important;
    font-size: var(--notes-type-base) !important;
  }

  .trial-gift-modal__dialog {
    max-height: calc(100dvh - var(--notes-safe-top) - var(--notes-safe-bottom) - 24px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 14px 14px 12px !important;
  }

  .trial-gift-modal__title {
    font-size: var(--notes-type-lg) !important;
  }

  .trial-gift-modal__lead {
    font-size: var(--notes-type-sm) !important;
  }

  .trial-gift-modal__list {
    font-size: var(--notes-type-sm) !important;
    line-height: 1.45 !important;
    padding-left: 1.1rem !important;
  }

  .trial-gift-modal__note {
    font-size: var(--notes-type-xs) !important;
  }

  .trial-gift-modal__cta,
  .trial-gift-modal__later {
    font-size: var(--notes-type-base) !important;
    min-height: 40px !important;
  }

  .toast,
  #toast {
    bottom: var(--notes-toast-bottom) !important;
    max-width: min(calc(100vw - 24px - var(--notes-safe-left) - var(--notes-safe-right)), 340px) !important;
    padding: 10px 14px !important;
    font-size: var(--notes-type-sm) !important;
    line-height: 1.42 !important;
    border-radius: 12px !important;
    z-index: 1310 !important;
  }

  .reminder-foreground-toast,
  #reminderForegroundToast {
    top: max(10px, calc(var(--notes-safe-top) + 8px)) !important;
    max-width: min(calc(100vw - 24px - var(--notes-safe-left) - var(--notes-safe-right)), 340px) !important;
    padding: 10px 14px !important;
    font-size: var(--notes-type-sm) !important;
    z-index: 1310 !important;
  }
}
