/* Precision Prep: phone layout for cheat sheets.
   Loaded by every sheet after its own styles. Only applies on narrow screens,
   so the desktop layout is unchanged. */
/* Tablets held upright: fit the page to the screen, keep the columns */
@media (min-width: 761px) and (max-width: 1040px) {
  html, body { min-width: 0 !important; max-width: 100% !important; width: auto !important; }
  .page, .wrap, .sheet, .container,
  [style*="width:1000px"], [style*="width: 1000px"] { width: auto !important; min-width: 0 !important; max-width: 100% !important; }
  .grid2 > *, .grid3 > *, .kc-grid > *, .kc-cols > *, .col2 > *, .col3 > *, .col-main > *, .row > * { min-width: 0; }
  svg { max-width: 100% !important; height: auto !important; }
  table { max-width: 100%; }
}

@media (max-width: 760px) {
  /* Slightly larger base size: most sheet text is set in rem */
  html { font-size: 17px !important; -webkit-text-size-adjust: 100%; }

  /* Pages were built at a fixed 1000px width: let them fit the screen */
  html, body {
    min-width: 0 !important;
    max-width: 100% !important;
    width: auto !important;
    overflow-x: hidden;
  }
  body { padding: 12px !important; }
  .page, .wrap, .sheet, .container,
  [style*="width:1000px"], [style*="width: 1000px"],
  [style*="width:820px"], [style*="width: 820px"] {
    width: auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* Multi-column layouts stack into one column */
  .grid2, .grid3, .kc-grid, .kc-cols, .col2, .col3, .col-main,
  .traps, .qr-grid, .range-grid, .compare-grid, .algo-grid, .jxn-grid,
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
  .qty-row { grid-template-columns: 1fr 1fr !important; }
  .hvl-row { grid-template-columns: repeat(3, 1fr) !important; }

  /* Grid and flex children may shrink instead of pushing the page wider */
  .grid2 > *, .grid3 > *, .kc-grid > *, .kc-cols > *, .col2 > *, .col3 > *,
  .col-main > *, .traps > *, .qr-grid > *, .row > *, [style*="display:flex"] > *,
  [style*="display: flex"] > * { min-width: 0; }

  /* Side-by-side card rows stack; header rows wrap */
  .row { flex-direction: column; }
  .page-head, .header-top, .pills, .f-eq,
  [style*="display:flex"], [style*="display: flex"] { flex-wrap: wrap; }
  .pills { justify-content: flex-start !important; }

  /* Diagrams scale down to the screen width, keeping their proportions */
  svg { max-width: 100% !important; height: auto !important; }
  .diagram-wrap { overflow-x: auto; }

  /* Wide diagrams (600px+ design width) would shrink too small to read, so keep
     them at a readable size and let the student swipe sideways inside the diagram */
  svg[viewBox^="0 0 6"], svg[viewBox^="0 0 7"], svg[viewBox^="0 0 8"],
  svg[viewBox^="0 0 9"] {
    max-width: none !important;
    min-width: 640px;
  }
  svg[viewBox^="0 0 8"], svg[viewBox^="0 0 9"] { min-width: 720px; }
  :has(> svg[viewBox^="0 0 6"]), :has(> svg[viewBox^="0 0 7"]),
  :has(> svg[viewBox^="0 0 8"]), :has(> svg[viewBox^="0 0 9"]) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* Start at the left edge. Centering a diagram wider than the screen hides
       its left side where swiping can't reach it. */
    justify-content: flex-start !important;
    /* Flex wrappers put the swipe hint on its own line under the diagram */
    flex-wrap: wrap !important;
  }
  :has(> svg[viewBox^="0 0 6"])::after, :has(> svg[viewBox^="0 0 7"])::after,
  :has(> svg[viewBox^="0 0 8"])::after, :has(> svg[viewBox^="0 0 9"])::after {
    content: "Swipe to see the full diagram \2192";
    display: block;
    position: sticky;
    left: 0;
    flex: 0 0 100%;
    width: 100%;
    margin-top: 6px;
    font-size: 0.7rem;
    color: #8ba3bc;
  }

  /* Tables: fit when they can, scroll sideways inside themselves when they can't */
  table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  td, th { overflow-wrap: break-word; hyphens: manual; }

  /* Long formulas and words wrap instead of running off the edge */
  .formula-box, .f-eq, .eq, code, pre { overflow-wrap: anywhere; white-space: normal; }
  img { max-width: 100%; height: auto; }
}
