/* glass — the shared Liquid Glass controls (#625, epic #533).
 *
 * Mockups: docs/design/mockups/liquid-glass-app-tab-bar.html (variant B) and
 * docs/design/mockups/liquid-glass-tabs-motion.html (the sliding lens, variant A).
 * Loaded by index.html, ideas.html and changelog.html. Replaces the copies that
 * lived in changelog.css, roadmap.css and nursery-chart.css.
 *
 * Uses ONLY var(--v2-*) tokens, all defined in /css/canopy-v2.css (section 20 holds
 * the glass tokens). No raw colour in this file. The Reduce Transparency and
 * Increase Contrast overrides are token overrides in canopy-v2.css; the rules
 * here only drop the blur.
 *
 * Pieces:
 *   .glass          the surface (opaque by default, translucent where backdrop-filter works)
 *   .glass-topbar   no bar background: round glass buttons and a title
 *   .glass-btn      a round 44px glass button
 *   .glass-tabbar   floating capsule of .glass-tab (+ .has-lens for the sliding lens)
 *   .glass-seg      segmented control with a sliding raised tile
 *   .app-tabbar, .glass-plus, .app-menu   the main app shell (index.html) on top of the above
 *   .scroll-edge    content fade under the bars (moved here from changelog.css, #626)
 *   .app-topbar     the main app bar: wordmark that gives way to the tab name once the large title scrolls (#626)
 */

/* ─── 1. The glass surface. Opaque by default. ─── */
.glass {
  background: var(--v2-glass-solid);
  border: 1px solid var(--v2-glass-edge);
  box-shadow: inset 0 1px 0 var(--v2-glass-highlight), inset 0 -1px 0 var(--v2-glass-lowlight), var(--v2-glass-shadow);
}
.glass.is-thick { background: var(--v2-bg-panel); }

@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass {
    background: var(--v2-glass-tint-regular);
    -webkit-backdrop-filter: var(--v2-glass-filter);
    backdrop-filter: var(--v2-glass-filter);
  }
  .glass.is-thin  { background: var(--v2-glass-tint-thin); }
  .glass.is-thick { background: var(--v2-glass-tint-thick); }
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .glass, .glass.is-thin {
    background: var(--v2-glass-solid);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  .glass.is-thick { background: var(--v2-bg-panel); }
}

/* ─── 2. Top bar and round button ─── */
/* Top bar: no bar background. Two round glass buttons and the title. */
.glass-topbar {
  position: fixed;
  top: var(--v2-safe-top);
  left: 0;
  right: 0;
  z-index: 30;
  height: var(--v2-topbar-height);
  padding: 0 calc(var(--v2-bar-inset) + var(--v2-safe-right)) 0 calc(var(--v2-bar-inset) + var(--v2-safe-left));
  display: flex;
  align-items: center;
  gap: 12px;
}
.glass-btn {
  width: var(--v2-space-touch);
  height: var(--v2-space-touch);
  flex: 0 0 var(--v2-space-touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--v2-radius-full);
  color: var(--v2-glass-label);
  font-family: var(--v2-font-display);
  font-weight: 500;
  font-size: var(--v2-font-size-body);
  line-height: 1;
  text-decoration: none;
}
.glass-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Press spring: scale down fast, spring back on release. Shared by every glass control. */
.glass-btn, .glass-tab, .glass-seg button {
  transition: transform var(--v2-transition-slow) var(--v2-ease-spring);
}
.glass-btn:active, .glass-tab:active, .glass-seg button:active {
  transform: scale(0.96);
  transition-duration: var(--v2-transition-fast);
  transition-timing-function: var(--v2-ease-out);
}
.glass-btn:focus-visible, .glass-tab:focus-visible, .glass-seg button:focus-visible {
  outline: 2px solid var(--v2-accent-text);
  outline-offset: 2px;
}

