/* ── Mobile and touch overrides ─────────────────────────
   Deliberately the last stylesheet: these rules have to outrank the desktop
   ones, and CSS breaks ties on source order. Run `node tools/check-mobile.mjs`
   after editing; it fails on an ungated hover rule, a fixed inline width,
   or this file no longer being last. */

/* ── The bar on a phone ──────────────────────────────────
   The wordmark, Contact, the theme and a "Menu" text button stay in view.
   The four pages (and, on Projects, its chapters) open as one sheet over the
   page under the bar. The sheet is built by script; with no script the
   links stay a row. */
.cta-short { display: none; }
.nav-menu-btn { display: none; }
@media (max-width: 760px) {
  .cta-long { display: none; }
  .cta-short { display: inline; }
  .brand > span { display: none; }
  .nav-inner { gap: 12px; }
  .btn-ghost { position: relative; min-height: 36px; padding: 0 12px; }
  .btn-ghost::after { content: ''; position: absolute; inset: -4px -2px; }
  .nav-jump-wrap { display: none; }

  nav.nav-collapsed .nav-menu-btn {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 6px;
    border: 0;
    background: none;
    color: var(--ink);
    font-size: 15px;
    cursor: pointer;
  }
  nav.nav-collapsed .nav-scroll {
    position: fixed;
    left: 0;
    right: 0;
    top: var(--bar-h);
    bottom: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 12px var(--margin) 32px;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface);
  }
  nav.nav-collapsed.nav-open .nav-scroll { display: flex; }
  /* The sheet drops 8px from the bar as it opens, so it reads as coming
     from the button; the links settle a row at a time, 30ms apart. Closing
     is instant. Only opacity and transform carry the delay. */
  nav.nav-collapsed .nav-scroll { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-drawer); }
  @starting-style {
    nav.nav-collapsed.nav-open .nav-scroll { opacity: 0; transform: translateY(-8px); }
  }
  nav.nav-collapsed .nav-scroll .nav-link {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 0;
    font-size: var(--step-lead);
    color: var(--ink);
    transition: color 150ms ease,
                opacity 200ms var(--ease-out) var(--d, 0ms),
                transform 200ms var(--ease-out) var(--d, 0ms);
  }
  nav.nav-collapsed .nav-scroll .nav-link[aria-current="page"] {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 10px;
    text-decoration-color: var(--accent-deep);
  }
  nav.nav-collapsed .nav-mark { display: none; }
  nav.nav-collapsed .nav-scroll .nav-chapter { display: flex; min-height: 48px; font-size: var(--step-body); color: var(--muted); padding-left: 16px; }
  nav.nav-collapsed .nav-scroll > :nth-child(2) { --d: 30ms; }
  nav.nav-collapsed .nav-scroll > :nth-child(3) { --d: 60ms; }
  nav.nav-collapsed .nav-scroll > :nth-child(n+4) { --d: 90ms; }
  @starting-style {
    nav.nav-collapsed.nav-open .nav-scroll .nav-link { opacity: 0; transform: translateY(6px); }
  }
  /* Reduced motion: the sheet and its rows fade in together, without the
     drop or the row-by-row rise. */
  @media (prefers-reduced-motion: reduce) {
    nav.nav-collapsed .nav-scroll { transition: opacity 200ms ease; }
    nav.nav-collapsed .nav-scroll .nav-link { transition: color 150ms ease, opacity 200ms ease; transform: none; }
  }
  html.menu-open { overflow: hidden; }
}

/* Between phone and desktop the bar keeps the mark and drops the name, so
   the four pages, the chapter jumper and the action share one row. */
@media (min-width: 760.02px) and (max-width: 999.98px) {
  .brand > span { display: none; }
}

/* ── Home on a phone: the title first, then the evidence ─
   The direction puts the figure on top; the brief puts the answer first,
   and on a 390px screen only one of them fits above the fold. */
@media (max-width: 899.98px) {
  .hero { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .hero-copy { padding: clamp(36px, 9vw, 64px) var(--margin) clamp(36px, 8vw, 56px); }
  .hero-rig { --rig-l: var(--margin); --rig-r: var(--margin); padding: 0 var(--margin) 36px; }
}
@media (max-width: 640px) {
  .hero-title { font-size: clamp(40px, 11.4vw, 56px); }
  .rig-switch { align-self: stretch; }
  .rig-switch button { flex: 1 1 0; justify-content: center; min-height: 44px; padding: 0 8px; }
}

/* ── Page heads on a phone ───────────────────────────────
   The index beside the title (Projects, the 404 page) drops under it in one
   column; it needs a section's breath above it, or its first group label
   reads as the last line of the sentence before. */
@media (max-width: 759.98px) {
  .page-head nav.col-side { margin-top: 40px; }
}

/* ── Tools on a phone: two groups to a row ───────────────
   In one column the nineteen names ran about a screen and a half; side by
   side the four groups fit in about one, and still read by their heads. */
@media (max-width: 640px) {
  .tools-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 16px; }
  .tool-item { align-items: flex-start; gap: 8px; font-size: 15px; }
  .tool-icon { width: 24px; height: 20px; }
  .tool-icon img { max-width: 24px; max-height: 18px; }
}

