/* spiral.css: SpiralLoader, StartScreen and the transition screen (TSK-2514).
   Markup: the spiral_loader macro of templates/_spiral.html; behaviour: spiral.js.
   Values only through var(--token) from tokens.css (motion group). */

/* --- SpiralLoader: draws from the centre outward, then turns ---------------- */
.sl { display: inline-grid; place-items: center; line-height: 0; }
.sl-svg {
  display: block;
  inline-size: var(--spiral-inline);
  block-size: var(--spiral-inline);
  overflow: visible;
  transform-origin: 50% 50%;
}
.sl-full .sl-svg { inline-size: var(--spiral-full); block-size: var(--spiral-full); }
.sl-media .sl-svg { inline-size: var(--spiral-media); block-size: var(--spiral-media); }
.sl-path {
  fill: none;
  stroke: var(--ink);
  stroke-width: var(--stroke-spiral);
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.sl-inline .sl-path { stroke-width: var(--stroke-spiral-mark); }
.sl-dot { fill: var(--orange); } /* the one orange touch */

@keyframes sl-draw { from { stroke-dashoffset: 1; } }
@keyframes sl-turn { to { transform: rotate(360deg); } }
@keyframes sl-in { from { opacity: 0; } }
@keyframes sl-out { to { opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: no-preference) {
  .sl-path { animation: sl-draw var(--dur-draw) var(--ease-standard) both; }
  .sl-dot { animation: sl-in var(--dur-fast) var(--ease-enter) var(--dur-draw) both; }
  .sl-svg { animation: sl-turn var(--dur-turn-slow) var(--ease-linear) var(--dur-draw) infinite; }
  .sl-inline .sl-svg { animation-duration: var(--dur-spiral); }
}

/* --- StartScreen and the transition screen: one paper sheet over the phone
   screen (.pf-screen; on a phone the screen is the viewport). Hidden unless
   spiral.js marks the page: html.sl-start (first page of the session) or
   .sl-screen.is-veil (a full-page navigation). Both end by CSS alone. ------- */
.sl-screen {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: none;
  place-items: center;
  background: var(--paper);
}
html.sl-start .sl-screen {
  display: grid;
  animation: sl-out var(--dur-slow) var(--ease-exit) var(--dur-start-max) forwards;
}
html.sl-start.sl-ready .sl-screen { animation: sl-out var(--dur-slow) var(--ease-exit) forwards; }
.sl-screen.is-veil {
  display: grid;
  animation: sl-in var(--dur-fast) var(--ease-enter) var(--dur-veil-wait) both,
             sl-out var(--dur-fast) var(--ease-exit) var(--dur-veil-max) forwards;
}

/* --- media: a picture box keeps its size; the spiral sits in its centre ----- */
.sl-box { position: relative; display: block; }
.sl-box > .sl-media {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.mx-snap-art > .sl-box { block-size: 100%; }
.mx-snap-art .sl-media .sl-svg { inline-size: 100%; block-size: 100%; max-inline-size: var(--spiral-media); max-block-size: var(--spiral-media); }
/* the full-size view: the box steps aside, the spiral centres on the sheet */
.mx-zoom[open] .sl-box { display: contents; }

/* --- page change: a cross-fade where the browser has view transitions ------- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-group(root) { animation-duration: var(--dur-fast); }
}

/* --- reduced motion: a still spiral, no start screen, no fade --------------- */
@media (prefers-reduced-motion: reduce) {
  html.sl-start .sl-screen { display: none; }
  .sl-screen.is-veil { animation: sl-hold var(--dur-veil-max) var(--ease-linear) forwards; }
}
@keyframes sl-hold { 99.9% { opacity: 1; visibility: visible; } to { opacity: 0; visibility: hidden; } }
