/*
Multi-page content: Section List page and its sections (the same page settings as Grav Helios Open Reader), in Quark 2's
style - hibbittsdesign.org
The guide templates are the same as in Quark Open Publishing, so the first part of this file gives the few Spectre classes
they use (grid columns, progress bar, side list, hidden text) a Quark 2 look. Buttons (btn btn-primary) are Quark 2's own,
filled with the accent colour. Colours, radii and shadows all come from
Quark 2's --q2-* tokens, so Light and Dark mode both work without extra rules.
*/

/* ---------- Classes from Quark Open Publishing's templates ---------- */

/* Text for screen readers only */
.text-assistive {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.img-responsive {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Section pages: the page and its side list, side by side on wider screens */
.columns:has(> #sections-nav) {
    gap: clamp(2rem, 4vw, 3rem);
}

/* the page takes its full reading width first (see below), and the side list the rest (at most 22rem, on the right),
   so the side list sits close beside the page rather than at the far edge. The side list is at least 17rem wide, so
   longer page titles wrap less on laptop screens (the page then gives up a little of its width, still a comfortable
   line length) */
@media (min-width: 960px) {
    .columns:has(> #sections-nav) {
        grid-template-columns: minmax(0, 42rem) minmax(17rem, 1fr);
    }

    #sections-nav {
        width: 100%;
        max-width: 22rem;
        justify-self: end;
    }

    /* the side list stays in view below the header while reading a long page; when the list of sections is taller
       than the window, it scrolls on its own */
    #sections-nav {
        position: sticky;
        top: calc(var(--q2-header-height) + 1.5rem);
        align-self: start;
        display: flex;
        flex-direction: column;
        max-height: calc(100vh - var(--q2-header-height) - 3rem);
    }

    #sections-nav > ul.nav {
        min-height: 0;
        overflow-y: auto;
    }

    /* with a Side Box, the side list and the box simply follow each other and scroll with the page (no sticky list
       scrolling on its own), so the whole list shows and the box comes into view as the reader scrolls - unless they
       fit in the window together, when js/reader.js adds the reader-side-box-fits class and the side list stays in view */
    #sections-nav:has(> .reader-side-box):not(.reader-side-box-fits) {
        position: static;
        max-height: none;
    }

    #sections-nav:has(> .reader-side-box):not(.reader-side-box-fits) > ul.nav {
        overflow-y: visible;
    }
}

/* Side Box: the author's Markdown under the side list, as the last part of the side list's card - a thin line above
   it (like the one under the search box) and no fill, so it never looks like a callout on the page or competes with
   the highlighted current section */
.reader-side-box {
    /* the same 1rem space on each side of the line as under the search box (less the last row's own 6px below it),
       and text lined up with the side list's 10px inset */
    margin-top: calc(1rem - 6px);
    padding: 1rem 10px 0;
    border-top: 1px solid var(--q2-divider);
    color: var(--q2-text);
}

.reader-side-box > :first-child {
    margin-top: 0;
}

.reader-side-box > :last-child {
    margin-bottom: 0;
}

.reader-side-box img {
    max-width: 100%;
    height: auto;
}

/* lists use less of the card's narrow width */
.reader-side-box :is(ul, ol) {
    margin: 0.5rem 0;
    padding-left: 1.1rem;
}

/* Section cards: 1, 2 or 3 per row (the template gives each card col-12, col-6 or col-4), one per row on phones */
.section-cards {
    list-style: none;
    margin: 0 0 2rem;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1.25rem;
}

.section-cards > .column {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
}

.section-cards > .col-12 { grid-column: span 12; }
.section-cards > .col-6 { grid-column: span 6; }
.section-cards > .col-4 { grid-column: span 4; }

@media (max-width: 840px) {
    .section-cards > .col-md-6 { grid-column: span 6; }
}

@media (max-width: 600px) {
    .section-cards > .col-sm-12 { grid-column: span 12; }
}

/* A course card without an image: a band in the image's place and shape (2:1, as the images are cropped), in the
   course's Course Color (--card-band-color, set on the card) or the site's accent colour, softened (see
   reader-list.html.twig) */
.card-color-band {
    aspect-ratio: 2 / 1;
    background: color-mix(in oklab, var(--card-band-color, var(--q2-accent)) 55%, transparent);
}

/* Cards side by side line up: each card's image, title and details share rows with the other cards in its row,
   so a one-line title leaves space to match a two-line title next to it (subgrid; older browsers keep each card's
   own heights). Only in lists without side-image cards, which have their own layout. */
@supports (grid-template-rows: subgrid) and selector(:has(*)) {
    .section-cards:not(:has(.section-card-image-side)) > .column,
    .section-cards:not(:has(.section-card-image-side)) .section-card {
        grid-row: span 3;
        display: grid;
        grid-template-rows: subgrid;
        row-gap: 0;
    }

    /* each part keeps its own row, even when a card has no image */
    .section-cards:not(:has(.section-card-image-side)) .section-card > .card-image { grid-row: 1; }
    .section-cards:not(:has(.section-card-image-side)) .section-card > .card-header { grid-row: 2; }
    .section-cards:not(:has(.section-card-image-side)) .section-card > .card-body { grid-row: 3; }
}

/* the author and date sit at the bottom of the card, so they line up even when descriptions differ in length
   (any spare space goes below the description; the author line keeps its own small gap above it) */
.section-card > .card-body {
    display: flex;
    flex-direction: column;
}