/* ── Touch targets ───────────────────────────────────────
   Every fix grows the hit area with a positioned ::after and leaves the
   painted pixel where it was. */
@media (max-width: 640px), (pointer: coarse) {
  .nav-link { position: relative; }
  .nav-link::after { content: ''; position: absolute; inset: -8px -2px; }
  .hobby-dot::after, .internship-dot::after { inset: -19px -9px; }
  .carousel-arrow { width: 44px; height: 44px; }
  .carousel-arrow.arrow-prev { left: 6px; }
  .carousel-arrow.arrow-next { right: 6px; }
  .carousel-playpause { width: 40px; height: 40px; top: 8px; right: 8px; }
  .theme-toggle { width: 44px; height: 44px; }
  .btn-quiet { min-height: 44px; }
  .ledger-more { position: relative; }
  .ledger-more::after { content: ''; position: absolute; inset: -12px -4px; }
}

/* ── Thumbnail strips ─────────────────────────────────────
   On a phone the strip snaps a thumbnail to its start edge, and fades only
   on the side that has more to see. */
@media (max-width: 640px) {
  .thumb-rail {
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 0;
  }
  .thumb-btn { scroll-snap-align: start; }
  .thumb-rail.fade-r { -webkit-mask-image: linear-gradient(to right, black calc(100% - 24px), transparent); mask-image: linear-gradient(to right, black calc(100% - 24px), transparent); } /* taste-skill-ignore: an edge mask on a scroll strip, not a fill */
  .thumb-rail.fade-l { -webkit-mask-image: linear-gradient(to left, black calc(100% - 24px), transparent); mask-image: linear-gradient(to left, black calc(100% - 24px), transparent); } /* taste-skill-ignore: an edge mask on a scroll strip, not a fill */
  .thumb-rail.fade-l.fade-r {
    -webkit-mask-image: linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent); /* taste-skill-ignore: edge mask */
    mask-image: linear-gradient(to right, transparent, black 24px, black calc(100% - 24px), transparent); /* taste-skill-ignore: edge mask */
  }
}

/* ── Lightbox: pan and zoom stage ─────────────────────── */
#lightbox-media { position: relative; overflow: hidden; touch-action: none; }
.lb-media-el {
  display: block;
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  background: var(--surface);
  padding: 16px;
  box-sizing: border-box;
  transform-origin: 0 0;
}
.lb-media-el.settling { transition: transform 260ms var(--ease-out); }
.lb-step, .lb-close {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(20, 22, 24, 0.6);
  color: rgba(255, 255, 255, 0.94);
  cursor: pointer;
  padding: 0;
  transition: background-color 150ms ease, transform 120ms var(--ease-out), opacity 150ms ease;
}
.lb-step { top: 50%; transform: translateY(-50%); }
.lb-step-prev { left: 8px; }
.lb-step-next { right: 8px; }
.lb-step:active { transform: translateY(-50%) scale(0.95); }
.lb-step[hidden] { display: none; }
#lightbox.is-zoomed .lb-step { opacity: 0; pointer-events: none; }
.lb-close { top: 0; right: 0; }
.lb-close:active { transform: scale(0.95); }
@media (hover: hover) and (pointer: fine) {
  .lb-step:hover, .lb-close:hover { background: rgba(20, 22, 24, 0.8); }
}
@media (max-width: 640px), (pointer: coarse) {
  #lightbox { padding: 8px; }
  .lb-caption-row { flex-direction: column; gap: 6px !important; }
  .lb-caption-row > span { flex: none !important; }
  #lightbox-media { height: 76vh; height: 76dvh; }
  .lb-media-el { height: 100%; max-height: none; padding: 6px; }
}

/* ── Touch: pointer-driven widgets ───────────────────────
   A vertical drag must still scroll the page; a horizontal one drives the
   turntable or the graph. */
@media (pointer: coarse) {
  .holo-stage { touch-action: pan-y; }
}
.swipe-x { touch-action: pan-y; }

/* ── Pointer-aware copy: "Hover" is wrong on a phone ──── */
.touch-only { display: none; }
@media (hover: none), (pointer: coarse) {
  .hover-only { display: none; }
  .touch-only { display: inline; }
}
