/* Print stylesheet for the generated songbook PDF (rendered by WeasyPrint). */

@page {
    size: A4;
    margin: 12mm 12mm 14mm;
}

html {
    font-family: "Latin Modern Roman", "Georgia", "Times New Roman", serif;
    /* Base size; everything else is sized in `em`, so this scales the whole book. */
    font-size: 12pt;
    line-height: 1.15;
    color: #000;
}

body {
    margin: 0;
}

/* Two-column flow: fill the first column top-to-bottom, then the second. */
.songs {
    column-count: 2;
    column-gap: 8mm;
    column-fill: auto;
}

/* --- Table of contents (optional, single column) ------------------------- */
/* break-after: right makes the songs start on a recto (right-hand, odd) page,
   so the table of contents always occupies a whole number of double-sided
   sheets — a blank verso page is inserted when it would otherwise be odd. That
   lets the printed contents be detached as complete sheets and moved to the end. */
.toc {
    break-after: right;
}

.toc-title {
    font-variant: small-caps;
    font-weight: bold;
    font-size: 1.9em;
    letter-spacing: 0.02em;
    margin: 0 0 4mm;
}

.toc-entry {
    display: flex;
    align-items: baseline;
    text-decoration: none;
    color: #000;
    margin: 0.6mm 0;
}

.toc-num {
    min-width: 2.4em;
}

/* Dotted leader that grows to fill the space between title and page number. */
.toc-fill {
    flex: 1 1 auto;
    margin: 0 0.4em;
    border-bottom: 1px dotted #999;
    transform: translateY(-0.25em);
}

/* Page number of the linked song, resolved by WeasyPrint after layout. */
.toc-entry::after {
    content: target-counter(attr(href), page);
}

.song {
    margin-bottom: 4mm;
    /* Every song begins at the top of a (new) column. */
    break-before: column;
    /* Keep a song on a single page: it may span the two columns of one page,
       but if it would cross a page boundary it starts fresh on the next page. */
    break-inside: avoid-page;
}

/* An empty column-filler the view drops in before a two-column song so the song
   starts in the left column of a page and never straddles a page boundary. It
   consumes its column (via break-before: column above) but shows nothing. */
.song.spacer {
    margin: 0;
}

/* A song with an image fills a whole column: text at the top, image below
   stretching to the bottom. Height = A4 (297mm) minus the 12mm top + 14mm
   bottom @page margins = one full column. */
.song.has-image {
    display: flex;
    flex-direction: column;
    height: 270mm;
    /* Keep the whole song+image together in a single column (must not split
       across the column boundary, which flex fragmentation would otherwise do). */
    break-inside: avoid;
    margin-bottom: 0;
}

.song.has-image .song-content {
    flex: 0 0 auto;
}

.song-image {
    flex: 1 1 auto;
    min-height: 0;
    margin-top: 3mm;
}

.song-image img {
    width: 100%;
    height: 100%;
    /* Scale as large as possible in the leftover space without cropping or
       distorting, centered. */
    object-fit: contain;
    object-position: center;
}

/* --- Song header: gray number box, small-caps title, italic author ------- */
.song-head {
    display: flex;
    align-items: flex-start;
    gap: 2mm;
    break-after: avoid;
    margin-bottom: 1.5mm;
}

.song-num {
    background: #d9d9d9;
    padding: 0 1.6mm;
    font-weight: bold;
    font-size: 1.15em;
    line-height: 1.35;
}

.song-title {
    display: block;
    font-variant: small-caps;
    font-weight: bold;
    font-size: 1.55em;
    letter-spacing: 0.02em;
    line-height: 1.05;
}

.song-author {
    display: block;
    font-style: italic;
    font-size: 0.9em;
}

/* --- Stanzas ------------------------------------------------------------- */
.stanza {
    margin: 0 0 2.6mm;
    break-inside: avoid;
}

/* A numbered verse lays its number in a fixed gutter to the left of the lines,
   so every line of the verse (including a long first line that wraps) aligns at
   the same left edge. A verse whose number is written inline in the lyrics is
   not "numbered" and stays flush-left. */
.stanza.verse.numbered {
    display: flex;
    align-items: baseline;  /* the number sits on the first line's baseline */
}

.stanza-body {
    flex: 1 1 auto;
    min-width: 0;  /* let the lines wrap within the column instead of overflowing */
}

/* Choruses: vertical rule down the left edge, no verse number. */
.stanza.chorus {
    border-left: 1.2pt solid #333;
    padding-left: 1.8mm;
}

.verse-num {
    flex: 0 0 auto;
    min-width: 1.4em;
    margin-right: 0.2em;
    font-weight: normal;
}

.chorus-label {
    margin-right: 0.4em;
    font-weight: bold;
}

/* --- A single rendered line ---------------------------------------------- */
/* Flex row: whitespace-only text nodes between segments are ignored, so the
   segments butt directly together and the spacing comes only from the lyric
   text itself (which is preserved with white-space: pre-wrap).
   flex-wrap: wrap keeps a too-long line inside its column by wrapping it onto a
   second visual row (breaking between whole chord+lyric segments, so the chords
   stay aligned over their syllables) instead of overflowing into the next
   column. A wrapped row starts at the line's left edge. */
.line {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
}

/* Each chord+lyric pair is a vertical stack, so its width is the wider of the
   chord and the lyric fragment and a wide chord never overlaps the next one.
   min-width: 0 lets a segment shrink below its content width so a single very
   long segment (e.g. a whole chord-less lyric line, which the parser emits as
   one segment) can wrap internally instead of spilling past the column. */
.seg {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    min-width: 0;
}

.chord {
    min-height: 1.15em;
    padding-right: 0.35em;
    font-weight: bold;
    font-size: 0.85em;
    line-height: 1.15;
    color: #c00014;
    white-space: pre;
}

.txt {
    /* pre-wrap preserves the alignment spacing baked into the lyric text but,
       unlike pre, still lets an over-long line wrap at its spaces so it stays
       within the column. break-word additionally breaks a single word that is
       itself wider than the column (a rare but otherwise-overflowing case). */
    white-space: pre-wrap;
    overflow-wrap: break-word;
    min-height: 1.15em;
    line-height: 1.15;
}

/* --- A chord-progression / section line ---------------------------------- */
/* Chords, section labels ("Intro:"), separators and repeat marks laid out
   inline on one baseline (an intro/interlude/"Em D G 4x"), rather than chords
   stacked above a lyric. font-size matches the stacked .chord above so a chord
   is the same size wherever it appears. */
.line.progression {
    align-items: baseline;
    gap: 0 0.5em;
    margin: 0.4mm 0 1.4mm;
    font-size: 0.85em;
}

.prog-chord {
    font-weight: bold;
    color: #c00014;  /* same red as the stacked .chord */
}

.prog-label {
    font-weight: bold;
}

.prog-sep {
    color: #777;
}
