/* The bottom bars as glass, for everyone (page-head.ejs adds html.glass; ?glass=0 switches it off in
   a browser, and "Reduce transparency" or a browser without blur keeps the solid bar). */



/* Glass as iOS 26 draws it, as far as Safari allows (no refraction: an SVG displacement inside
   backdrop-filter renders in Chromium only). Built from four things:
   - a clear body: light blur, so shapes beneath stay recognisable
   - a specular rim: a gradient border, bright where the light comes from (top left), fading away
   - thickness: inner shadows, light along the top, faintly dark along the bottom
   - glare: a soft light patch in the upper half
   The open tab is a small glass bubble of its own. */
html.glass {
  --glass-bg: rgba(255, 255, 255, 0.38);
  --glass-rim: linear-gradient(135deg, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.55) 18%, rgba(255, 255, 255, 0.08) 48%, rgba(255, 255, 255, 0.12) 72%, rgba(255, 255, 255, 0.7) 100%);
  --glass-depth: inset 0 1px 1px rgba(255, 255, 255, 0.95), inset 0 -1px 2px rgba(15, 23, 42, 0.07);
  --glass-glare: radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0.18) 45%, rgba(255, 255, 255, 0) 70%);
  --glass-edge: rgba(15, 23, 42, 0.06);
  --glass-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  --glass-bubble: rgba(255, 255, 255, 0.6);
  --glass-bubble-depth: inset 0 1px 1px rgba(255, 255, 255, 1), inset 0 -1px 1px rgba(15, 23, 42, 0.06), 0 2px 8px rgba(15, 23, 42, 0.12);
}
html.glass[data-theme="dark"] {
  --glass-bg: rgba(30, 38, 52, 0.42);
  --glass-rim: linear-gradient(135deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0.2) 20%, rgba(255, 255, 255, 0.03) 50%, rgba(255, 255, 255, 0.05) 72%, rgba(255, 255, 255, 0.3) 100%);
  --glass-depth: inset 0 1px 1px rgba(255, 255, 255, 0.25), inset 0 -1px 2px rgba(0, 0, 0, 0.3);
  --glass-glare: radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.04) 45%, rgba(255, 255, 255, 0) 70%);
  --glass-edge: rgba(0, 0, 0, 0.35);
  --glass-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  --glass-bubble: rgba(255, 255, 255, 0.14);
  --glass-bubble-depth: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 2px 8px rgba(0, 0, 0, 0.35);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  /* The top bar stays solid (tried as glass: a dark bar made see-through came out grey-white). */

  /* Round floating buttons over a map (Travel's "+"): small glass bubbles with a blue icon. */
  @media (max-width: 899px) {
    html.glass .travel-map-fab {
      background: rgba(255, 255, 255, 0.55);
      color: var(--primary-color);
      -webkit-backdrop-filter: blur(8px);
      backdrop-filter: blur(8px);
      border: 1px solid rgba(255, 255, 255, 0.7);
      box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.95), inset -1px -1px 0 rgba(255, 255, 255, 0.3), 0 8px 22px rgba(15, 23, 42, 0.2);
    }
    html.glass[data-theme="dark"] .travel-map-fab { background: rgba(30, 38, 52, 0.6); border-color: rgba(255, 255, 255, 0.15); }
  }

  /* Bottom bars: a floating glass pill above the home indicator, the content visible beneath. */
  @media (max-width: 899px) {
    html.glass .app-bottom-nav,
    html.glass .feature-bottom-nav {
      left: 12px;
      right: 12px;
      bottom: calc(env(safe-area-inset-bottom, 0px) + 6px);
      height: var(--bottom-nav-h);
      min-height: 0;
      padding: 0 4px;
      border: 0;
      outline: 1px solid var(--glass-edge);
      border-radius: 999px;
      background: var(--glass-bg);
      /* Custom properties do not resolve inside -webkit-backdrop-filter in Safari: written out.
         Blur only, and light: the bar is fixed, so the page beneath is blurred again on every
         scroll and animation frame, and saturate/brightness or a wider radius cost frames on phones. */
      -webkit-backdrop-filter: blur(8px);
      backdrop-filter: blur(8px);
      box-shadow: var(--glass-depth), var(--glass-shadow);
      overflow: hidden;
      isolation: isolate;
      /* Its own compositing layer: without one, iOS redrew the blurred pill a frame behind the
         page during fast momentum scrolling, and it jittered up and down. */
      transform: translateZ(0);
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
    }
    /* The specular rim: a gradient border, masked to its 1.5px edge. */
    html.glass .app-bottom-nav::before,
    html.glass .feature-bottom-nav::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: inherit;
      padding: 1.5px;
      background: var(--glass-rim);
      -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
      -webkit-mask-composite: xor;
      mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
      pointer-events: none;
      z-index: 2;
    }
    /* The glare: soft light in the upper half. */
    html.glass .app-bottom-nav::after,
    html.glass .feature-bottom-nav::after {
      content: '';
      position: absolute;
      left: 6%;
      right: 6%;
      top: 1px;
      height: 55%;
      border-radius: 999px 999px 40% 40%;
      background: var(--glass-glare);
      pointer-events: none;
      z-index: 0;
    }
    html.glass .app-nav-item,
    html.glass .feature-bottom-tab,
    html.glass .app-bottom-nav .app-nav-trigger,
    html.glass .feature-bottom-nav .app-nav-trigger { position: relative; z-index: 1; }
    /* The open tab: a glass bubble, not the flat bar's top rule. */
    html.glass .app-nav-item,
    html.glass .feature-bottom-tab { border-top-color: transparent !important; border-radius: 999px; margin: 5px 1px; }
    html.glass .app-nav-item.active,
    html.glass .feature-bottom-tab.active {
      background: var(--glass-bubble);
      box-shadow: var(--glass-bubble-depth);
    }
    html.glass .app-bottom-nav .app-nav-trigger,
    html.glass .feature-bottom-nav .app-nav-trigger { border-left-color: var(--glass-edge); }
    /* The collection page is dark in either theme (Facet, collection.css / facet.css): light-theme
       glass over it came out a washed grey with grey icons. There the pill takes the dark glass and
       Facet's own inks, so it reads on the black wall and on the photos alike. */
    html.glass body:has(.facet-wall) .app-bottom-nav,
    html.glass body:has(.facet-wall) .feature-bottom-nav {
      --glass-bg: rgba(16, 17, 20, 0.66);
      --glass-rim: linear-gradient(135deg, rgba(255, 255, 255, 0.45) 0%, rgba(255, 255, 255, 0.14) 20%, rgba(255, 255, 255, 0.03) 50%, rgba(255, 255, 255, 0.05) 72%, rgba(255, 255, 255, 0.24) 100%);
      --glass-depth: inset 0 1px 1px rgba(255, 255, 255, 0.18), inset 0 -1px 2px rgba(0, 0, 0, 0.4);
      --glass-glare: radial-gradient(120% 100% at 50% 0%, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 65%);
      --glass-edge: rgba(0, 0, 0, 0.5);
      --glass-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
      --glass-bubble: rgba(255, 255, 255, 0.12);
      --glass-bubble-depth: inset 0 1px 1px rgba(255, 255, 255, 0.22), 0 2px 8px rgba(0, 0, 0, 0.4);
      --muted: #9B9CA1;
      --nav-ink: #9B9CA1;
      --primary-color: #EDEAE4;
    }
    /* Room for the pill's lift above the home indicator. */
    html.glass body.has-standard-bottom-nav {
      padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
    }

    /* What sits on the pill takes its shape and line: the same 12px sides, 8px clear above it,
       buttons fully round, bars as rounded glass rather than full-width strips. The pill's top
       is 6px + its height above the safe area. While typing the pill is hidden (kb-focus), and a
       chat open full screen (ck-fullscreen) has no pill: there the bars keep their own layout. */
    html.glass {
      --above-pill: calc(env(safe-area-inset-bottom, 0px) + 6px + var(--bottom-nav-h) + 8px);
    }
    /* Settings: Save Settings */
    html.glass .save-button {
      bottom: var(--above-pill) !important;
      border-radius: 999px !important;
      box-shadow: 0 8px 24px rgba(5, 150, 105, 0.28);
    }
    /* Diary: the Save Entry bar loses its strip, its buttons float above the pill. */
    html.glass .entry-save-bar {
      left: 12px !important;
      right: 12px !important;
      bottom: var(--above-pill) !important;
      padding: 0 !important;
      background: transparent !important;
      border-top: 0 !important;
    }
    html.glass .entry-save-bar > * { border-radius: 999px !important; box-shadow: 0 8px 20px rgba(15, 23, 42, 0.14); }
    /* Wardrobe: Generate try-on */
    html.glass .wardrobe-generate {
      bottom: var(--above-pill) !important;
      border-radius: 999px !important;
    }
    /* Oracle's input bar (fixed above the pill) and the coach tab's (at the page's end): rounded
       glass with the pill's sides. */
    html.glass body:not(.kb-focus):not(.ck-fullscreen) .oracle-input-bar {
      left: 12px !important;
      right: 12px !important;
      bottom: var(--above-pill) !important;
      border-radius: 24px;
      border: 1px solid var(--glass-line) !important;
      box-shadow: var(--glass-sheet-rim), 0 10px 28px rgba(15, 23, 42, 0.14) !important;
    }
    /* Oracle's conversation reserves the bar's height above the pill, which floats 14px higher
       than the flat bar did (oracle.css reserves bottom-nav + bar). */
    html.glass body:not(.kb-focus):not(.ck-fullscreen) .oracle-conversation-area {
      padding-bottom: calc(var(--above-pill) + var(--oracle-bar-h, 130px) + 8px);
    }
    html.glass body:not(.kb-focus):not(.ck-fullscreen) #training-tab-coach .chat-input-row {
      margin: 0 12px 8px;
      border-radius: 24px;
      border: 1px solid var(--glass-line) !important;
      padding-bottom: 10px !important;
      box-shadow: var(--glass-sheet-rim), 0 10px 28px rgba(15, 23, 42, 0.12);
    }
  }
}