/* ─── 3. Tab bar: a floating capsule, inset from the screen edges, clear of the home indicator ─── */
.glass-tabbar {
  position: fixed;
  z-index: 30;
  left: calc(var(--v2-bar-inset) + var(--v2-safe-left));
  right: calc(var(--v2-bar-inset) + var(--v2-safe-right));
  bottom: var(--v2-nav-bottom);
  max-width: 528px;
  margin: 0 auto;
  height: var(--v2-tabbar-height);
  padding: var(--v2-glass-pad);
  display: flex;
  align-items: stretch;
  border-radius: var(--v2-radius-full);
}
.glass-tab {
  position: relative;
  flex: 1 1 0;
  min-width: var(--v2-space-touch);
  min-height: var(--v2-space-touch);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: var(--v2-radius-bar-inner);
  color: var(--v2-glass-label);
  text-decoration: none;
  font-size: var(--v2-font-size-caption2);
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}
/* A tab that is a <button> (the main app switches views without a page load). */
button.glass-tab { margin: 0; padding: 0; border: 0; background: transparent; font-family: inherit; cursor: pointer; }
/* Current tab, static pages: a raised glass pill behind icon and label. Shape and weight say "current", not colour alone. */
.glass-tab::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: var(--v2-radius-bar-inner);
  background: var(--v2-glass-raised);
  border: 1px solid var(--v2-glass-edge);
  box-shadow: 0 1px 3px var(--v2-glass-lowlight), inset 0 1px 0 var(--v2-glass-highlight);
  opacity: 0;
  transition: opacity var(--v2-transition-fast) var(--v2-ease-out);
}
.glass-tab[aria-current="page"] { color: var(--v2-glass-label-selected); font-weight: 700; }
.glass-tab[aria-current="page"]::before { opacity: 1; }
.glass-tab[aria-current="page"] span { color: var(--v2-glass-tab-label-selected); }
.glass-tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* Sliding lens (.has-lens bars): one raised pill under the tabs that travels to the chosen one.
 * --gt-i is the chosen index, --gt-n the tab count; both are set by the script. */
.gt-lens {
  position: absolute;
  top: var(--v2-glass-pad);
  bottom: var(--v2-glass-pad);
  left: var(--v2-glass-pad);
  width: calc((100% - 2 * var(--v2-glass-pad)) / var(--gt-n, 4));
  border-radius: var(--v2-radius-bar-inner);
  background: var(--v2-glass-raised);
  border: 1px solid var(--v2-glass-edge);
  box-shadow: 0 1px 3px var(--v2-glass-lowlight), inset 0 1px 0 var(--v2-glass-highlight);
  transform: translateX(calc(var(--gt-i, 0) * 100%));
  transition: transform var(--v2-transition-slow) var(--v2-ease-spring);
  pointer-events: none;
}
.has-lens .glass-tab { z-index: 1; }
.has-lens .glass-tab::before { display: none; }
.has-lens .glass-tab.is-swell { animation: glass-tab-swell var(--v2-transition-slow) var(--v2-ease-out); }
@keyframes glass-tab-swell { 0% { transform: scale(0.96); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }

/* ─── 4. Segmented control: equal columns; a raised tile slides under the chosen one ─── */
/* The count defaults to 3; .glass-seg--2 and .glass-seg--4 set it. The chosen segment
 * is aria-selected, aria-checked or aria-pressed, so no script is needed to move the tile. */
.glass-seg {
  --seg-n: 3;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  height: var(--v2-seg-height);
  padding: var(--v2-glass-pad);
  border-radius: var(--v2-radius-full);
  position: relative;
}
.glass-seg--2 { --seg-n: 2; }
.glass-seg--4 { --seg-n: 4; }
.glass-seg::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: var(--v2-glass-pad);
  bottom: var(--v2-glass-pad);
  left: var(--v2-glass-pad);
  width: calc((100% - 2 * var(--v2-glass-pad) - (var(--seg-n) - 1) * 2px) / var(--seg-n));
  border-radius: var(--v2-radius-bar-inner);
  background: var(--v2-glass-raised);
  border: 1px solid var(--v2-glass-edge);
  box-shadow: 0 1px 3px var(--v2-glass-lowlight), inset 0 1px 0 var(--v2-glass-highlight);
  transform: translateX(0);
  transition: transform var(--v2-transition-base) var(--v2-ease-spring);
}
.glass-seg:has(button:nth-child(2):is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]))::before { transform: translateX(calc(100% + 2px)); }
.glass-seg:has(button:nth-child(3):is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]))::before { transform: translateX(calc(200% + 4px)); }
.glass-seg:has(button:nth-child(4):is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]))::before { transform: translateX(calc(300% + 6px)); }
.glass-seg button {
  position: relative;
  z-index: 1;
  min-width: 0;
  height: var(--v2-space-touch);
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  border: none;
  border-radius: var(--v2-radius-bar-inner);
  background: transparent;
  color: var(--v2-glass-label);
  font-family: var(--v2-font-body);
  font-size: var(--v2-font-size-subhead);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--v2-transition-fast) var(--v2-ease-out), transform var(--v2-transition-slow) var(--v2-ease-spring);
}
.glass-seg button .n { font-family: var(--v2-font-display); font-variant-numeric: tabular-nums; font-weight: 500; }
.glass-seg button:is([aria-selected="true"], [aria-checked="true"], [aria-pressed="true"]) {
  color: var(--v2-glass-tab-label-selected);
  font-weight: 700;
}
/* Tighter labels for a control that sits inside a card. */
.glass-seg--compact button { padding: 0 4px; font-size: var(--v2-font-size-footnote); }

