/*
 * Narrow screens fly the same route with a shorter lens: less depth, larger
 * hit targets, and the orbital skills system relaxed into a readable list.
 */

@media (max-width: 860px) {
  .nav__toggle {
    display: block;
    order: 3;
  }

  .nav__list {
    order: 4;
    flex-basis: 100%;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height var(--speed) var(--ease-out), opacity var(--speed) ease;
  }

  #universe-nav.is-open {
    background: rgba(4, 3, 10, 0.96);
  }

  #universe-nav.is-open .nav__list {
    max-height: 70vh;
    opacity: 1;
    padding-bottom: 1.2rem;
  }

  .nav__inner {
    flex-wrap: wrap;
  }

  .nav__link {
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    padding: 0.45rem 0;
  }

  .nav__motion {
    order: 2;
  }
}

@media (max-width: 720px) {
  :root {
    /* --focal is deliberately NOT changed here: it must stay equal to FOCAL
       in js/universe/constants.js so the starfield and the words in front of
       it are projected through the same lens. Places that would not fit are
       scaled down individually instead (see measureFit in world.js). */
    --shell: 86vw;
  }

  .place__inner,
  .place__inner--wide {
    width: 86vw;
  }

  .entrance__links {
    flex-wrap: wrap;
    gap: 1.2rem;
  }

  /*
   * No type override here on purpose. Every size in the portfolio is already
   * a clamp with a floor chosen for a phone, so shrinking anything again at
   * this width would only undo the hierarchy the scale was built to hold.
   */

  /*
   * There is no room to fly an orbital system on a phone, and no pointer to
   * explore it with — so the same markup becomes a plain, readable list of
   * technologies under a single core label. Nothing is lost.
   */
  .orbits__field {
    width: 100%;
    aspect-ratio: auto;
    display: grid;
    gap: 1rem;
    transform-style: flat;
  }

  .orbits__ring {
    display: none;
  }

  .orbits__core {
    position: static;
    translate: none;
    scale: 1;
    opacity: 1;
    justify-items: start;
  }

  .orbits__core-glow {
    display: none;
  }

  .orbits__bodies {
    position: static;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.4rem;
  }

  .orbit-body {
    position: static;
    margin: 0;
    opacity: 1 !important;
    transform: none !important;
  }

  .orbit-body__name {
    transform: none;
  }

  .orbits__readout {
    display: none;
  }

  .waypoints,
  .record {
    grid-template-columns: 1fr;
  }

  [data-section="about"] {
    grid-template-columns: 1fr;
    grid-template-areas:
      "eyebrow"
      "figure"
      "lead"
      "body"
      "meta";
  }

  .artifact {
    width: 74vw;
  }

  .lightbox__nav--prev {
    left: 0;
  }

  .lightbox__nav--next {
    right: 0;
  }
}

/* ── Motion off ─────────────────────────────── */
/*
 * The static portfolio.
 *
 * This is not the moving one with the movement taken out. The flight is
 * replaced by a document: the places stop being layers stacked in depth and
 * become sections down a page, each given the room the camera used to give
 * it. Everything the flight revealed on arrival is revealed here from the
 * start (world.js marks every place arrived when motion is off), so nothing
 * is left half-built, invisible, or stopped partway through a transition.
 *
 * The starfield stays. It is the one part of the universe that costs the
 * reader nothing: it holds still, and it keeps the page in the same world as
 * the moving version rather than dropping it onto a flat background.
 */
html.is-calm .world {
  position: relative;
  perspective: none;
  pointer-events: auto;
}

html.is-calm .place {
  position: relative;
  inset: auto;
  visibility: visible;
  display: block;
  min-height: 0;
  /* Room enough to separate one section from the next without the empty
     screens a fixed viewport-height section would leave behind. */
  padding: clamp(4.5rem, 11vh, 8rem) 0;
  border-top: 1px solid var(--hairline);
}

/* The landing screen keeps its full frame; nothing else needs one. */
html.is-calm .place--entrance {
  border-top: 0;
  padding-top: clamp(2rem, 6vh, 4rem);
}