/* ── Floating surfaces as glass: the chats' input bars, the sheets and menus ─────────────────────
   Thicker than the bottom pill (more white, more blur), since text is read on them. The rim is
   inset light, brightest top left; no pseudo-elements, which several of these already use. */
html.glass {
  --glass-sheet-bg: rgba(255, 255, 255, 0.72);
  --glass-bar-bg: rgba(255, 255, 255, 0.66);
  --glass-sheet-rim: inset 1px 1px 0 rgba(255, 255, 255, 0.95), inset -1px -1px 0 rgba(255, 255, 255, 0.3);
  --glass-sheet-shadow: 0 18px 48px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.08);
  --glass-line: rgba(255, 255, 255, 0.7);
  --glass-field: rgba(255, 255, 255, 0.75);
}
html.glass[data-theme="dark"] {
  --glass-sheet-bg: rgba(30, 38, 52, 0.74);
  --glass-bar-bg: rgba(30, 38, 52, 0.66);
  --glass-sheet-rim: inset 1px 1px 0 rgba(255, 255, 255, 0.22), inset -1px -1px 0 rgba(255, 255, 255, 0.06);
  --glass-sheet-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
  --glass-line: rgba(255, 255, 255, 0.1);
  --glass-field: rgba(15, 20, 30, 0.55);
}

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  /* Chat input bars (SERVIS #input-container, Coach .chat-input-row with its chip row above,
     Oracle .oracle-input-bar): glass. The conversation ends above them as each chat lays it out:
     reaching beneath them (a negative margin, a replaced bottom padding) hid the last message
     behind the bottom pill in Oracle and the coach tab, where the bar sits above it. */
  html.glass #input-container,
  html.glass .chat-input-row,
  html.glass #chat-quick-actions,
  html.glass .oracle-input-bar {
    z-index: 3;
    background: var(--glass-bar-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  html.glass #input-container,
  html.glass .oracle-input-bar,
  html.glass #chat-quick-actions { border-top: 1px solid var(--glass-line); box-shadow: inset 0 1px 0 var(--glass-line), 0 -8px 20px rgba(15, 23, 42, 0.06); }
  html.glass #chat-quick-actions + .chat-input-row { border-top: 0; }
  /* Oracle's bar keeps its own sticky position; the others are lifted over the conversation. */
  html.glass #input-container,
  html.glass .chat-input-row,
  html.glass #chat-quick-actions { position: relative; }
  html.glass #userInput,
  html.glass #chat-input,
  html.glass .oracle-input-row textarea { background: var(--glass-field); }

  /* Sheets and menus: the More drawer, notifications, the "+" and ⋯ menus, the quick check-in. */
  html.glass .app-nav-sheet,
  html.glass .nc-panel,
  html.glass .wardrobe-more,
  html.glass .training-more,
  html.glass .travel-map-fab-item,
  html.glass .qd-panel {
    background: var(--glass-sheet-bg) !important;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-color: var(--glass-line) !important;
    box-shadow: var(--glass-sheet-rim), var(--glass-sheet-shadow) !important;
  }

  /* Under the solid top bar, the page fades out instead of meeting a hard edge (as iOS 26 does at
     a scroll edge). */
  html.glass .top-bar::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: 14px;
    background: linear-gradient(to bottom, var(--bg), transparent);
    pointer-events: none;
  }
}
