/* Guided tour: the hero button, the persistent pill, and what gets out of the way while it plays. */
.btn--tour { gap: 0.55rem; }
.btn--tour svg { width: 0.95em; height: 0.95em; flex: none; fill: var(--noodle); }

.tour-pill {
  position: fixed; left: var(--gutter); bottom: calc(env(safe-area-inset-bottom, 0px) + 1.1rem); z-index: 35;
  display: flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.35rem 0.3rem 0.3rem;
  max-width: min(27rem, calc(100vw - 2 * var(--gutter))); overflow: hidden;
  border-radius: 999px; background: rgba(var(--veil-rgb), 0.78);
  box-shadow: 0 0 0 1px var(--hair-strong), 0 12px 40px -12px var(--shadow);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out), visibility 0s 0.5s;
}
.tour-pill.is-shown { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.is-loading .tour-pill { opacity: 0; visibility: hidden; }
.tour-pill[hidden], .tour-pill [hidden] { display: none; }

.tour-toggle {
  display: inline-flex; align-items: center; gap: 0.5rem; min-height: 2.5rem; padding: 0 1rem 0 0.8rem; border-radius: 999px;
  background: var(--noodle); color: var(--on-accent); font-size: 0.875rem; font-weight: 650; font-stretch: 100%; white-space: nowrap;
  transition: filter 0.25s, transform 0.25s var(--ease-out);
}
.tour-toggle:hover { filter: brightness(1.08) saturate(1.05); }
.tour-toggle svg { width: 1rem; height: 1rem; flex: none; fill: currentColor; }
.tour-pill:not([data-state="idle"]) .tour-toggle { background: rgba(var(--ivory-rgb), 0.12); color: var(--ivory); box-shadow: inset 0 0 0 1px var(--hair-strong); }
.tour-pill:not([data-state="idle"]) .tour-toggle:hover { background: rgba(var(--ivory-rgb), 0.2); filter: none; }
.tour-pill[data-state="paused"] .tour-toggle, .tour-pill[data-state="done"] .tour-toggle { background: var(--noodle); color: var(--on-accent); box-shadow: none; }

.tour-name {
  margin: 0; padding: 0 0.7rem 0 0.5rem; min-width: 0; font-size: 0.8125rem; line-height: 1.2; color: var(--ivory);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tour-pill[data-state="idle"] .tour-name { color: var(--dim); }
.tour-stop { flex: none; width: 2.25rem; height: 2.25rem; display: grid; place-items: center; border-radius: 50%; }
.tour-stop:hover { background: rgba(var(--ivory-rgb), 0.12); }
.tour-stop svg { width: 0.9rem; height: 0.9rem; fill: none; stroke: var(--ivory); stroke-width: 1.8; stroke-linecap: round; }
.tour-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(var(--ivory-rgb), 0.1); pointer-events: none; }
.tour-bar i { position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(0); background: linear-gradient(90deg, var(--noodle), var(--held)); }
.tour-pill[data-state="idle"] .tour-bar { opacity: 0; }

/* The hero's own reconstruction note lives bottom-left: ride above it there */
body[data-chapter="hero"] .tour-pill { bottom: calc(env(safe-area-inset-bottom, 0px) + 3.6rem); }

/* While the tour plays: no coach mark, no scroll rail */
.tour-on .place-hint { display: none !important; }
.tour-on .rail { opacity: 0; transition: opacity 0.4s; }

/* Speed presets: a small segmented control inside the pill */
.tour-speed { display: flex; flex: none; padding: 2px; border-radius: 999px; background: rgba(var(--ivory-rgb), 0.07); }
.tour-speed button {
  min-width: 2.35rem; min-height: 2.1rem; padding: 0 0.45rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  color: var(--caption); font-variant-numeric: tabular-nums; transition: background-color 0.25s, color 0.25s;
}
.tour-speed button:hover { color: var(--ivory); }
.tour-speed button[aria-pressed="true"] { background: rgba(var(--ivory-rgb), 0.16); color: var(--ivory); box-shadow: inset 0 0 0 1px var(--hair-strong); }

@media (max-width: 820px), (orientation: portrait) and (max-width: 1100px) {
  .tour-pill { bottom: calc(env(safe-area-inset-bottom, 0px) + 2.9rem); }
  .tour-name { max-width: 9.5rem; }
}
@media (max-width: 560px) {
  /* narrow: play and name on one row, the speed presets and the stop button on the next */
  .tour-pill { flex-wrap: wrap; border-radius: 1.5rem; row-gap: 0.25rem; padding-bottom: 0.45rem; max-width: min(21rem, calc(100vw - 2 * var(--gutter))); }
  .tour-name { flex: 1 1 0; max-width: none; }
  .tour-speed { order: 5; }
  .tour-stop { order: 6; margin-left: auto; }
  .tour-pill:not([data-state="idle"]) .tour-stop:not([hidden]) { display: grid; }
}
@media (max-width: 420px) {
  .tour-toggle { padding: 0 0.85rem 0 0.7rem; font-size: 0.8125rem; }
  .tour-name { font-size: 0.75rem; max-width: 7.5rem; }
}
@media (prefers-reduced-motion: reduce) { .tour-pill, .tour-toggle { transition: none; } }

/* While the tour plays, a soft band along the bottom edge hides the next chapter's heading as it peeks in, and gives the
   pill a clean backdrop. Below the pill (z 35), above page content and the 3D badge. */
html.tour-on::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; pointer-events: none;
  height: calc(env(safe-area-inset-bottom, 0px) + 5.5rem);
  background: linear-gradient(to bottom, rgba(var(--veil-rgb), 0), rgba(var(--veil-rgb), 0.9) 62%, rgba(var(--veil-rgb), 0.96));
  animation: tour-scrim-in 0.6s ease both;
}
@keyframes tour-scrim-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { html.tour-on::after { animation: none; } }

