/* Mandala landing intro. Shown once per browser session over the home page
   (html.mi-on is set by the inline script in <head>). Clicking the centre
   bubble expands the layers outward and fades the backdrop, revealing the
   landing page underneath. */

html.mi-on, html.mi-on body { overflow: hidden; }

.mi-intro {
  /* mandala diameter: phones fill the width, desktops/landscape fit the height */
  --md: min(94vw, 80vh);
  position: fixed; inset: 0; z-index: 1000; overflow: hidden;
  touch-action: none; -webkit-tap-highlight-color: transparent;
}
@supports (height: 1svh) { .mi-intro { --md: min(94vw, 80svh); } }

.mi-bg {
  position: absolute; inset: 0;
  background: #0b2a17 url("intro/background.jpg") center / cover no-repeat;
  transition: opacity 900ms ease 330ms;
}

.mi-mandala { position: absolute; inset: 0; will-change: transform; }

/* each SVG is cropped to a square around the mandala centre; --s is its
   size relative to the outermost layer */
.mi-layer {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--md) * var(--s)); aspect-ratio: 1;
  margin: calc(var(--md) * var(--s) / -2) 0 0 calc(var(--md) * var(--s) / -2);
  will-change: transform;
}
.mi-layer img { display: block; width: 100%; height: 100%; will-change: transform, opacity; }
.mi-l5 { --s: 1;     z-index: 1; animation: mi-cw 52s linear infinite; }
.mi-l4 { --s: .8457; z-index: 2; animation: mi-ccw 43s linear infinite; }
.mi-l3 { --s: .642;  z-index: 3; animation: mi-cw 35s linear infinite; }
.mi-l2 { --s: .5154; z-index: 4; animation: mi-ccw 27s linear infinite; }
.mi-l1 { --s: .4167; z-index: 5; animation: mi-cw 19s linear infinite; }
@keyframes mi-cw  { to { transform: rotate(360deg); } }
@keyframes mi-ccw { to { transform: rotate(-360deg); } }

/* the centre bubble is the button */
.mi-enter {
  position: absolute; z-index: 8; left: 50%; top: 50%;
  width: calc(var(--md) * .341); aspect-ratio: 1; transform: translate(-50%, -50%);
  display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer;
  color: #e8c46a; font-family: MahiraSerif, Georgia, serif;
}
.mi-enter:focus-visible { outline: 2px solid #c8a14d; outline-offset: 8px; }
/* Mahira's round logo inside the bubble (sized to the bubble, a thin ring of
   the mandala's centre disc left showing around it) */
.mi-title { display: grid; place-items: center; width: 100%; height: 100%; opacity: 0; transform: scale(.94); transition: opacity 900ms ease, transform 900ms ease; }
.mi-logo { display: block; width: 90%; height: auto; border-radius: 50%; box-shadow: 0 4px 18px rgba(0, 20, 10, .45); }
.mi-intro.is-idle .mi-title { opacity: 1; transform: none; }

/* waiting for the SVGs: show only the backdrop */
.mi-intro.is-loading .mi-mandala { visibility: hidden; }

/* layers fly in from outside */
.mi-intro.is-entering .mi-enter { pointer-events: none; }
.mi-intro.is-entering .mi-layer img { animation: mi-close 1450ms cubic-bezier(.16,.8,.2,1) both; }
.mi-intro.is-entering .mi-l5 img { animation-delay: 275ms; }
.mi-intro.is-entering .mi-l4 img { animation-delay: 205ms; }
.mi-intro.is-entering .mi-l3 img { animation-delay: 135ms; }
.mi-intro.is-entering .mi-l2 img { animation-delay: 70ms; }
@keyframes mi-close {
  0% { transform: scale(3.15); opacity: 0; }
  52% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* slow drift in while waiting, capped at 14% */
.mi-intro.is-idle .mi-mandala { animation: mi-zoom 23s linear forwards; }
@keyframes mi-zoom { from { transform: scale(1); } to { transform: scale(1.14); } }

/* portal opens: layers expand outward in sequence, backdrop fades to the site */
.mi-intro.is-opening { pointer-events: none; }
.mi-intro.is-opening .mi-bg { opacity: 0; }
.mi-intro.is-opening .mi-mandala { animation-play-state: paused; }
.mi-intro.is-opening .mi-layer { animation-play-state: paused; }
.mi-intro.is-opening .mi-title { opacity: 0; transition-duration: 250ms; }
.mi-intro.is-opening .mi-layer img { animation: mi-open 1450ms cubic-bezier(.16,.8,.2,1) forwards; }
.mi-intro.is-opening .mi-l4 img { animation-delay: 70ms; }
.mi-intro.is-opening .mi-l3 img { animation-delay: 135ms; }
.mi-intro.is-opening .mi-l2 img { animation-delay: 205ms; }
.mi-intro.is-opening .mi-l1 img { animation-delay: 275ms; }
@keyframes mi-open {
  0% { transform: scale(1); opacity: 1; }
  45% { opacity: 1; }
  100% { transform: scale(3.15); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mi-layer, .mi-intro.is-idle .mi-mandala { animation: none; }
  .mi-title { transform: none; }
  .mi-intro.is-entering .mi-layer img { animation: none; }
  .mi-intro.is-opening .mi-layer img { animation: none; opacity: 0; transition: opacity 400ms ease; }
  .mi-intro.is-opening .mi-bg { transition-delay: 0ms; transition-duration: 400ms; }
}
