/* ===================================
   Print

   Every page prints as something made for paper, not a screenshot of
   the site. Linked LAST in each page's <head> with media="print", so
   these rules win ties against styles.css, project-details.css and the
   pages' inline <style> blocks.

     album page          → a photobook        (#printBook, js/print.js)
     album + open photo  → a single photo print (the lightbox)
     photos.html         → a contents sheet of albums
     projects.html       → a portfolio of the filtered projects
                           (#printPortfolio, js/print.js)
     project page        → a short report
     log post            → a paper

   styles.css sets font-size on `*`, so nothing inherits a size: every
   size here is explicit, and the built blocks reset their children with
   a zero-specificity :where() so class rules still win.
   =================================== */

@page {
    margin: 0.6in 0.65in;

    @bottom-right {
        content: counter(page);
        font-family: 'IBM Plex Mono', monospace;
        font-size: 7pt;
        color: #727272;
    }
}

@page :first {
    @bottom-right { content: none; }
}

/* A landscape photo on its own gets a landscape sheet (set by js/print.js). */
@page photo-landscape {
    size: landscape;
    margin: 0.5in;

    @bottom-right { content: none; }
}

@page photo-portrait {
    margin: 0.6in;

    @bottom-right { content: none; }
}

/* ===================================
   Shared
   =================================== */
html,
body {
    background: #fff;
    color: #000;
}

#bar,
#time,
.page-back,
.post-back,
.lightbox:not(.active) {
    display: none !important;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Pages without QR references keep their links visible as links. */
body:not(:has(.print-links, #printBook, #printPortfolio, #galleryGrid)) main a {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

img,
figure,
video {
    break-inside: avoid;
}

/* The letterhead stays: it's already a letterhead. Tightened and ruled off. */
#letterhead {
    margin: 0 0 0.3in;
    padding-bottom: 7pt;
    border-bottom: 0.5pt solid #000;
    line-height: 1.5;
}

#letterhead a {
    font-size: 7.5pt;
    font-weight: 400;
}

#letterhead .letterhead-name {
    font-size: 13pt;
    line-height: 1.3;
}

footer {
    margin-top: 0.4in;
    padding: 0;
    font-size: 7pt;
    color: #727272;
}

footer .motto-link {
    font-size: 9pt;
}

/* Built blocks are [hidden] on screen; printing reveals them. */
#printBook[hidden],
#printPortfolio[hidden] {
    display: block;
}

.print-caption[hidden] {
    display: flex;
}

/* ===================================
   Photobook — album pages
   Cover (with a small QR back to the album), then the photographs —
   one to a page, or two horizontals sharing one.
   =================================== */
