/* tour.css: the guided tour on the Research page (tour.js).
   Class names use the guide- prefix because site.css already uses tour-* for the home page's video player.
   Only the start button is in the page before the tour starts; everything under .guide-root is built by
   tour.js when the tour starts and removed when it closes. Colours come from the site's tokens (site.css),
   so light and dark mode follow the page. */

/* ── Start button: part of the page from first paint, so it never shifts the layout ─────────────────── */
.guide-cta { margin-top: 14px; }
.guide-start {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  margin: 0;
  padding: 4px 15px 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-fg);
  font: 500 14px/1.4 var(--f-body);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.guide-start svg { display: block; flex: none; overflow: visible; }
@media (hover: hover) {
  .guide-start:hover { border-color: currentColor; }
  .guide-start:hover svg { animation: guide-icon-hop 0.5s ease-out; }
}
@keyframes guide-icon-hop {
  0%, 100% { transform: none; }
  40% { transform: translateY(-3px) rotate(-6deg); }
}
@media (pointer: coarse) { .guide-start { min-height: 44px; } }

/* ── Tour layers ─────────────────────────────────────────────────────────────────────────────────────── */
.guide-root {
  --guide-dim: rgba(14, 21, 32, 0.56);
  --guide-glow: transparent;            /* a soft halo around the lit item (dark mode only) */
  --guide-light: transparent;           /* a faint lift inside the lit item (dark mode only) */
  --guide-lift: 0 22px 44px -16px rgba(10, 16, 24, 0.45), 0 2px 8px rgba(10, 16, 24, 0.12);
}
@media (prefers-color-scheme: dark) {
  .guide-root {
    --guide-dim: rgba(0, 0, 0, 0.62);
    --guide-glow: rgba(134, 180, 247, 0.2);
    --guide-light: rgba(134, 180, 247, 0.045);
    --guide-lift: 0 22px 48px -14px rgba(0, 0, 0, 0.8), 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}
.guide-root [hidden] { display: none !important; }

/* The spotlight: a rounded hole whose huge outer shadow dims the page and whose inset shadow softens the cut.
   tour.js sets its position and size (document coordinates) and --guide-spread (enough to cover the page). */
.guide-spot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9000;
  border-radius: 16px;
  background: var(--guide-light);
  box-shadow:
    0 0 26px 1px var(--guide-glow),
    0 0 0 var(--guide-spread, 6000px) var(--guide-dim),
    inset 0 0 14px 6px var(--guide-dim);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.guide-spot.is-on { opacity: 1; }

/* ── The card: next to the item on wide screens, a bottom sheet on phones ────────────────────────────── */
.guide-card {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9002;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--guide-lift);
  font-size: 15px;
  line-height: 1.55;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.guide-card.is-shown {
  opacity: 1;
  transform: none;
  pointer-events: auto;
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.guide-card.is-dock {
  position: fixed;
  top: auto;
  right: 0;
  bottom: 16px;
  margin-inline: auto;
  width: min(460px, calc(100vw - 32px));
  max-height: min(56vh, 520px);       /* leave room above for the item */
}
.guide-card.is-sheet {
  bottom: 0;
  width: 100%;
  max-height: 62vh;
  max-height: 62dvh;
  border-width: 1px 0 0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -14px 40px -12px rgba(10, 16, 24, 0.35);
}
/* If a short window can't fit the whole card, the text scrolls and the Back / Next row stays in view. */
.guide-inner {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  transition: opacity 0.2s ease;
}
.guide-card.is-swapping .guide-inner { opacity: 0; transition: none; }
.guide-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 18px 0;
}
.guide-body.is-clipped {
  -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
  mask-image: linear-gradient(#000 calc(100% - 28px), transparent);
}
.guide-card.is-sheet .guide-body { padding-top: 10px; }
.guide-card.is-sheet .guide-title { font-size: 20px; margin-bottom: 4px; }
.guide-card.is-sheet .guide-links { margin-top: 8px; }

.guide-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.guide-count {
  margin: 0;
  font: 500 12px/1 var(--f-mono);
  letter-spacing: 0.06em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.guide-x {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -4px -10px -4px 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.guide-x:hover { background: var(--badge-bg); color: var(--ink); }
.guide-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
.guide-title {
  margin: 0 0 6px;
  font-family: var(--f-display);
  font-weight: 600;
  font-size: 21px;
  line-height: 1.25;
  color: var(--ink);
}
.guide-text { margin: 0; }
.guide-links { margin-top: 10px; }
.guide-nav {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 18px 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.guide-card.is-sheet .guide-nav {
  margin: 10px 18px calc(10px + env(safe-area-inset-bottom, 0px));
  padding-top: 10px;
}
.guide-keys { margin: 0; font: 12px var(--f-mono); color: var(--muted); }
@media (hover: none), (pointer: coarse) { .guide-keys { display: none; } }
.guide-btn {
  min-height: 36px;
  padding: 6px 16px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: 500 14px/1.4 var(--f-body);
  cursor: pointer;
}
.guide-btn:hover:not(:disabled) { border-color: var(--muted); }
.guide-btn:disabled { opacity: 0.4; cursor: default; }
.guide-btn--next { margin-left: auto; background: var(--link); border-color: var(--link); color: var(--paper); }
.guide-btn--next:hover:not(:disabled) { border-color: var(--ink); }
@media (pointer: coarse) { .guide-btn, .guide-x { min-height: 44px; min-width: 44px; } }
.guide-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── The bird ────────────────────────────────────────────────────────────────────────────────────────────
   .guide-bird         positioned by tour.js (translate to the feet, scale for take-off); fixed or absolute
   .guide-bird__flip   faces left or right (--guide-dir) and tilts in flight (--guide-tilt)
   .guide-bird__fx     one-shot squash on landing and the hop when the dimmed page is clicked
   .guide-bird__art    the drawing: the inline SVG (perch bob, wing flap) or a painted sprite sheet         */
.guide-bird {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9003;
  width: var(--guide-bw, 60px);
  height: var(--guide-bh, 52px);
  pointer-events: none;
  transform-origin: var(--guide-ax, 50%) var(--guide-ay, 100%);
  will-change: transform;
}
.guide-bird.is-fixed { position: fixed; }
.guide-bird.is-gone { opacity: 0; transition: opacity 0.25s ease; }
.guide-bird__flip, .guide-bird__fx, .guide-bird__art { width: 100%; height: 100%; }
.guide-bird__flip {
  scale: var(--guide-dir, 1) 1;
  rotate: var(--guide-tilt, 0deg);
  transform-origin: 50% 62%;
  transition: scale 0.16s ease;
}
.guide-bird__fx, .guide-bird__art { transform-origin: var(--guide-ax, 50%) var(--guide-ay, 100%); }
.guide-bird svg { display: block; overflow: visible; }

/* Perched: a small bob and the odd blink. Flying: wings up, legs tucked, a quick flap. */
.guide-bird[data-pose="perch"] .guide-bird__art { animation: guide-bob 2.2s ease-in-out infinite; }
@keyframes guide-bob {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50% { transform: translateY(-2px) scale(0.985, 1.025); }
}
.guide-bird .gb-eye { transform-origin: 40.5px 24px; animation: guide-blink 4.4s linear infinite; }
@keyframes guide-blink {
  0%, 93%, 100% { transform: none; }
  95% { transform: scaleY(0.12); }
}
.guide-bird .gb-wing-fly { display: none; transform-origin: 24.5px 29px; }
.guide-bird[data-pose="fly"] .gb-wing-fly { display: inline; animation: guide-flap 0.2s ease-in-out infinite alternate; }
.guide-bird[data-pose="fly"] .gb-wing-rest,
.guide-bird[data-pose="fly"] .gb-legs { display: none; }
@keyframes guide-flap {
  from { transform: rotate(14deg); }
  to { transform: rotate(-96deg); }
}
.guide-bird.is-landing .guide-bird__fx { animation: guide-land 0.36s ease-out; }
@keyframes guide-land {
  0% { transform: scale(1.08, 0.84); }
  55% { transform: scale(0.97, 1.05); }
  100% { transform: none; }
}
.guide-bird.is-hop .guide-bird__fx { animation: guide-hop 0.5s ease-out; }
@keyframes guide-hop {
  0%, 100% { transform: none; }
  15% { transform: scale(1.06, 0.9); }
  45% { transform: translateY(-12px) scale(0.97, 1.04); }
  75% { transform: translateY(0) scale(1.05, 0.93); }
}

/* Painted sprites (BIRD.mode = 'sprites' in tour.js): each sheet is one row of frames, played with steps().
   tour.js sets --guide-{perch,fly}-src / -frames / -dur and the frame size --guide-bw / --guide-bh. */
.guide-bird.is-sprites[data-pose] .guide-bird__art {
  background-image: var(--guide-perch-src);
  background-repeat: no-repeat;
  background-size: calc(var(--guide-perch-frames) * var(--guide-bw)) var(--guide-bh);
  animation: guide-sprite-perch var(--guide-perch-dur) steps(var(--guide-perch-frames)) infinite;
}
.guide-bird.is-sprites[data-pose="fly"] .guide-bird__art {
  background-image: var(--guide-fly-src);
  background-size: calc(var(--guide-fly-frames) * var(--guide-bw)) var(--guide-bh);
  animation: guide-sprite-fly var(--guide-fly-dur) steps(var(--guide-fly-frames)) infinite;
}
@keyframes guide-sprite-perch { to { background-position: calc(var(--guide-perch-frames) * var(--guide-bw) * -1) 0; } }
@keyframes guide-sprite-fly { to { background-position: calc(var(--guide-fly-frames) * var(--guide-bw) * -1) 0; } }

/* Reduced motion: no flight, no bob or flap, no fades; tour.js also jumps the scroll. */
@media (prefers-reduced-motion: reduce) {
  .guide-start, .guide-start svg,
  .guide-spot, .guide-card, .guide-card.is-shown, .guide-inner,
  .guide-bird, .guide-bird * {
    animation: none !important;
    transition: none !important;
  }
  .guide-card { transform: none; }
}

/* Forced colours drop box-shadows, so outline the lit item instead. */
@media (forced-colors: active) {
  .guide-spot { outline: 3px solid Highlight; outline-offset: -3px; }
}

@media print {
  .guide-cta, .guide-root { display: none !important; }
}