.section-card > .card-body > .section-card-description {
    margin-bottom: auto;
}

/* ---------- Titles and labels ---------- */

/* The guide's title is an h1 (and section page titles too), shown at Quark 2's h3 size */
.sections-page-title-template {
    margin: 0 0 0.75rem;
    font-size: clamp(1.25rem, 1.5vw + 0.5rem, 1.5rem);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.005em;
}

/* Small label above a section's title, for example "Unit 2", scaled up by the same amount as the links above it;
   smaller on the section cards */
.reader-section-label {
    color: var(--q2-text-muted);
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.857rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin: 0 0 0.25rem;
}

.section-card .reader-section-label {
    font-size: 0.75rem;
}

/* the page title sits just below its section label, as in Quark Open Publishing (without Quark 2's usual space above headings) */
.reader-section-label + .sections-page-title-template {
    margin-top: 0;
}

/* ---------- Section List page header: cover image and details ---------- */

.reader-header {
    display: flex;
    align-items: flex-start;
    gap: 1.5rem;
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--q2-divider);
}

.reader-cover {
    flex: 0 0 auto;
    width: 10rem;
    border-radius: var(--q2-radius);
    box-shadow: var(--q2-shadow-card);
}

/* Section List page with a small cover: a 4:3 cover (about as tall as the title, details and Start button beside it),
   cropped to fill it */
.section-list-page .reader-cover {
    width: 18rem;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

/* A portrait cover (such as a book cover) is shown whole, at its own shape and a narrower width, also on phones
   (both class names are needed so this also replaces the full-width cover on phones). An unusually tall image
   is kept to 18rem high, and narrows to keep its shape. */
.section-list-page .reader-cover.reader-cover-portrait {
    width: auto;
    max-width: 11rem;
    max-height: 18rem;
    aspect-ratio: auto;
}

.reader-details p {
    margin: 0 0 0.3rem;
}

.reader-details .sections-page-title-template {
    margin-top: 0;
}

/* the guide's title, as large as its section pages' titles */
.section-list-page .sections-page-title-template {
    font-size: clamp(1.5rem, 2vw + 0.75rem, 1.875rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.015em;
}

/* the subtitle in Quark 2's "lead" style, as under a blog page's title */
.reader-subtitle {
    color: var(--q2-text-muted);
    font-size: 1.125rem;
    font-weight: 300;
    letter-spacing: -0.2px;
    line-height: 1.55;
}

.reader-edition {
    color: var(--q2-text-muted);
    font-size: 0.875rem;
}

.reader-license.label {
    margin-top: 0.25rem;
}

/* the Start button at the end of the details */
.reader-details .section-list-start {
    margin: 0.75rem 0 0;
}

/* the Start Reading link after the section cards */
.section-list-start-below {
    margin: 1.5rem 0 0;
    font-weight: 600;
}

.section-list-start-below .fa {
    margin-left: 0.25rem;
    font-size: 0.85em;
}

/* Large cover: full width of the content area, at the top */
.reader-cover-large {
    display: block;
    width: 100%;
    max-height: 36rem;
    object-fit: cover;
    border-radius: var(--q2-radius-md);
    box-shadow: var(--q2-shadow-card);
    margin-bottom: 1.5rem;
}

/* A portrait cover (such as a book cover): shown whole, at its own width up to the full width and at most
   36rem high, instead of trimmed to fill the width */
.reader-cover-large-portrait {
    width: auto;
    max-width: 100%;
    height: auto;
}

@media (max-width: 600px) {
    .reader-header {
        flex-direction: column;
    }

    .section-list-page .reader-cover {
        width: 100%;
    }
}

/* ---------- Section List page: search box, parts and cards ---------- */

/* the row above the section cards: the "Continue reading" bar on the left and the guide's search box on the right
   (stacked and full width on tablets and phones). The row is hidden when it has nothing to show. */
.section-list-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0 2rem;
}

/* hide the row when everything in it is hidden (:has() checks the row's contents) */
.section-list-actions:not(:has(> :not([hidden]))) {
    display: none;
}

.section-list-actions .reader-search {
    flex: 0 1 22rem;
    margin-left: auto;
}

/* With no "Continue reading" bar, the search box moves to the left
   ([hidden] matches the hidden bar; + means the element right after it) */
.section-list-actions .reader-resume[hidden] + .reader-search,
.section-list-actions > .reader-search:first-child {
    margin-left: 0;
}

/* Guides List search box with 2 or 3 cards per row: as wide as one card, using the cards' 12-column grid and
   column gap (the template gives the box the same col-6 or col-4 classes as the cards) */
.section-list-actions.reader-list-search-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: 1.25rem;
}

.reader-list-search-grid > .reader-search {
    width: auto;
    max-width: none;
    margin-left: 0;
}

.reader-list-search-grid > .col-6 { grid-column: span 6; }
.reader-list-search-grid > .col-4 { grid-column: span 4; }

@media (max-width: 840px) {
    .reader-list-search-grid > .col-md-6 { grid-column: span 6; }
}

@media (max-width: 600px) {
    .reader-list-search-grid > .col-sm-12 { grid-column: span 12; }
}

/* stacked below 960px, so a long page title in the bar still fits on one line */
@media (max-width: 959px) {
    .section-list-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .section-list-actions .reader-search {
        flex-basis: auto;
        margin-left: 0;
    }
}