body:has(#printBook) .gallery-shell,
body:has(#printBook) #letterhead,
body:has(#printBook) > footer {
    display: none;
}

:where(#printBook, .print-caption) * {
    font-size: inherit;
    font-family: inherit;
}

#printBook {
    font-family: var(--font-family);
    font-size: 7pt;
}

.book-cover {
    break-after: page;
}

.book-kicker,
.book-byline,
.book-folio,
.book-cover-foot p {
    margin: 0;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

.book-cover img {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 6.2in;
    margin: 0.35in 0 0.3in;
}

.book-cover h1 {
    margin: 0 0 8pt;
    font-family: var(--font-display);
    font-size: 36pt;
    font-weight: 400;
    line-height: 1.05;
}

.book-description {
    max-width: 4.5in;
    margin: 0 0 18pt;
    font-family: var(--font-text);
    font-size: 11pt;
    line-height: 1.5;
}

/* Fixed at 9in so it fits both Letter and A4 without spilling a blank page. */
.book-page {
    break-before: page;
    height: 9in;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --ratio (w/h) is set per photo, so the image and its folio line share
   one width and the folio sits flush with the photograph's edges. */
.book-page figure {
    --photo-h: 8.2in;
    --photo-w: min(100%, calc(var(--photo-h) * var(--ratio, 0.8)));
    width: var(--photo-w);
    margin: 0;
}

.book-page img {
    display: block;
    width: 100%;
    height: auto;
    max-height: var(--photo-h);
    object-fit: contain;
    border: 0;
    background: none;
}

.book-page--pair {
    flex-direction: column;
    gap: 0.35in;
}

.book-page--pair figure {
    --photo-h: 3.9in;
}

.book-folio {
    display: flex;
    justify-content: space-between;
    gap: 12pt;
    margin-top: 8pt;
}

.book-folio .book-folio-title {
    font-family: var(--font-text);
    font-style: italic;
    font-size: 9pt;
    text-transform: none;
    letter-spacing: normal;
    color: #000;
}

.book-cover-foot {
    display: flex;
    align-items: flex-end;
    gap: 8pt;
    margin-top: 0.3in;
}

.book-cover-foot .motto {
    margin: 2pt 0 0;
    font-family: var(--font-text);
    font-style: italic;
    font-size: 9pt;
}

/* ===================================
   Single photo — album page with the lightbox open
   A print with a wide mat and a ruled caption line.
   =================================== */
body:has(.lightbox.active) > :not(.lightbox) {
    display: none !important;
}

.lightbox.active {
    position: static;
    page: photo-portrait;
    height: 9.4in;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
}

body.print-landscape .lightbox.active {
    page: photo-landscape;
    height: 7.2in;
}

.lightbox.active {
    --photo-h: 7.4in;
    --photo-w: min(100%, calc(var(--photo-h) * var(--ratio, 0.8)));
}

body.print-landscape .lightbox.active {
    --photo-h: 5.7in;
}

.lightbox.active img {
    width: var(--photo-w);
    max-width: none;
    height: auto;
    max-height: var(--photo-h);
    object-fit: contain;
    background: none;
}

.print-caption {
    width: var(--photo-w);
    justify-content: space-between;
    align-items: baseline;
    gap: 12pt;
    margin-top: 0.3in;
    padding-top: 6pt;
    border-top: 0.5pt solid #000;
    font-family: var(--font-family);
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

.print-caption .print-caption-title {
    font-family: var(--font-text);
    font-style: italic;
    font-size: 11pt;
    text-transform: none;
    letter-spacing: normal;
    color: #000;
}

/* ===================================
   Photos index — photos.html
   =================================== */
#galleryGrid:not(.gallery-grid) {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.3in;
    margin: 0;
}

#galleryGrid:not(.gallery-grid)::before {
    content: "Photographs";
    grid-column: 1 / -1;
    margin-bottom: 4pt;
    font-family: var(--font-display);
    font-size: 30pt;
    line-height: 1.05;
}

#galleryGrid:not(.gallery-grid) .gallery-card {
    gap: 6pt;
    padding: 0;
    border: 0;
    break-inside: avoid;
}

#galleryGrid:not(.gallery-grid) .gallery-cover {
    aspect-ratio: 4 / 3;
    border: 0.5pt solid #000;
}

#galleryGrid:not(.gallery-grid) .gallery-title {
    font-size: 11pt;
}

/* ===================================
   QR references — shared by reports, logs, papers and the portfolio
   Anything paper can't hold (a link, a video, an embedded PDF) gets a
   small number in the text and a QR code in .print-links (js/print.js).
   =================================== */
.print-ref[hidden] {
    display: inline;
}

.print-links[hidden] {
    display: grid;
}

.print-ref {
    margin-left: 1pt;
    font-family: var(--font-family);
    font-size: 6pt;
    font-style: normal;
    vertical-align: super;
    line-height: 0;
    color: #727272;
}

.print-qr {
    display: block;
    flex: none;
    width: 0.5in;
    height: 0.5in;
}

.print-qr svg {
    display: block;
    width: 100%;
    height: 100%;
}

.print-links {
    gap: 8pt 14pt;
    margin-top: 12pt;
    padding-top: 10pt;
    border-top: 0.5pt solid #000;
    break-inside: avoid;
}

