/* Waei v4 — mobile layout and usability fixes */
:root { scroll-padding-top: 18px; }
html { -webkit-text-size-adjust: 100%; }
body { overflow-wrap: anywhere; }
img, video, iframe { max-width: 100%; }
button, input, select, textarea { font: inherit; }
button, a { touch-action: manipulation; }
:focus-visible { outline: 3px solid #1687c9; outline-offset: 3px; }

/* Keep the homepage header and title in normal flow on phones. */
@media (max-width: 700px) {
  nav { position: relative !important; top: auto !important; }
  nav .wrap { min-height: 60px; height: auto; padding-block: 10px; overflow: visible; }
  nav .links { flex: 1 1 auto; min-width: 0; max-width: calc(100vw - 100px); overflow-x: auto; overscroll-behavior-inline: contain; }
  .hero { padding-top: 28px !important; overflow: visible; }
  .hero .wrap { display: flex !important; flex-direction: column; align-items: stretch; gap: 16px; }
  .hero .tx { width: 100%; padding: 0 !important; }
  .hero h1 { font-size: clamp(30px, 8vw, 39px) !important; line-height: 1.35 !important; max-width: 100%; overflow-wrap: normal; }
  .hero p { max-width: none; font-size: clamp(17px, 4.4vw, 20px); line-height: 1.85; margin: 14px 0 22px; }
  .btns { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
  .btns .btn { width: 100%; min-height: 48px; justify-content: center; text-align: center; }
  .hero .char { display: flex !important; flex-direction: column; align-items: center; gap: 10px; width: 100%; margin: 0; padding: 0; }
  .hero .bubble { position: relative !important; inset: auto !important; transform: none !important; order: 0; display: block; width: fit-content; max-width: min(340px, 100%); margin: 0 auto 4px; padding: 12px 18px; white-space: normal !important; overflow-wrap: break-word; text-align: center; font-size: 15px; line-height: 1.65; z-index: 1; }
  .stage { width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; }
  .stage img { display: block; width: auto; height: clamp(250px, 72vw, 330px) !important; max-width: 100%; object-fit: contain; }
  .ctrl { justify-content: center; flex-wrap: wrap; gap: 10px; }
  section { scroll-margin-top: 16px; }
  .frame { aspect-ratio: 4 / 3; }
  .video-poster-link, .video-poster-link img { min-height: 190px; }
  .demos, .grid3 { grid-template-columns: minmax(0, 1fr) !important; }
  .demo .shot { height: auto; aspect-ratio: 4 / 3; }
  .demo .shot img { height: 100%; }
  .card, .ph { min-width: 0; padding: 20px; }
  footer .wrap { gap: 14px; }
}
@media (max-width: 380px) {
  .wrap, .hero .wrap { padding-inline: 14px; }
  nav .wrap { padding-inline: 8px; gap: 8px; }
  nav img { height: 28px; }
  nav .links { max-width: calc(100vw - 80px); gap: 10px; font-size: 12px; }
  .hero h1 { font-size: 29px !important; }
  .hero .bubble { max-width: 100%; font-size: 14px; }
  .stage img { height: 250px !important; }
}

/* Secondary pages: keep floating Waei and home navigation away from screen edges. */
.waei-home-link { inset-block-start: max(10px, env(safe-area-inset-top)); }
#wb { bottom: max(12px, env(safe-area-inset-bottom)) !important; left: max(10px, env(safe-area-inset-left)) !important; }
@media (max-width: 520px) {
  #wb .av { width: 62px !important; height: 82px !important; }
  #wb .bb { max-width: min(235px, calc(100vw - 92px)) !important; margin-bottom: 40px !important; font-size: 13px !important; padding: 10px 12px !important; }
  #wb .bb .row { gap: 5px; }
  #wb .bb button { min-height: 34px; }
  .waei-home-link { max-width: calc(100vw - 24px); }
  .waei-search .waei-search-row { flex-direction: column; }
  .waei-search button { width: 100%; min-height: 44px; }
  main, .in { padding-bottom: max(28px, env(safe-area-inset-bottom)); }
}

/* Library topics are long print pages; on phones allow natural height and readable QR grids. */
@media screen and (max-width: 820px) {
  section.page { max-width: 100%; }
  section.page.topic.ix { min-height: 0 !important; height: auto !important; overflow: visible !important; }
  .qgrid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .q { min-width: 0; overflow-wrap: anywhere; }
  .q svg { width: min(100%, 105px); height: auto; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  #wb, .waei-home-link, .waei-search { display: none !important; }
}