/* Keep My Place: the "Continue reading" bar above the section cards, as in Helios Open Reader. It uses Quark 2's
   alert recipe (a light tint of the accent colour over the card surface), and its close button follows Quark 2's
   round icon button (the light/dark toggle) */
.reader-resume {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem 0.625rem 1rem;
    background: color-mix(in oklab, var(--q2-accent) 6%, var(--q2-bg-elev));
    border-radius: var(--q2-radius);
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.9375rem;
    color: var(--q2-text);
}

.reader-resume[hidden] {
    display: none;
}

.reader-resume > .fa {
    color: var(--q2-accent);
    flex: 0 0 auto;
}

.reader-resume-link {
    flex: 1;
    min-width: 0;
    color: var(--q2-text);
    text-decoration: none;
}

.reader-resume-title {
    color: var(--q2-link);
    font-weight: 600;
}

.reader-resume-link:hover .reader-resume-title {
    text-decoration: underline;
}

.reader-resume-dismiss {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--q2-radius-pill);
    background: transparent;
    box-shadow: none;
    color: var(--q2-text-muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.reader-resume-dismiss:hover {
    background: var(--q2-bg-muted);
    color: var(--q2-text-strong);
}

/* a solid ring in the link colour, as Quark 2's lighter focus ring is too faint on the tinted bar in Dark mode */
.reader-resume-dismiss:focus-visible {
    outline: 2px solid var(--q2-link);
    outline-offset: 2px;
}

/* in Dark mode, the title a little lighter than Quark 2's link colour, for enough contrast on the tinted bar */
:root[data-theme="dark"] .reader-resume-title {
    color: color-mix(in oklab, var(--q2-link) 90%, white);
}

/* Part headings, and headings in the text below the cards, with Quark 2's divider line */
.reader-part-heading,
.section-list-below h2,
.section-list-below h3,
.section-list-below h4 {
    font-weight: 600;
    letter-spacing: 0;
    color: var(--q2-text);
    font-size: 1.1rem;
    padding-bottom: 0.5rem;
    margin: 2rem 0 1.25rem;
    border-bottom: 1px solid var(--q2-divider);
}

/* part headings (and h2 below the cards) a step larger than the card titles, so the groups stand out */
.reader-part-heading,
.section-list-below h2 {
    font-size: 1.25rem;
}

/* Section cards use Quark 2's card; the title link covers the whole card */
.section-card {
    position: relative;
    width: 100%;
}

/* A card with just a label and title: the same space below the title as above it
   (Quark 2's card header leaves less space below, for a description that would follow) */
.section-card-title-only .card-header {
    padding-bottom: 1.25rem;
}

/* Card titles are h2 or h3, shown at Quark 2's h5 size */
.section-card .card-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: 0.2px;
}

/* No accent bar above these h2s (Quark 2 adds one to h2 headings) */
.reader-part-heading::before,
.section-list-below h2::before,
.section-card .card-title::before {
    display: none;
}

.section-card-link {
    color: var(--q2-text-strong);
    text-decoration: none;
}

.section-card-link::after {
    content: "";
    position: absolute;
    inset: 0;
}

/* Quark 2 positions card titles, which would keep the link's cover to the title alone; this lets it cover the whole
   card, image included, like the blog's cards */
.section-card .card-title {
    position: static;
}

.section-card:hover .section-card-link {
    text-decoration: underline;
}

.section-card:focus-within {
    outline: 2px solid var(--q2-focus-ring);
    outline-offset: 2px;
}

.section-card-description {
    color: var(--q2-text-muted);
    font-size: 0.9375rem;
    margin: 0;
}

/* the section's Author(s), below its description */
.section-card-author {
    color: var(--q2-text-muted);
    font-size: 0.8125rem;
    margin: 0;
}

.section-card-description + .section-card-author {
    margin-top: 0.5rem;
}

/* Card Image Layout "side" (as in Grav Helios Open Reader): on wider screens the card becomes two columns, with its
   image in a fixed-width column on the left (narrower with 2 cards per row) and the label, title and description on
   the right, with an arrow after the title. On phones the image goes on top, at a fixed height. */
@media (min-width: 600px) {
    .section-card-image-side {
        display: grid;
        grid-template-columns: 12rem 1fr;
        grid-template-rows: auto 1fr;
    }

    .section-cards > .col-6 .section-card-image-side {
        grid-template-columns: 9rem 1fr;
    }

    .section-card-image-side .card-image {
        grid-row: 1 / 3;
        position: relative;
        min-height: 9rem;
    }

    /* a colour band fills its column, as an image does */
    .section-card-image-side .card-color-band {
        aspect-ratio: auto;
    }

    /* the image is cropped to fill its column, however tall the text beside it is */
    .section-card-image-side .card-image img {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
        object-fit: cover;
    }

    .section-card-image-side .card-header {
        padding: 1.5rem 1.5rem 0;
    }

    .section-card-image-side .card-body {
        padding: 0.75rem 1.5rem 1.5rem;
    }
}

@media (max-width: 599px) {
    .section-card-image-side .card-color-band {
        height: 10rem;
    }

    .section-card-image-side .card-image img {
        height: 10rem;
        aspect-ratio: auto;
        object-fit: cover;
    }
}

