/* tinyblue-persistent-flair.css — site-wide floating overlay styles.
 *
 * Loaded on every page (companion to tinyblue-persistent-flair.js). Owns
 * the look of the Dynamic Island (top-center transient), the Fleet
 * Pulse (bottom-left ambient), and the Cursor Glow. The homepage-only
 * hero atmosphere stays in tinyblue-flair.css.
 *
 * Apple alignment rules followed here:
 *   1. Each floating widget occupies a distinct corner zone so they
 *      never collide:
 *        top-center      → Dynamic Island
 *        bottom-left     → Fleet Pulse
 *        bottom-right    → chat bubble + network FAB (other modules)
 *        top-left/right  → brand + nav (other modules)
 *   2. Glass surfaces transition smoothly across theme changes
 *      (~240ms ease) — no hard color snaps.
 *   3. Every offset uses env(safe-area-inset-*) so notched/round-corner
 *      devices don't clip.
 *   4. Reduced-motion disables pip pulses and entrance transforms.
 */

/* Motion + tokens (mirrors tinyblue-flair.css for parity, but namespaced) */
:root {
  --tbpf-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --tbpf-dur-sm: 180ms;
  --tbpf-dur-md: 320ms;
  --tbpf-theme-dur: 240ms;
  --tbpf-glass-bg: rgba(255, 255, 255, 0.78);
  --tbpf-glass-border: rgba(0, 0, 0, 0.08);
  --tbpf-glass-shadow: 0 18px 42px -10px rgba(15, 22, 38, 0.16),
                      0 1px 0 rgba(255, 255, 255, 0.65) inset;
  --tbpf-text: #1d1d1f;
  --tbpf-text-soft: rgba(29, 29, 31, 0.7);
}
[data-theme="dark"] {
  --tbpf-glass-bg: rgba(28, 28, 30, 0.72);
  --tbpf-glass-border: rgba(255, 255, 255, 0.10);
  --tbpf-glass-shadow: 0 18px 42px -10px rgba(0, 0, 0, 0.55),
                      0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --tbpf-text: #f5f5f7;
  --tbpf-text-soft: rgba(245, 245, 247, 0.65);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tbpf-glass-bg: rgba(28, 28, 30, 0.72);
    --tbpf-glass-border: rgba(255, 255, 255, 0.10);
    --tbpf-glass-shadow: 0 18px 42px -10px rgba(0, 0, 0, 0.55),
                        0 1px 0 rgba(255, 255, 255, 0.06) inset;
    --tbpf-text: #f5f5f7;
    --tbpf-text-soft: rgba(245, 245, 247, 0.65);
  }
}

/* Theme-flux moment: when the user toggles, every glass surface gets a
 * cross-fade. Already-applied transitions on individual properties do
 * the heavy lifting; this just makes sure backdrop-filter changes don't
 * snap. */
html.tb-theme-flux #tb-island,
html.tb-theme-flux #tb-fleet-pulse,
html.tb-theme-flux .tb-cursor-glow {
  transition-duration: var(--tbpf-theme-dur), var(--tbpf-theme-dur), var(--tbpf-theme-dur), var(--tbpf-theme-dur) !important;
}

/* ─────────────────────────── Pulse keyframe ─────────────────────────── */
@keyframes tbpf-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(95, 209, 122, 0.55); }
  70%  { box-shadow: 0 0 0 10px rgba(95, 209, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(95, 209, 122, 0); }
}

/* ─────────────────────────── Dynamic Island ───────────────────────────
 * Real iOS Dynamic Island lives at the top, centered under the notch.
 * We mirror that — always top, always centered, on every viewport.
 * Sits below the glass nav (~64-72px tall) on desktop, and just under
 * the notch on mobile.
 */
