/* ---------- phones, tablets and small laptops (loaded last; the header folds at 1140px, the rest at 1020px) ---------- */
.nav-toggle { display: none; }

@media (max-width: 1140px) {
  /* header: one slim row (logo, menu, primary action); the nav opens as a panel instead of a second row.
     The full header needs about 1,115px (logo + eight links + button), so it folds before it can spill sideways. */
  .top-you { display: none !important; }
  .top-in { flex-wrap: nowrap; min-height: 56px; padding-block: 6px; gap: 10px; }
  .top-in > .btn { margin-left: auto; min-height: 40px; padding: 8px 14px; font-size: 0.9rem; }
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px; margin-right: -6px;
    appearance: none; -webkit-appearance: none; padding: 0;
    border: 1px solid var(--ink); border-radius: 10px; background: var(--ink); color: #fff; cursor: pointer;
  }
  .nav-toggle svg { display: block; width: 22px; height: 22px; color: inherit; }
  .nav-toggle svg path { stroke: currentColor; }
  .nav-toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
  .nav-toggle .x { display: none; }
  .top.open .nav-toggle .x { display: block; }
  .top.open .nav-toggle .bars { display: none; }
  .top-in .nav {
    display: none; position: absolute; left: 0; right: 0; top: 100%; width: auto; margin: 0; order: 0;
    flex-direction: column; gap: 0; padding: 6px var(--gutter) 14px; overflow: visible;
    background: #fff; border-bottom: 1px solid var(--line); box-shadow: 0 14px 30px rgba(20, 40, 59, 0.12);
    max-height: calc(100dvh - 56px); overflow-y: auto;
  }
  .top.open .nav { display: flex; }
  .top-in .nav a { padding: 13px 4px; font-size: 1.05rem; border-bottom: 1px solid var(--line-2); }
  .top-in .nav a:last-child { border-bottom: 0; }
  .top-in .nav a.on::after { left: 0; right: auto; top: 12px; bottom: 12px; width: 3px; height: auto; }
  .top-in .nav a.on { padding-left: 14px; }
}

@media (max-width: 1020px) {
  /* the brass invitation bar scrolls away with the page instead of riding under the header */
  .sample-bar, .story-bar { position: static; top: auto; }

  /* sticky side panels become ordinary blocks on narrow screens */
  .aw-preview, .ar-leaders, .aside-stick, .qaside, .toc, .lab-panel, .pl-side { position: static; top: auto; }
}

@media (max-width: 640px) {
  :root { --gutter: 16px; }
  html, body { overflow-x: hidden; }
  .brand-logo img { height: 28px; }
  .top-in > .btn { padding: 8px 12px; font-size: 0.86rem; }

  .sample-bar, .story-bar { padding: 9px var(--gutter); font-size: 0.86rem; line-height: 1.45; text-align: left; }
  .story-bar .story-go { white-space: nowrap; }

  /* type that was sized for desktop heroes */
  h1 { font-size: clamp(1.7rem, 8vw, 2.3rem) !important; line-height: 1.15 !important; overflow-wrap: anywhere; }
  h2 { font-size: clamp(1.35rem, 6.2vw, 1.8rem) !important; line-height: 1.2 !important; overflow-wrap: anywhere; }
  h3 { overflow-wrap: anywhere; }
  p, li, dd, td { overflow-wrap: anywhere; }

  /* buttons wrap their label and fill the row instead of pushing past the edge */
  .btn { white-space: normal; text-align: center; max-width: 100%; }
  main .btn-row, main .actions, main .cta-row { flex-wrap: wrap; }

  /* media and wide things never exceed the screen */
  main img, main svg, main video, main canvas { max-width: 100%; height: auto; }
  main pre, main code { white-space: pre-wrap; overflow-wrap: anywhere; }
  main table { display: block; max-width: 100%; overflow-x: auto; }

  /* home boards: long titles get the full width; the badge sits under them */
  .pz-row-main b { overflow-wrap: anywhere; }
  .pz-board li a:has(.pz-first) { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .pz-board li a .pz-first { justify-self: start; }
  /* leaderboard rows: name and "from our team" stack instead of colliding with the score */
  .rm-who { flex-direction: column; align-items: flex-start; gap: 3px; white-space: normal; }

  .toast { left: 12px; right: 12px; bottom: 16px; transform: translate(0, 24px); text-align: center; }
  .toast.on, .toast.show { transform: none; }
}

/* phones: the brass invitation keeps its question and its button on one short line; the longer sentence is still
   read out by screen readers, it just doesn't take a third of the first screen */
@media (max-width: 640px) {
  .story-bar { flex-wrap: nowrap; justify-content: space-between; gap: 10px; padding-block: 8px; }
  .story-bar .story-text { font-size: 0; line-height: 0; }
  .story-bar .story-text b { font-size: 0.86rem; line-height: 1.35; display: block; }
  .story-bar .story-go { padding: 8px 14px; font-size: 0.86rem; }
}