/* the title and its arrow on one line, the arrow at the far right (a long title wraps beside it) */
.section-card .card-title {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.section-card-arrow {
    flex-shrink: 0; /* keeps its size beside a long title */
    margin-left: auto;
    font-size: 0.8em;
    opacity: 0.5;
    transition: opacity 0.15s;
    pointer-events: none; /* clicks pass through to the card's link, so the arrow opens the section too */
}

.section-card:hover .section-card-arrow {
    opacity: 1;
}

/* Section badges (Badge Label and Badge Color settings, as in Grav Helios Open Reader): a small status tag such as
   "New" or "Draft" beside the section label on a card, in a light tint of its colour */
.section-card-label-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.25rem;
}

.section-card-label-row .reader-section-label {
    margin: 0;
}

.section-badge.label {
    --badge-color: var(--q2-accent);
    margin: 0;
    padding: 0.125rem 0.5rem;
    border: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--badge-color);
    background: color-mix(in oklab, var(--badge-color) 14%, transparent);
}

.section-badge-blue.label { --badge-color: #1d4ed8; }
.section-badge-green.label { --badge-color: #166534; }
.section-badge-yellow.label { --badge-color: #854d0e; }
.section-badge-red.label { --badge-color: #b91c1c; }
.section-badge-purple.label { --badge-color: #7e22ce; }

.section-badge-plain.label {
    color: var(--q2-text-muted);
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--q2-divider);
}

/* lighter colours in Dark mode, so the badges stay easy to read */
:root[data-theme="dark"] .section-badge.label { --badge-color: color-mix(in oklab, var(--q2-link) 75%, white); }
:root[data-theme="dark"] .section-badge-blue.label { --badge-color: #93c5fd; }
:root[data-theme="dark"] .section-badge-green.label { --badge-color: #86efac; }
:root[data-theme="dark"] .section-badge-yellow.label { --badge-color: #fde047; }
:root[data-theme="dark"] .section-badge-red.label { --badge-color: #fca5a5; }
:root[data-theme="dark"] .section-badge-purple.label { --badge-color: #d8b4fe; }

/* Description Line Limit (as in Open Reader): card descriptions cut to 2 or 3 lines, ending in "..." */
.section-cards-lines-2 .section-card-description,
.section-cards-lines-3 .section-card-description {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.section-cards-lines-2 .section-card-description {
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.section-cards-lines-3 .section-card-description {
    -webkit-line-clamp: 3;
    line-clamp: 3;
}

.section-list-below {
    margin-top: 1rem;
}

/* ---------- Section pages: back link, Previous/Next at the top, side list ---------- */

.reader-top-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    /* centred, not lined up by text baseline: the back and Sections links are paragraphs (taller line height)
       and the top Previous/Next links aren't, so baseline alignment left Previous/Next slightly higher */
    align-items: center;
    gap: 0 1.25rem;
}

/* the back link, Sections link and top Previous/Next links, at body text size and without an underline; the links are
   in the link colour, so they look tappable (on phones there's no hover to show it), as in Grav Open Course Hub and
   Quark Open Publishing */
.reader-back-link,
.reader-sections-link,
.reader-prev-next-top {
    font-family: var(--pico-font-family-sans-serif);
    font-size: 1rem;
    margin: 0 0 1rem;
    color: var(--q2-text-muted);
}

.reader-back-link a,
.reader-sections-link a,
.reader-prev-next-top a {
    padding: 0.25rem 0; /* a little taller, for easier tapping */
    color: var(--q2-link);
    text-decoration: none;
}

.reader-back-link a:hover,
.reader-sections-link a:hover,
.reader-prev-next-top a:hover {
    color: var(--q2-text-strong);
}

.reader-prev-next-top {
    white-space: nowrap;
    align-items: center; /* keeps the dot between the links centred */
}

.reader-back-link .fa,
.reader-sections-link .fa,
.reader-prev-next-top .fa {
    font-size: 0.75em;
}

.reader-prev-next-top-divider {
    color: var(--q2-text-muted);
    margin: 0 0.5rem;
}

/* the Sections link is only needed when the side list sits below the page (phones and narrow windows) */
@media (min-width: 960px) {
    .reader-sections-link {
        display: none;
    }
}

/* The top of the side list: the Hide/Show sidebar button (on a guide's pages) and the search box, with the line below
   them that was under the search box */
#sections-nav .reader-sidebar-top {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--q2-divider);
}

/* on phones and narrow windows, where the button isn't shown, a guide without a search box has nothing in this top
   area, so it (and its line) is left out */
@media (max-width: 959.98px) {
    #sections-nav .reader-sidebar-top:not(:has(.reader-search)) {
        display: none;
    }
}

/* The Hide/Show sidebar button: only on wider screens, where the side list sits beside the page. In its own row at the
   top right of the sidebar (not beside the search box, where it would look like a search button), in the page's text
   colour, at least 40px tall: "Hide sidebar »" while expanded, and just « in the collapsed tab, its name then read by
   screen readers and shown on hover (see js/reader.js) */
.reader-sidebar-toggle-row {
    display: none;
}

@media (min-width: 960px) {
    .reader-sidebar-toggle-row {
        display: flex;
        justify-content: flex-end;
        margin: -0.5rem 0 0.5rem;
    }
}

.reader-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 2.5rem;
    min-height: 2.5rem;
    margin: 0;
    padding: 0 0.5rem;
    border: 0;
    border-radius: var(--q2-radius-sm);
    background: none;
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.875rem;
    color: var(--q2-text);
    cursor: pointer;
}

.reader-sidebar-toggle[hidden] {
    display: none;
}

/* until js/reader.js shows the button, its row keeps the button's height (the class is added in
   templates/sections.html.twig), so the search box below it doesn't jump down as each page loads */
.reader-sidebar-js .reader-sidebar-toggle-row {
    min-height: 2.5rem;
}

.reader-sidebar-toggle:hover {
    background: var(--q2-bg-muted);
    color: var(--q2-text-strong);
}

.reader-sidebar-toggle:focus-visible {
    outline: 2px solid var(--q2-link);
    outline-offset: 2px;
}

/* the words: "Hide sidebar" shown while expanded; while collapsed, "Show sidebar" is for screen readers only */
html:not(.reader-sections-hidden) .reader-sidebar-toggle-show,
.reader-sections-hidden .reader-sidebar-toggle-hide {
    display: none;
}

.reader-sidebar-toggle-show {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Collapsed (wider screens): the sidebar becomes a slim tab with just the button, in exactly the same top corner (the
   card keeps its padding), still staying in view while reading; the page is centred, at the same comfortable width.
   (The tab always stays in view, even with a Side Box, hence !important over the Side Box's "scroll with the page" rule) */
@media (min-width: 960px) {
    .reader-sections-hidden .columns:has(> #sections-nav) {
        grid-template-columns: 1fr minmax(0, 42rem) 1fr;
    }

    .reader-sections-hidden #sections-content {
        grid-column: 2;
    }

    .reader-sections-hidden #sections-nav {
        grid-column: 3;
        width: auto;
        position: sticky !important;
        max-height: none;
    }

    .reader-sections-hidden #sections-nav > :not(.reader-sidebar-top),
    .reader-sections-hidden #sections-nav .reader-search {
        display: none;
    }

    .reader-sections-hidden #sections-nav .reader-sidebar-top {
        margin: 0;
        padding: 0;
        border: 0;
    }

    .reader-sections-hidden .reader-sidebar-toggle-row {
        margin: -0.5rem 0;
    }

    /* the arrows point back («) to expand */
    .reader-sections-hidden .reader-sidebar-toggle-icon {
        transform: rotate(180deg);
    }
}

/* ---------- Section pages: comfortable reading, as in a book ---------- */

/* a comfortable line length: the page column is at most about 80 characters of text wide
   (centred when the page is embedded, without its side list) */
#sections-content {
    max-width: 42rem;
}

#sections-content.col-12 {
    margin-inline: auto;
}

/* the page's text a little larger than elsewhere, without words broken across lines
   (Quark 2 hyphenates by default, which suits cards but interrupts longer reading) */
.reader-content p,
.reader-content li,
.reader-content dd,
.reader-content blockquote {
    font-size: 1.0625rem;
}

.reader-content,
.reader-content * {
    hyphens: manual;
}

/* the same for the Guides page's own text and a guide home's details and intro, but not their cards */
.reader-list-page > p,
.reader-list-page > ul:not(.section-cards) li,
.section-list-page p,
.section-list-page li {
    hyphens: manual;
}

.section-list-page .section-cards p,
.section-list-page .section-cards li {
    hyphens: auto;
}

/* the section's title is the largest heading on the page, as in a book's chapter title */
#sections-content .sections-page-title-template {
    font-size: clamp(1.5rem, 2vw + 0.75rem, 1.875rem);
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: -0.015em;
}

/* headings in the page's text keep Quark 2's styles (and h2's accent dash), a step below the title */
.reader-content h2 {
    font-size: clamp(1.25rem, 1vw + 0.875rem, 1.5rem);
    margin-top: 2.5rem;
}

.reader-content h3 {
    font-size: clamp(1.125rem, 0.5vw + 1rem, 1.25rem);
    margin-top: 2rem;
}

.reader-content h4 {
    font-size: 1.0625rem;
}

/* wide tables scroll sideways inside the text column (js/reader.js puts each table in this box) */
.reader-table-scroll {
    overflow-x: auto;
    margin-bottom: 1rem;
}

.reader-table-scroll table {
    margin-bottom: 0;
}

/* on phones, table cells get less padding and slightly smaller text, so tables of three or four columns fit the
   screen instead of scrolling sideways (wider tables still scroll) */
@media (max-width: 600px) {
    .reader-content table th,
    .reader-content table td {
        padding: 0.5rem 0.4rem;
        font-size: 0.875rem;
    }
}

/* quotations in the reading font, keeping Quark 2's left border (its display font suits short pull quotes,
   but is heavy for the longer quoted passages common in textbooks) */
.reader-content blockquote {
    font-family: var(--pico-font-family-sans-serif);
    font-size: 1.0625rem;
    line-height: 1.7;
}

/* footnotes (with Markdown Extra) as smaller, muted notes below the text */
.reader-content .footnotes p,
.reader-content .footnotes li {
    font-size: 0.875rem;
    color: var(--q2-text-muted);
}

/* The search box and side list of sections share one of Quark 2's sidebar cards (as in the blog's sidebar), so they
   read as one place to find your way around the guide. The padding is a little less at the sides than in the blog's
   cards, leaving more room for page titles. */
#sections-nav {
    background: var(--q2-bg-elev);
    border-radius: var(--q2-radius-md);
    box-shadow:
        rgba(19, 19, 22, 0.04) 0 1px 2px,
        rgba(19, 19, 22, 0.06) 0 8px 24px -8px;
    padding: 1.25rem 1rem;
}

:root[data-theme="dark"] #sections-nav {
    box-shadow:
        rgba(0, 0, 0, 0.4) 0 1px 2px,
        rgba(0, 0, 0, 0.55) 0 10px 28px -8px;
}

