/* Added by the site build to each module page.
   1. The link back to the Atlas home, styled like the module's own top-bar buttons.
   2. A layout for phones. The modules are designed for a projector or a laptop: their bars and
      panels float over a full-screen scene. On a phone that leaves no scene to look at, so here
      the scene gets a box of its own between the top bar and the transport, and the graph and
      Explore & learn panels open as a sheet beside it (below when the phone is upright, on the
      right when it is sideways) that shrinks the scene instead of covering it. */

.atlas-home {
  pointer-events: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border: 1px solid #a9bed826;
  border-radius: 5px;
  background: #0b111c66;
  color: #ccd7e4;
  font: 11px/1.3 "Segoe UI", Arial, sans-serif;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}
.atlas-home:hover { background: #2c3b4ab0; color: #fff; }
.atlas-home:focus-visible { outline: 2px solid #bfd8ff; outline-offset: 4px; }
.atlas-home b { font-weight: 400; }
/* Label: "All modules" on wide screens, arrow only on tablets, "Atlas" on phones. */
.atlas-home .short { display: none; }
@media (max-width: 1100px) {
  .atlas-home .long { display: none; }
}
.atlas-hint { display: none; }

/* ---- Phones, upright or sideways ---------------------------------------------------------- */
@media (max-width: 760px) and (orientation: portrait), (max-height: 559px) and (orientation: landscape) {
  .atlas-home .short { display: inline; }

  /* Page frame: top bar, then the scene box, then the transport. */
  #app {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 100dvh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    background: #06090f;
  }
  #app .topbar {
    position: static;
    flex: none;
    padding: 6px 10px;
    gap: 8px;
    align-items: center;
    pointer-events: auto;
    background: #0a111b;
    border-bottom: 1px solid #a9bed81f;
  }
  #app .topbar .brand,
  #app .topbar .part { display: none; }
  #app .view-tools { margin-left: auto; min-width: 0; gap: 5px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #app .view-tools button { flex: none; width: auto !important; min-width: 0 !important; max-width: none !important; padding: 7px 8px; font-size: 11px; white-space: nowrap; }
  /* Short button labels, and Reset view only while Free orbit is on (it has no effect otherwise). */
  #app .view-tools .label-long,
  #app .view-tools #reset-camera span { display: none; }
  #app .view-tools .label-short { display: inline; }
  #app .view-tools:has(#orbit-toggle[aria-pressed="false"]) #reset-camera { display: none; }
  #app main { position: relative; inset: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; }
  #app .visual { position: relative; inset: auto; flex: 1; min-height: 0; }
  #app .transport {
    position: static;
    flex: none;
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 0;
    background: #0d1621;
    backdrop-filter: none;
  }
  /* Left to larger screens: captions, the long legend text, stage names (previous/next and the
     scrubber remain) and Lecture mode, which is a projector feature. */
  #app > footer,
  #app .scene-top,
  #app .scene-bottom,
  #app .charge-key,
  #app .tower-scale p,
  #app .stage-nav,
  #app .lecture-controls { display: none; }

  /* What stays on the scene: one status line, the time, a small colour scale, small labels. */
  #app .event-note {
    top: 6px !important;
    left: 10px !important;
    right: 10px;
    max-width: none;
    font-size: 11px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #app .time-summary { top: 26px !important; left: 10px !important; font-size: 11px; }
  #app .physical-readout { top: 26px !important; left: 10px !important; right: 10px; gap: 1px; font-size: 11px; }
  #app .physical-readout #physical-time { font-size: 15px; }
  #app .tower-scale {
    top: auto !important;
    bottom: 6px !important;
    left: 8px !important;
    width: min(250px, 64%) !important;
    padding: 4px 8px 1px;
    font-size: 10px;
  }
  #app .chapter-card { top: 34%; }
  #app .chapter-card strong { font-size: 19px; }
  /* Part I: the P / N / LP name tags would sit on top of the chapter titles in so small a
     scene; the + and - signs drawn in the cloud remain, and Explore & learn names the regions. */
  #app #cloud-charge-labels { display: none !important; }
  #app .annotation { font-size: 10px; padding: 3px 6px; }
  #app .graphics-error { top: 12%; left: 6%; width: 88%; padding: 14px; box-sizing: border-box; font-size: 13px; line-height: 1.5; }

  /* The sheet: whichever of the graph or Explore & learn is open. */
  #app .sidebar,
  #app section.waveform {
    position: fixed !important;
    z-index: 8;
    transform: none !important;
    box-sizing: border-box;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    max-height: none !important;
    margin: 0;
    border-radius: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #0e1621;
    box-shadow: none;
    backdrop-filter: none;
  }
  #app .sidebar { z-index: 9; }
}

/* ---- Phone upright: sheet below ------------------------------------------------------------ */
@media (max-width: 430px) and (orientation: portrait) {
  .atlas-home .short { display: none !important; }
  #app .view-tools button { padding: 7px 7px; }
}
@media (max-width: 760px) and (orientation: portrait) {
  #app { --sheet: 46dvh; }
  #app:has(.sidebar:not([hidden]), section.waveform:not([hidden])) { padding-bottom: var(--sheet); }
  #app .sidebar,
  #app section.waveform {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    height: var(--sheet) !important;
    border-width: 1px 0 0;
  }
  #app .transport { padding: 8px 12px 10px; }

  /* Hint to rotate the phone; the script adds it, this rule shows it only when upright. */
  .atlas-hint {
    position: fixed;
    z-index: 30;
    left: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 5px 5px 12px;
    border: 1px solid #a9bed840;
    border-radius: 6px;
    background: #101a27f2;
    color: #dce3eb;
    font: 12px/1.4 "Segoe UI", Arial, sans-serif;
  }
  .atlas-hint span { flex: 1; }
  .atlas-hint button {
    flex: none;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    background: transparent;
    color: #ccd7e4;
    font-size: 18px;
    line-height: 1;
  }
}

/* ---- Phone sideways: sheet on the right, transport as one slim row -------------------------- */
@media (max-height: 559px) and (max-width: 700px) and (orientation: landscape) {
  .atlas-home .short { display: none !important; }
}
@media (max-height: 559px) and (orientation: landscape) {
  #app { --sheet: min(42vw, 420px); }
  #app:has(.sidebar:not([hidden]), section.waveform:not([hidden])) { padding-right: var(--sheet); }
  #app .sidebar,
  #app section.waveform {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: var(--sheet) !important;
    border-width: 0 0 0 1px;
  }
  #app .transport { display: flex; align-items: center; gap: 12px; padding: 4px 10px; }
  #app .transport-top { flex: none; flex-wrap: nowrap; gap: 10px; }
  #app .playback > button { height: 30px; }
  #app .playback > .primary { min-width: 0; padding: 2px 14px; }
  #app .speed-wrap { display: none; }
  #app .current-stage { order: 0; flex: none; width: auto; max-width: 200px; gap: 8px; justify-content: flex-start; }
  #app .current-stage strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  #app .transport .scrubber { flex: 1; min-width: 80px; margin-top: 0; }
}
