/* ═══════════════════════════════════════════════════════════════════════
   MOBILE & ACCESSIBILITY LAYER — loaded on every public page via
   partials/_head_common.html, together with js/mobile-nav.js.

   It only *adjusts* the existing design for small screens and keyboards:
   no sections, animations or features are removed. Breakpoints match
   style.css (768px = phone/tablet nav switch, 480px = small phones).
   Selectors are prefixed with `html` where they must outrank a page's own
   inline <style> block, which loads after this file.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  --tap: 44px;                       /* minimum touch target (WCAG 2.5.5 / Apple HIG) */
  --gutter: 20px;                    /* page side padding on phones */
  --focus-ring: #7DD3FC;
  --fab-clearance: 96px;             /* room left under the last content for the floating buttons */
}
[data-theme="light"] { --focus-ring: #0369A1; }

/* ── 1. Never scroll sideways ─────────────────────────────────────────── */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { max-width: 100%; }
body { overflow-wrap: break-word; }
img, video, canvas, iframe, svg:not([width]) { max-width: 100%; }
img, video { height: auto; }
pre, code, kbd, samp { overflow-wrap: anywhere; }
pre { max-width: 100%; overflow-x: auto; }
table { max-width: 100%; }
/* Grid/flex children default to min-width:auto, which lets one long word or URL widen a whole column. */
html .container > *, html .ct-split > *, html .hero-container > * { min-width: 0; }

/* ── 2. Keyboard focus that is visible on both themes ─────────────────── */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}
/* Mouse clicks keep the existing look; only keyboard focus draws the ring. */
:focus:not(:focus-visible) { outline: none; }

/* ── 3. Navigation ─────────────────────────────────────────────────────── */
/* Hamburger → animated "X" while the drawer is open (state set by js/mobile-nav.js). */
.hamburger span { transition: transform .25s ease, opacity .2s ease; transform-origin: center; }
.hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.is-open span:nth-child(2) { opacity: 0; }
.hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Small tablets (≤900px, where the homepage links + CTA no longer fit) and touch tablets up to 1024px
   (iPad landscape — the desktop links are only 36px tall) use the same drawer as phones.
   Mirrors the ≤768px drawer rules in style.css; /solutions already collapses at 900px. */
@media (max-width: 900px), (max-width: 1024px) and (pointer: coarse) {
  html .nav-menu { display: none; }
  html .hamburger { display: flex; }
  html .nav-desktop-only { display: none; }
  html .nav-menu.open {
    display: flex; flex-direction: column; position: fixed; top: var(--nav-h, 64px); left: 0; right: 0; gap: 4px; z-index: 899;
    background: linear-gradient(180deg, rgba(12,16,30,.99), rgba(8,11,22,.99));
    -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
    padding: 18px 20px 22px; border-bottom: 1px solid rgba(125,211,252,.18); box-shadow: 0 24px 50px rgba(0,0,0,.5);
  }
  [data-theme="light"] .nav-menu.open { background: rgba(245,249,255,.98); }
  html .nav-menu.open .nav-mobile-only { display: block; margin-top: 10px; text-align: center; }
  html .nav-menu.open .nav-item { padding: 11px 14px; font-size: 14.5px; }
  html .nav-menu .nav-item:not(.nav-priya-link):not(.nav-connect-btn)::after { display: none; }
  html .nav-dropdown-panel, html .nav-more-panel {
    position: static; transform: none; width: 100%; opacity: 1; visibility: visible; pointer-events: auto;
    max-height: 0; overflow: hidden; padding: 0; border: none; box-shadow: none; background: transparent;
  }
  html .nav-dropdown.open .nav-dropdown-panel { transform: none; left: auto; max-height: 400px; padding: 4px 0 4px 8px; }
  html .nav-dropdown-menu { position: static; transform: none !important; opacity: 1; pointer-events: all; box-shadow: none;
    background: transparent; border: none; padding: 0 0 0 14px; display: none; min-width: unset; }
  html .nav-dropdown.open .nav-dropdown-menu { display: flex; flex-direction: column; }
}

