/* ==========================================================================
   PHONE GUARD. This file is loaded AFTER style.css on every page, so nothing
   added to style.css later can override the phone layout.
   Rule for edits: any desktop change to a multi-column layout must also be
   checked here, and `node tools/check-mobile.js` must pass before publishing.
   ========================================================================== */
@media (max-width: 700px) {
  /* never let anything be wider than the screen */
  /* "clip" stops sideways scrolling without breaking the top bar staying pinned (hidden would unpin it) */
  html, body { overflow-x: clip; }
  @supports not (overflow-x: clip) { body { overflow-x: hidden; } }
  img, video, iframe, svg, table, pre { max-width: 100%; }
  main, .wrap, .card, .card-body, .about-layout, .about-text, .story-info { min-width: 0; }
  p, h1, h2, h3, li, a, .card-title, .post-desc { overflow-wrap: anywhere; }

  /* everything that is side by side on a laptop stacks on a phone */
  .card { grid-template-columns: 1fr !important; gap: .8rem !important; margin: 0 !important; padding: 0 !important; }
  .about-layout, .story-info, .story-info.with-notes { grid-template-columns: 1fr !important; }
  .about-photo { position: static !important; grid-column: 1 !important; grid-row: 1 !important; }
  .about-text { grid-column: 1 !important; grid-row: 2 !important; }
  .story-grid, .story-grid.lead { grid-template-columns: 1fr !important; }
  .story-grid.lead > li:first-child a { aspect-ratio: 4 / 3 !important; }
  .ph-row { flex-direction: column !important; }
  .ph-row .photo { flex: none !important; width: 100% !important; }
  .ph-row .photo > a, .ph-row .photo > a img { height: auto !important; }
  .photo-wall { columns: 1 !important; }
  .card-title { font-size: 1.15rem; }
}
@media (max-width: 700px) {
  .prose table { font-size: .9rem; }
  .prose td:first-child { white-space: normal; }
  .prose th, .prose td { padding: .55rem .6rem; }
}
/* phone menu: the same social icons as the footer, pinned to the bottom of the menu */
.mobile-menu { flex-direction: column; }
.menu-socials { margin-top: auto; padding-bottom: max(1.2rem, env(safe-area-inset-bottom)); opacity: 0; transform: translateY(8px);
  transition: opacity .3s ease .25s, transform .3s ease .25s; }
.menu-open .menu-socials { opacity: 1; transform: none; }
.menu-socials .socials { gap: .6rem; margin-left: -.55rem; }
.menu-socials .socials a { padding: .55rem; font-size: inherit; letter-spacing: 0; }
.menu-socials .socials svg { width: 1.5rem; height: 1.5rem; }
@media (prefers-reduced-motion: reduce) { .menu-socials { transition: none; } }

/* lists of posts and work on phones: clear space between entries, so each picture
   reads as belonging to the title under it, not to the text above it */
@media (max-width: 700px) {
  .cards { gap: 2.8rem !important; }
  .card { gap: .7rem !important; }
  .card .post-meta { margin: .2rem 0 .45rem; }
}

/* post contents box on phones: section jumps land just under the smaller top bar */
@media (max-width: 700px) {
  .prose h2[id] { scroll-margin-top: 5rem; }
  .toc-box { margin-bottom: 1.5rem; }
}

/* previous / next post on phones: one under the other, full width */
@media (max-width: 700px) {
  .post-nav { grid-template-columns: 1fr; gap: 1.6rem; margin-top: 3.5rem; }
  .pn-empty { display: none; }
}

/* post tags on phones: their own line, lined up with the date (no stray indent) */
@media (max-width: 700px) {
  .post-meta .ptags { display: block; margin: .15rem 0 0; }
}

/* Work timeline on phones and small tablets: the period and place above its tiles, one tile per row */
@media (max-width: 860px) {
  .wgroup { grid-template-columns: 1fr; gap: 1rem; padding: 1.4rem 0; }
  .wgroup-head { position: static; }
}
@media (max-width: 700px) {
  .wtiles { grid-template-columns: 1fr; gap: 1rem; }
  .wcover { margin: 1.2rem 0 1.4rem; }
}
/* work pages on phones: the picture uses the full width */
@media (max-width: 700px) { .wcover { max-width: none; } }

/* Home on phones (like rajrajhans.com): the painting fills the top of the screen behind the text, and the whole
   section fits in the first screen so "Lately" (and the start of the posts) shows without scrolling.
   The painting sits along the bottom; above it each layer paints its own sky (colours from the painting's top edge)
   and the painting's top dissolves into it, so day and night always change together.
   Height follows the phone's width (165vw, capped by the screen height), so it lands in the same place whichever
   browser is used (browsers report screen height differently with their toolbars). The first screen shows the painting, Lately and the "Latest posts"
   heading peeking at the bottom, with the first post's picture just out of view (as on rajrajhans.com).
   --art-h is worked out so the peak sits just below the text: hero height minus the text block (~24rem), over 0.73. */
@media (max-width: 700px) {
  .home .hero { --hero-h: max(min(165vw, calc(100vh - 4rem)), 30rem); --hero-h: max(min(165vw, calc(100svh - 4rem)), 30rem);
    --art-h: clamp(16rem, calc((var(--hero-h) - 24rem) / .73), 36rem);
    display: block; height: var(--hero-h); min-height: 0; background: #05132e; }
  .home .hero .art { position: absolute; inset: 0; height: auto; order: 0; }
  .home .hero .art::after { content: none; }
  .home .art-layer.day { background: linear-gradient(180deg, #5f97cb 0%, #82afd8 55%, #93bcda 100%); }
  .home .art-layer.night { background:
      radial-gradient(1.4px 1.4px at 12% 14%, rgba(255,255,255,.85), transparent 60%),
      radial-gradient(1.2px 1.2px at 31% 7%, rgba(255,255,255,.7), transparent 60%),
      radial-gradient(1px 1px at 47% 22%, rgba(255,255,255,.6), transparent 60%),
      radial-gradient(1.5px 1.5px at 66% 11%, rgba(255,255,255,.8), transparent 60%),
      radial-gradient(1px 1px at 83% 26%, rgba(255,255,255,.6), transparent 60%),
      radial-gradient(1.3px 1.3px at 91% 6%, rgba(255,255,255,.75), transparent 60%),
      radial-gradient(1px 1px at 22% 33%, rgba(255,255,255,.5), transparent 60%),
      radial-gradient(1.2px 1.2px at 58% 37%, rgba(255,255,255,.55), transparent 60%),
      linear-gradient(180deg, #030914 0%, #0a1a34 55%, #0d2344 100%); }
  .home .art.painted img { inset: auto 0 0 0; top: auto; height: var(--art-h); object-position: 74% 100%;
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22%); mask-image: linear-gradient(180deg, transparent 0, #000 22%); }
  .home .hero-text { position: relative; z-index: 1; padding-top: 4.4rem; padding-bottom: 0; }   /* heading sits close under the top bar, like Raj's */
  /* text sizes like rajrajhans.com on a phone: a ~36px heading, both paragraphs at the same ~17px */
  .home .hero-text h1 { font-size: 2.25rem; margin-bottom: .7rem; }
  .home .hero-text .lede, .home .hero-text p { font-size: 1rem; line-height: 1.6; margin-bottom: .9rem; }
}
/* home on phones: a little more room between Lately and "Latest posts", so the first post picture stays below the first screen */
@media (max-width: 700px) {
  .home main > .section-head:first-child { margin-top: 3.2rem; }
}
