/* ==========================================================================
   Responsive rules, mobile first overrides
   Tested against 320 / 375 / 425 / 768 / 1024 / 1440 / 1920
   ========================================================================== */

/* ---- ≤1024px: collapse nav, stack about ---- */
@media (max-width: 1024px) {
  .nav-links { display: none; }
  .hamburger { display: flex; }
  .hero-arcs { width: 440px; height: 440px; right: -140px; }
}

/* ---- ≤768px: compact single-screen layout — header to footer fits one
   viewport with no scroll. Uses dvh + flex so mobile browser toolbars
   (which resize the viewport) don't break the fit. ---- */
@media (max-width: 768px) {
  :root { --nav-h: 52px; }

  html, body { height: 100%; }
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto; /* safety net only — layout is sized to need no scrolling */
  }

  .container { padding-inline: var(--space-4); }

  .nav { flex: 0 0 auto; height: var(--nav-h); }
  .brand img { width: 26px; height: 26px; }
  .brand span { font-size: 0.92rem; }

  #main-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .hero {
    flex: 1 1 auto;
    padding: var(--space-3) 0;
    min-height: 0;
    overflow: visible;
  }
  .hero-arcs { opacity: 0.3; width: 220px; height: 220px; top: -40px; right: -60px; }
  .hero .container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 0;
    height: 100%;
  }

  .hero-head { margin-bottom: var(--space-3); text-align: center; flex: 0 0 auto; }
  .hero-head .eyebrow { display: none; }
  .hero-head p.lede { display: none; }
  .hero-head h1 { font-size: 1.4rem; margin-bottom: 0; }
  .hero-stats { display: none; }

  .converter { padding: var(--space-4); flex: 0 1 auto; min-height: 0; }
  .category-search { margin-bottom: var(--space-3); }
  .category-search input { padding: 10px 16px 10px 42px; font-size: 0.86rem; }
  .chip-scroll { gap: var(--space-2); padding-bottom: 2px; }
  .chip { padding: 7px 14px; font-size: 0.8rem; }

  .convert-grid { grid-template-columns: 1fr; gap: var(--space-2); }
  .swap-btn {
    margin: 0 auto;
    width: 36px; height: 36px;
    transform: rotate(90deg);
  }
  .swap-btn:hover { transform: rotate(270deg); }

  .convert-field label { margin-bottom: 4px; font-size: 0.66rem; }
  .field-box { padding: var(--space-3); }
  .field-box input[type="number"],
  .field-box input[type="text"] { font-size: 1.2rem; margin-bottom: var(--space-2); }
  .unit-select-trigger { padding: 8px 10px 8px 12px; font-size: 0.82rem; }
  .unit-option { padding: 12px 14px; font-size: 0.88rem; }

  .result-strip {
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: var(--space-2);
  }
  .result-readout { min-width: 0; overflow: hidden; }
  .result-readout .r-line1 {
    font-size: 0.64rem;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .result-readout .r-line2 { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .result-actions { flex-wrap: nowrap; }
  .result-actions .btn-sm { padding: 6px 10px; font-size: 0.72rem; }

  .shortcuts-hint { display: none; }

  .site-footer { flex: 0 0 auto; padding: var(--space-2) 0; }
  .footer-inner { flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px; }
  .footer-left, .footer-right { font-size: 0.66rem; }

  .fab-group { display: none; }

  .unit-select-panel { max-height: min(36vh, 240px); }
}

/* ---- ≤425px: tighter spacing ---- */
@media (max-width: 425px) {
  .converter { padding: var(--space-3); }
  .field-box input[type="number"],
  .field-box input[type="text"] { font-size: 1.1rem; }
  .list-card { flex-wrap: wrap; }
  .fab-group { right: 14px; bottom: 18px; }
  .hero-head h1 { font-size: 1.25rem; }
}

/* ---- ≤375px: extra-small phones ---- */
@media (max-width: 375px) {
  .hero-head h1 { font-size: 1.15rem; }
  .btn { padding: 11px 18px; font-size: 0.85rem; }
  .result-readout .r-line2 { font-size: 1rem; }
}

/* ---- ≤320px: smallest supported width ---- */
@media (max-width: 320px) {
  .container { padding-inline: var(--space-3); }
  .field-box input[type="number"],
  .field-box input[type="text"] { font-size: 1rem; }
  .hero-head h1 { font-size: 1.05rem; }
}

/* ---- ≥1440px: give the layout more breathing room ---- */
@media (min-width: 1440px) {
  .container { max-width: 1320px; }
  .hero-arcs { width: 720px; height: 720px; }
}

/* ---- ≥1920px: large / 4K displays ---- */
@media (min-width: 1920px) {
  .container { max-width: 1480px; }
  body { font-size: 1.05rem; }
}

/* ---- Landscape phones: reduce hero padding ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .hero { padding: var(--space-2) 0; }
  .hero-stats { display: none; }
  .page-loader .loader-mark { width: 40px; height: 40px; }
}

/* ---- Touch-friendly tap targets on coarse pointers ---- */
@media (pointer: coarse) {
  .btn, .chip, .unit-select-trigger, .unit-option, .list-card .lc-actions button { min-height: 44px; }
  .fab { width: 54px; height: 54px; }
}

/* ---- High contrast support ---- */
@media (prefers-contrast: more) {
  :root {
    --border-soft: rgba(255,255,255,0.28);
    --border-strong: rgba(255,255,255,0.5);
    --ink-dim: #c7c6cf;
    --ink-faint: #a3a1ab;
  }
  .glass, .field-box, .chip, .list-card, .quick-card, .faq-item { background: var(--surface-1); }
}

/* ---- Print ---- */
@media print {
  .nav, .fab-group, .toast-region, .page-loader { display: none !important; }
  body { background: #fff; color: #000; }
}