.print-links-label {
    grid-column: 1 / -1;
    margin: 0;
    font-family: var(--font-family);
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

.print-link {
    display: flex;
    align-items: flex-start;
    gap: 7pt;
    min-width: 0;
    break-inside: avoid;
}

.print-link-text {
    display: flex;
    flex-direction: column;
    gap: 1.5pt;
    min-width: 0;
}

.print-link-text span {
    font-family: var(--font-family);
    font-size: 6.5pt;
    font-style: normal;
    line-height: 1.35;
    text-indent: 0;
    overflow-wrap: anywhere;
}

.print-link-kind,
.print-link-url {
    color: #727272;
}

.print-link-kind {
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

/* ===================================
   Portfolio — projects.html
   Cover with contents, then exactly one page per project: a fixed-height
   sheet where the photograph gives up space to the text, never the other
   way round.
   =================================== */
body:has(#printPortfolio) main,
body:has(#printPortfolio) > footer {
    display: none;
}

:where(#printPortfolio) * {
    font-size: inherit;
    font-family: inherit;
    font-weight: inherit;
}

#printPortfolio {
    font-family: var(--font-family);
    font-size: 8.5pt;
}

.pf-cover {
    break-after: page;
}

.pf-cover h1 {
    margin: 1.2in 0 10pt;
    font-family: var(--font-display);
    font-size: 44pt;
    line-height: 1;
}

.pf-label,
.pf-meta,
.pf-url,
.pf-specs dt {
    margin: 0;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

.pf-contents {
    margin: 0.5in 0 0;
    padding: 0;
    list-style: none;
    border-top: 0.75pt solid #000;
}

.pf-contents li {
    display: grid;
    grid-template-columns: 0.35in 1fr 0.6in 2in;
    gap: 8pt;
    padding: 4pt 0;
    border-bottom: 0.5pt solid #cfcfcf;
    break-inside: avoid;
}

.pf-contents .pf-cat,
.pf-contents .pf-num {
    color: #727272;
}

/* 9.3in fits inside both Letter and A4 page areas. */
.pf-project {
    break-before: page;
    height: 9.3in;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pf-head {
    display: flex;
    align-items: baseline;
    gap: 12pt;
    padding-bottom: 6pt;
    border-bottom: 0.75pt solid #000;
}

.pf-head .pf-num {
    font-size: 8pt;
    color: #727272;
}

.pf-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 22pt;
    font-weight: 400;
    line-height: 1.1;
}

.pf-meta {
    margin: 6pt 0 14pt;
}

.pf-figure {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    align-items: flex-start;
    margin: 0 0 16pt;
}

.pf-figure img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: 0.5pt solid #000;
}

.pf-body {
    flex: none;
    display: grid;
    grid-template-columns: 2.1in 1fr;
    gap: 0.3in;
    align-items: start;
}

.pf-body:not(:has(.pf-specs)) {
    grid-template-columns: 1fr;
}

.pf-specs {
    margin: 0;
    padding: 8pt 10pt;
    border: 0.75pt solid #000;
}

.pf-specs dd {
    margin: 1pt 0 6pt;
    font-size: 7.5pt;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.pf-specs dd:last-child {
    margin-bottom: 0;
}

.pf-summary p {
    margin: 0 0 7pt;
    font-size: 9pt;
    line-height: 1.6;
}

.pf-foot {
    flex: none;
    text-align: left;
    display: flex;
    align-items: flex-end;
    gap: 10pt;
    margin-top: auto;
    padding-top: 10pt;
    border-top: 0.5pt solid #000;
}

.pf-foot-text {
    display: flex;
    flex-direction: column;
    gap: 2pt;
    min-width: 0;
}

.pf-url {
    text-transform: none;
    letter-spacing: 0.04em;
    word-break: break-all;
}

.pf-colophon {
    margin: 6pt 0 0;
    font-size: 7pt;
    color: #727272;
}

.pf-colophon .motto {
    font-family: var(--font-text);
    font-style: italic;
    font-size: 9pt;
}

/* ===================================
   Report — a single project page
   Text down the left beside the hero, numbered figures beneath, QR
   references at the end. Runs as many pages as it needs, but no block
   (spec box, figure, questions, QR strip) is ever split across a page.
   =================================== */
#projectGrid,
#projectGrid.project--brief,
#projectGrid.project--log {
    display: grid;
    grid-template-columns: minmax(0, 3.1in) minmax(0, 1fr);
    grid-template-areas:
        "label   label"
        "title   title"
        "info    hero"
        "gallery gallery";
    align-items: start;
    column-gap: 0.3in;
    max-width: none;
    margin: 0;
}

/* Nothing to show on the right: one column of text. */
#projectGrid:not(.project--log, :has(#projectHero, #projectGallery, .project-doc)) {
    grid-template-columns: minmax(0, 5.6in);
    grid-template-areas: "label" "title" "info";
}

#projectGrid::before {
    grid-area: label;
    content: "Project Report";
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

#projectGrid:is(.project--full, .project--brief, .project--log) #projectTitle {
    grid-area: title;
    max-width: none;
    margin: 4pt 0 14pt;
    font-size: 30pt;
    break-after: avoid;
}

