/* Phone layout for Whole Person Counseling pages.
   Everything is inside a narrow-screen media query, so the desktop layout is unchanged.
   Pages link this file and mark oversized elements with these classes:
     wpc-fit    picture wider than 300px: scaled to the screen, shape kept
     wpc-shrink picture 41-300px wide: may shrink in a tight spot, shape kept
     wpc-bar    long thin divider bar: capped to the screen width
     wpc-wide   table or box with a fixed width of 360px or more: made fluid
     wpc-narrow table 280-359px wide: shrinks to fit small (320px) phones
     wpc-stack  2-3 column layout table spanning most of the page: cells stacked
     wpc-cols   2-3 column table read across its rows (comparison, labels beside
                values): columns kept side by side, never stacked
     wpc-scroll table with 4 or more columns: scrolls sideways inside itself
     wpc-rule   divider or arrow typed with - ~ * = . characters: clipped to fit;
                wpc-rule-r keeps its right end (the arrow point) visible
     wpc-frame  table narrower than the pictures it holds (picture frame, button box):
                sized to its content so the pictures are not crushed */
@media screen and (max-width: 760px) {
  html, body { width: auto !important; min-width: 0 !important; }
  body {
    margin: 8px !important;
    word-wrap: break-word;    /* older browsers */
    overflow-wrap: anywhere;  /* long words, links and fill-in lines wrap instead of widening the page */
    -webkit-text-size-adjust: 100%;
  }

  /* Nothing may be wider than the screen. */
  body * { max-width: 100% !important; box-sizing: border-box; }

  /* Wide pictures fill the available width and keep their shape.
     Medium pictures shrink only when they must, keeping their shape.
     Small pictures (buttons, icons) never resize, so they are never squashed. */
  img { max-width: none !important; box-sizing: content-box !important; }
  img.wpc-fit { width: 100% !important; max-width: 100% !important; height: auto !important; box-sizing: border-box !important; }
  img.wpc-shrink { max-width: 100% !important; height: auto !important; }
  img.wpc-bar { max-width: 100% !important; }
  /* A photo floated beside text leaves only a sliver for the words on a phone,
     so it gets its own line instead. */
  img.wpc-fit[align="left" i], img.wpc-fit[align="right" i], img.wpc-fit[style*="float" i],
  img.wpc-shrink[align="left" i], img.wpc-shrink[align="right" i], img.wpc-shrink[style*="float" i] {
    float: none !important; display: block; margin: 6px auto !important;
  }
  img[hspace] { margin-left: 4px !important; margin-right: 4px !important; }
  video, iframe, embed, object { height: auto !important; }
  /* Flash movies played by Ruffle (flash.js gives each its movie's shape and
     desktop width): as wide as the screen allows, never wider than on desktop.
     Sized from the screen, not the container, because old pages often wrap
     movies in tables that take their width from what is inside them. */
  ruffle-embed[style*="--wpc-w"], ruffle-object[style*="--wpc-w"] {
    display: inline-block; width: min(100vw - 24px, var(--wpc-w)) !important; height: auto !important;
  }

  /* Fixed-width boxes and tables become fluid. */
  .wpc-wide { width: 100% !important; margin-left: 0 !important; margin-right: 0 !important; }
  table.wpc-wide, table.wpc-narrow { height: auto !important; }
  td, th, col, colgroup { width: auto !important; white-space: normal !important; }
  /* Inside table cells only break a word when it is wider than the whole cell,
     so small button boxes grow to fit their label as they do on desktop. */
  td, th { overflow-wrap: break-word; }
  table.wpc-wide > tbody > tr > td, table.wpc-stack > tbody > tr > td,
  table.wpc-wide > tr > td, table.wpc-stack > tr > td { overflow-wrap: anywhere; }

  table.wpc-stack > tbody > tr > td,
  table.wpc-stack > tbody > tr > th,
  table.wpc-stack > tr > td,
  table.wpc-stack > tr > th { display: block; width: 100% !important; height: auto !important; }

  /* Tables read across their rows (a comparison under column headings, labels
     beside values) keep their columns side by side. Words only break when
     wider than the whole column, and padding shrinks to leave room for text. */
  table.wpc-cols > tbody > tr > td, table.wpc-cols > tbody > tr > th,
  table.wpc-cols > tr > td, table.wpc-cols > tr > th {
    overflow-wrap: break-word !important; word-wrap: break-word;
    -webkit-hyphens: auto; hyphens: auto;
    padding: 4px !important; height: auto !important;
  }
  /* A picture in a cell would hold its column at full picture width, so a table
     holding one gets equal columns and the picture shrinks to fit its column. */
  table.wpc-cols:has(img.wpc-fit, img.wpc-shrink) { table-layout: fixed; }
  table.wpc-cols img.wpc-fit, table.wpc-cols img.wpc-shrink {
    width: auto !important; max-width: 100% !important; height: auto !important;
  }

  /* Text wraps onto more lines on a phone, so fixed heights would make lines overlap. */
  div, p, center, blockquote, span, font, a, h1, h2, h3, h4, h5, h6, li, ul, ol { height: auto !important; }

  /* Netscape's largest font sizes are too big for a phone; scale them with the screen. */
  font[size="7"], font[size="+4"], font[size="+5"], font[size="+6"], font[size="+7"] { font-size: min(48px, 10vw) !important; }
  font[size="6"], font[size="+3"] { font-size: min(32px, 8.5vw) !important; }

  table.wpc-frame, table.wpc-narrow { width: auto !important; }

  table.wpc-scroll { display: block; overflow-x: auto; max-width: calc(100vw - 16px) !important; -webkit-overflow-scrolling: touch; }
  table.wpc-scroll, table.wpc-scroll * { overflow-wrap: normal; word-wrap: normal; }

  /* Form fields sized in characters can be wider than a phone. */
  input, textarea, select { max-width: calc(100vw - 40px) !important; }
  /* Indented with lists or quotes, the screen-based cap above is too wide. */
  ul select, ol select, blockquote select, dl select { max-width: 100% !important; }

  /* Typed divider lines and arrows: clipped instead of wrapping, so a number
     between two arrows stays centred on its own line. */
  .wpc-rule {
    display: inline-flex; justify-content: flex-start; overflow: hidden;
    white-space: nowrap; max-width: 40% !important; vertical-align: bottom;
  }
  .wpc-rule-r { justify-content: flex-end; }

  pre { white-space: pre-wrap !important; }
  blockquote { margin-left: 10px !important; margin-right: 6px !important; }
  ul, ol { padding-left: 22px !important; }
}
