/* The Course of Empire, 3D version — every screen that is not the 1440 desktop.
   Loaded by index.html, after css/style.css (whose small-screen stop-gap it replaces).
   The sizes are the pixel values from the Figma mockups: phones 390 × 844, tablets 768 × 1024.

   1. Phones            up to 767 wide, and any phone held sideways (a wide screen under 561 high)
   2. Phones sideways   what changes when the phone layout has width but no height
   3. Tablets           768 to 1023 wide
   4. The original      its tablet layout serves every screen from 768 to 1399 wide
   5. Large screens     above 1680 wide the whole interface grows with the window */

@font-face { font-family: "Geist"; src: url("../assets/fonts/geist-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }

.rail__view { display: none; }   /* "Click to view" on a chapter's thumbnail: phones only */

/* ---------------------------------------------------------------- 1. Phones ---- */
@media (max-width: 767px), (orientation: landscape) and (max-height: 560px) {
  /* Header: About, the name, the sound bars without their label */
  .header { height: 84px; padding: 24px 16px; }
  .header__logo { top: 24px; font-size: 20px; font-weight: 400; }
  .header .sound { position: relative; }
  .header .sound::after { content: ""; position: absolute; inset: -16px; }   /* a finger-sized target around the bars */
  .header .sound [data-sound-label], .sound--overlay [data-sound-label] { display: none; }

  .fade--bottom { height: 246px; }
  .hint { display: none; }

  /* A phone browser's bars come and go as the page is scrolled. The picture keeps one size all the while (the
     screen with the bars away), and what stands at the bottom is lifted clear of the bars while they are out. */
  @supports (height: 100lvh) {
    .stage { bottom: auto; height: 100lvh; --lift: calc(100lvh - 100dvh); }
  }

  /* Scene texts: label and title bottom left, the paragraph in the middle of the screen */
  .title { left: 16px; right: 16px; bottom: calc(var(--title-bottom, 24px) + var(--lift, 0px)); gap: 16px; }
  .stage.has-rail .title { --title-bottom: 123px; }   /* above the rail: 24 + 75 + 24 */
  .title__label { font-size: 12px; color: var(--paper-70); white-space: nowrap; }
  .title__text { font-size: min(44px, 11.28vw); line-height: 0.8; letter-spacing: -0.04em; white-space: normal; max-width: none; }
  .title__text br.wide { display: none; }
  .body, .center {
    left: 50%; right: auto; top: 50%; transform: translate(-50%, -50%);
    width: min(var(--wm, 308px), 100vw - 32px) !important; max-width: none;
    font-size: 14px; line-height: 1.2; letter-spacing: -0.02em; text-align: center; white-space: normal;
  }

  /* No card: the rail is three thumbnails across the bottom, and the current one opens the original */
  .card { display: none; }
  .rail { left: 16px; right: 16px; bottom: calc(24px + var(--lift, 0px)); gap: 12px; }
  .rail .rail__item, .rail .rail__item:not(.is-current) { display: flex; flex: 1 1 0; width: auto; min-width: 0; gap: 12px; }
  .rail__row { position: relative; display: block; }
  .rail__thumb { width: 100%; height: 62px; opacity: 1; }
  .rail__text { display: none; }
  .has-card .rail__item.is-current .rail__row::after { content: ""; position: absolute; inset: 0; background: rgba(15, 11, 8, 0.2); }
  .has-card .rail__item.is-current .rail__view {
    display: block; position: absolute; z-index: 1; left: 50%; top: 50%; transform: translate(-50%, -50%);
    font-weight: 500; font-size: 12px; line-height: 1.2; letter-spacing: -0.02em; text-transform: uppercase; white-space: nowrap;
  }

  /* Buttons */
  .btn-frame { padding: 20px 32px; font-size: 20px; }

  /* Preloader */
  .preloader__frame { width: min(100vw - 32px, 358px); height: min(202px, 52vh); }
  .preloader__title { font-size: 20px; }
  .preloader__enter { gap: 20px; margin-top: 17px; }

  /* The original painting: the canvas in the middle, its title above, the text below */
  .overlay {
    display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto 1fr; gap: 32px;
    padding: 64px 16px; overflow-y: auto; overscroll-behavior: contain;
  }
  .overlay[hidden] { display: none; }
  .overlay__close { top: 24px; right: 16px; }
  .overlay__left { position: static; transform: none; width: auto; align-self: end; gap: 16px; }
  .overlay__year, .overlay__label, .overlay__right p { font-size: 14px; }
  .overlay__title { font-size: min(44px, 11.28vw); }
  .overlay__label { white-space: normal; }
  .overlay__figure { position: static; transform: none; width: 100%; }
  .overlay__right { position: static; transform: none; width: auto; align-self: start; gap: 16px; }
  .overlay__note { position: absolute; left: 16px; bottom: 24px; transform: none; width: 289px; max-width: calc(100% - 72px); font-size: 12px; text-align: left; }
  .sound--overlay { display: inline-flex; right: 16px; bottom: 24px; }
}

/* A phone too short for all of the original at once: the same order, read by scrolling. */
@media (max-width: 767px) and (max-height: 779px) {
  .overlay { grid-template-rows: auto auto auto auto; align-content: start; padding-bottom: 24px; }
  .overlay__note { position: static; grid-row: 4; grid-column: 1; margin-top: 8px; }
  .sound--overlay { position: static; grid-row: 4; grid-column: 1; justify-self: end; align-self: end; }
}

/* ------------------------------------------------------- 2. Phones sideways ---- */
@media (orientation: landscape) and (max-height: 560px) {
  .title { right: auto; max-width: calc(58vw - 16px); }
  .title__text { font-size: 44px; }
  .rail { right: auto; width: min(100vw - 32px, 358px); }
  .body { left: auto; right: 16px; transform: translateY(-50%); width: min(var(--wm, 308px), 42vw - 32px) !important; text-align: left; }
  /* the original: its title and text on the left, the canvas on the right */
  .overlay { grid-template-columns: minmax(0, 1fr) min(46vw, 110vh); grid-template-rows: auto auto auto; align-content: start; gap: 16px 24px; padding: 56px 16px 24px; }
  .overlay__left { grid-column: 1; grid-row: 1; align-self: start; }
  .overlay__title { font-size: 32px; }
  .overlay__right { grid-column: 1; grid-row: 2; }
  .overlay__figure { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
  .overlay__note { position: static; grid-column: 1; grid-row: 3; margin-top: 8px; }
  .sound--overlay { position: static; grid-column: 2; grid-row: 3; justify-self: end; align-self: end; }
}

/* --------------------------------------------------------------- 3. Tablets ---- */
@media (min-width: 768px) and (max-width: 1023px) and (min-height: 561px) {
  .header__logo { font-size: 24px; }
  .hint { display: block; }

  /* Titles keep their desktop size and break to the width of the screen */
  .title { right: 24px; }
  .stage.has-rail .title { --title-bottom: 139px; }   /* above the rail: 24 + 91 + 24 */
  .title__label { color: var(--paper-70); white-space: nowrap; }
  .title__text { font-size: 80px; white-space: normal; max-width: none; }
  .title__text br.wide { display: none; }
  .body { left: auto; right: 24px; top: 50%; transform: translateY(-50%); width: 244px !important; max-width: none; }
  .center { width: auto; white-space: nowrap; text-align: left; }

  .card { top: 92px; padding: 12px; gap: 8px; }
  .card__img { width: 220px; height: 124px; }
  .card__cap { font-size: 14px; }

  /* The rail: three thumbnails, no captions */
  .rail { gap: 16px; }
  .rail .rail__item, .rail .rail__item:not(.is-current) { display: flex; width: 130px; gap: 16px; }
  .rail__thumb { width: 130px; height: 74px; }
  .rail__text { display: none; }
}

/* ------------------------------------------- 4. The original, 768 to 1399 wide ---- */
@media (min-width: 768px) and (max-width: 1399px) and (min-height: 561px) {
  .overlay {
    display: grid; grid-template-columns: minmax(0, 1fr) min(50vw - 32px, 68vh); grid-template-rows: 1fr auto 1fr; gap: 0 32px;
    padding: 0 24px 0 16px; overflow-x: hidden; overflow-y: auto;
  }
  .overlay[hidden] { display: none; }
  .overlay__left { position: static; transform: none; width: 350px; max-width: 100%; grid-column: 1; grid-row: 1 / span 3; align-self: start; margin-top: 110px; gap: 16px; }
  .overlay__title { font-size: 44px; }
  .overlay__figure { position: static; transform: none; width: 100%; grid-column: 2; grid-row: 2; }
  .overlay__right { position: static; transform: none; width: auto; grid-column: 2; grid-row: 3; align-self: start; margin-top: 32px; }
  .overlay__note { position: absolute; left: 16px; bottom: 24px; transform: none; width: 289px; text-align: left; }
  .sound--overlay { display: inline-flex; }
}

/* --------------------------------------------------------- 5. Large screens ---- */
/* One design pixel grows with the window, held back by its height so nothing outgrows a wide, low screen. */
@media (min-width: 1681px) and (min-height: 901px) {
  :root { --u: max(1px, min(100vw / 1680, 100vh / 900)); }
}