#projectGrid:is(.project--full, .project--brief, .project--log) #projectInfo {
    grid-area: info;
    display: flex;
    flex-direction: column;
    gap: 14pt;
    max-width: none;
    margin: 0;
}

#projectGrid #projectLabel {
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 14pt;
    row-gap: 3pt;
    margin: 0;
    padding: 8pt 10pt;
    border: 0.75pt solid #000;
    break-inside: avoid;
}

#projectGrid #projectLabel dt,
#projectGrid #projectLabel dd {
    margin: 0;
    font-size: 7pt;
}

#projectGrid #projectLabel a {
    font-size: inherit;
}

#projectGrid #projectSummary {
    margin: 0;
    gap: 0.8em;
}

#projectGrid #projectSummary p,
#projectGrid #projectSummary a {
    font-size: 8.5pt;
    line-height: 1.55;
    orphans: 3;
    widows: 3;
}

#projectGrid #projectNotes {
    margin: 0;
    break-inside: avoid;
}

#projectGrid #projectNotes::before {
    font-size: 7pt;
}

#projectGrid .note-block {
    font-size: 10.5pt;
    border-bottom: 0.5pt solid #000;
}

#projectGrid #projectHero,
#projectGrid .project-doc {
    grid-area: hero;
    margin: 0;
    break-inside: avoid;
}

#projectGrid #projectHero {
    flex-direction: column;
    align-items: flex-start;
}

#projectGrid #projectHero img,
#projectGrid #projectHero video {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 5.2in;
    object-fit: contain;
    border: 0.5pt solid #000;
}

#projectGrid .project-doc {
    padding: 8pt 10pt;
    border: 0.75pt solid #000;
}

/* PDFs don't print inside an iframe; the QR at the end carries it. */
#projectGrid .project-doc iframe {
    display: none;
}

#projectGrid .project-doc .doc-meta,
#projectGrid .project-doc a {
    font-size: 7pt;
}

#projectGrid #projectGallery,
#projectGrid #projectGallery.gallery--even {
    grid-area: gallery;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12pt;
    margin: 18pt 0 0;
    padding-top: 12pt;
    border-top: 0.5pt solid #000;
    counter-reset: fig;
}

#projectGrid #projectGallery > * {
    gap: 5pt;
    padding: 5pt;
    border: 0.5pt solid #000;
    break-inside: avoid;
}

#projectGrid #projectGallery img,
#projectGrid #projectGallery video {
    max-height: 2.4in;
    aspect-ratio: auto;
}

#projectGrid #projectGallery figcaption,
#projectGrid #projectGallery > div span {
    font-size: 6.5pt;
    line-height: 1.4;
}

#projectGrid #projectGallery figcaption::before,
#projectGrid #projectGallery > div span::before {
    counter-increment: fig;
    content: "Fig. " counter(fig) " — ";
    color: #000;
}

/* The QR list sits inside the hero's figure (two across), under the text
   when there's no hero, or ahead of a log's entries (four across). Either
   way it is one unsplittable block with what it's attached to. */
#projectGrid .print-links {
    align-self: stretch;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 14pt;
    break-inside: avoid;
}

#projectGrid #projectInfo .print-links {
    margin-top: 4pt;
}

