/* The model viewer on phones (loaded by touch.js, after pages.css).
   On a narrow screen the controls sit below the model instead of on top of it, every control is at
   least 44 px tall with its name written out, and the layer switches fold away behind one button.
   On touch screens the model takes over all gestures once it has been tapped (see touch.js). */

.viewer-panel .layers-toggle, .touch-done, .touch-hint { display: none; }

@media (max-width: 620px) {
  /* the viewer becomes a column: the model, then what was picked, then the controls */
  .stage .viewer, .v2 .stage .viewer { display: flex; flex-direction: column; height: auto; aspect-ratio: auto; padding-bottom: 8px; }
  .stage .viewer canvas { flex: none; height: 56vh; height: 56svh; min-height: 300px; }
  .stage .viewer .viewer-labels { bottom: auto; } /* touch.js keeps its height equal to the canvas */
  .stage .viewer.fullpage, .v2 .stage .viewer.fullpage { height: 100%; padding-bottom: max(8px, env(safe-area-inset-bottom)); overflow-y: auto; }
  .stage .viewer.fullpage canvas { flex: 1 1 0; height: auto; min-height: 240px; }
  /* the site name stays on the model's bottom-right corner, above the controls below it */
  .stage .viewer .viewer-mark { bottom: auto; top: calc(max(56svh, 300px) - 22px); right: 10px; font-size: 11px; }
  .stage .viewer.fullpage .viewer-mark { display: none; }

  /* what was tapped: over the foot of the model, so naming a structure does not move the controls */
  .stage .viewer .viewer-picked, .stage .viewer.has-list .viewer-picked { top: max(56svh, 300px); bottom: auto; left: 8px; right: 8px; transform: translateY(calc(-100% - 8px)); min-height: 44px; flex-wrap: wrap; gap: 2px 12px; }
  .stage .viewer.fullpage .viewer-picked, .stage .viewer.fullpage.has-list .viewer-picked { position: static; order: 1; transform: none; margin: 8px 8px 0; }
  .stage .viewer .viewer-picked a { display: inline-flex; align-items: center; min-height: 32px; }

  /* camera: views, zoom, full page */
  .viewer-tools.cam { position: static; order: 2; transform: none; width: auto; max-width: none; margin: 8px 8px 0; flex-wrap: wrap; justify-content: stretch; gap: 2px; overflow: visible; }
  .viewer-tools.cam button { flex: 1 0 44px; min-height: 44px; padding: 0 4px; font-size: 14px; }
  /* two tidy rows: the views, then reset, zoom and full page */
  .viewer-tools.cam [data-view] { order: 1; }
  .viewer-tools.cam::before { content: ''; order: 2; flex: 0 0 100%; height: 0; }
  .viewer-tools.cam :is([data-reset], [data-zoom], [data-fullpage]) { order: 3; }
  .viewer-tools.cam [data-zoom] { min-width: 44px; font-size: 20px; }
  .viewer-tools.cam .icon { padding: 0; }
  .viewer-tools.cam .sep { display: none; }

  /* layers: one row with Layers and X-ray; the switches open below it */
  .viewer-panel { position: static; order: 3; width: auto; margin: 8px 8px 0; flex-direction: column; gap: 6px; max-height: none; overflow: visible; }
  .viewer-panel .pane { flex-direction: row; flex-wrap: wrap; align-items: stretch; gap: 4px; padding: 4px; }
  .viewer-panel .pane:last-child { order: 0; }
  .viewer-panel .pane[role="group"] { order: 1; display: none; }
  .viewer.layers-open .viewer-panel .pane[role="group"] { display: flex; }
  .viewer-panel button { flex: 1 0 30%; width: auto; min-height: 44px; padding: 0 10px; font-size: 14px; gap: 8px; }
  .viewer-panel .depth { flex: 1 0 100%; order: 99; padding: 0; justify-content: center; gap: 8px; }
  .viewer-panel .depth button { flex: none; min-width: 44px; min-height: 44px; padding: 0; font-size: 22px; }
  .viewer-panel .depth-label { min-width: 120px; font-size: 14px; }
  .viewer-panel .layers-toggle { display: flex; align-items: center; justify-content: space-between; }
  .viewer-panel .layers-toggle::before { content: none; }
  .layers-toggle::after { content: ''; width: 8px; height: 8px; margin: 0 4px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); }
  .viewer.layers-open .layers-toggle::after { transform: translateY(2px) rotate(-135deg); }

  /* the list of muscles (or vessels) in view: a block of its own, under the controls */
  .stage .viewer .muscle-list { position: static; order: 4; width: auto; max-height: none !important; margin: 8px 8px 0; font-size: 14.5px; }
  .muscle-list .list-head { min-height: 44px; }
  .muscle-list ul { max-height: 44vh; overflow-y: auto; overscroll-behavior: contain; }
  .muscle-list .name { min-height: 44px; }
  .muscle-list .eye { width: 44px; height: 44px; }
}

