/* Project-wide style overrides on top of BeerCSS (Material 3). */

:root {
    --primary: #1a73e8;
    /* Link accent used for in-content links (see "Content links" below). */
    --link: #1558b0;
}

body.dark {
    /* Brighter blue so links stay legible on the dark background. */
    --link: #8ab4f8;
}

main.responsive {
    min-height: 70vh;
    /* <body> is a CSS grid and this is a grid item. Without min-width:0 the
       item's default min-width:auto lets a wide child (e.g. a stats table with
       a min-width) blow the whole page out horizontally instead of scrolling
       inside its own wrapper — unreadable on mobile. This lets the item shrink
       to its column so the .table-scroll wrappers below become the scroller. */
    min-width: 0;
}

/* Wide data tables scroll horizontally on narrow screens instead of cramming
   their columns. Wrap a table in <div class="table-scroll"> to make the
   wrapper (not the page) the horizontal scroller, with momentum on iOS. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

/* Default readable floor; an inline min-width on the table (e.g. the
   aggregated table's 52rem) overrides this. Below the floor it scrolls. */
.table-scroll > table {
    min-width: 40rem;
}

/* Content links — make links obvious everywhere EXCEPT the menu bar. The nav,
   banner and footer live outside <main>, so scoping to `main` leaves them
   untouched. Buttons/chips rendered as <a> are excluded so they keep their
   BeerCSS look. */
main.responsive a:not(.button):not(.chip):not(.nav-link):not([role="button"]) {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

main.responsive a:not(.button):not(.chip):not(.nav-link):not([role="button"]):hover {
    text-decoration-thickness: 2px;
}

/* External links get a small outward arrow so they're distinguishable. */
main.responsive a[href^="http"]:not(.button):not(.chip):not([role="button"])::after {
    content: " \2197"; /* ↗ */
    font-size: 0.85em;
    line-height: 0;
    vertical-align: baseline;
}

/* Site banner — full-width strip ABOVE the menu. BeerCSS makes <body> a grid
   and pins nav.top to row 1, so we place the banner in row 1 (spanning all
   columns) and push the sticky nav to row 2. Scoped with :has() so pages
   without a banner keep the nav in its default row. */
.site-banner {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    line-height: 0;
}

body:has(.site-banner) nav.top {
    grid-row: 2;
}

.site-banner-img {
    /* Show the full image (no cropping). Natural aspect ratio; cap height
       on very tall images with contain-fit letterboxing. */
    display: block;
    width: 100%;
    height: auto;
    max-height: 380px;
    object-fit: contain;
    object-position: center;
}

/* Top nav */
nav.top {
    border-bottom: 3px solid var(--primary);
    gap: 0.35rem;
    align-items: center;
    /* Span the full body-grid width like the banner does — BeerCSS otherwise
       drops the bar into the main column, leaving a ~230px gap on the left
       (a reserved drawer column) that pushes the menu off-centre. */
    grid-column: 1 / -1;
    /* Centre the menu in the bar (aligns with the centred banner on wide
       screens). !important beats BeerCSS's justify-content:space-around; the
       mobile block overrides this back to flex-start. */
    justify-content: center !important;
}

/* Per-item menu styling chosen in the admin (colour + bold). Targets the
   element AND its inner span/icon with !important so it reliably beats
   BeerCSS's <button> styles (dropdown toggles are buttons). */
nav.top .nav-colored,
nav.top .nav-colored > span,
nav.top .nav-colored > i {
    color: var(--nav-item-color) !important;
}

nav.top .nav-bold,
nav.top .nav-bold > span {
    font-weight: 700 !important;
}

/* Hamburger toggle: hidden on wide screens, shown on narrow ones. Filled with
   the primary colour so it reads clearly as a control instead of a bare icon
   fading into the nav background. */
.nav-hamburger {
    display: none;
    /* Fixed brand blue rather than var(--primary): BeerCSS reassigns --primary
       to a pale purple in dark mode, which left white-on-pale (washed out).
       !important beats BeerCSS's nav-button reset (bare circle buttons render
       transparent in the top nav otherwise). */
    background: #1a73e8 !important;
    color: #fff !important;
}

.nav-hamburger > i {
    color: #fff !important;
}

.nav-items {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

@media (max-width: 900px) {
    /* BeerCSS spreads nav children with justify-content:space-around and
       centres their text; override so the collapsed menu is a clean, left
       aligned, full-width vertical list. */
    nav.top {
        flex-wrap: wrap;
        justify-content: flex-start !important;
        text-align: left !important;
    }
    .nav-hamburger {
        display: inline-flex;
    }
    /* The menu collapses under the bar and expands on tap. !important on the
       basis/width beats BeerCSS's flex:0 0 auto on nav children, which
       otherwise keeps this from taking its own full-width row. */
    .nav-items {
        display: none;
        flex-basis: 100% !important;
        width: 100% !important;
        order: 10;
        flex-direction: column;
        align-items: stretch;
        gap: 0.1rem;
        padding: 0.3rem 0 0.5rem;
    }
    /* Open menu is a solid dropdown panel so page content never shows through
       (the sticky nav sits in a fixed-height grid row, so the expanded items
       overflow on top of <main>). */
    nav.top.nav-open .nav-items {
        display: flex;
        background: var(--surface-container-high, #2a2930);
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.35);
        border-radius: 0 0 0.6rem 0.6rem;
        padding: 0.3rem 0.5rem 0.6rem;
        position: relative;
        z-index: 40;
    }
    .nav-items .nav-link,
    .nav-items .nav-dropdown,
    .nav-items .trolls-menu {
        width: 100%;
    }
    .nav-items .nav-link {
        padding: 0.7rem 0.8rem;
        border-radius: 0.4rem;
        /* BeerCSS renders nav links as centred flex boxes; start-align them so
           every row's text lines up at the left. */
        justify-content: flex-start;
        text-align: left;
    }
    .nav-items .nav-dropdown > button,
    .nav-items .trolls-menu > button {
        /* Fill the row so the arrow can sit at the right edge. width/min-width
           carry !important because the Dossiers toggle also has .nav-link,
           whose min-width:max-content + flex:0 0 auto would otherwise shrink it
           to its text. */
        width: 100% !important;
        min-width: 0 !important;
        justify-content: flex-start;
        /* Match the plain links' left padding so every row's text starts at
           the same x — the Trolls toggle lacks the .nav-link class. margin:0
           drops BeerCSS's 8px button margin that would over-indent them. */
        padding: 0.7rem 0.8rem;
        margin: 0;
        text-align: left;
    }
    /* Push the dropdown arrow to the right edge instead of hugging the label. */
    .nav-items .nav-dropdown > button > i,
    .nav-items .trolls-menu > button > i {
        margin-left: auto;
    }
    /* Dropdown panels flow inline inside the open menu instead of overlaying. */
    .nav-dropdown,
    .trolls-menu {
        position: static;
    }
    .nav-dropdown-panel,
    .trolls-dropdown {
        position: static;
        left: auto;
        right: auto;
        width: auto;
        max-height: none;
        box-shadow: none;
        margin: 0 0 0.3rem 0.75rem;
        border-left: 2px solid rgba(128, 128, 128, 0.35);
    }
}

/* General mobile polish: smaller headings, no accidental overflow. */
@media (max-width: 600px) {
    main.responsive h3 {
        font-size: 1.5rem;
        line-height: 1.2;
    }
    main.responsive h4 {
        font-size: 1.2rem;
    }
}

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

main.responsive pre {
    overflow-x: auto;
}

nav.top .nav-link {
    /* Override BeerCSS's fixed-width icon-button sizing for text links */
    flex: 0 0 auto;
    width: auto;
    min-width: max-content;
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    font-weight: 500;
    white-space: nowrap;
}

nav.top .nav-link:hover {
    background: rgba(26, 115, 232, 0.08);
}

nav.top .nav-link.active {
    color: var(--primary);
}

/* Static pages */
.static-page img.responsive-img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
}

.static-page {
    max-width: 52rem;
}

/* Author page sections */
.author-section {
    margin: 1.5rem 0 2rem;
    scroll-margin-top: 88px; /* under the sticky nav */
}

.author-section > h4 {
    margin: 0.5rem 0 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid rgba(128, 128, 128, 0.25);
}

.section-nav {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-align: right;
}

.biography-body {
    max-width: 52rem;
    line-height: 1.55;
}

.biography-body img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 0.75rem 0;
}