html.is-calm [data-section="hero"] {
  height: auto;
  min-height: 78vh;
}

html.is-calm .place__inner {
  opacity: 1 !important;
  transform: none !important;
  filter: none !important;
  max-height: none;
  width: var(--shell);
  margin: 0 auto;
  pointer-events: auto;
}

html.is-calm .place__inner--wide {
  width: var(--shell);
}

/*
 * Nothing is hidden waiting for an arrival that will not come, and nothing is
 * left mid-transition: the reveal is simply already finished.
 */
html.is-calm .place__inner [data-section] > * {
  opacity: 1 !important;
  transform: none !important;
  transition: none;
}

/*
 * The orbital system is revealed but NOT flattened: its positions come from
 * the animation loop, which still runs when motion is off — it simply holds
 * the system still instead of turning it. Clearing the transform here would
 * pile every technology on top of the core.
 */
html.is-calm .orbit-body,
html.is-calm .orbits__ring,
html.is-calm .orbits__core {
  opacity: 1 !important;
  scale: 1;
  transition: none;
}

html.is-calm .orbit-body {
  opacity: 0.92 !important;
}

/*
 * The photographs stop floating and become a plain row of images beside —
 * never under — the words they belong to. Set out deliberately, at a size
 * worth looking at, rather than frozen mid-drift at whatever angle the
 * animation happened to reach.
 */
html.is-calm .stack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  height: auto;
}

html.is-calm .stack__photo {
  position: static;
  width: calc(50% - 0.45rem);
  opacity: 1;
  filter: none;
  transform: none !important;
  transition: none;
}

html.is-calm .stack__photo img {
  animation: none;
  border-radius: 14px;
}

html.is-calm .stack__count {
  position: static;
  opacity: 1;
  transform: none;
  margin-top: 0.4rem;
}

html.is-calm .place__stack,
html.is-calm .record__stack,
html.is-calm .waypoint__stack {
  height: auto;
  pointer-events: auto;
}

/* Depth cues that mean nothing without depth. */
html.is-calm .place__coords {
  position: static;
  margin-top: 2rem;
  opacity: 0.5 !important;
}

html.is-calm #scroll-track {
  display: none;
}

/*
 * The atmosphere is a fixed wash tied to whichever region the camera is
 * nearest. With no camera it would sit on one colour for the whole document,
 * so it is dropped and the page keeps the void's own ground.
 */
html.is-calm .atmosphere {
  opacity: 0.5;
}

html.is-calm .entrance__enter-line,
html.is-calm .orbits__core-glow,
html.is-calm .place__name,
html.is-calm .exit__title,
html.is-calm .entrance__name-ink,
html.is-calm .about__lead,
html.is-calm .finale__title {
  animation: none;
}

/* The gradients stay: they are colour, not motion. */
html.is-calm .entrance__name-ink,
html.is-calm .finale__line,
html.is-calm .nav__brand,
html.is-calm .timeline__crown {
  background-position: 50% 50%;
}

/*
 * The timeline cannot be drawn by the star path when the path is not moving
 * toward it, so it draws itself: the same trunk and fork, held still.
 */
html.is-calm .timeline {
  height: auto;
  padding-top: 3.5rem;
}

html.is-calm .timeline__crown,
html.is-calm .timeline__branches {
  position: static;
  transform: none;
}

html.is-calm .timeline__crown {
  display: block;
  text-align: center;
}

html.is-calm .timeline__branches {
  position: static;
  transform: none;
  width: 100%;
  margin-top: 2.4rem;
}

html.is-calm .timeline__trunk {
  transform: translate(-50%, calc(var(--trunk-top) + 250px));
  top: 3.2rem;
}

html.is-calm .timeline__fork,
html.is-calm .timeline__drop {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  #universe-canvas,
  .atmosphere,
  #universe-nav,
  .region-skip,
  #intro,
  #scroll-track {
    display: none !important;
  }

  .world {
    position: static;
    perspective: none;
  }

  .region {
    position: static;
    visibility: visible;
    page-break-inside: avoid;
  }

  .place__inner {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
    max-height: none;
  }

  body {
    background: #fff;
    color: #000;
  }
}