/* the search box at the top of the card, with a thin line between it and the list of sections */

/* Side list of sections (and the current section's subsections): rounded rows, with the current page highlighted */
#sections-nav .nav {
    list-style: none;
    margin: 0;
    padding: 0;
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.9375rem;
}

#sections-nav .nav .nav {
    margin: 0.125rem 0 0.375rem 0.75rem;
    padding: 0 0 0 0.5rem;
    border-left: 1px solid var(--q2-divider);
    font-size: 0.875rem;
}

#sections-nav .nav-item {
    list-style: none;
    margin: 0;
    padding: 0;
}

#sections-nav .nav-item a {
    display: block;
    padding: 0.375rem 0.625rem;
    border-radius: var(--q2-radius-sm);
    color: var(--q2-text);
    text-decoration: none;
    line-height: 1.4;
}

/* hover is a lighter shade than the current page's (half of it, mixed with transparent so it suits Light and Dark modes),
   so the page being read stays the one clearly highlighted row */
#sections-nav .nav-item a:hover {
    background: color-mix(in srgb, var(--q2-bg-muted) 50%, transparent);
    color: var(--q2-text-strong);
}

#sections-nav .nav-item.active > a {
    background: var(--q2-bg-muted);
    color: var(--q2-text-strong);
    font-weight: 600;
}