#tb-island {
  position: fixed;
  /* Sit BELOW the fixed nav (~64-72px tall) plus safe-area padding for
   * notched devices. Without this offset, the Island visually collides
   * with the brand + theme toggle in the nav row. */
  top: max(calc(env(safe-area-inset-top, 0px) + 76px), 76px);
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  min-height: 32px;
  min-width: 32px;
  max-width: min(86vw, 460px);
  background: rgba(0, 0, 0, 0.86);
  color: #fff;
  border-radius: 999px;
  font: 500 12.5px/1.2 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  letter-spacing: -0.005em;
  box-shadow: 0 18px 42px -10px rgba(0, 0, 0, 0.45),
              0 1px 0 rgba(255, 255, 255, 0.05) inset;
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--tbpf-dur-sm) ease,
              transform var(--tbpf-dur-md) var(--tbpf-spring),
              max-width var(--tbpf-dur-md) var(--tbpf-spring),
              padding var(--tbpf-dur-md) var(--tbpf-spring),
              background-color var(--tbpf-theme-dur) ease;
}
#tb-island.is-shown {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
#tb-island.is-wide {
  padding: 10px 18px;
  max-width: min(86vw, 540px);
}
#tb-island .tb-island__pip {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #5fd17a;
  box-shadow: 0 0 0 0 rgba(95, 209, 122, 0.5);
  animation: tbpf-pulse 2s infinite;
  flex: 0 0 auto;
  transition: background-color var(--tbpf-dur-sm) ease;
}
#tb-island.is-warn .tb-island__pip {
  background: #ffb84d;
  animation: none;
}
#tb-island.is-busy .tb-island__pip {
  background: #6cc8ff;
  animation: tbpf-pulse 1.2s infinite;
}
#tb-island .tb-island__text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}

/* On very narrow viewports, sit at the top still but with tighter padding
 * so it doesn't visually replace the nav. */
@media (max-width: 480px) {
  #tb-island {
    max-width: calc(100vw - 32px);
    padding: 7px 12px;
    font-size: 12px;
  }
  #tb-island.is-wide {
    padding: 8px 14px;
  }
}

/* ─────────────────────────── Fleet Pulse ───────────────────────────
 * Bottom-LEFT, opposite corner from chat + network FAB so it never
 * collides with the action dock. Acts as an ambient operator-status
 * widget — fades in only after the brief returns.
 */
#tb-fleet-pulse {
  position: fixed;
  left: max(env(safe-area-inset-left, 0px), 18px);
  bottom: max(env(safe-area-inset-bottom, 0px), 20px);
  z-index: 55;
  display: none;          /* flipped to inline-flex by JS when data lands */
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 12px;
  background: var(--tbpf-glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(170%);
  backdrop-filter: blur(20px) saturate(170%);
  border: 1px solid var(--tbpf-glass-border);
  border-radius: 999px;
  box-shadow: var(--tbpf-glass-shadow);
  font: 500 12px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  letter-spacing: 0.01em;
  color: var(--tbpf-text);
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  transform: translateY(8px);
  opacity: 0;
  transition: transform var(--tbpf-dur-md) var(--tbpf-spring),
              opacity var(--tbpf-dur-sm) ease,
              background-color var(--tbpf-theme-dur) ease,
              border-color var(--tbpf-theme-dur) ease,
              color var(--tbpf-theme-dur) ease,
              box-shadow var(--tbpf-theme-dur) ease;
}
#tb-fleet-pulse.is-shown {
  display: inline-flex;
  transform: translateY(0);
  opacity: 1;
}
#tb-fleet-pulse .tb-fp__pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5fd17a;
  box-shadow: 0 0 0 0 rgba(95, 209, 122, 0.55);
  animation: tbpf-pulse 2s infinite;
}
#tb-fleet-pulse.is-warn .tb-fp__pip {
  background: #ffb84d;
  animation: none;
}
#tb-fleet-pulse .tb-fp__count {
  font-variant-numeric: tabular-nums;
  color: var(--tbpf-text);
}
#tb-fleet-pulse .tb-fp__sep {
  opacity: 0.5;
  color: var(--tbpf-text-soft);
}
#tb-fleet-pulse .tb-fp__label {
  opacity: 0.78;
  color: var(--tbpf-text-soft);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#tb-fleet-pulse:hover {
  transform: translateY(-1px);
  box-shadow: 0 22px 50px -10px rgba(15, 22, 38, 0.22),
              0 1px 0 rgba(255, 255, 255, 0.7) inset;
}
[data-theme="dark"] #tb-fleet-pulse:hover {
  box-shadow: 0 22px 52px -10px rgba(0, 0, 0, 0.65),
              0 1px 0 rgba(255, 255, 255, 0.08) inset;
}

/* Narrow viewports: the network FAB centers itself at bottom-middle
 * (left:50%, translate(-50%, 0)) and the chat orb owns bottom-right.
 * At <= 640px the full pulse ("14 / 20 · 136 pods · FLEET") would
 * stretch into the FAB's column, so we shrink it to a compact
 * "● 14/20" pill — same visual rhythm as Apple's macOS menu-bar
 * compact indicators on narrow screens. */
@media (max-width: 640px) {
  #tb-fleet-pulse {
    left: 14px;
    bottom: max(env(safe-area-inset-bottom, 0px), 22px);
    padding: 6px 11px 6px 10px;
    font-size: 11.5px;
    gap: 8px;
  }
  #tb-fleet-pulse .tb-fp__label { display: none; }
  #tb-fleet-pulse .tb-fp__sep { display: none; }
  /* Hide the " · pods" tail on narrow: just show the online ratio. */
  #tb-fleet-pulse .tb-fp__count {
    max-width: 88px;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
  }
}

