/* ==========================================================================
   MODULE FLOW — shared layout for the 16 taught-course module pages
   --------------------------------------------------------------------------
   Two jobs, one file:

     1. .module-layout / .module-flow — a two-column grid that puts the page's
        sections in a readable column and parks a sticky in-page rail beside
        them on wide screens. On narrow screens the rail collapses to a single
        sticky disclosure bar above the content.

     2. .mflow-3d — the "Want to see this in 3D?" opt-in card that now gates the
        Everyday 3D stage, so the heavy WebGL story no longer competes with the
        2D precision lab above the fold.

   Tokens only (studio-tokens.css): --ink, --ink-2, --muted, --accent,
   --accent-tint, --line, --line-strong, --surface, --surface-2, --panel,
   --recessed, --font-display, --font-mono. Course hue arrives via the
   .course-alg1 / .course-geo / .course-ess wrappers. No color literals.
   ========================================================================== */

:root {
  --mflow-rail-w: 16rem;
  --mflow-stick: calc(var(--header-height, 72px) + 1.25rem);
  /* Narrow screens stack a fixed site header AND the sticky rail bar above the
     content, so an anchor jump has to clear both or it lands underneath them. */
  --mflow-scroll: calc(var(--header-height, 72px) + 5rem);
}
@media (min-width: 1180px) {
  :root { --mflow-scroll: var(--mflow-stick); }
}

/* --------------------------------------------------------------------------
   0 · NARROW-VIEWPORT GUARD  (not this file's bug — see the note)
   --------------------------------------------------------------------------
   Measured 2026-08-07 at a 320px viewport: .header-inner has a 405px intrinsic
   width (logo 241 + bell 40 + command-palette trigger 44 + menu toggle 40) in a
   304px box, so the SITE HEADER overflows horizontally. That is site-wide, not
   a module-page defect — /notes/ (160px over) and /support/ (42px over) show it
   too, and neither loads anything from this rebuild.

   Module pages never showed it because viz-everyday-3d.css sets
   `html.has-everyday-3d { overflow-x: clip }` and the 3D stage used to mount on
   every load. It is now opt-in, so the clip no longer arrives for free. This
   rule carries the same guard so making the 3D optional does not regress
   horizontal scrolling. `clip` (not `hidden`) is deliberate: it does not create
   a scroll container, so the sticky rail below still sticks. Delete this block
   once the header itself fits 320px.
   -------------------------------------------------------------------------- */

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

/* --------------------------------------------------------------------------
   1 · LAYOUT
   -------------------------------------------------------------------------- */

/* .module-layout IS the page .container, so anything a script appends to
   `main .container` (the Practice Gym auto-block, the Mental Picture embed)
   becomes a grid item in the reading column instead of escaping the layout.
   NOTE: never set row-gap here — the rail spans many implicit rows. */
.module-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: 0;
  row-gap: 0;
}

.module-flow {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}

/* Everything the scripts append lands under the flow, still in column 1. */
.module-layout > .pe-autoblock,
.module-layout > .mp-embed,
.module-layout > section,
.module-layout > p {
  grid-column: 1;
  min-width: 0;
}

.mod-section {
  margin: 3rem 0;
  scroll-margin-top: var(--mflow-scroll);
}
.mod-section:first-child { margin-top: 1.75rem; }

/* Zero-height duplicate anchors so historic deep links (#lab vs #explore,
   #guide) keep resolving after the rename. */
.anchor-alias {
  display: block;
  height: 0;
  overflow: hidden;
  scroll-margin-top: var(--mflow-scroll);
}

.module-layout > .pe-autoblock,
.module-layout > .mp-embed {
  scroll-margin-top: var(--mflow-scroll);
}

/* Algebra I modules 2 and 4 kept vocabulary and TEKS in a two-column grid.
   Lifting the TEKS panel into its own Standards section leaves one child, which
   would otherwise hang in a half-width column. Let it take the full row. */
#vocab > div > .panel:only-child {
  grid-column: 1 / -1;
}

/* Sections are focus targets for rail jumps; never draw a stray outline. */
.mod-section:focus { outline: none; }
.mod-section:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
  border-radius: 12px;
}

/* --------------------------------------------------------------------------
   2 · THE RAIL
   -------------------------------------------------------------------------- */

.mrail {
  grid-column: 1;
  grid-row: 1;
  position: sticky;
  top: var(--header-height, 72px);
  z-index: 30;
  margin: 0 0 1.25rem;
  font-family: var(--font-mono);
}

