/* bubble size and spacing; the vine between two bubbles spans exactly one step (--b + --g).
   Phones show three at a time (the row is 90vw wide); wider screens fit as many as they can. */
:host {
  --b: clamp(118px, 11vw, 150px);
  --g: 40px;
  --ring: 3.5px;
}
@media (max-width: 600px) {
  :host { --g: 18px; --b: calc((90vw - var(--g) * 2) / 3); --ring: 3px; }
}

.rail {
  position: relative;
  display: grid;
  justify-items: center;
}

.track {
  display: flex;
  /* centred when every bubble fits, otherwise it starts at the left and scrolls */
  justify-content: safe center;
  gap: var(--g);
  width: 100%;
  margin: 0;
  /* room for the ring's glow and the labels; side padding lines the first bubble up with the heading */
  padding: 10px max(5vw, calc((100vw - 1120px) / 2)) 18px;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: max(5vw, calc((100vw - 1120px) / 2));
  scrollbar-width: none;
  /* bubbles drift in and out softly at the edges */
  mask-image: linear-gradient(90deg, transparent, #000 4vw, #000 calc(100% - 4vw), transparent);
}
.track::-webkit-scrollbar { display: none; }

.bubble {
  position: relative;
  flex: none;
  width: var(--b);
  display: grid;
  justify-items: center;
  gap: 12px;
  scroll-snap-align: start;
}

/* ---------- the bud: a slowly turning ring in the flower's colours around a paper face ---------- */
.ring, .face {
  grid-area: 1 / 1;
  width: var(--b);
  aspect-ratio: 1;
  border-radius: 50%;
}
.ring {
  background: conic-gradient(from 20deg,
    var(--color-petal), var(--color-face), var(--color-leaf-light), var(--color-petal-light), var(--color-petal));
  /* only the outer band shows: a ring */
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring)), #000 calc(100% - var(--ring) + 0.5px));
          mask: radial-gradient(farthest-side, transparent calc(100% - var(--ring)), #000 calc(100% - var(--ring) + 0.5px));
  opacity: 0.55;
  animation: turn 6s linear infinite;
  animation-delay: calc(var(--i) * -0.7s);
}
.face {
  width: calc(var(--b) - var(--ring) * 2 - 6px);
  align-self: center;
  border-radius: 50%;
  box-shadow: inset 0 2px 6px rgba(36, 31, 38, 0.06);
}
.label {
  width: 70%;
  height: 9px;
  border-radius: 99px;
}

/* ---------- a real sprout: the photo in the bud, its title underneath ---------- */
button.face {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  overflow: hidden;
  isolation: isolate;
  cursor: pointer;
  background: var(--color-paper);
  box-shadow: 0 10px 24px -14px rgba(36, 31, 38, 0.45);
  -webkit-tap-highlight-color: transparent;
}
button.face .framed { transition: scale 0.5s cubic-bezier(0.3, 0.8, 0.3, 1); }
button.face:hover .framed { scale: 1.06; }
button.face:focus-visible { outline: 2.5px solid var(--color-leaf); outline-offset: 5px; }
.label.text {
  width: 100%;
  height: auto;
  overflow: hidden;
  font: italic 600 clamp(14px, 1.5vw, 16px)/1.2 var(--font-serif);
  color: var(--color-name);
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}
:host([in-view]) .label.text { animation: bud 0.5s ease-out calc(var(--t) + 0.15s) forwards; }

/* ---------- the vine from this bud to the next ---------- */
.vine {
  position: absolute;
  z-index: -1;
  left: calc(var(--b) / 2);
  top: calc(var(--b) / 2 - (var(--b) + var(--g)) * 0.15);
  width: calc(var(--b) + var(--g));
  aspect-ratio: 100 / 30;
  overflow: visible;
}
.bubble:nth-child(even) .vine { scale: 1 -1; }
.vine .stem {
  fill: none;
  stroke: var(--color-leaf);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0.55;
  vector-effect: non-scaling-stroke;
}
.vine .leaf {
  fill: var(--color-leaf-light);
  stroke: var(--color-ink);
  stroke-width: 1.2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transform-box: fill-box;
  transform-origin: 0% 100%;
  scale: 0;
}

/* ---------- arriving: the vine grows bud to bud, each bud pops open as the vine reaches it ---------- */
.bubble { --t: calc(var(--i) * 0.16s); }
.ring, .face, .label { scale: 0.4; opacity: 0; }

:host([in-view]) .ring { animation: turn 6s linear infinite, bud-ring 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) var(--t) forwards; }
:host([in-view]) .face { animation: bud 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) var(--t) forwards; }
:host([in-view]) .label { animation: bud 0.5s ease-out calc(var(--t) + 0.15s) forwards; }
:host([in-view]) .vine .stem { animation: grow 0.5s ease-in-out calc(var(--t) + 0.15s) forwards; }
:host([in-view]) .vine .leaf { animation: leaf 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) calc(var(--t) + 0.35s) forwards; }

@keyframes turn { to { rotate: 1turn; } }
@keyframes bud { to { scale: 1; opacity: 1; } }
@keyframes bud-ring { to { scale: 1; opacity: 0.55; } }
@keyframes grow { to { stroke-dashoffset: 0; } }
@keyframes leaf { to { scale: 1; } }

/* ---------- couldn't fetch ---------- */
.offline-note {
  position: absolute;
  top: calc(var(--b) / 2 + 10px);
  translate: 0 -50%;
}
.note-icon { display: inline-flex; width: 18px; color: var(--color-petal-shade); }
:host([state="offline"]) .ring, :host([state="empty"]) .ring { opacity: 0.3; animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
  .ring, .face, .label { scale: 1; opacity: 1; animation: none !important; }
  .ring { opacity: 0.55; }
  .vine .stem { stroke-dashoffset: 0; animation: none !important; }
  .vine .leaf { scale: 1; animation: none !important; }
}