#projectGrid #projectLogEntries .print-links {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 0 0 14pt;
    padding: 0 0 12pt;
    border-top: 0;
    border-bottom: 0.5pt solid #cfcfcf;
}

/* ---- Log variant: one reading column, entries kept with their dates ---- */
#projectGrid.project--log {
    grid-template-columns: minmax(0, 6in);
    grid-template-areas: "label" "title" "meta" "entries";
}

#projectGrid.project--log::before {
    content: "Project Log";
}

#projectGrid #projectMeta {
    grid-area: meta;
    margin: 0 0 12pt;
    font-size: 7pt;
}

#projectGrid #projectLogEntries {
    grid-area: entries;
    padding-top: 12pt;
    border-top: 0.5pt solid #000;
}

#projectGrid #projectLogEntries h2 {
    font-size: 7pt;
    break-after: avoid;
}

#projectGrid #projectLogEntries h2 ~ h2 {
    margin-top: 14pt;
    padding-top: 10pt;
}

#projectGrid #projectLogEntries p,
#projectGrid #projectLogEntries ul,
#projectGrid #projectLogEntries ol,
#projectGrid #projectLogEntries blockquote {
    font-size: 8.5pt;
    line-height: 1.55;
    margin-bottom: 0.7em;
    orphans: 3;
    widows: 3;
}

#projectGrid #projectLogEntries :is(p, li, blockquote) :not(.print-ref) {
    font-size: inherit;
}

#projectGrid #projectLogEntries img,
#projectGrid #projectLogEntries video {
    width: auto;
    max-width: 100%;
    max-height: 3.2in;
    margin: 0.5em 0;
    border: 0.5pt solid #000;
    break-inside: avoid;
}

/* ===================================
   Paper — a log post
   A centred serif column; the writing side of the site, so DM Serif Text.
   =================================== */
:where(#post) * {
    font-family: inherit;
    font-size: inherit;
}

#post {
    max-width: 5.8in;
    margin: 0.45in auto 0;
    font-family: var(--font-text);
    font-size: 11pt;
    line-height: 1.55;
    orphans: 3;
    widows: 3;
}

#post h1 {
    margin: 0 0 22pt;
    font-family: var(--font-display);
    font-size: 26pt;
    line-height: 1.1;
}

#post h1::after {
    content: "Christopher Lam";
    display: block;
    margin-top: 10pt;
    font-family: var(--font-family);
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: #727272;
}

#post h2,
#post h3 {
    margin: 18pt 0 6pt;
    font-family: var(--font-display);
    font-weight: 400;
    line-height: 1.2;
    break-after: avoid;
}

#post h2 { font-size: 15pt; }
#post h3 { font-size: 12pt; font-style: italic; }

#post p,
#post ul,
#post ol,
#post blockquote {
    font-size: inherit;
    margin: 0;
}

/* Paragraphs run on with an indent, like a printed essay. */
#post p + p {
    text-indent: 1.5em;
}

#post ul,
#post ol {
    margin: 6pt 0;
    padding-left: 1.5em;
}

#post blockquote {
    margin: 10pt 1.5em;
    padding: 0;
    border: 0;
    color: #000;
    font-style: italic;
}

#post a {
    text-decoration: none;
}

#post img {
    width: auto;
    max-width: 100%;
    max-height: 4in;
    margin: 12pt auto;
}

#post code,
#post pre {
    font-family: var(--font-family);
    font-size: 8.5pt;
    background: none;
}

#post pre {
    margin: 8pt 0;
    padding: 0 0 0 10pt;
    border-left: 0.5pt solid #000;
    white-space: pre-wrap;
}

#post hr {
    width: 1in;
    margin: 18pt auto;
    border: 0;
    border-top: 0.5pt solid #000;
}

body:has(#post) > footer {
    max-width: 5.8in;
    margin: 0.5in auto 0;
    padding-top: 6pt;
    border-top: 0.5pt solid #000;
    text-align: left;
}

/* Endnotes: the links and videos in the post, with QR codes. */
body:has(#post) .print-links {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-width: 5.8in;
    margin: 0.35in auto 0;
}
