/*
 * Trip reveal: Orbit's own tokens (src/orbit/orbit.css) for the glass, the type and the eases, so the host's
 * few controls sit on Orbit's globe as if they were its own.
 */

:root {
  --night: #06080c; /* Orbit's intro, behind the globe until it's ready */
  --ink: #161513;
  --body: #3f3c38;
  --muted: #57524b;
  --panel: linear-gradient(180deg, rgba(252, 250, 246, 0.86), rgba(246, 243, 236, 0.8));
  --edge: rgba(255, 255, 255, 0.72);
  --hi: rgba(255, 255, 255, 0.95);
  --drop: rgba(40, 30, 10, 0.38);
  --chip: rgba(255, 255, 255, 0.42);
  --sans: 'Manrope', system-ui, sans-serif;
  --serif: 'Instrument Serif', Georgia, serif;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-snap: cubic-bezier(0.23, 1, 0.32, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font: 15px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible {
  outline: 1.5px solid rgba(150, 185, 255, 0.75);
  outline-offset: 3px;
}

.reveal {
  position: fixed;
  inset: 0;
  overflow: clip;
  background: var(--night);
}

/* ---------- the layers: Orbit, the miniatures, the clouds ---------- */

.orbit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  opacity: 0;
  transition: opacity 0.9s ease;
}

/* Orbit's globe and the title come in together once the Earth is drawn: nothing half-loaded ever shows */
.reveal.lit .orbit {
  opacity: 1;
}

.reveal:not(.lit) .intro {
  opacity: 0;
}

.miniature {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--paper);
  opacity: 0;
  visibility: hidden;
  transform-origin: 50% 50%;
}

/* behind full cloud cover a plate comes and goes at once, so nothing shows through as the clouds thin */
.miniature.on {
  opacity: 1;
  visibility: visible;
}