@media (max-width: 900px), (max-width: 1024px) and (pointer: coarse) {
  html .nav-inner { padding: 0 max(16px, env(safe-area-inset-left)); gap: 12px; }
  html .nav-actions { gap: 6px; }
  html .nav-brand { min-width: var(--tap); min-height: var(--tap); }
  html .theme-toggle,
  html .hamburger,
  html .nav-actions .nav-priya-link { width: var(--tap); height: var(--tap); min-width: var(--tap); min-height: var(--tap); }
  html .nav-actions .nav-priya-link { display: inline-flex; align-items: center; justify-content: center; padding: 0 !important; }

  /* The open drawer: scrolls on short screens, 44px rows, room for the iPhone home bar. */
  html .nav-menu.open {
    max-height: calc(100dvh - var(--nav-h, 64px));
    overflow-y: auto; overscroll-behavior: contain;
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
  html .nav-menu.open .nav-item,
  html .nav-menu.open .nav-dropdown-trigger,
  html .nav-menu.open .nav-dropdown-toggle { min-height: var(--tap); display: flex; align-items: center; }
  html .nav-menu.open .nav-dropdown-item,
  html .nav-menu.open .nav-dd-item { min-height: var(--tap); }
  /* Drawer open: the floating buttons would sit on top of the menu items. */
  html.nav-open #priyaBtn, html.nav-open .vnav-fab, html.nav-open .vnav-pill, html.nav-open .cmdk-fab { visibility: hidden; }
}

/* ── 4. Touch targets: every control at least 44 × 44px on touch / small screens ── */
@media (max-width: 768px), (pointer: coarse) {
  /* Already flex / inline-flex / buttons → a minimum height is enough to grow the box, content stays centred. */
  html .comment-submit, html .pg-run-btn, html .run-btn, html .pd-price-btn, html .pricing-cta, html .priya-job-btn,
  html #tabPaste, html #tabUpload, html .new-chat-btn, html .send-btn, html .tl-btn,
  html .card-link, html .pc-btn, html .namecard-social-btn, html .sol-related-chip, html .sol-cs-link,
  html .cs-link, html .sol-back, html .cs-back, html .pd-back, html .arch-back, html .bp-back, html .bp-ask-ai,
  html .learn-strip-btn, html .btn-admin-sm, html .btn-primary, html .btn-secondary, html .tl-switch a,
  html .cs-more .cs-stack a, html .sol-demo-btn, html .sol-cta-btn, html .jd-hero-full, html .hero-path {
    min-height: var(--tap);
  }
  html .tl-chip, html .qbtn, html .rtab, html .tab-btn, html .react-btn, html .filter-btn, html .sample-q { min-height: var(--tap); }
  html .chat-page-sidebar button { min-height: var(--tap); }
  html .chat-page-sidebar .clear-hist { min-width: var(--tap); }
  html .cs-build-similar a, html .cs-ask-ai a { min-height: var(--tap); display: inline-flex; align-items: center; }
  html .footer-link { min-width: var(--tap); }
  /* Text links that render as plain blocks: centre their text vertically in the taller box. */
  html .hire-card-cta, html .pricing-demo-link, html .stack-cta-actions .stack-see-projects, html .footer-link {
    display: flex; align-items: center; min-height: var(--tap);
  }
  html .pricing-demo-link { justify-content: center; }
  html .card-link { display: inline-flex; align-items: center; }
  html .footer-social a { min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center; justify-content: center; }
  html .banner-dismiss { width: var(--tap); height: var(--tap); flex-shrink: 0; margin: -2px -10px -2px 0; }
  html .vnav-fab { width: var(--tap); height: var(--tap); }
  html .vnav-pill-help { width: var(--tap); height: var(--tap); }
  html .jd-hero-close, html .tw-close { min-width: var(--tap); min-height: var(--tap); }
  html summary { min-height: var(--tap); }
  html input[type="range"] { min-height: var(--tap); }
}

/* ── 5. Forms ──────────────────────────────────────────────────────────── */
@media (max-width: 768px), (pointer: coarse) {
  /* 16px stops iOS Safari zooming into the page when a field is tapped. */
  html input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  html select, html textarea {
    font-size: 16px !important;
  }
  html input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not([type="file"]),
  html select { min-height: var(--tap); }
  html textarea { min-height: 96px; }
  html input[type="checkbox"], html input[type="radio"] { width: 20px; height: 20px; }
  /* Form rows that sit side by side on desktop stack on phones. */
  html .form-grid, html .comment-form-row { grid-template-columns: 1fr; }
}

/* ── 6. Typography & spacing on phones ─────────────────────────────────── */
@media (max-width: 768px) {
  html .container { padding-left: var(--gutter); padding-right: var(--gutter); }
}
@media (max-width: 480px) {
  :root { --gutter: 16px; }
  html .section { padding: 64px 0; }

  /* Hero: six lines of 40px display type → four, with calmer spacing. */
  html .hero { padding-top: 128px; padding-bottom: 64px; }
  html .hero-container { padding: 0 var(--gutter); }
  html .hero-heading { font-size: clamp(28px, 8.4vw, 36px); line-height: 1.16; letter-spacing: -.2px; }
  html .hero-tagline { font-size: 12.5px; line-height: 1.7; letter-spacing: 0; }
  html .hero-bio { font-size: 15.5px; line-height: 1.7; }
  html .hero-cta { flex-direction: column; align-items: stretch; gap: 12px; width: 100%; max-width: 360px; margin-left: auto; margin-right: auto; }
  html .hero-cta > .btn-primary, html .hero-cta > .btn-secondary { width: 100%; justify-content: center; text-align: center; min-height: 48px; }

  /* Section headings scale with the screen instead of jumping straight to their desktop size. */
  html .section-title { font-size: clamp(26px, 7.4vw, 34px); line-height: 1.2; }
  html .section-sub, html .section-desc { font-size: 15px; }

  /* Readable minimums: descriptive text never below 12px, badges and eyebrow labels never below 10.5px. */
  html .card-capability, html .pc-tagline, html .pricing-from, html .card-stack span, html .pc-stack span,
  html .pick-tagline, html .pick-sub, html .pick-card-hint { font-size: 12px; }
  html .card-cat, html .card-badge, html .pricing-card-category, html .pricing-badge, html .pc-stat-lbl,
  html .pc-badge-soon, html .pc-badge-live, html .priya-sc-tag, html .priya-sc-badge, html .pc-preview-url { font-size: 10.5px; }

  /* Project filter tabs: one swipeable row instead of wrapped / clipped labels. */
  html .proj-hd-right { width: 100%; min-width: 0; }
  html .filter-bar { max-width: 100%; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
                     scroll-snap-type: x proximity; overscroll-behavior-x: contain; }
  html .filter-bar::-webkit-scrollbar { display: none; }
  html .filter-btn { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; font-size: 13px; }

  /* Cards: one column, consistent radius and padding. */
  html .projects-grid, html .knowledge-grid, html .hire-grid, html .pricing-grid,
  html .resource-grid, html .learn-grid, html .proof-grid { grid-template-columns: 1fr !important; }
  html .project-card .card-links { flex-wrap: wrap; gap: 8px; }
  html .project-card .card-link { flex: 1 1 auto; justify-content: center; }
  html .pc-actions { flex-wrap: wrap; }
  html .pc-actions .pc-btn { flex: 1 1 140px; justify-content: center; }

  /* Footer: centred, stacked columns with tappable links. */
  html .footer-inner { flex-direction: column; text-align: center; gap: 10px; }
  html .footer-grid { grid-template-columns: 1fr !important; gap: 24px; text-align: left; }
  html .footer-bottom { flex-direction: column; gap: 8px; text-align: center; }
  html .footer-social { flex-wrap: wrap; }
}
@media (max-width: 360px) {
  html .hero { padding-top: 116px; }
  html .hero-heading { font-size: 27px; }
  html .availability-badge { font-size: 12px; padding-left: 14px; padding-right: 14px; white-space: nowrap; }
  html .open-banner { font-size: 10.5px; }
}

/* ── 7. Floating buttons (PRIYA chatbot orb, voice control) ───────────── */
@media (max-width: 768px) {
  /* Both buttons sit in the bottom corners, level with each other, clear of the iPhone home bar. */
  html .vnav-fab { left: max(14px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); }
  html .vnav-pill { left: calc(max(14px, env(safe-area-inset-left)) + 54px); bottom: calc(max(18px, env(safe-area-inset-bottom)) + 2px); }
  /* The last screen of every page gets enough empty space under it that the buttons never cover the footer links. */
  html body > footer, html body > .footer { padding-bottom: calc(var(--fab-clearance) + env(safe-area-inset-bottom)); }
  /* While typing, the on-screen keyboard pushes the buttons up over the field — hide them until it closes. */
  html.field-focus #priyaBtn, html.field-focus .vnav-fab, html.field-focus .vnav-pill, html.field-focus .cmdk-fab { visibility: hidden; }
  /* Chat panel open: the voice button would overlap its bottom-left corner. */
  html body:has(#priyaPanel.open) .vnav-fab, html body:has(#priyaPanel.open) .vnav-pill { visibility: hidden; }
  html #priyaPanel { max-height: calc(100dvh - 180px); }
}

/* ── 8. Reduced motion: keep animations, but calm them for people who ask ── */
@media (prefers-reduced-motion: reduce) {
  .hamburger span { transition: none; }
}