/* Part labels in the side list, styled like the section labels */
/* Part labels in the side list, like the headings in Quark 2's sidebar cards */
#sections-nav .reader-part-label {
    list-style: none;
    color: var(--q2-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 1rem 0 0.375rem;
    padding: 0 0.625rem;
}

#sections-nav .reader-part-label:first-child {
    margin-top: 0;
}


/* ---------- Reading progress and Previous/Next tiles ---------- */

.reader-nav-block {
    margin-top: 2.5rem;
}

.reader-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
}

.reader-progress .bar {
    width: min(100%, 22rem);
    height: 6px;
    border-radius: var(--q2-radius-pill);
    background: var(--q2-bg-muted);
    overflow: hidden;
}

.reader-progress .bar-item {
    height: 100%;
    background: var(--q2-accent);
    border-radius: var(--q2-radius-pill);
}

.reader-progress-text {
    color: var(--q2-text-muted);
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.8125rem;
    margin: 0;
}

.reader-prev-next {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    border-top: 1px solid var(--q2-divider);
    padding-top: 1.75rem;
}

.reader-nav-tile {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1rem 1.25rem;
    background: var(--q2-bg-elev);
    border-radius: var(--q2-radius-md);
    box-shadow: var(--q2-shadow-card);
    color: var(--q2-text);
    text-decoration: none;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.reader-nav-tile:hover {
    box-shadow: var(--q2-shadow-raised);
    transform: translateY(-2px);
    text-decoration: none;
}

.reader-nav-tile:hover .reader-nav-title {
    text-decoration: underline;
}

.reader-nav-tile:focus-visible {
    outline: 2px solid var(--q2-focus-ring);
    outline-offset: 2px;
}

.reader-nav-next {
    justify-content: flex-end;
    text-align: right;
}

.reader-nav-text {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.reader-nav-label {
    color: var(--q2-text-muted);
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.reader-nav-title {
    color: var(--q2-link);
    font-weight: 600;
}

.reader-nav-tile .fa {
    color: var(--q2-text-muted);
}

@media (max-width: 600px) {
    .reader-prev-next {
        grid-template-columns: 1fr;
    }

    /* on phones the tiles are a little more compact, with less padding and a slightly smaller title, so more titles fit
       on one line and the pair takes less of the screen at the end of the page */
    .reader-nav-tile {
        gap: 0.625rem;
        padding: 0.75rem 1rem;
    }

    .reader-nav-title {
        font-size: 1rem;
    }

    .reader-nav-next {
        order: -1;
    }

    .reader-nav-empty {
        display: none;
    }
}

/* Classic Next/Prev buttons on Multi-Section pages */
.prev-next {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 2.5rem;
}

.prev-next .btn {
    width: auto;
}

/* ---------- Reduced motion ---------- */
/* Cards and Previous/Next tiles don't lift on hover for visitors who ask for less motion */
@media (prefers-reduced-motion: reduce) {
    .section-card:hover,
    .reader-nav-tile:hover {
        transform: none;
    }
}


/* Images in a guide page's text are no taller than a little over half the screen, so an image and the text around
   it fit on screen together - for reading, and when presenting by screen sharing. A shortened image keeps its shape,
   and an image on its own line (".reader-content p > img:only-child") is centred */
.reader-content img {
    max-height: 55vh;
    width: auto;
    max-width: 100%;
}

.reader-content p > img:only-child {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

/* An image with a caption (HTML <figure> and <figcaption>, as content from the Pressbooks Converter uses), the same as in
   Grav Helios Open Reader: the figure is centred, and its caption sits just below the image in small italic text, centred.
   (In raw HTML, Grav doesn't adjust image addresses, so the <img> needs one that starts with the page's name in its address (its folder name without the number),
   such as page-name/photo.jpg - for authors, the plain Markdown caption below is simpler) */
.reader-content figure {
    max-width: 100%;
    margin: 1.5rem auto;
    text-align: center;
}

.reader-content figure img {
    display: block;
    margin: 0 auto;
}

.reader-content figcaption {
    margin-top: 0.375rem;
    font-size: 0.875rem;
    font-style: italic;
    text-align: center;
}

/* A caption in plain Markdown: an italic line right after an image on its own, such as
   ![A photo](photo.jpg) followed by *Photo by …* - shown like a figure caption (small, centred, just below the image),
   so authors need no HTML. It works with the italic line in its own paragraph (after a blank line) or on the line just
   below the image (the same paragraph). (":only-child" here looks at elements only, so text beside them still counts) */
.reader-content p:has(> img:only-child):has(+ p > em:only-child) {
    margin-bottom: 0.375rem;
}

.reader-content p:has(> img:only-child) + p:has(> em:only-child),
.reader-content p > img:first-child + em:last-child {
    display: block;
    margin-top: 0;
    font-size: 0.875rem;
    text-align: center;
    /* the same muted grey as Quark 2's own figure captions, in light and dark modes */
    color: var(--pico-muted-color);
}

/* the image in the same paragraph as its caption sits on its own line, centred */
.reader-content p > img:first-child:has(+ em:last-child) {
    display: block;
    margin: 0 auto 0.375rem;
}

/* The current page's own sections (its h2 headings), as in Grav Open Course Hub's module pages (needs the Page TOC
   plugin): on wider screens, a smaller indented list under the current page in the side list; on phones and narrow
   windows, where the side list comes after the page, an "On this page" box above the text that opens when tapped */
.reader-page-sections-item {
    list-style: none;
}

/* indented and a little smaller than the page names, as in Grav Open Course Hub's module list */
.reader-page-sections {
    margin: 0.2rem 0 0.5rem 1rem;
    padding-left: 0;
}

.reader-page-sections .nav-item {
    margin: 0;
}

/* the same colour as the page names (no lighter shade, so the contrast stays as high as theirs in Light and Dark modes) */
.reader-page-sections a {
    font-size: 0.875em;
    line-height: 1.3;
}

/* the section being read (marked by js/reader.js as you scroll): bold, in the link colour, so it stands out without
   relying on colour alone - and without a bar beside it, which would look like the thin rule that marks a section's own
   pages in the side list */
#sections-nav .reader-page-sections a.is-current {
    color: var(--q2-link);
    font-weight: 600;
}

/* the side list's nested lists (a section's own pages) have a thin rule beside them; the page's sections don't, so they
   read as part of the current page rather than more pages ("#sections-nav .nav" outranks that nested-list rule) */
#sections-nav .nav .reader-page-sections {
    margin: 0.2rem 0 0.5rem 1rem;
    padding-left: 0;
    border-left: 0;
    font-size: inherit;
}

.reader-page-sections-above {
    margin: 0 0 1.25rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
    border-radius: 0.375rem;
}

.reader-page-sections-above summary {
    cursor: pointer;
    font-weight: 600;
}

.reader-page-sections-above ul {
    margin: 0.5rem 0 0.25rem;
    padding-left: 1.25rem;
}

/* a heading reached from one of these links (or any link to a heading) stops below the fixed header, not under it */
.reader-content :is(h2, h3, h4)[id] {
    scroll-margin-top: 5rem;
}

/* only one of the two at a time: the side list version beside the page, the box when the side list is below it */
@media (max-width: 959px) {
    .reader-page-sections-item {
        display: none;
    }
}

@media (min-width: 960px) {
    .reader-page-sections-above {
        display: none;
    }
}

/* On phones, when the page's text starts with a heading right after the "On this page" box, the heading doesn't add its
   own large space above (the box's margin is enough), so the gap below the box matches the gap above it */
@media (max-width: 959px) {
    .reader-page-sections-above + .reader-content > :is(h2, h3, h4):first-child {
        margin-top: 0;
    }
}

/* On phones and narrow windows, the site header and Quark 2's menu button slide out of view while scrolling down a guide
   page, and back when scrolling up (js/reader.js adds and removes reader-header-away). Only with Quark 2's Header Fixed
   setting on (body.header-fixed) and the theme's Hide Header While Scrolling setting on (body.header-hide-on-scroll);
   with Header Fixed off, the header already scrolls away with the page. Without animation for
   anyone whose device asks for reduced motion */
@media (max-width: 959px) {
    /* the slide, plus the transitions Quark 2 already gives each one (a transition setting replaces any earlier one) */
    body.header-fixed.header-hide-on-scroll #header {
        transition: transform 0.2s ease, padding 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    }

    body.header-fixed.header-hide-on-scroll .mobile-menu {
        transition: transform 0.2s ease, top 0.2s ease;
    }

    body.header-fixed.header-hide-on-scroll.reader-header-away #header {
        transform: translateY(-100%);
    }

    /* the button sits 10px down from the top and is 44px tall, so it moves a little further than its own height */
    body.header-fixed.header-hide-on-scroll.reader-header-away .mobile-menu {
        transform: translateY(-60px);
    }
}

