/* Atoms.world — phone layout.  Linked LAST on every page, so it only ever overrides.
 *
 * The desktop games are a full-screen 3-D stage with floating side panels (#controls on the
 * left, one info panel on the right, a hint bar at the bottom).  That cannot fit 390 px: the
 * panels land on top of each other and on the molecule.  On a phone this sheet keeps the stage
 * pinned at the top of the screen and lets the panels stack and scroll underneath it, so the
 * molecule stays in view while you change a setting.  Nothing here touches what a control does.
 *
 * Wider than 820 px (laptops, tablets in landscape) none of this applies.  A phone held
 * sideways gets the stage on the left and the panels in a scrolling column on the right.
 *
 * Panels are laid out with position:relative here; each page's stageBand() ignores any panel
 * that is not position:absolute, so the camera framing is not thrown off by stacked panels.
 */

/* ===== 1. top bar: one swipeable row (every page) ===================================== */
@media (max-width: 820px) {
  .topnav{gap:6px;padding:0 8px 0 12px;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;
    -webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;
    -webkit-mask-image:linear-gradient(90deg,#000 0,#000 calc(100% - 28px),transparent);
            mask-image:linear-gradient(90deg,#000 0,#000 calc(100% - 28px),transparent)}
  .topnav::-webkit-scrollbar{display:none}
  .topnav{background:#090d16}                      /* fully opaque: scrolled content must not show through */
  .topnav .grow,.topnav .navlbl{display:none}
  .topnav a.logo{flex:0 0 auto;font-size:16px;margin-right:4px}
  .topnav .navgrp{flex:0 0 auto}
  .topnav a.nav{white-space:nowrap;padding:8px 10px;font-size:13.5px}
  .topnav a.nav.active::after{display:none}      /* the underline would sit outside the clipped bar */
  .topnav .theme-toggle{flex:0 0 auto}
  .topnav::after{content:"";flex:0 0 22px}       /* room to swipe the last link clear of the fade */
  /* phones scroll by touch; the themed desktop scrollbar would show as a dark strip */
  html,body{scrollbar-width:none}
  html::-webkit-scrollbar,body::-webkit-scrollbar{display:none}
  html:has(> body > #app){scroll-padding-top:calc(56px + var(--stage-h) + 12px)}   /* focus/anchor scrolls stop below the pinned stage */
  /* one-line labels and buttons must not break in two: keep the label whole, let the control shrink */
  .field{white-space:nowrap}
  .field select{min-width:0;flex:1 1 0;max-width:62%}
  #playSpec,#torrandom,#resetbtn,#refinebtn{white-space:nowrap}
  #playSpec{flex:0 0 auto}
  #torrandom,#resetbtn{padding-left:8px;padding-right:8px;font-size:13px}
  #refinebtn{font-size:12px;padding-left:8px;padding-right:8px}
  /* home page section headings: the title stays whole on its line, the description drops below it */
  .grp-h{flex-wrap:wrap;row-gap:1px;padding-left:18px;padding-right:18px}
  .grp-h h2{flex-wrap:wrap;column-gap:9px;row-gap:0;font-size:19px;white-space:nowrap}
  .grp-h .d{flex:1 1 100%;font-size:12px}
  /* when text must wrap (headings, tab captions), break it evenly instead of leaving one orphan word */
  h1,h2,h3,.tname,.tab{text-wrap:balance}
  /* iOS zooms the page when a field under 16 px gets focus */
  select,input[type=text],input[type=number],input[type=search],textarea{font-size:16px}
}

/* ===== 2. games and tools, portrait phone: stage on top, panels stacked below ========= */
@media (max-width: 820px) {
  :root{--stage-h:clamp(250px,42vh,420px)}
  @supports (height:1dvh){:root{--stage-h:clamp(250px,42dvh,420px)}}

  /* the page itself scrolls; the stage does not */
  html:has(> body > #app), html:has(> body > #app) body{
    overflow-x:hidden !important;overflow-y:auto !important;height:auto !important}
  body:has(> #app){display:flex;flex-direction:column;
    padding:calc(56px + var(--stage-h) + 6px) 0 32px !important}

  /* the 3-D stage: pinned under the top bar, opaque so scrolled panels slide behind it */
  body > #app{inset:56px 0 auto 0 !important;height:var(--stage-h) !important;z-index:8 !important;
    background:linear-gradient(180deg,#0c1424,#080c14);border-bottom:1px solid var(--line)}

  /* every floating panel becomes an ordinary block in the column */
  body > #app ~ .panel{position:relative !important;inset:auto !important;left:auto !important;
    right:auto !important;top:auto !important;bottom:auto !important;width:auto !important;
    max-width:none !important;max-height:none !important;overflow:visible !important;
    transform:none !important;margin:10px 12px 0 !important;order:2}
  body > #app ~ #controls{order:3}                /* what is happening first, the settings after */
  body > #app ~ #hud{order:1;pointer-events:auto;text-align:left;font-size:12.5px;padding:9px 13px;
    line-height:1.45}

  /* the page scrolls by touch: no scrollbar (the themed one would show as a dark strip) */
  html:has(> body > #app){scrollbar-width:none}
  html:has(> body > #app)::-webkit-scrollbar{display:none}

  /* pieces that were positioned against the desktop viewport */
  #elemMenu{position:fixed !important}
  body > .status-pill{position:fixed !important;top:64px !important;z-index:9 !important}
  /* captions that sat over the molecule: small, along the bottom edge of the stage */
  #stagecap{top:auto !important;bottom:8px !important;max-width:calc(100% - 24px) !important;
    width:max-content;font-size:12px !important;padding:5px 11px !important;line-height:1.35}
  /* the "Learn" bubble: a compact button in the stage's top-right corner instead of
     floating over the panel text */
  #learnDock{top:62px !important;bottom:auto !important;right:8px !important;
    flex-direction:column-reverse !important;max-width:calc(100vw - 16px)}
  #learnDock [class*="hint"]{display:none !important}
  #learnDock [class*="dock-btn"]{padding:6px !important}      /* just the round book icon */
  #learnDock [class*="dock-lbl"]{display:none !important}
  #learnDock [class*="dock-panel"]{max-height:calc(100vh - 150px)}

  /* thumbs: bigger targets inside the panels (not the tiny round "?" help buttons) */
  body > #app ~ .panel button:not(.hq),body > #app ~ .panel select,
  body > #app ~ .panel input[type=number],body > #app ~ .panel input[type=text]{min-height:42px}
}

/* ===== 3. games and tools, phone held sideways: stage left, panels in a column right == */
@media (orientation:landscape) and (max-height:520px) and (max-width:1100px) {
  :root{--col-w:42%}
  html:has(> body > #app), html:has(> body > #app) body{
    overflow-x:hidden !important;overflow-y:auto !important;height:auto !important}
  body:has(> #app){display:flex;flex-direction:column;
    padding:56px 0 24px calc(100% - var(--col-w)) !important}
  body > #app{inset:56px var(--col-w) 0 0 !important;height:auto !important;z-index:8 !important;
    background:linear-gradient(180deg,#0c1424,#080c14)}
  body > #app ~ .panel{position:relative !important;inset:auto !important;left:auto !important;
    right:auto !important;top:auto !important;bottom:auto !important;width:auto !important;
    max-width:none !important;max-height:none !important;overflow:visible !important;
    transform:none !important;margin:8px 10px 0 8px !important;order:2}
  body > #app ~ #controls{order:3}
  body > #app ~ #hud{order:1;pointer-events:auto;text-align:left;font-size:12px;padding:8px 12px}
  html:has(> body > #app){scrollbar-width:none}
  html:has(> body > #app)::-webkit-scrollbar{display:none}
  #elemMenu{position:fixed !important}
  body > .status-pill{position:fixed !important;top:64px !important;left:30% !important;z-index:9 !important}
  #stagecap{top:auto !important;bottom:8px !important;max-width:calc(100% - 24px) !important;
    width:max-content;font-size:11.5px !important;padding:4px 10px !important}
  #learnDock{top:62px !important;bottom:auto !important;right:calc(var(--col-w) + 8px) !important;
    flex-direction:column-reverse !important}
  #learnDock [class*="hint"]{display:none !important}
  #learnDock [class*="dock-btn"]{padding:6px !important}
  #learnDock [class*="dock-lbl"]{display:none !important}
  .topnav{overflow-x:auto;overflow-y:hidden;scrollbar-width:none}
  .topnav::-webkit-scrollbar{display:none}
}
