/* Floating bar, built by floating-bar.js: bottom-anchored, so a taller mode
   frame grows upward from the pinned bottom edge and mid-morph slack opens at
   the top, clipped by overflow.
   It is the small-screen chrome: from 960px on a fine pointer the header's
   preference pair takes over (screen.css) and the bar is not laid out.
   see DESIGN.md → Components · Floating Bar */

.float-bar {
  /* One slot: every control reads this box and both frame heights derive from
     it. 2.75rem is the 44px touch minimum. */
  --float-control: 2.75rem;
  position: fixed;
  /* Equal insets: bottom matches right, both from --bar-inset. Never derive one
     from the bar's own width or the gaps drift apart when the slot changes. */
  right: var(--bar-inset, 1rem);
  bottom: var(--bar-inset, 1rem);
  z-index: 40;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0;
  /* 3 slots + 0.5rem padding + 0.25rem border (border-box) */
  height: calc(3 * var(--float-control) + 0.5rem + 0.25rem);
  padding: var(--space-2xs);
  border: 2px solid transparent;
  border-radius: var(--radius-pill);
  /* Keep the 2px though the rim colour is retired: they are part of the box
     (the height calc counts them) and .site-header-inner reserves the same 2px.
     Only the paint is gone; the surface is screen.css' shared blur. */
  color: var(--glass-ink);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.75rem);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out),
    height 224ms var(--ease-in-out), visibility var(--dur-base) linear;
}

/* The shared header surface provides a readable fallback when backdrop blur is unavailable. */

.float-bar.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
  animation: fb-bar-enter 0.6s var(--ease-spring);
}

@keyframes fb-bar-enter {
  from {
    transform: translateY(0.75rem);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* --- Controls --------------------------------------------------------
   .fab, the 44px control box and its glyph stack, lives in screen.css with the
   rest of the chrome: the header draws the same control and paints it on the
   first frame. Only the bar's own pieces live here. */

[data-fab="top"] svg {
  transform: translateY(-1px); /* optical: up-chevron reads low */
}

/* --- Morph ------------------------------------------------------------
   Each slot's transition lives on the mode where it settles: exit on the mode
   that hides it (fast ease-in), enter on the one that shows it (spring pop).
   Delays read from the after-change state.

   Retune as ratios: 224/123/280/168 and stagger 22/67/90 = design ×0.56. */

.float-bar[data-mode="lang"] {
  height: calc(4 * var(--float-control) + 0.5rem + 0.25rem); /* 4 slots (border-box) */
}

/* Exiting: 123ms ease-in, blur + scale + height→0. Closers lead. */
.float-bar[data-mode="default"] .fab-flag,
.float-bar[data-mode="lang"] [data-fab="top"],
.float-bar[data-mode="lang"] [data-fab="theme"] {
  height: 0;
  opacity: 0;
  filter: blur(8px);
  transform: scale(0.6);
  pointer-events: none;
  transition: height 123ms var(--ease-in),
    opacity 123ms var(--ease-in),
    filter 123ms var(--ease-in),
    transform 123ms var(--ease-in);
}

/* Entering: spring transform, height eased, blur/opacity fade in. Followers
   arrive late. */
.float-bar[data-mode="lang"] .fab-flag,
.float-bar[data-mode="default"] [data-fab="top"],
.float-bar[data-mode="default"] [data-fab="theme"] {
  transition: height 224ms var(--ease-in-out),
    transform 280ms var(--ease-spring),
    filter 224ms var(--ease-out),
    opacity 168ms var(--ease-out); /* height has no overshoot — keeps the frame exact */
}

/* Exit delays (closer leads). */
.float-bar[data-mode="default"] .fab-flag[data-lang="en"] {
  transition-delay: 0ms;
}
.float-bar[data-mode="default"] .fab-flag[data-lang="es"] {
  transition-delay: 22ms;
}
.float-bar[data-mode="lang"] [data-fab="top"] {
  transition-delay: 0ms;
}
.float-bar[data-mode="lang"] [data-fab="theme"] {
  transition-delay: 22ms;
}

/* Enter delays (followers follow ~67/90ms after morph start). */
.float-bar[data-mode="lang"] .fab-flag {
  transition-delay: 67ms;
}
.float-bar[data-mode="default"] [data-fab="top"] {
  transition-delay: 67ms;
}
.float-bar[data-mode="default"] [data-fab="theme"] {
  transition-delay: 90ms;
}

/* --- Interaction states ---------------------------------------------- */

/* Tap: scoped to the visible set per mode so collapsed rules stay in force. */
.float-bar[data-mode="default"] [data-fab="top"]:active,
.float-bar[data-mode="default"] [data-fab="lang"]:active,
.float-bar[data-mode="default"] [data-fab="theme"]:active,
.float-bar[data-mode="lang"] [data-fab="lang"]:active,
.float-bar[data-mode="lang"] .fab-flag:active {
  transform: scale(0.92);
  /* 80ms, a step under --dur-fast on purpose: press feedback must land under
     the finger, before the tap resolves. */
  transition: transform 80ms var(--ease-out);
}

.fab-flag.is-current {
  background: rgba(59, 73, 83, 0.18); /* teal 18%: visible on cream glass */
}

/* --- Flags (flat SVGs; emoji flags don't render on Windows) ----------- */

.fab-flag svg {
  width: 1rem;
  height: calc(1rem * 2 / 3); /* exact 24:16 viewBox ratio — no letterboxing */
  --r: var(--radius-hair);
  border-radius: var(--radius-hair);
}

.fab-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- Stacked icons: the language button's globe/X swap ----------------
   The shared glyph stack (.fab-icon) and the theme's moon/sun pair live in
   screen.css; the bar only owns its open-state swap. */
.float-bar[data-mode="lang"] [data-fab="lang"] .fab-icon--globe {
  opacity: 0;
  filter: blur(6px);
  transform: rotate(-90deg) scale(0.6);
}
.float-bar[data-mode="lang"] [data-fab="lang"] .fab-icon--close {
  opacity: 1;
  filter: none;
  transform: none;
}

/* --- View Transition: circle reveal from the theme button ---------------
   The toggle's own geometry; the page transition reuses this circle's pixel
   radius for both halves. */

html[data-vt="circle"]::view-transition-old(root) {
  animation: none;
  mix-blend-mode: normal;
}
html[data-vt="circle"]::view-transition-new(root) {
  mix-blend-mode: normal;
  animation: vt-circle-reveal var(--vt-circle-duration, var(--dur-slow))
    var(--vt-circle-ease, var(--ease-in-out));
}

/* --- Reduced motion: everything instant -------------------------------
   Specificity matched to (and declared after) the morph/icon rules, so no
   !important is needed: the `none` here wins over the mode shorthands. */

@media (prefers-reduced-motion: reduce) {
  .float-bar,
  .float-bar.is-visible,
  .float-bar[data-mode] .fab,
  .float-bar[data-mode] .fab .fab-icon,
  .float-bar[data-mode] .fab:active,
  html[data-vt="circle"]::view-transition-old(root),
  html[data-vt="circle"]::view-transition-new(root) {
    transition: none;
    animation: none;
  }
}

/* --- Desktop hand-off -------------------------------------------------
   From 960px on a fine pointer the header carries theme + language, so the bar
   is not laid out there: one chrome, one set of controls. The breakpoint is the
   header's, measured (adding that pair costs the row 104px, which the wordmark
   cannot absorb under 960). Touch tablets keep the bar at every width. */

@media (min-width: 960px) and (hover: hover) and (pointer: fine) {
  .float-bar {
    display: none;
  }
}
