/* ==========================================================
   kianshah.in - mobile styles for the SUBPAGES
   Loaded AFTER assets/style.css. Every rule is scoped to
   @media (max-width: 768px); removing the <link> fully reverts.
   Interactive nav (.m-bar / .m-drawer) is built by assets/mobile.js,
   which sets html.m-on; without JS the original stacked <nav> stays.
   ========================================================== */

@media (max-width: 768px) {

  /* ---------- base hygiene ---------- */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(148, 210, 189, 0.18);
  }
  html, body { max-width: 100%; overflow-x: hidden; }

  /* long URLs and identifiers wrap instead of forcing a scrollbar */
  p, li, .timeline-item p, .note, .card-meta, .fit-model,
  .contact-links a, .authors { overflow-wrap: anywhere; }

  /* ---------- layout & spacing ---------- */
  .container {
    max-width: 100%;
    padding-left: 16px;
    padding-right: 16px;
  }
  section { margin-bottom: clamp(44px, 9vh, 64px); }
  p { max-width: none; }
  ul.linked, .skill-rows, .contact-links, .fit-models { max-width: none; }

  /* mobile-tuned display type (desktop is untouched above 768px) */
  h1 { font-size: clamp(32px, 8.5vw, 46px); margin-bottom: 16px; }
  h2 { font-size: clamp(26px, 7vw, 34px); }
  h3 { font-size: clamp(21px, 5.5vw, 25px); }
  .subtitle { margin-bottom: 32px; }

  /* ---------- hide the original stacked nav once JS enhances it ----------
     (the injected drawer is also a <nav>, so exclude it) */
  html.m-on nav:not(.m-drawer) { display: none; }

  /* space for the fixed bar (JS present). Without JS the original nav is
     static and assets/style.css keeps padding-top: 40px. */
  html.m-on .container {
    padding-top: calc(58px + env(safe-area-inset-top, 0px) + 14px);
  }

  /* ---------- compact top bar (built by mobile.js) ---------- */
  .m-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 160;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 58px;
    padding: 0 8px 0 14px;
    padding-top: env(safe-area-inset-top, 0px);
    background: rgba(0, 18, 25, 0.86);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(148, 210, 189, 0.12);
  }
  .m-bar .m-back {
    font-family: var(--mono);
    font-size: 20px;
    line-height: 1;
    color: var(--wheat);
    text-decoration: none;
    display: grid; place-items: center;
    width: 44px; height: 44px;
    border-radius: 6px;
    flex: none;
  }
  .m-bar .m-brand {
    font-family: var(--serif);
    font-size: 20px;
    letter-spacing: 0.04em;
    color: #f2ede0;
    text-decoration: none;
    margin-right: auto;
    white-space: nowrap;
  }
  .m-bar .m-menu {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--aqua);
    background: transparent;
    border: 1px solid rgba(148, 210, 189, 0.5);
    border-radius: 6px;
    cursor: pointer;
    flex: none;
  }
  .m-bar .m-menu .m-burger {
    position: relative;
    width: 18px; height: 12px; flex: none;
  }
  .m-bar .m-menu .m-burger::before,
  .m-bar .m-menu .m-burger::after,
  .m-bar .m-menu .m-burger span {
    content: "";
    position: absolute; left: 0; right: 0; height: 2px;
    background: currentColor; border-radius: 2px;
  }
  .m-bar .m-menu .m-burger::before { top: 0; }
  .m-bar .m-menu .m-burger span { top: 5px; }
  .m-bar .m-menu .m-burger::after { top: 10px; }

  /* homepage bar hosts the relocated view toggle */
  .m-bar #viewToggle { flex: none; margin-left: 0; }

  /* ---------- slide-in drawer + scrim ---------- */
  .m-scrim {
    position: fixed; inset: 0;
    z-index: 170;
    background: rgba(0, 8, 12, 0.6);
    opacity: 0;
    visibility: hidden;          /* no pointer-blocking / no tab stops when closed */
    transition: opacity 0.28s ease, visibility 0.28s ease;
  }
  .m-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    z-index: 171;
    width: min(86vw, 330px);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px
             calc(env(safe-area-inset-bottom, 0px) + 24px);
    background: #04202a;
    border-left: 1px solid rgba(148, 210, 189, 0.16);
    transform: translateX(100%);
    visibility: hidden;          /* keep the off-screen links out of the tab order */
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.32s ease;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  html.m-drawer-open .m-drawer { transform: none; visibility: visible; }
  html.m-drawer-open .m-scrim { opacity: 1; visibility: visible; }

  .m-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
  }
  .m-drawer-head .m-drawer-title {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .m-drawer .m-close {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    font-size: 26px; line-height: 1;
    color: var(--wheat);
    background: transparent; border: 0; cursor: pointer;
  }
  .m-drawer a {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-height: 54px;
    padding: 12px 12px;
    font-family: var(--mono);
    font-size: 18px;
    letter-spacing: 0.06em;
    color: #e6ecee;
    text-decoration: none;
    border-bottom: 1px solid rgba(148, 210, 189, 0.08);
  }
  .m-drawer a[aria-current="page"] {
    color: var(--wheat);
  }
  .m-drawer a[aria-current="page"]::before {
    content: "▸";
    color: var(--teal);
    font-size: 14px;
  }
  .m-drawer a small {
    font-size: 12px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--muted);
    margin-left: auto;
  }

  html.m-drawer-open, html.m-drawer-open body { overflow: hidden; }

  /* ---------- touch targets ---------- */
  .btn { min-height: 46px; }
  .btn-row { gap: 10px; }
  .tag { padding: 8px 12px; margin: 8px 8px 0 0; }
  .pill { padding: 5px 12px; }
  footer .foot-social a { width: 48px; height: 48px; }

  /* hover-only affordances get a resting state on touch */
  .card, .film-card, .about-photo { transition: none; }
  .card:hover, .film-card:hover, .about-photo:hover { transform: none; }

  /* ---------- cards ---------- */
  .card { padding: 22px 18px; }
  .paper-card { padding: 22px 18px; }

  /* ---------- timeline (tighter rail) ---------- */
  .timeline { padding-left: 20px; gap: 34px; }
  .timeline-item::before { left: -24.5px; width: 7px; height: 7px; }
  .timeline-item h3 { font-size: 19px; }

  /* ---------- values table -> stacked cards (research) ---------- */
  html.m-on .values-table,
  html.m-on .values-table tbody,
  html.m-on .values-table tr,
  html.m-on .values-table td { display: block; width: 100%; }
  html.m-on .values-table thead { display: none; }
  html.m-on .values-table { font-size: 13px; }
  html.m-on .values-table tr {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 12px 14px;
    margin-bottom: 12px;
  }
  html.m-on .values-table td {
    border: none;
    padding: 3px 0;
  }
  html.m-on .values-table .col-d { display: block; }
  html.m-on .values-table td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
  }
  html.m-on .values-table td:first-child::before { color: var(--muted); }
  html.m-on .values-table td:first-child {
    font-size: 15px; color: var(--wheat);
    border-bottom: 1px solid rgba(20, 51, 61, 0.7);
    padding-bottom: 8px; margin-bottom: 4px;
  }
  html.m-on .values-table td:last-child {
    word-break: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }

  /* ---------- growth chart (research) ---------- */
  .growth-fig { padding: 16px 12px; }
  #growth-chart { touch-action: pan-y; }
  #growth-chart svg { touch-action: pan-y; max-width: 100%; }
  .chart-legend { gap: 6px 16px; }
  .chart-tip { font-size: 11.5px; max-width: 78vw; }
  .fit-model { font-size: 14px; }

  /* ---------- math & preformatted: scroll, never overflow ---------- */
  html.m-on .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  html.m-on pre { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .bibtex pre { padding: 14px; font-size: 12px; }

  /* ---------- about ---------- */
  .about-container { gap: 22px; }
  .about-photo {
    flex: 0 0 auto;
    width: clamp(150px, 42vw, 190px);
    align-self: center;
    border-radius: 16px;
  }
  .about-text { flex: 1 1 100%; }

  /* film shelf: deliberate 2-column grid, all 15 films kept */
  .film-shelf { grid-template-columns: 1fr 1fr; gap: 10px; }
  .film-card { padding: 12px 12px 10px; }

  /* book shelf already scrolls horizontally; keep it contained */
  .book-shelf { max-width: 100%; }

  /* ---------- contact ---------- */
  .contact-links { max-width: none; }
  .contact-links a { padding: 10px 14px; }

  /* ---------- CV: PDF iframe is genuinely bad on phones ----------
     Replace the hidden embed with a prominent download card (mobile.js
     injects the button; here we reveal the wrapper and hide the iframe). */
  html.m-on .cv-embed-wrapper { display: block; border: none; }
  html.m-on .cv-embed-wrapper iframe { display: none; }
  .m-pdf-cta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 6px;
  }
  .m-pdf-cta .m-pdf-note { font-size: 14px; color: var(--muted); margin: 0; }

  /* ---------- footer clears the home indicator ---------- */
  html.m-on footer {
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }
}

/* honour reduced motion for the drawer slide */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .m-drawer, .m-scrim { transition: none; }
}