.biography-body h2,
.biography-body h3,
.biography-body h4 {
    margin-top: 1.25rem;
}

/* Quoted comment box ([[comment:ID]] token, site-wide) */
.comment-quote {
    max-width: 52rem;
    margin: 1rem 0;
    padding: 0.6rem 0.85rem;
    border: 1px solid rgba(128, 128, 128, 0.25);
    border-left: 3px solid var(--primary);
    border-radius: 0.5rem;
    background: rgba(128, 128, 128, 0.06);
}

.comment-quote .cq-head {
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
    flex-wrap: wrap;
}

.comment-quote .cq-author {
    font-weight: 600;
}

.comment-quote .cq-meta {
    font-size: 0.82rem;
    opacity: 0.7;
}

.comment-quote .cq-article {
    margin: 0.15rem 0 0.45rem;
    font-size: 0.9rem;
}

.comment-quote .cq-body {
    line-height: 1.5;
}

.comment-quote .cq-missing {
    color: #b71c1c;
    font-size: 0.85rem;
}

/* Top-nav dropdowns: the dynamic Trolls menu and admin-defined menu groups */
.trolls-menu,
.nav-dropdown {
    position: relative;
}

.trolls-dropdown,
.nav-dropdown-panel {
    position: absolute;
    top: 100%;
    z-index: 50;
    min-width: 14rem;
    max-height: 70vh;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* Trolls sits at the right end (align right); admin groups align left under
   their button. */
.trolls-dropdown {
    right: 0;
}

.nav-dropdown-panel {
    left: 0;
}

.trolls-dropdown a,
.nav-dropdown-panel a {
    display: block;
    padding: 0.5rem 1rem;
    white-space: nowrap;
}

.trolls-dropdown a:hover,
.nav-dropdown-panel a:hover {
    background: rgba(0, 0, 0, 0.06);
}

.trolls-dropdown hr,
.nav-dropdown-panel hr {
    margin: 0.3rem 0;
}
