/* Shared small-screen adjustments. Desktop typesetting and artwork stay with noir.css. */
@media screen and (max-width: 768px) {
  :root { --pad: clamp(14px, 4.3vw, 28px); }
  .top .wrap { flex-wrap: wrap; gap: 3px 8px; padding-block: 5px; }
  .top .wrap > a, .top nav a {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; min-width: 44px;
  }
  .top .brand { justify-content: flex-start; }
  .top .brand b { font-size: 18px; }
  .top img { width: 32px; height: 32px; }
  .top nav { flex-wrap: wrap; justify-content: end; gap: 0 4px; font-size: 14px; }
  .top nav a { padding: 5px 9px; line-height: 1.3; }
  .top nav a[aria-current="page"] { color: var(--gold); text-decoration: underline; }
  .disc { font-size: 11px; line-height: 1.5; }

  /* Keep long product names, search results and source titles readable, not ellipsized. */
  main.wrap, .wx-copy, .pi-body, .pi-heading > *, .g > span,
  .wx-reads > *, .card, .info-card, .episode-reader { min-width: 0; overflow-wrap: anywhere; }
  .wx-track { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wx-track a { min-height: 44px; text-align: center; line-height: 1.35; }
  .wx-cover { height: auto; }
  .wx-copy .wx-btn, .pi-strong { max-width: 100%; white-space: normal; }
  .wx-btn, .pi-action, .pi-back, .pi-tools button, .pi-jumps a,
  .sns a, .pager a, .teaser-link, .memory .buy, #visit-settings, footer .wrap a,
  .wx-more summary, .wx-shop summary, .pi-more summary { min-height: 44px; }
  .pi-jumps a, footer .wrap a, .memory .buy { display: inline-flex; align-items: center; }
  footer .wrap a { padding-inline: 3px; }
  .pi-tools button { min-width: 44px; }
  .pi-search { flex-wrap: wrap; }
  .pi-search input { flex: 1 1 9em; min-height: 44px; }
  .pi-search button, .pi-filters button { max-width: 100%; white-space: normal; }
  .pi-tags li { max-width: 100%; }

  article :is(img, iframe, video), .toon img { max-inline-size: 100%; }
  article .toon img { height: auto; }
  .info-card > h2:first-child { margin-top: 0; }
  .info-card ul, .episode-reader ol { padding-inline-start: 1.4em; }
  .episode-reader dd { margin-inline-start: 1em; }
  .info-card li + li { margin-top: .45em; }
  .info-card > p:last-child > a:only-child { display: inline-flex; align-items: center; min-height: 44px; }

  #visit-stats {
    inset-inline-end: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    max-height: 65vh; max-height: 65dvh; overflow-y: auto;
    overscroll-behavior: contain; overflow-wrap: anywhere;
  }
  #visit-stats div { flex-wrap: wrap; }
  #visit-stats button { flex: 1 1 5em; min-height: 44px; }
  /* Avoid a second floating panel under the privacy choice; no JS/state changes. */
  body:has(#visit-stats:not([hidden])) .wx-weather-dock { visibility: hidden; }
}

@media screen and (max-width: 580px) {
  /* A dedicated navigation row avoids shrinking the wordmark or hiding the new fourth link. */
  .top .wrap { column-gap: 5px; }
  .top nav {
    flex: 1 0 100%; justify-content: start; gap: 0;
    border-top: 1px solid var(--line); margin: 0;
  }
  .top nav a { flex: 1 1 max-content; padding-inline: 7px; text-align: center; }
  .top nav a:focus-visible { outline-offset: -2px; }
  .wx-track a { flex-direction: column; gap: 1px; padding: 5px 2px; }
  .wx-copy .wx-btn { justify-content: space-between; }
  .wx-archive .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card small { font-size: 12px; }

  /* Related-item CTAs sit below the copy rather than taking a third of the reading column. */
  .gear .g { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 6px 9px; }
  .gear .go { grid-column: 2; justify-self: start; margin: 0; }
  .pi-heading, .pi-jumps, .pager, .sns { gap: 8px; }
  .pi-card { grid-template-columns: clamp(64px, 21vw, 100px) minmax(0, 1fr); }
  .pi-body { padding: 10px 12px; }
  article { padding: clamp(12px, 3.8vw, 20px); }
  article h2 { margin-top: 1.3em; }
  article.memory .option, article.memory .memo { padding: 12px 14px; }
  article.memory .steps li { padding-inline-start: 32px; }
  .info-card .note { line-height: 1.8; }
  #visit-stats {
    inset-inline-start: max(10px, env(safe-area-inset-left, 0px));
    inset-inline-end: max(10px, env(safe-area-inset-right, 0px));
    width: auto; max-width: none; padding: 12px 14px;
  }
}

@media screen and (max-width: 360px) {
  .wx-copy { width: 100%; padding-inline: 16px; }
  .wx-copy .wx-btn { display: flex; width: fit-content; }
  .wx-archive .grid { gap: 8px; }
}