.miniature .shot {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.miniature img,
.miniature canvas {
  position: absolute;
  display: block;
  pointer-events: none;
}

/* the float tips this about the window's middle; the plate and the plane's canvas ride inside it */
.miniature .tilt {
  position: absolute;
  inset: 0;
  transform-origin: 50% 50%;
}

/* the plate's edge feathers into it (2 % a side), well short of the painted rim and its shadow */
.miniature .shot > img {
  --feather: linear-gradient(to right, transparent, #000 2%, #000 98%, transparent);
  --feather-y: linear-gradient(to bottom, transparent, #000 2.5%, #000 97.5%, transparent);
  -webkit-mask-image: var(--feather), var(--feather-y);
  -webkit-mask-composite: source-in;
  mask-image: var(--feather), var(--feather-y);
  mask-composite: intersect;
}

.flashes {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.clouds {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

/* ---------- the intro: Orbit's own dark globe behind, its title and a pill ---------- */

.intro {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  transition: opacity 1.4s ease, visibility 1.4s;
}

.intro.gone {
  opacity: 0;
  visibility: hidden;
  transition-duration: 0.9s;
}

/* the title cycles through languages (Orbit's own module); each phrase breathes in and out as one piece */
.title {
  display: grid;
  place-items: center;
  height: 110px;
  margin: 0 0 38px;
  font: italic 400 76px/1 var(--serif);
  letter-spacing: -0.01em;
  color: #f3efe6;
  text-shadow:
    0 0 3px rgba(6, 8, 12, 0.5),
    0 0 16px rgba(6, 8, 12, 0.55),
    0 2px 30px rgba(0, 0, 0, 0.6);
}

.title .phrase {
  grid-area: 1 / 1;
  white-space: nowrap;
  will-change: transform, filter, opacity;
  backface-visibility: hidden;
}

.title .phrase:lang(zh) {
  font: 400 62px/1 'Noto Serif SC', serif;
  letter-spacing: 0.08em;
}

.title .phrase:lang(ja) {
  font: 400 62px/1 'Noto Serif JP', serif;
  letter-spacing: 0.06em;
}

.title .phrase:lang(el) {
  font: italic 400 70px/1 'Noto Serif Display', serif;
}

.title .phrase:lang(ar) {
  font: 400 68px/1.35 'Amiri', serif;
  letter-spacing: 0;
}

@property --orb {
  syntax: '<angle>';
  inherits: false;
  initial-value: 0deg;
}

@keyframes orb {
  to {
    --orb: 360deg;
  }
}

.begin {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  padding: 0 38px;
  border: 0;
  border-radius: 999px;
  color: #f3efe6;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background:
    radial-gradient(120% 150% at 50% 0%, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0) 62%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.03));
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.36),
    inset 0 -14px 24px -16px rgba(110, 160, 230, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 24px 60px -22px rgba(90, 140, 230, 0.6);
  transition:
    transform 0.6s var(--ease-out),
    box-shadow 0.6s,
    color 0.5s ease;
}

/* a pointer that hovers only: on a touch screen a tapped control kept its hover look until the next tap elsewhere */
@media (hover: hover) {
  .begin:hover {
    transform: translateY(-2px);
  }
}

.begin:active {
  transform: translateY(0) scale(0.98);
  transition-duration: 0.15s;
}

.begin:disabled {
  color: rgba(243, 239, 230, 0.72);
  cursor: default;
}

.begin .orb {
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.9)) drop-shadow(0 0 7px rgba(170, 200, 255, 0.7));
}

.begin:not(:disabled) .orb {
  opacity: 1;
}

.begin .orb::before {
  content: '';
  position: absolute;
  inset: 0;
  padding: 1.6px;
  border-radius: inherit;
  background: conic-gradient(
    from var(--orb),
    transparent 0 52%,
    rgba(190, 215, 255, 0.35) 64%,
    #fff 76%,
    transparent 84%
  );
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: orb 7s linear infinite;
}

/* ---------- glass, as Orbit's ---------- */

.glass {
  background: var(--panel);
  backdrop-filter: blur(30px) saturate(1.5) brightness(1.4);
  -webkit-backdrop-filter: blur(30px) saturate(1.5) brightness(1.4);
  border: 1px solid var(--edge);
  border-radius: 26px;
  box-shadow:
    inset 0 1px 0 var(--hi),
    0 1px 2px rgba(22, 21, 19, 0.05),
    0 30px 70px -34px var(--drop);
}

/* ---------- the controls: play and pause, and Start again ---------- */

.controls {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px;
  border-radius: 999px;
  translate: -50% 0;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.8s ease,
    visibility 0.8s;
}

.controls.on {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.8s ease; /* visible at once, so Begin can hand focus to play */
}

.play {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(180deg, rgba(58, 55, 50, 0.9), rgba(16, 15, 14, 0.94));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -3px 8px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 14px 28px -10px rgba(0, 0, 0, 0.6);
  transition:
    transform 0.25s var(--ease-out),
    filter 0.25s;
}

/* a pointer that hovers only (a tap left it lifted and bright) */
@media (hover: hover) {
  .play:hover {
    transform: translateY(-1px);
    filter: brightness(1.18);
  }
}

.play:active {
  transform: translateY(0) scale(0.95);
  transition-duration: 0.08s;
}

.play svg {
  grid-area: 1 / 1;
  width: 14px;
  height: 14px;
  fill: currentColor;
  opacity: 0;
  transition: opacity 0.22s;
}

.play:not(.paused) .pause,
.play.paused .resume {
  opacity: 1;
}

/* at the end, play steps aside: Start again is the one control left (reveal.js, setPlaying) */
.play[hidden] {
  display: none;
}

/* Start again, always beside play and pause */
.restart {
  height: 38px;
  padding: 0 18px 0 16px;
  border: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(22, 21, 19, 0.08);
  box-shadow: inset 0 1px 2px rgba(22, 21, 19, 0.12);
  transition: background 0.3s;
}

/* a pointer that hovers only (a tap left it darker) */
@media (hover: hover) {
  .restart:hover {
    background: rgba(22, 21, 19, 0.14);
  }
}

/* its icon is for a phone only ("Phones", below) */
.restart svg {
  display: none;
}

/* ---------- the arrival: the envelope (envelope.css), and bringing the closed pass back ---------- */

/* as Start again's cloud gathers, the note goes with the scene */
.mail.leaving {
  opacity: 0;
  transition: opacity 0.8s ease;
}

.view-pass[hidden] {
  display: none;
}

.view-pass:not([hidden]) {
  animation: view-pass-in 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes view-pass-in {
  from {
    opacity: 0;
    scale: 0.92;
  }
}

@media (prefers-reduced-motion: reduce) {
  .begin .orb::before {
    animation: none;
  }
}

/* ---------- phones (src/shared/phone.js has the same queries) ---------- */

/* the film never scrolls or zooms under a finger; taps still land */
@media (orientation: landscape) and (max-height: 500px), (orientation: portrait) and (max-width: 500px) {
  html,
  body {
    overscroll-behavior: none;
  }

  .reveal {
    touch-action: none;
  }

  .title {
    height: 64px;
    margin-bottom: 22px;
    font-size: min(46px, 10.5vw);
  }

  /* the other scripts at Orbit's phone sizes (orbit.css), in the same proportion to the Latin title */
  .title .phrase:lang(zh),
  .title .phrase:lang(ja) {
    font-size: min(38px, 8.7vw);
  }

  .title .phrase:lang(el) {
    font-size: min(42px, 9.6vw);
  }

  .title .phrase:lang(ar) {
    font-size: min(41px, 9.4vw);
  }
}

/* sideways, the film's way up: the controls a small column in the bottom left corner, clear of the notch and the
   home indicator, so the globe, the plates and the pass have the whole window (Orbit's inset is 0, reveal.js);
   Start again is its icon, named for screen readers by its words */
@media (orientation: landscape) and (max-height: 500px) {
  .controls {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    flex-direction: column-reverse;
    gap: 6px;
    padding: 5px;
    translate: none;
  }

  .play,
  .restart {
    width: 44px;
    height: 44px;
  }

  .restart {
    display: grid;
    place-items: center;
    padding: 0;
  }

  .restart svg {
    display: block;
    width: 16px;
    height: 16px;
  }

  .restart span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* a city's clip (clip.js) at the arrival: over Orbit and the plates, under the flashes and the clouds;
   reveal.js places it each frame; its grade is an SVG filter of no size */
.clip {
  position: absolute;
  z-index: 2;
  visibility: hidden;
  object-fit: fill;
  pointer-events: none;
}

.clip-grade {
  position: absolute;
  width: 0;
  height: 0;
}