@media (max-width: 959px) and (prefers-reduced-motion: reduce) {
    body.header-fixed.header-hide-on-scroll #header,
    body.header-fixed.header-hide-on-scroll .mobile-menu {
        transition: none;
    }
}

/* The Previous/Next bar fixed to the bottom of the screen, on phones and narrow windows (the same width where the side
   list moves below the page), as in Grav Helios Open Reader: Previous on the left and Next on the right, each with its
   page title on one line. There it takes the place of the Previous/Next links at the top of the page and the tiles at
   its end, which are hidden; wider screens hide the bar. Very short screens (phones turned sideways, under 500px tall)
   keep the links and tiles instead, as the bar would take too much of the screen there. (Quark 2's phone menu covers
   the whole screen, bar included.) */
.reader-prev-next-bar {
    display: none;
}

@media (max-width: 959px) and (min-height: 500px) {
    .reader-prev-next-bar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        /* below the site header and the phone menu */
        z-index: 45;
        background: var(--q2-bg-elev);
        border-top: 1px solid var(--q2-divider);
        /* room for the iPhone's home bar, when the browser leaves it to the page */
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* the other Previous/Next navigation, while the bar is there (:has matches a page that has the bar) */
    body:has(.reader-prev-next-bar) .reader-prev-next-top,
    body:has(.reader-prev-next-bar) .reader-prev-next {
        display: none;
    }

    /* room below the page for the bar, so it never covers the end of the page */
    body:has(.reader-prev-next-bar) {
        padding-bottom: calc(3.75rem + env(safe-area-inset-bottom));
    }

    /* links and buttons reached with the Tab key, and places jumped to, are kept above the bar rather than behind it
       (the browser leaves this much room at the bottom of the screen when it scrolls to them) */
    html:has(.reader-prev-next-bar) {
        scroll-padding-bottom: calc(3.75rem + env(safe-area-inset-bottom));
    }

    /* while typing in a box, such as the search box (whose on-screen keyboard some phones place the bar above), the bar
       steps aside so it doesn't cover the box. (input:not(...) matches text boxes, leaving out checkboxes and buttons) */
    body:has(input:not([type="checkbox"], [type="radio"], [type="button"], [type="submit"], [type="reset"]):focus, textarea:focus) .reader-prev-next-bar {
        display: none;
    }
}