/* Very narrow phones — even tighter. */
@media (max-width: 380px) {
  #tb-fleet-pulse {
    padding: 5px 10px 5px 9px;
    font-size: 11px;
  }
  #tb-fleet-pulse .tb-fp__count { max-width: 72px; }
}

/* ─────────────────────────── Cursor Glow ───────────────────────────
 * Desktop-only soft radial that follows pointer. Plus-lighter blend so
 * it lifts atmosphere without darkening real content underneath.
 */
.tb-cursor-glow {
  position: fixed;
  top: 0; left: 0;
  width: 320px; height: 320px;
  border-radius: 50%;
  background: radial-gradient(closest-side,
              rgba(126, 156, 216, 0.16) 0%,
              rgba(126, 156, 216, 0.08) 35%,
              rgba(126, 156, 216, 0) 72%);
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transform: translate3d(50vw, 50vh, 0) translate3d(-50%, -50%, 0);
  transition: opacity var(--tbpf-dur-md) ease,
              background var(--tbpf-theme-dur) ease;
  mix-blend-mode: plus-lighter;
}
.tb-cursor-glow.is-on { opacity: 1; }
[data-theme="dark"] .tb-cursor-glow {
  background: radial-gradient(closest-side,
              rgba(140, 170, 230, 0.20) 0%,
              rgba(140, 170, 230, 0.10) 35%,
              rgba(140, 170, 230, 0) 72%);
}

/* ─────────────────────────── Smooth theme transitions on global chrome ───────────────────────────
 * The site-wide nav, footer, and body inherit smooth color crossfades when
 * the theme toggles. Without this, [data-theme] flips look like a hard
 * snap — Apple's apps crossfade these surfaces in ~250ms.
 */
html, body,
.nav, .nav__inner, .nav-drawer, .nav__menu-btn,
.footer, .footer__inner {
  transition: background-color var(--tbpf-theme-dur) ease,
              color var(--tbpf-theme-dur) ease,
              border-color var(--tbpf-theme-dur) ease;
}

/* ─────────────────────────── Spotlight (Cmd-K) ───────────────────────────
 * Apple-style command palette. Modal centered slightly above true center
 * (iOS / macOS feels) with a backdrop blur, hairline border, and SF
 * monospace-ish key hints. Items styled like macOS Spotlight rows.
 */
#tb-spotlight {
  position: fixed;
  inset: 0;
  z-index: 2147483640;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(60px, 14vh, 140px) 16px 16px;
  pointer-events: none;
}
#tb-spotlight.is-open { display: flex; pointer-events: auto; }

#tb-spotlight .tb-spot__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 18, 24, 0.42);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  opacity: 0;
  transition: opacity 220ms ease;
}
#tb-spotlight.is-open .tb-spot__backdrop { opacity: 1; }
[data-theme="light"] #tb-spotlight .tb-spot__backdrop {
  background: rgba(220, 226, 238, 0.55);
}

#tb-spotlight .tb-spot__panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(72vh, 640px);
  background: var(--tbpf-glass-bg);
  border: 1px solid var(--tbpf-glass-border);
  border-radius: 18px;
  box-shadow:
    0 30px 80px -20px rgba(15, 22, 38, 0.45),
    0 1px 0 rgba(255, 255, 255, 0.5) inset;
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  backdrop-filter: blur(28px) saturate(180%);
  color: var(--tbpf-text);
  font: 500 14px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  transform: translateY(-12px) scale(0.985);
  opacity: 0;
  transition: transform var(--tbpf-dur-md) var(--tbpf-spring),
              opacity var(--tbpf-dur-sm) ease,
              background-color var(--tbpf-theme-dur) ease,
              border-color var(--tbpf-theme-dur) ease,
              color var(--tbpf-theme-dur) ease;
  overflow: hidden;
}
#tb-spotlight.is-open .tb-spot__panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}
[data-theme="dark"] #tb-spotlight .tb-spot__panel {
  box-shadow:
    0 30px 80px -20px rgba(0, 0, 0, 0.65),
    0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