/* Touch screens: no hover, so no tooltip; a hint, and a way to give scrolling back to the page. */
@media (pointer: coarse) {
  .viewer-tip { display: none !important; }
  .viewer.touch .touch-hint {
    display: block; position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 2; pointer-events: none; white-space: nowrap;
    padding: 7px 12px; border-radius: 999px; font-size: 13px; background: rgba(13, 16, 19, 0.82); border: 1px solid #2c343c; color: #e9e6df;
  }
  .viewer.touch.engaged .touch-hint, .viewer.touch.fullpage .touch-hint { display: none; }
  .viewer.touch.engaged:not(.fullpage) .touch-done {
    display: inline-flex; align-items: center; position: absolute; top: 8px; right: 8px; z-index: 2; min-height: 44px; padding: 0 14px;
    appearance: none; border: 1px solid #2c343c; border-radius: 999px; background: rgba(13, 16, 19, 0.88); color: #fff; font: inherit; font-size: 14px; font-weight: 600;
  }
  .viewer.touch.engaged:not(.fullpage) canvas { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 14px 14px 0 0; }
}

/* ---- The page around the model, on phones (mobile-page.js) ----
   What sits above the model is kept short so the model starts on the first screen: the breadcrumb
   and the page details take one line each and the lead paragraph three, with the rest a tap away.
   The header is one 48 px row (brand, search, menu; the regions live in the menu) and the region
   bar under it scrolls sideways: its links get a 44 px tap area, the current one is scrolled into
   view, and a fade at an edge says there is more that way. */
.lead-more { display: none; }
@media (max-width: 620px) {
  .site-head > .wrap { height: 48px; gap: 4px; }
  .site-head .brand { font-size: 16.5px; }
  .site-head .brand img { width: 28px; height: 28px; }
  .site-head .search-open { flex: none; min-width: 0; width: 44px; height: 44px; margin-left: auto; padding: 0; justify-content: center; border: 0; background: none; }
  .site-head .search-open svg { width: 20px; height: 20px; color: var(--ink); }
  .site-head .search-open .label, .site-head .search-open kbd { display: none; }
  .site-head .menu summary { width: 44px; height: 44px; }
  .site-head .lang-menu summary { padding: 4px 8px; font-size: 12px; }
  .site-head .lang-panel { position: fixed; top: 48px; right: 8px; }
  .site-head .menu-panel { position: fixed; top: 48px; left: 0; right: 0; width: auto; max-height: calc(100dvh - 48px); border-width: 1px 0; border-radius: 0 0 14px 14px; padding: 4px 20px 18px; }
  .site-head .subnav .wrap { height: 44px; gap: 20px; }
  .site-head .subnav a { position: relative; }
  .site-head .subnav a::before { content: ''; position: absolute; left: -6px; right: -6px; top: 0; bottom: 0; }
  .site-head .subnav nav.fade-r { -webkit-mask-image: linear-gradient(to left, transparent, #000 40px); mask-image: linear-gradient(to left, transparent, #000 40px); }
  .site-head .subnav nav.fade-l { -webkit-mask-image: linear-gradient(to right, transparent, #000 40px); mask-image: linear-gradient(to right, transparent, #000 40px); }
  .site-head .subnav nav.fade-l.fade-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); mask-image: linear-gradient(to right, transparent, #000 40px, #000 calc(100% - 40px), transparent); }

  .crumbs { padding-top: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .v2-head .lead { font-size: 17.5px; }
  .v2-head .lead.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; cursor: pointer; }
  .v2-head .lead.clamp + .lead-more { display: block; margin: 0; padding: 4px 0 6px; font-size: 14.5px; font-weight: 600; color: var(--accent); cursor: pointer; }
  .v2-meta { flex-wrap: nowrap; white-space: nowrap; overflow: hidden; margin-top: 6px; }
  .v2-meta > :first-child { display: none; }           /* the date gives way on a phone; reading time, the free note and Sources stay */
  .v2-meta > :nth-child(2)::before { content: none; }
  .v2-head { margin-bottom: 10px; }

  /* tables: a label column that never squeezes the value into a few letters per line */
  .facts th { width: 36%; }
  .facts th, .facts td { padding: 9px 10px; overflow-wrap: anywhere; }
}

/* Data-saver: the model waits for this button (touch.js, prepareForDevice). */
.viewer-status .load-model { appearance: none; min-height: 48px; padding: 0 20px; border-radius: 999px; border: 1px solid #3a444d; background: rgba(13, 16, 19, 0.88); color: #fff; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; }
