/* The Secret Life Of The Pencil — styles */

:root {
  --ink: #111;
  --text: #444;
  --grey: #9e9e9e;
  --rule: #e7e6e6;
  --slab: "Antic Slab", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: #fff; color: var(--text); font: 13px/20px "PT Sans", Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; z-index: 100; background: #fff; padding: 6px 10px; }

.topbar { height: 32px; background: #a0a0a0; }

/* ---------- Logo: live type + cycling hand-drawn "Pencil" ---------- */
.logo { display: block; width: min(520px, 100%); margin: 31px auto; }
.logo > svg { display: block; width: 100%; height: auto; overflow: hidden; }
.logo .title { font: 600 47px "Montserrat", sans-serif; fill: var(--ink); }
.logo .names { font: 500 14.4px "Cormorant Garamond", serif; fill: #222; }
/* The hand-drawn "Pencil": one window onto a strip of 4 frames; main.js steps through them
   (speed: SCRIBBLE_MS in build.mjs) */
.logo .scribble { overflow: hidden; }

/* ---------- Nav ---------- */
.nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 0 38px; list-style: none; margin: 0 0 40px; padding: 0; }
.nav a { display: block; font: 14px/40px var(--slab); color: #333; border-top: 1px solid transparent; transition: color .2s, border-color .2s; }
.nav a:hover, .nav a[aria-current] { color: var(--grey); border-top-color: var(--grey); }

/* ---------- Sticky header ---------- */
.sticky { position: fixed; inset: 0 0 auto; z-index: 50; height: 72px; overflow: hidden; background: rgba(255, 255, 255, .97);
          box-shadow: 0 1px 3px rgba(0, 0, 0, .12); transform: translateY(-110%); transition: transform .35s ease; }
.sticky.on { transform: none; }
.sticky .wrap { height: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0 32px; }
.sticky .logo { grid-column: 2; width: 110px; margin: 0; }  /* centre column: always central, even with the menu hidden */
.sticky .nav { margin: 0; gap: 0 26px; flex-wrap: nowrap; }
.sticky .nav:first-child { justify-content: flex-end; }
.sticky .nav:last-child { justify-content: flex-start; }
@media (max-width: 760px) { .sticky .nav { display: none; } }

/* ---------- Filter tabs ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 0 30px; list-style: none; margin: 0 0 40px; padding: 0;
           border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.filters a { display: block; margin-top: -1px; font: 13px/31px var(--slab); color: #333; border-top: 3px solid transparent; transition: color .2s, border-color .2s; }
.filters a:hover { color: var(--grey); }
.filters .active a { color: var(--grey); border-top-color: var(--grey); }

/* ---------- Masonry tiles (positioned by main.js) ---------- */
.tiles { position: relative; margin: 0 -12px 80px; overflow: clip; } /* clip: tile transforms must never widen the page (phones would zoom out) */
.tile { position: absolute; top: 0; left: 0; width: 33.333%; padding: 12px; transform-origin: center; }
.tiles.ready .tile { transition: transform .6s ease, opacity .6s ease; }
/* Before JS runs: a plain CSS column layout */
.tiles:not(.ready) { columns: 3 260px; column-gap: 0; }
.tiles:not(.ready) .tile { position: static; width: auto; break-inside: avoid; }

.image { position: relative; display: block; overflow: hidden; background: #f3f3f3; cursor: pointer;
         transition: transform .25s cubic-bezier(.3, .7, .4, 1); -webkit-tap-highlight-color: transparent; }
.image img { display: block; width: 100%; height: auto; transition: transform 1.2s cubic-bezier(.2, .7, .2, 1); }
.image:focus-visible { outline: 2px solid #111; outline-offset: 3px; }

/* Hover: the image gently zooms in */
.tile:hover .image img, .tile:focus-within .image img { transform: scale(1.05); }

/* Click: tile presses in, pencil shading ripples out from the click point */
.image:active { transform: scale(.975); }
.image::after { content: ""; position: absolute; z-index: 2; left: var(--x, 50%); top: var(--y, 50%); width: 220%; aspect-ratio: 1; border-radius: 50%;
                background: radial-gradient(closest-side, rgba(40, 40, 40, .32), rgba(40, 40, 40, .12) 60%, transparent);
                transform: translate(-50%, -50%) scale(0); opacity: 0; pointer-events: none; }
.tile.clicked .image::after { animation: shade .7s cubic-bezier(.2, .7, .3, 1); }
@keyframes shade { 0% { transform: translate(-50%, -50%) scale(0); opacity: 1; } 100% { transform: translate(-50%, -50%) scale(1); opacity: 0; } }

.site-footer { border-top: 1px solid var(--rule); padding: 24px 0 40px; text-align: center; color: var(--grey); font-size: 12px; }

@media (prefers-reduced-motion: reduce) {
  .tiles.ready .tile, .sticky, .image, .image img { transition: none; }
  .tile.clicked .image::after { animation: none; }
}

/* =====================================================================
   SINGLE-PAGE SANDBOX — sections, news, instagram, lightbox
   ===================================================================== */
html { scroll-behavior: smooth; scroll-padding-top: 104px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

.entry-text a, .news-text a, .press-grid a, .press-note a { color: #111; border-bottom: 1px solid #bbb; transition: border-color .2s; }
.entry-text a:hover, .news-text a:hover, .press-grid a:hover { border-color: #111; }

/* Group headings: title sits on a dotted pencil rule, like the logo */
.group { padding: 40px 0 20px; }
.group-title { position: relative; margin: 0 0 40px; text-align: center; font: 600 28px/1 "Montserrat", sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--ink); }
.group-title::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 2px dotted #2a2a2a; }
.group-title span { position: relative; background: #fff; padding: 0 22px; }
.to-top { display: block; width: max-content; margin: 10px auto 30px; font: 13px var(--slab); color: var(--grey); }
.to-top:hover { color: #111; }

/* One entry per old page */
.entry { padding: 36px 0; border-top: 1px solid var(--rule); }
.group-title + .entry { border-top: 0; padding-top: 0; }
.entry-title { margin: 0 0 22px; font: 26px/1.2 var(--slab); color: var(--ink); }
.entry-body { display: grid; gap: 36px; }
.entry.split .entry-body { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
@media (max-width: 800px) { .entry.split .entry-body { grid-template-columns: 1fr; } }
.entry-text { font-size: 15px; line-height: 1.65; color: #333; max-width: 62ch; }
.entry.text-only .entry-text { max-width: 72ch; }
.entry-text p { margin: 0 0 1em; }
.entry-text p.lead { font: 17px/1.6 var(--slab); color: #222; }
.entry-text h3 { margin: 1.4em 0 .4em; font: 600 12px/1.3 "Montserrat", sans-serif; letter-spacing: .1em; text-transform: uppercase; color: #111; }
.entry-text h3:first-child { margin-top: 0; }
.entry .entry-text.list-cols { max-width: none; columns: 4 180px; column-gap: 32px; }
.entry-text.list-cols p { margin: 0 0 .35em; break-inside: avoid; }

/* Galleries: thumbnails, click to open large */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery.one { grid-template-columns: 1fr; }
.gallery.many { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.entry.gallery-only .gallery:not(.one) { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.entry.gallery-only .gallery.one { max-width: 900px; }
.gallery:not(.one) .shot { aspect-ratio: 1; }
.gallery:not(.one) .shot:first-child:not(:only-child) { grid-column: span 2; grid-row: span 2; }
.gallery.many .shot:first-child { grid-column: auto; grid-row: auto; }
.shot { display: block; overflow: hidden; background: #f3f3f3; cursor: zoom-in; }
.shot img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform 1.2s cubic-bezier(.2, .7, .2, 1); }
.gallery.one .shot img { height: auto; }
.shot:hover img { transform: scale(1.05); }

.video { position: relative; aspect-ratio: 16 / 9; margin: 0 0 1em; background: #111; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.entry.text-only .video { max-width: 900px; }

/* Press: captioned cuttings */
.press-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 28px 20px; }
.press-grid figure { margin: 0; }
.press-grid .shot { aspect-ratio: 2 / 1; }
.press-grid figcaption { margin-top: 8px; font-size: 13px; line-height: 1.45; color: #444; }
.press-note { grid-column: 1 / -1; margin: 0; font-size: 14px; }

/* News: compact cards, thumbnails beside the text */
.news-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 48px; }
@media (max-width: 900px) { .news-list { grid-template-columns: 1fr; } }
.news-item { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 20px; padding: 24px 0; border-top: 1px solid var(--rule); align-items: start; }
.news-item:target { background: linear-gradient(#faf8f2, #faf8f2) padding-box; }
@media (max-width: 480px) { .news-item { grid-template-columns: 96px minmax(0, 1fr); gap: 14px; } }
.news-thumbs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.news-thumbs .shot { aspect-ratio: 1; }
.news-thumbs .shot:only-child, .news-thumbs:not(.lots) .shot:first-child:nth-last-child(odd) { grid-column: span 2; }
.news-thumbs:empty { display: none; }
.news-item:has(.news-thumbs:empty) { grid-template-columns: 1fr; }
.news-text { font-size: 14px; line-height: 1.6; color: #333; min-width: 0; }
.news-text time { display: block; font: 11px/1 "Montserrat", sans-serif; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--grey); }
.news-text h3 { margin: 8px 0 10px; font: 19px/1.25 var(--slab); color: var(--ink); }
.news-text p { margin: 0 0 .8em; overflow-wrap: anywhere; }
.news-text .more { font-weight: 700; }
.fold summary { cursor: pointer; width: max-content; font: 13px var(--slab); color: #111; border-bottom: 1px solid #bbb; list-style: none; margin-bottom: .8em; }
.fold summary::-webkit-details-marker { display: none; }
.fold[open] summary { display: none; }

/* Instagram */
.insta-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-bottom: 28px; }
.insta-grid a { aspect-ratio: 1; overflow: hidden; }
.insta-grid img { width: 100%; height: 100%; object-fit: cover; transition: transform 1.2s cubic-bezier(.2, .7, .2, 1); }
.insta-grid a:hover img { transform: scale(1.05); }
.insta-follow { display: flex; align-items: center; gap: 12px; width: max-content; max-width: 100%; margin: 0 auto 60px; padding: 14px 26px;
                border: 1px solid #222; border-radius: 40px; font: 15px var(--slab); color: #111; transition: background .25s, color .25s; }
.insta-follow svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; flex: none; }
.insta-follow svg .dot { fill: currentColor; stroke: none; }
.insta-follow:hover { background: #111; color: #fff; }

/* Lightbox */
.lightbox { width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(255, 255, 255, .97); }
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop { background: transparent; }
/* Photo with the arrows + counter directly underneath; swipeable (main.js) */
.lb-stage { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; touch-action: pan-y; user-select: none; }
.lightbox img { display: block; max-width: calc(100vw - 140px); max-height: calc(100vh - 130px); object-fit: contain; box-shadow: 0 10px 40px rgba(0, 0, 0, .15); -webkit-user-drag: none; will-change: transform, opacity; touch-action: pan-y; }
.lb-bar { display: flex; align-items: center; justify-content: center; gap: 28px; min-height: 28px; }
.lb-caption { max-width: 60ch; text-align: center; font: 13px var(--slab); color: #444; }
.lightbox button { border: 0; background: none; color: #222; cursor: pointer; font: 300 44px/1 "PT Sans", sans-serif; padding: 12px 18px; opacity: .7; }
.lightbox button:hover { opacity: 1; }
.lightbox button[hidden] { display: none; }
.lb-close { position: absolute; top: 8px; right: 10px; }
/* Computer: arrows at the sides of the screen */
.lb-prev, .lb-next { position: fixed; top: 50%; transform: translateY(-50%); }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
/* Phones: arrows in the row under the photo, either side of the counter */
@media (max-width: 600px) {
  .lightbox img { max-width: calc(100vw - 24px); max-height: calc(100vh - 170px); }
  .lb-prev, .lb-next { position: static; transform: none; padding: 4px 18px; font-size: 40px; }
  .lb-bar { gap: 8px; }
}
.gallery.few { grid-template-columns: repeat(var(--n, 2), 1fr); align-items: start; }
.gallery.few.n2 { --n: 2; } .gallery.few.n3 { --n: 3; } .gallery.few.n4 { --n: 2; }
.gallery.few .shot { aspect-ratio: auto; grid-column: auto !important; grid-row: auto !important; }
.gallery.few .shot img { height: auto; }
.press-note p { margin: 0 0 .3em; }
.press-note h3 { margin: 12px 0 4px; font: 600 12px/1.3 "Montserrat", sans-serif; letter-spacing: .1em; text-transform: uppercase; }

/* "Read more" accordion for long text (e.g. Congo) */
.clampable .clamp-inner { position: relative; }
.clampable.needs .clamp-inner { max-height: var(--clamp-h); overflow: hidden; transition: max-height .7s cubic-bezier(.3, .7, .2, 1); }
.clampable.needs .clamp-inner::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 110px; pointer-events: none;
                                       background: linear-gradient(rgba(255, 255, 255, 0), #fff); transition: opacity .4s; }
.clampable.needs.open .clamp-inner { max-height: var(--full-h); }
.clampable.needs.open .clamp-inner::after { opacity: 0; }
.read-more { display: none; margin-top: 14px; padding: 9px 20px; border: 1px solid #222; border-radius: 30px; background: #fff; cursor: pointer;
             font: 13px var(--slab); color: #111; transition: background .2s, color .2s; }
.read-more::after { content: " ↓"; }
.open .read-more::after { content: " ↑"; }
.read-more:hover { background: #111; color: #fff; }
.clampable.needs .read-more { display: inline-block; }

/* Buttons under section text (e.g. Buy the book) */
.btn-row { margin-top: 1.6em !important; }
.entry-text a.btn { display: inline-flex; gap: 8px; align-items: center; padding: 12px 26px; border: 1px solid #111; border-radius: 40px; background: #111; color: #fff;
                    font: 15px var(--slab); transition: background .25s, color .25s; }
.entry-text a.btn span { transition: transform .25s; }
.entry-text a.btn:hover { background: #fff; color: #111; border-color: #111; }
.entry-text a.btn:hover span { transform: translateX(4px); }

/* Stacked: text on top, images across the full width (e.g. Lusenda) */
.entry.stacked .entry-body { grid-template-columns: 1fr; gap: 22px; }
.entry.stacked .gallery { grid-template-columns: repeat(var(--cols, 6), 1fr); }
.entry.stacked .gallery .shot:first-child { grid-column: auto; grid-row: auto; }
@media (max-width: 600px) { .entry.stacked .gallery { grid-template-columns: repeat(var(--cols-sm, 3), 1fr); gap: 4px; } }

/* Feature first: the first image spans the whole gallery at its natural shape (e.g. the Congo maps);
   the rest sit in even rows below */
.gallery.feature-first { grid-template-columns: repeat(var(--cols, 4), 1fr); }
@media (max-width: 600px) { .gallery.feature-first { grid-template-columns: repeat(var(--cols-sm, 3), 1fr); } }
.gallery.feature-first .shot:first-child { grid-column: 1 / -1 !important; grid-row: auto !important; aspect-ratio: auto; }
.gallery.feature-first .shot:first-child img { height: auto; object-fit: contain; }

/* Phones: header at half size, no filter row */
@media (max-width: 600px) {
  .site-header .logo { width: 50%; margin: 16px auto; }
  /* Menu on one line: evenly spread across the width */
  .site-header .nav { margin-bottom: 24px; flex-wrap: nowrap; justify-content: space-between; gap: 0 6px; }
  .site-header .nav a { font-size: 13px; white-space: nowrap; }
  .filters { display: none; }
  .topbar { display: none; }
}
@media (max-width: 360px) { .site-header .nav a { font-size: 12px; } }

/* Back link to alexhammond.co.uk — same style as the Imagefactory page */
.back { display: block; width: max-content; font: 400 13px/1.7 "Montserrat", system-ui, sans-serif; color: #6b8794;
        text-decoration: underline; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
.site-header .back { margin: 16px 0 0; }
.site-footer { padding: 24px 16px 40px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 24px; text-align: left; }
.site-footer p { margin: 0; }

/* Lightbox focus: no box on open or on mouse clicks; a quiet outline only when tabbing */
.lightbox:focus, .lightbox button:focus { outline: none; }
.lightbox button:focus-visible { outline: 1px solid #999; outline-offset: 2px; border-radius: 4px; }