.mrail-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--arch-shadow-sm, none);
}
.mrail-toggle:hover { border-color: var(--accent); background: var(--surface-2); }
.mrail-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.mrail-toggle-label {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  flex: 0 0 auto;
}
.mrail-toggle-current {
  color: var(--accent);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mrail-caret {
  flex: 0 0 auto;
  color: var(--muted);
  transition: transform .18s ease;
}
.mrail-toggle[aria-expanded="true"] .mrail-caret { transform: rotate(180deg); }

.mrail-panel {
  margin-top: 0.5rem;
  padding: 0.85rem 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--arch-shadow-sm, none);
}
.mrail-panel[hidden] { display: none; }

.mrail-eyebrow {
  margin: 0 0 0.55rem 0.35rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.mrail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: mrail;
}
.mrail-list li { margin: 0; }

.mrail-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  padding: 0.35rem 0.6rem;
  border-radius: 9px;
  border-left: 2px solid transparent;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.79rem;
  line-height: 1.35;
}
.mrail-link:hover { background: var(--recessed); color: var(--ink); }
.mrail-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.mrail-link[aria-current="location"] {
  color: var(--accent);
  background: var(--accent-tint);
  border-left-color: var(--accent);
  font-weight: 700;
}

.mrail-num {
  flex: 0 0 auto;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
}
.mrail-link[aria-current="location"] .mrail-num {
  border-color: var(--accent);
  color: var(--accent);
}
.mrail-text { min-width: 0; }

.mrail-tools {
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}
.mrail-tools-title {
  margin: 0 0 0.4rem 0.35rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.mrail-tool {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0.3rem 0.6rem;
  border-radius: 9px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.76rem;
}
.mrail-tool:hover { background: var(--recessed); color: var(--accent); }
.mrail-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* --- wide screens: real side rail ------------------------------------- */
@media (min-width: 1180px) {
  .module-layout {
    grid-template-columns: minmax(0, 1fr) var(--mflow-rail-w);
    column-gap: 2.75rem;
  }
  .module-flow { grid-row: 1; }
  .mrail {
    grid-column: 2;
    /* Span far enough to cover every script-appended row. Row-gap is 0, so
       the surplus implicit rows collapse to nothing. */
    grid-row: 1 / span 99;
    align-self: start;
    position: sticky;
    top: var(--mflow-stick);
    z-index: 5;
    margin: 0;
    max-height: calc(100vh - var(--mflow-stick) - 1.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .mrail-toggle { display: none; }
  .mrail-panel[hidden] { display: block; }
  .mrail-panel { margin-top: 0; }
}

/* --------------------------------------------------------------------------
   3 · STANDARDS LIST (Earth Systems Science)
   The ESS hero used to carry paragraph-length standards as pill badges. They
   now read as a list in the Standards section, where length is fine.
   -------------------------------------------------------------------------- */

.std-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.85rem;
}
.std-list li {
  position: relative;
  padding: 0 0 0 1.5rem;
  color: var(--ink-2);
  font-size: 0.92rem;
  line-height: 1.65;
}
.std-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
  background: var(--accent);
}

/* --------------------------------------------------------------------------
   4 · THE 3D OPT-IN
   -------------------------------------------------------------------------- */

.mflow-3d-actions { margin: 1.1rem 0 0; }

.mflow-3d-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 48px;
  padding: 0.7rem 1.3rem;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.mflow-3d-btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.mflow-3d-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.mflow-3d-btn-icon { transition: transform .18s ease; }
.mflow-3d-btn[aria-expanded="true"] .mflow-3d-btn-icon { transform: rotate(180deg); }

.mflow-3d-wrap { margin-top: 1.5rem; }
.mflow-3d-wrap[hidden] { display: none; }

.mflow-3d-note {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

/* --------------------------------------------------------------------------
   5 · MOTION + NARROW VIEWPORTS
   -------------------------------------------------------------------------- */

/* Printing a module page should give the reading column, not the rail or an
   empty 3D shell. */
@media print {
  .module-layout { display: block; }
  .mrail,
  .mflow-3d-actions { display: none !important; }
  .mflow-3d-wrap[hidden] { display: none !important; }
  html, body { overflow-x: visible; }
}

@media (prefers-reduced-motion: reduce) {
  .mrail-caret,
  .mflow-3d-btn,
  .mflow-3d-btn-icon { transition: none; }
  .mflow-3d-btn:hover { transform: none; }
}

@media (max-width: 420px) {
  .mrail-toggle { font-size: 0.72rem; padding-inline: 0.7rem; }
  .mrail-toggle-label { display: none; }
  .mflow-3d-btn { width: 100%; justify-content: center; }
}