#tb-spotlight .tb-spot__inputwrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tbpf-glass-border);
}
#tb-spotlight .tb-spot__glyph {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--tbpf-text-soft);
  opacity: 0.7;
}
#tb-spotlight .tb-spot__input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  font: 500 17px/1.2 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  color: var(--tbpf-text);
  letter-spacing: -0.01em;
}
#tb-spotlight .tb-spot__input::placeholder {
  color: var(--tbpf-text-soft);
  opacity: 0.65;
}
#tb-spotlight .tb-spot__hint {
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--tbpf-text-soft);
  background: color-mix(in srgb, var(--tbpf-text) 8%, transparent);
  border-radius: 6px;
  text-transform: uppercase;
}

#tb-spotlight .tb-spot__list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  scrollbar-width: thin;
}
#tb-spotlight .tb-spot__row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition: background 120ms ease, transform 120ms ease;
}
#tb-spotlight .tb-spot__row:hover,
#tb-spotlight .tb-spot__row.is-active {
  background: color-mix(in srgb, var(--tbpf-text) 10%, transparent);
}
#tb-spotlight .tb-spot__row.is-active {
  transform: translateX(2px);
}
[data-theme="dark"] #tb-spotlight .tb-spot__row:hover,
[data-theme="dark"] #tb-spotlight .tb-spot__row.is-active {
  background: color-mix(in srgb, var(--tbpf-text) 12%, transparent);
}
#tb-spotlight .tb-spot__row-icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--tbpf-text) 8%, transparent);
  color: var(--tbpf-text);
}
#tb-spotlight .tb-spot__row-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
#tb-spotlight .tb-spot__row-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--tbpf-text);
}
#tb-spotlight .tb-spot__row-sub {
  font-size: 12px;
  color: var(--tbpf-text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#tb-spotlight .tb-spot__row-tag {
  flex: 0 0 auto;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 6px;
  color: var(--tbpf-text-soft);
  background: color-mix(in srgb, var(--tbpf-text) 6%, transparent);
}
#tb-spotlight .tb-spot__row-tag--page { color: #7e9cd8; background: color-mix(in srgb, #7e9cd8 14%, transparent); }
#tb-spotlight .tb-spot__row-tag--site { color: #5fd17a; background: color-mix(in srgb, #5fd17a 14%, transparent); }
#tb-spotlight .tb-spot__row-tag--action { color: #ffb84d; background: color-mix(in srgb, #ffb84d 14%, transparent); }

#tb-spotlight .tb-spot__empty {
  padding: 22px 16px;
  color: var(--tbpf-text-soft);
  font-size: 13px;
  text-align: center;
}

#tb-spotlight .tb-spot__footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-top: 1px solid var(--tbpf-glass-border);
  font-size: 11px;
  color: var(--tbpf-text-soft);
}
#tb-spotlight .tb-spot__footer kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 1px 5px;
  margin-right: 4px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 10px;
  background: color-mix(in srgb, var(--tbpf-text) 10%, transparent);
  border-radius: 4px;
  color: var(--tbpf-text);
}

@media (max-width: 480px) {
  #tb-spotlight {
    padding: clamp(40px, 8vh, 80px) 12px 12px;
    align-items: flex-start;
  }
  #tb-spotlight .tb-spot__panel {
    max-height: 80vh;
    border-radius: 16px;
  }
  #tb-spotlight .tb-spot__row-sub { display: none; }
}

/* ─────────────────────────── Reduced motion ───────────────────────────
 * Real users with prefers-reduced-motion: reduce get a stripped-down
 * variant. The `:not(.tb-force-motion)` guard lets ?motion=force in the
 * URL override this for showcase/test purposes (the JS publishes the
 * class on <html> when the query flag is present).
 */
@media (prefers-reduced-motion: reduce) {
  html:not(.tb-force-motion) #tb-island,
  html:not(.tb-force-motion) #tb-island.is-shown { transition: opacity var(--tbpf-dur-sm) ease !important; transform: translateX(-50%) !important; }
  html:not(.tb-force-motion) #tb-island .tb-island__pip { animation: none !important; }
  html:not(.tb-force-motion) #tb-fleet-pulse,
  html:not(.tb-force-motion) #tb-fleet-pulse.is-shown { transition: opacity var(--tbpf-dur-sm) ease !important; transform: none !important; }
  html:not(.tb-force-motion) #tb-fleet-pulse .tb-fp__pip { animation: none !important; }
  html:not(.tb-force-motion) .tb-cursor-glow { display: none !important; }
  html:not(.tb-force-motion) #tb-spotlight .tb-spot__panel {
    transition: opacity var(--tbpf-dur-sm) ease !important;
    transform: none !important;
  }
  html:not(.tb-force-motion) #tb-spotlight .tb-spot__backdrop {
    transition: opacity var(--tbpf-dur-sm) ease !important;
  }
}