/* ─── 5. Main app shell (index.html) ─── */
/* The tab bar leaves room for the round "+" button that trails it, same height. */
.app-tabbar {
  z-index: 100;
  right: calc(var(--v2-bar-inset) + var(--v2-safe-right) + var(--v2-tabbar-height) + var(--v2-nav-gap));
  max-width: none;
  margin: 0;
}
.glass-plus {
  position: fixed;
  z-index: 100;
  right: calc(var(--v2-bar-inset) + var(--v2-safe-right));
  bottom: var(--v2-nav-bottom);
  width: var(--v2-tabbar-height);
  height: var(--v2-tabbar-height);
  flex: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.glass-plus svg { width: 28px; height: 28px; transition: transform var(--v2-transition-slow) var(--v2-ease-spring); }
.glass-plus.open { color: var(--v2-glass-label-selected); }
.glass-plus.open svg { transform: rotate(45deg); }

/* Quick-actions menu: a thick glass card above the "+". Concentric radii: card 24, padding 8, rows 16. */
.app-scrim {
  position: fixed;
  inset: 0;
  z-index: 89;
  display: none;
  background: var(--v2-glass-lowlight);
}
.app-scrim.open { display: block; }
.app-menu {
  position: fixed;
  z-index: 95;
  display: none;
  right: calc(var(--v2-bar-inset) + var(--v2-safe-right));
  bottom: calc(var(--v2-nav-bottom) + var(--v2-tabbar-height) + var(--v2-nav-gap));
  width: 248px;
  max-width: calc(100vw - 2 * var(--v2-bar-inset));
  padding: 8px;
  border-radius: 24px;
}
.app-menu.open { display: block; }
.app-menu-row {
  width: 100%;
  min-height: var(--v2-space-touch);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: var(--v2-glass-label);
  font-family: var(--v2-font-body);
  font-weight: 600;
  font-size: var(--v2-font-size-subhead);
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.app-menu-row svg { width: 20px; height: 20px; flex: none; fill: none; stroke: var(--v2-accent-text); stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.app-menu-row:active { background: var(--v2-glass-control-fill); }
.app-menu-row:focus-visible { outline: 2px solid var(--v2-accent-text); outline-offset: -2px; }
.app-menu-divider { height: 1px; background: var(--v2-glass-edge); margin: 4px 12px; }
/* The search button keeps its own look; it floats above the "+", clear of the bar. */
.fab-stack {
  bottom: calc(var(--v2-nav-bottom) + var(--v2-tabbar-height) + var(--v2-nav-gap));
  right: calc(var(--v2-bar-inset) + var(--v2-safe-right) + 7px);
}

/* ─── 6. Scroll edge: content fades as it passes under the status bar and the bars ─── */
/* Opaque default is the plain fade; the blur is added only where supported.
 * Moved here from changelog.css (#626); the Changelog and Ideas pages render the same. */
.scroll-edge { position: fixed; left: 0; right: 0; z-index: 20; pointer-events: none; }
.scroll-edge.is-top {
  top: 0;
  height: calc(var(--v2-safe-top) + var(--v2-topbar-height) + 24px);
  background: linear-gradient(to bottom, var(--v2-scroll-edge-tint) 0, var(--v2-scroll-edge-tint) 76%, transparent);
}
.scroll-edge.is-bottom {
  bottom: 0;
  height: calc(var(--v2-safe-bottom) + var(--v2-tabbar-height) + 28px);
  background: linear-gradient(to top, var(--v2-scroll-edge-tint) 0, transparent);
}
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .scroll-edge { -webkit-backdrop-filter: var(--v2-scroll-edge-blur); backdrop-filter: var(--v2-scroll-edge-blur); }
  .scroll-edge.is-top {
    -webkit-mask-image: linear-gradient(to bottom, black 76%, transparent);
    mask-image: linear-gradient(to bottom, black 76%, transparent);
  }
  .scroll-edge.is-bottom {
    -webkit-mask-image: linear-gradient(to top, black 40%, transparent);
    mask-image: linear-gradient(to top, black 40%, transparent);
  }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .scroll-edge { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
/* The main app's top edge only shows once a tab's large title has collapsed (NavBar sets .is-on). */
.scroll-edge.is-adaptive { opacity: 0; transition: opacity var(--v2-transition-base) var(--v2-ease-out); }
.scroll-edge.is-adaptive.is-on { opacity: 1; }

/* ─── 7. Nav bars on the main tabs (#626, variant A) ─── */
/* Each tab opens with a large title in its content, clear of the bar. At rest the bar holds
 * the leaf, the "Canopy" wordmark and the glass buttons. Once the title has scrolled away
 * (.is-collapsed, set by public/js/ui/nav-bar.js) the tab name takes the wordmark's place. */
.app-content .view-scroll { position: relative; padding-top: calc(var(--v2-safe-top) + var(--v2-topbar-height)); }
/* 1px marker NavBar watches; the title has collapsed once the tab scrolls past it. */
.nav-sentinel { position: absolute; top: 48px; left: 0; width: 1px; height: 1px; pointer-events: none; visibility: hidden; }
/* Sticky parts of a tab dock under the bar instead of under the screen edge. */
.app-content .gh-sticky { top: calc(var(--v2-safe-top) + var(--v2-topbar-height)); }
/* Jump to (#599) lands a section under the bar, not behind it. */
.app-content .gh-section, .app-content .gh-failed { scroll-margin-top: calc(var(--v2-safe-top) + var(--v2-topbar-height)); }

.app-topbar { gap: var(--v2-space-sm); }
.tb-lead { position: relative; flex: 1 1 auto; min-width: 0; height: var(--v2-space-touch); display: flex; align-items: center; }
.tb-end { display: flex; align-items: center; gap: var(--v2-space-sm); flex: none; }
.tb-brand {
  display: flex;
  align-items: center;
  gap: var(--v2-space-sm);
  min-width: 0;
  color: var(--v2-accent-text);
}
.tb-brand .leaf { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.tb-wordmark {
  font-family: var(--v2-font-display);
  font-weight: 700;
  font-size: var(--v2-font-size-body);
  letter-spacing: -0.01em;
  transition: opacity var(--v2-transition-base) var(--v2-ease-out), transform var(--v2-transition-base) var(--v2-ease-out);
}
.tb-title {
  position: absolute;
  left: calc(22px + var(--v2-space-sm));
  right: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--v2-font-display);
  font-weight: 600;
  font-size: var(--v2-font-size-body);
  line-height: 1.15;
  color: var(--v2-text-primary);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity var(--v2-transition-base) var(--v2-ease-out), transform var(--v2-transition-base) var(--v2-ease-out);
}
.app-topbar.is-collapsed .tb-wordmark { opacity: 0; transform: translateY(-6px); }
.app-topbar.is-collapsed .tb-title { opacity: 1; transform: translateY(0); }

/* Reduce Motion: no slide, no scale, no swell. State changes at once. */
@media (prefers-reduced-motion: reduce) {
  .glass-btn, .glass-tab, .glass-tab::before, .gt-lens, .glass-plus svg, .glass-seg::before, .glass-seg button,
  .scroll-edge.is-adaptive, .tb-wordmark, .tb-title { transition: none; }
  .app-topbar.is-collapsed .tb-wordmark, .tb-title { transform: none; }
  .glass-btn:active, .glass-tab:active, .glass-seg button:active { transform: none; }
  .has-lens .glass-tab.is-swell { animation: none; }
}
