/* zodiakk — mobile & responsive layout.
 *
 * Strategy:
 *  - Below 900px: tighten spacing, drop ornamental chrome, stack columns.
 *  - Below 640px (phones): smaller gutters, single column throughout,
 *    hide the fixed hairline frame (too cramped), hide the "meta" clock
 *    cluster in the topbar, stack section heads, stop marquee animations.
 *  - All type sizes scale via clamp() already; we only override when
 *    the clamp floor is still too large for 360–420px viewports.
 */

/* ========== TABLET (≤ 900px) ========== */
@media (max-width: 900px) {
  .page {
    padding-left: 24px;
    padding-right: 24px;
  }

  /* Topbar: keep 3-col grid, but drop the meta clock cluster */
  .topbar .meta { display: none; }

  /* HERO: marquee */
  .hero-marquee .coords { display: none; }
  .hero-marquee .foot {
    grid-template-columns: 1fr 1fr;
    gap: 20px 24px;
  }

  /* HERO: ledger */
  .hero-ledger {
    grid-template-columns: 1fr;
    gap: 32px;
    padding: 32px 0;
  }
  .hero-ledger .ledger-row {
    grid-template-columns: 60px 1fr 80px;
    gap: 16px;
  }
  .hero-ledger .ledger-row .excerpt,
  .hero-ledger .ledger-row .len { display: none; }

  /* HERO: grid */
  .hero-grid .top {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  .hero-grid .top p {
    justify-self: start;
    max-width: 100%;
  }
  .hero-grid .cells { grid-template-columns: repeat(2, 1fr); }

  /* NOW strip */
  .now-strip {
    grid-template-columns: auto 1fr;
    gap: 16px 20px;
    padding: 20px 0;
  }
  .now-strip .date {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  /* Section heads stack */
  .sec-head {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 64px 0 32px;
  }
  .sec-head .note {
    justify-self: start;
    max-width: 100%;
  }

  /* Gallery: cap at 3 cols on tablet regardless of tweak choice */
  .gallery.cols-4,
  .gallery.cols-5 { grid-template-columns: repeat(3, 1fr); }
  .gallery { gap: 16px; }

  /* Posts.list */
  .posts.list .row {
    grid-template-columns: 60px 1fr 90px;
    gap: 16px 20px;
  }
  .posts.list .row .excerpt {
    grid-column: 1 / -1;
    grid-row: 2;
    padding-top: 4px;
  }

  /* Posts.grid */
  .posts.grid { grid-template-columns: repeat(2, 1fr); }

  /* Projects */
  .project {
    grid-template-columns: 80px 1fr 100px;
    gap: 20px;
    padding: 28px 24px;
  }
  .project .desc {
    grid-column: 1 / -1;
    padding-top: 4px;
  }

  /* Footer */
  .footer {
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-top: 80px;
  }
  .footer .big-col {
    grid-column: 1 / -1;
  }
  .footer .sig {
    flex-direction: column;
    gap: 8px;
    margin-top: 40px;
  }
}

/* ========== PHONE (≤ 640px) ========== */
@media (max-width: 640px) {
  /* Drop the fixed viewport frame — feels claustrophobic on phones */
  .frame { display: none; }

  /* Topbar: sit flush to viewport edges, smaller, 2-col (brand | nav) */
  .topbar {
    top: 0; left: 0; right: 0;
    height: 44px;
    padding: 0 14px;
    grid-template-columns: auto 1fr;
    gap: 0;
  }
  .topbar .brand { font-size: 11px; }
  .topbar .brand::after { display: none; }
  .topbar nav {
    justify-self: end;
    gap: 14px;
  }
  .topbar nav a {
    font-size: 10px;
    letter-spacing: 0.1em;
  }
  /* Show only 3 primary nav links on narrow */
  .topbar nav a:nth-child(n+4) { display: none; }
  .topbar nav a.active::before { display: none; }

  .page {
    padding-top: 60px;
    padding-left: 16px;
    padding-right: 16px;
    padding-bottom: 48px;
  }

  /* HERO marquee — allow overflow control */
  .hero-marquee {
    min-height: calc(100vh - 60px);
    padding: 24px 0;
  }
  .hero-marquee h1 {
    font-size: clamp(56px, 20vw, 96px);
    letter-spacing: -0.04em;
  }
  .hero-marquee .caption { font-size: 13px; }
  .hero-marquee .foot {
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 32px;
    padding-top: 16px;
  }

  /* HERO ledger — simpler rows */
  .hero-ledger {
    gap: 24px;
    padding: 24px 0;
  }
  .hero-ledger .main h1 { font-size: clamp(40px, 12vw, 64px); }
  .hero-ledger .ledger-row {
    grid-template-columns: 50px 1fr;
    gap: 12px;
    padding: 14px 0;
  }
  .hero-ledger .ledger-row .date,
  .hero-ledger .ledger-row .kind { display: none; }
  .hero-ledger .ledger-row .title { font-size: 15px; }

  /* HERO grid — single column */
  .hero-grid { padding: 24px 0; }
  .hero-grid .top h1 { font-size: clamp(40px, 11vw, 56px); }
  .hero-grid .top p { font-size: 13px; }
  .hero-grid .cells { grid-template-columns: 1fr; }
  .hero-grid .cell { padding: 20px; aspect-ratio: 16/10; }

  /* NOW strip */
  .now-strip {
    grid-template-columns: 1fr;
    padding: 16px 0;
    margin-top: 32px;
  }
  .now-strip .date {
    grid-column: 1;
    grid-row: 3;
  }
  .now-strip .txt { font-size: 14px; }

  /* Section heads */
  .sec-head {
    padding: 48px 0 24px;
    gap: 14px;
  }
  .sec-head h2 { font-size: clamp(32px, 9vw, 44px); }
  .sec-head .note { font-size: 13px; }

  /* Gallery — 2 cols max on phone */
  .gallery,
  .gallery.cols-2,
  .gallery.cols-3,
  .gallery.cols-4,
  .gallery.cols-5 {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .gallery .tile .cap,
  .gallery .tile .idx { font-size: 8px; }
  .gallery .tile .cap { left: 8px; right: 8px; bottom: 8px; }
  .gallery .tile .idx { top: 8px; left: 8px; }

  /* Hover EXIF overlay isn't useful on touch — disable */
  .gallery .tile:hover .exif { opacity: 0; }
  .gallery .tile:hover .cap,
  .gallery .tile:hover .idx { opacity: 1; }
  .gallery .tile:hover .bg { filter: grayscale(0.9) contrast(1.08) brightness(0.7); }

  /* Posts list — collapse to 2-line rows */
  .posts.list .row {
    grid-template-columns: 40px 1fr;
    gap: 8px 12px;
    padding: 16px 0;
  }
  .posts.list .row .kind,
  .posts.list .row .date { display: none; }
  .posts.list .row .title { font-size: 16px; }
  .posts.list .row .excerpt {
    font-size: 13px;
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .posts.list .row:hover { padding-left: 0; }

  /* Posts grid — single col */
  .posts.grid { grid-template-columns: 1fr; }
  .posts.grid .row {
    padding: 24px 20px;
    min-height: 0;
  }
  .posts.grid .row .title { font-size: 20px; margin: 12px 0; }

  /* Posts marquee — pause animation to save perf + legibility */
  .posts.marquee .track {
    animation-duration: 120s;
  }
  .posts.marquee .item { font-size: 20px; }

  /* Projects — stack */
  .project {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 24px 20px;
  }
  .project .idx,
  .project .year,
  .project .status {
    display: inline-block;
    margin-right: 12px;
  }
  .project .status { grid-column: 1; }
  .project .title { font-size: 20px; }
  .project .title small { margin-top: 2px; }
  .project .desc { font-size: 13px; }

  /* Footer */
  .footer {
    grid-template-columns: 1fr;
    gap: 28px;
    margin-top: 56px;
  }
  .footer .big { font-size: clamp(32px, 9vw, 48px); }
  .footer .sig { font-size: 9px; }

  /* Tweaks panel — full-width bottom sheet feel */
  .tweaks {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
  }
  .tweaks-toggle {
    right: 12px;
    bottom: 12px;
  }
}

/* Pager: keep the horizontal 3-column design on mobile, just shrink it
   so it fits the viewport (desktop .pg-edge has min-width:160px which
   blows past phone widths). Cells still horizontally scroll internally
   if pagination grows beyond the middle column. */
@media (max-width: 640px) {
  .pager {
    margin-top: 32px;
    min-width: 0;
  }
  .pg-edge {
    min-width: 0;
    padding: 10px 12px;
    gap: 8px;
  }
  .pg-arrow { font-size: 14px; }
  .pg-lab   { font-size: 7px; letter-spacing: 0.18em; }
  .pg-num   { font-size: 11px; }
  .pg-edge-label { gap: 3px; }

  .pg-cells {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    min-width: 0;
  }
  .pg-cells::-webkit-scrollbar { display: none; }
  .pg-cells li { flex-shrink: 0; }
  .pg-cell { width: 40px; font-size: 11px; }
}

/* ========== VERY NARROW (≤ 380px) ========== */
@media (max-width: 380px) {
  .page { padding-left: 12px; padding-right: 12px; }
  .topbar nav a:nth-child(n+3) { display: none; }
  .hero-marquee h1 { font-size: clamp(44px, 18vw, 72px); }
  .hero-ledger .main h1 { font-size: clamp(32px, 12vw, 48px); }
  .sec-head h2 { font-size: clamp(28px, 10vw, 36px); }
}

/* ========== ATLAS (map section) mobile ========== */
@media (max-width: 640px) {
  .atlas-frame { overflow-x: hidden; }
  .atlas-bar {
    font-size: 8px;
    letter-spacing: 0.1em;
    gap: 10px;
    padding: 8px 10px;
    flex-wrap: wrap;
  }
  .atlas-bar > * { flex: 0 0 auto; }

  /* Fit the map to viewport — no horizontal scroll. */
  .atlas-grid {
    overflow: hidden;
    padding: 16px 8px !important;
    display: flex;
    justify-content: center;
  }
  .atlas-ascii {
    font-size: 3px !important;
    line-height: 1 !important;
    letter-spacing: 0;
  }

  /* Smaller pin dots + rings + labels on mobile */
  .atlas-dot-core { width: 3px !important; height: 3px !important; }
  .atlas-dot-ring { width: 9px !important; height: 9px !important; }
  .atlas-dot-label { font-size: 7px !important; top: calc(100% + 2px) !important; }
  .atlas-dot.on .atlas-dot-core { transform: scale(1.4); }

  .atlas-readout {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 8px 10px;
  }
  .ar-pill { flex: 0 0 auto; }

  .ap-grid { grid-template-columns: 1fr 1fr; }
  .ap-img-wrap { aspect-ratio: 16 / 10; }
}

/* ========== VERY NARROW MAP (≤ 420px) ========== */
@media (max-width: 420px) {
  .atlas-ascii { font-size: 2.5px !important; }
  .atlas-dot-core { width: 2.5px !important; height: 2.5px !important; }
  .atlas-dot-ring { width: 7px !important; height: 7px !important; }
  .atlas-dot-label { font-size: 6px !important; }
}

/* ========== BLOG POST DETAIL mobile ========== */
@media (max-width: 640px) {
  .pd-meta {
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px !important;
  }
  .post-detail { padding: 24px 0 !important; }
  .pd-body {
    padding: 0 16px !important;
    font-size: 15px !important;
    line-height: 1.6 !important;
  }
  .pd-gallery {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 0 16px !important;
  }
  .pd-quote {
    padding: 0 16px !important;
    font-size: 20px !important;
  }
  .pd-footer {
    flex-direction: column;
    gap: 12px;
    padding: 16px !important;
  }
}

/* ========== PROJECT DETAIL mobile ========== */
@media (max-width: 640px) {
  .prj-bar {
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 9px !important;
    padding: 10px 14px !important;
  }
  .prj-body {
    grid-template-columns: 1fr !important;
    padding: 20px 16px !important;
    gap: 24px !important;
  }
  .prj-metrics {
    grid-template-columns: 1fr 1fr !important;
  }
  .prj-gallery {
    grid-template-columns: 1fr !important;
  }
  .prj-links {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ========== Reduced motion ========== */
@media (prefers-reduced-motion: reduce) {
  .posts.marquee .track { animation: none; }
  .reveal { opacity: 1 !important; transform: none !important; }
  .topbar .meta .dot { animation: none; }
}
