/* SD Code site — mobile and tablet correction layer.
   Loaded after the main stylesheet. Every rule here exists because the desktop
   layout broke below 900px: oversized headings, a nav that could not fit, wide
   tables and code blocks that pushed past the viewport, and reveal-wrapped
   sections that stayed invisible until a scroll event fired. */

:root {
  --tap: 44px;
  --page-x: 24px;
}

/* ---------- tablet and phone ---------- */
@media (max-width: 900px) {
  /* Content must never depend on a scroll event to become visible.
     The desktop animation is kept; below this width it is disabled so a tall
     card cannot stay at opacity 0 while it waits for 15% of itself to scroll in. */
  .reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  :root {
    --page-x: 20px;
  }

  .wrap {
    width: min(1180px, 100% - (var(--page-x) * 2));
  }

  .nav-inner {
    height: 60px;
    gap: 12px;
  }

  .nav-links {
    top: 60px;
    max-height: calc(100dvh - 60px);
    overflow-y: auto;
    padding: 10px var(--page-x) 18px;
    /* The desktop drawer colour is 97% opaque, which let page content show
       through the menu on a phone. */
    background: #060b15;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.72);
    border-bottom: 1px solid var(--line-strong);
  }

  .nav-links.open::before {
    content: '';
    position: fixed;
    inset: 90px 0 0;
    background: rgba(3, 6, 12, 0.55);
    z-index: -1;
    pointer-events: none;
  }

  .nav-link {
    padding: 12px 10px;
    min-height: var(--tap);
    font-size: 1rem;
    border-radius: 10px;
  }

  .nav-right .btn.small {
    height: 40px;
    padding: 0 14px;
    font-size: 0.88rem;
  }

  .menu-toggle {
    width: var(--tap);
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .page-head {
    padding: 34px 0 20px;
  }

  .page-head p {
    font-size: 1rem;
  }

  h1 {
    font-size: clamp(1.8rem, 7.2vw, 2.5rem);
  }

  h2 {
    font-size: clamp(1.35rem, 5.2vw, 1.85rem);
  }

  .hero-grid {
    gap: 22px;
  }

  /* Text before the screenshot: a full-width app mock-up as the first screen
     pushed the headline off a phone display. */
  .hero-shot {
    order: 0;
  }

  .hero-shot img,
  .hero-shot .shot-frame img {
    max-height: 300px;
    width: 100%;
    object-fit: cover;
    object-position: top left;
  }

  .hero-grid h1 {
    font-size: clamp(1.85rem, 6.4vw, 2.4rem);
  }

  .section {
    padding: 34px 0;
  }

  .section-head {
    margin-bottom: 16px;
  }

  .card,
  .glass,
  .download-card {
    padding: 18px 18px;
    border-radius: var(--radius-lg);
  }

  /* Wide tables and code blocks get their own scroll area instead of
     stretching the page. A bare <pre> with long lines was the cause of the
     768px overflow on the documentation page. */
  .table {
    min-width: 520px;
  }

  div:has(> .table),
  div:has(> table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  pre > code {
    display: block;
    min-width: max-content;
  }

  .prose pre,
  .demo-code {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.78rem;
  }

  .demo-body {
    min-height: 0;
  }

  .demo-code {
    padding: 12px 14px;
    line-height: 1.6;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 22px;
  }

  .footer {
    padding: 30px 0 26px;
  }

  .btn {
    height: var(--tap);
    padding: 0 18px;
  }

  .footer-bottom {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Cookie notice: buttons wrap to their own full-width row. */
  .cookie-banner {
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .cookie-banner p {
    flex: 1 1 100%;
    font-size: 0.84rem;
  }

  .cookie-banner .btn {
    flex: 1 1 auto;
  }

  /* Long identifiers and hashes stay inside the column. */
  code,
  .hash,
  .meta-row {
    overflow-wrap: anywhere;
  }

  .meta-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .chip {
    white-space: normal;
  }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  :root {
    --page-x: 16px;
  }

  .nav-inner {
    height: 56px;
    gap: 8px;
  }

  .nav-links {
    top: 56px;
  }

  .nav-links.open::before {
    inset: 56px 0 0;
  }

  .brand {
    font-size: 1rem;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .nav-right {
    gap: 6px;
  }

  .nav-right .btn.small {
    height: 38px;
    padding: 0 12px;
    font-size: 0.82rem;
  }

  .page-head {
    padding: 26px 0 16px;
  }

  .hero-grid h1 {
    font-size: clamp(1.7rem, 7.8vw, 2.05rem);
  }

  h1 {
    font-size: clamp(1.55rem, 6.6vw, 1.95rem);
  }

  .hero-actions,
  .cta-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .hero-actions .btn,
  .cta-actions .btn {
    width: 100%;
  }

  .grid.cols-2,
  .grid.cols-3 {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .footer-grid {
    grid-template-columns: 1fr;
    gap: 26px;
  }

  .footer-bottom {
    flex-direction: column;
    align-items: flex-start;
    font-size: 0.8rem;
  }

  .stat-row,
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  .table {
    min-width: 520px;
    font-size: 0.84rem;
  }

  .table th,
  .table td {
    padding: 10px 12px;
  }

  .card,
  .glass,
  .download-card {
    padding: 16px;
  }

  .download-card .btn.primary {
    width: 100%;
  }

  .faq-q {
    padding: 14px 0;
    min-height: var(--tap);
    font-size: 0.98rem;
  }

  .prose h2 {
    font-size: 1.22rem;
  }

  .prose ul,
  .prose ol {
    padding-left: 18px;
  }
}

/* ---------- very small phones ---------- */
@media (max-width: 400px) {
  .nav-right .btn.small span,
  .nav-right .btn.small .btn-label {
    display: none;
  }

  .stat-row,
  .stats {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: clamp(1.6rem, 8.6vw, 2rem);
  }
}

/* Anchor links must clear the sticky header. */
html {
  scroll-padding-top: 72px;
}

@media (max-width: 640px) {
  html {
    scroll-padding-top: 64px;
  }
}

/* Visible focus for keyboard users, which the glass panels can swallow. */
a:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid #7fb3ff;
  outline-offset: 2px;
  border-radius: 8px;
}