/* each half of the bar: an arrow and a small label above the page title */
.reader-bar-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    min-height: 3.5rem;
    padding: 0.5rem 1rem;
    color: var(--q2-text);
    text-decoration: none;
}

.reader-bar-link:hover .reader-bar-title {
    text-decoration: underline;
}

.reader-bar-link:focus-visible {
    outline: 2px solid var(--q2-focus-ring);
    outline-offset: -2px;
}

/* a thin line between Previous and Next */
.reader-bar-prev {
    border-right: 1px solid var(--q2-divider);
}

.reader-bar-next {
    grid-column: 2;
    justify-content: flex-end;
    text-align: right;
}

.reader-bar-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.reader-bar-label {
    color: var(--q2-text-muted);
    font-family: var(--pico-font-family-sans-serif);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* the page title on one line, cut with "…" when it's too long (as in Grav Helios Open Reader; "Previous" and "Next"
   say where each goes, and the full title is on the page itself) */
.reader-bar-title {
    overflow: hidden;
    color: var(--q2-link);
    font-size: 0.9375rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader-bar-link .fa {
    flex-shrink: 0;
    color: var(--q2-text-muted);
}

/* ---------- Seeing an image larger ---------- */

/* An image in the page's text that's shown smaller than its full size can be tapped or clicked to see it larger
   (js/reader.js adds reader-image-zoom to it): a zoom-in pointer, and a visible focus ring for keyboard users */
.reader-content img.reader-image-zoom {
    cursor: zoom-in;
}

/* (Quark 2 styles anything with role="button" as a purple button, with padding, a border and rounded corners - the
   image keeps its own look instead, also while hovered, focused or pressed) */
.reader-content img.reader-image-zoom[role="button"],
.reader-content img.reader-image-zoom[role="button"]:is(:hover, :focus, :active) {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    color: inherit;
    font-size: inherit;
    line-height: inherit;
    transition: none;
}

.reader-content img.reader-image-zoom:focus-visible {
    outline: 2px solid var(--q2-focus-ring);
    outline-offset: 0.2rem;
}

/* the larger view: the image as large as fits the screen, on a dark background, with a Close button at the top right */
.reader-image-dialog {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 3.5rem 1rem 1rem;
    border: 0;
    background: rgba(0, 0, 0, 0.92);
    cursor: zoom-out;
}

.reader-image-dialog[open] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-image-dialog::backdrop {
    background: rgba(0, 0, 0, 0.92);
}

.reader-image-dialog img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* the Close button: white on the dark background, 44px so it's easy to tap */
.reader-image-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 44px;
    height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.reader-image-close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* glossary definition box (css/glossary.css), styled like the section cards */
.glossary-popover {
    --glossary-popover-bg: #fff;
    --glossary-popover-border: 0;
    --glossary-popover-radius: 12px;
    --glossary-popover-shadow: 0 1px 2px rgba(19, 19, 22, 0.06), 0 12px 32px -8px rgba(19, 19, 22, 0.2), 0 0 0 1px rgba(19, 19, 22, 0.05);
}

[data-theme="dark"] .glossary-popover {
    --glossary-popover-bg: rgb(29, 31, 37);
    --glossary-popover-shadow: 0 12px 32px -8px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08);
}

/* a table's caption (from a "Table:" line), like a figure's caption; and the number on figures and tables */
.reader-content table caption {
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-style: italic;
    text-align: center;
}

.reader-content table caption.caption-bottom {
    caption-side: bottom;
    margin: 0.375rem 0 0;
}

.reader-content .figure-number {
    font-style: normal;
    font-weight: 600;
}