/* ---- iPad landscape (1180x820 Home Screen app; query = stacked.js IPAD_LANDSCAPE_QUERY) ----
   The bottom-left is page content there (the sandbox's "Save this frame", the caption under it), so the pill lives bottom-right, left of the
   3D badge. Idle it is a single round play button (a pill full of presets over content was the problem); while a tour runs it opens leftwards
   into the full pill at its usual height, so tour.js's bottom reserve (which assumes 1.1 rem) still keeps every stop clear of it. */
@media (min-width: 1100px) and (max-width: 1290px) and (min-height: 700px) and (max-height: 900px) {
  .stage-badge { bottom: calc(env(safe-area-inset-bottom, 0px) + 1.1rem); }
  body[data-chapter] .tour-pill, body[data-chapter="hero"] .tour-pill {
    left: auto; right: calc(max(var(--gutter), env(safe-area-inset-right, 0px)) + 18rem); bottom: calc(env(safe-area-inset-bottom, 0px) + 1.1rem);
  }
  .tour-pill[data-state="idle"] { padding: 0.15rem; gap: 0; max-width: none; background: rgba(var(--veil-rgb), 0.6); }
  .tour-pill[data-state="idle"] .tour-name, .tour-pill[data-state="idle"] .tour-speed, .tour-pill[data-state="idle"] .tour-bar { display: none; }
  .tour-pill[data-state="idle"] .tour-toggle { width: 2.75rem; min-height: 2.75rem; padding: 0; justify-content: center; }
  .tour-pill[data-state="idle"] .tour-toggle svg { width: 1.15rem; height: 1.15rem; margin-left: 0.1rem; }
  .tour-pill[data-state="idle"] .tour-toggle__t { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  /* pointer devices: hovering (or keyboard focus) opens the full pill */
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) { padding: 0.3rem 0.35rem 0.3rem 0.3rem; gap: 0.3rem; max-width: min(27rem, calc(100vw - 2 * var(--gutter))); background: rgba(var(--veil-rgb), 0.78); }
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-name, .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-speed { display: flex; }
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-name { display: block; }
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-toggle { width: auto; padding: 0 1rem 0 0.8rem; }
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-toggle__t { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .tour-pill[data-state="idle"]:is(:hover, :focus-within) .tour-toggle svg { width: 1rem; height: 1rem; margin-left: 0; }
  /* hero: keep the joint-state card and the reconstruction note above/left of the pill while a tour runs */
  .telemetry--hero { bottom: 5rem; }
  .hero-note { max-width: 17rem; }
}