/* ── Photographs on narrow screens ──────────────────── */
/*
 * Below a laptop there is no column to spare beside the words.
 *
 * The floating groups are not moved under the text — a photograph sitting
 * directly beneath a paragraph is the generic arrangement this composition
 * exists to avoid, and on a narrow screen it also pushes the words off the
 * frame. They are withdrawn instead, and every place that had them offers a
 * way in: the details control, which opens the same images in a view of
 * their own.
 *
 *   wide                          narrow
 *   ┌──────────────┬────────┐     ┌───────────────────┐
 *   │ THE PLACE    │   ▫    │     │ THE PLACE         │
 *   │ description  │ ▫   ▫  │     │ description       │
 *   │ details      │        │     │ details ›  ← the images live here
 *   └──────────────┴────────┘     └───────────────────┘
 */
@media (max-width: 1180px) {
  .place__stack,
  .record__stack,
  .waypoint__stack {
    display: none;
  }

  /* One column, full width, now that nothing shares the frame with it. */
  [data-section="project"],
  [data-section="event"],
  [data-section="certifications"],
  .place:nth-of-type(even) [data-section="project"],
  .place:nth-of-type(even) [data-section="event"] {
    grid-template-columns: minmax(0, 1fr);
  }

  [data-section="project"] > *,
  [data-section="event"] > *,
  [data-section="certifications"] > *,
  .place:nth-of-type(even) [data-section="project"] > *,
  .place:nth-of-type(even) [data-section="event"] > * {
    grid-column: 1;
  }

  .waypoint {
    grid-template-columns: minmax(0, 1fr);
  }

  /*
   * The control is now the only route to the images rather than an
   * alternative to noticing them, so it is given the weight to be found.
   */
  .cue[data-record],
  .cue[data-event],
  .cue[data-details] {
    font-size: var(--t-meta);
    letter-spacing: 0.18em;
    color: var(--text);
    border-color: var(--hairline-strong);
  }

  /* Copy can run wider without a column beside it. */
  .place__summary,
  .about__body,
  .about__interests,
  .waypoint__body,
  .ledger__detail {
    max-width: 58ch;
  }
}

/* ── The education timeline on narrow screens ────────── */
/*
 * The fork needs width to be a fork. Where there is not enough of it the
 * branches come down the trunk one after the other instead, still on the
 * same path, still in order — a route rather than a diagram.
 */
@media (max-width: 900px) {
  .timeline {
    height: auto;
    padding-top: 3.5rem;
  }

  .timeline__crown,
  .timeline__trunk,
  .timeline__fork,
  .timeline__drop,
  .timeline__branches {
    position: static;
    transform: none;
  }

  .timeline__crown {
    display: block;
    text-align: left;
  }

  .timeline__trunk,
  .timeline__fork,
  .timeline__drop {
    display: none;
  }

  .timeline__branches {
    width: 100%;
    margin-top: 1.6rem;
    grid-template-columns: 1fr;
    row-gap: clamp(1.6rem, 4vh, 2.6rem);
  }

  .timeline__branch,
  .timeline__branch--left,
  .timeline__branch--right {
    max-width: none;
    justify-self: stretch;
    text-align: left;
    padding-top: 0;
    padding-left: 1.6rem;
    border-left: 1px solid var(--hairline);
  }

  .timeline__branch--left > :not(.timeline__node) {
    text-align: left;
  }

  .timeline__branch--left .timeline__node,
  .timeline__branch--right .timeline__node {
    top: 0.45rem;
    left: -5px;
    right: auto;
  }
}

/* ── Phones ────────────────────────────────── */
@media (max-width: 720px) {
  .ledger__entry {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.35rem;
  }

  .waypoints {
    grid-template-columns: minmax(0, 1fr);
  }
}
