:root {
    --background: #f8f8f8;
    --on-background: #000;
    --primary: #000;
    --on-primary: #fff;
    --secondary: #ddd;
    --on-secondary: #444;
    background: var(--background);
    color: var(--on-background);
    /* inspired by https://modernfontstacks.com/ */
    font: 1em 'Open Sans', Ubuntu, Calibri, 'DejaVu Sans', source-sans-pro, sans-serif;
    --image-filter: none;
    --invertable-image-filter: none;
}
:root[themed] {
    --background: hsl(calc(var(--hue) - 25), calc(10% * var(--saturation, 1)), 95%);
    --on-background: hsl(var(--hue), calc(100% * var(--saturation, 1)), 5%);
    --primary: hsl(calc(var(--hue) + 25), calc(80% * var(--saturation, 1)), 20%);
    --on-primary: hsl(calc(var(--hue) + 25), calc(100% * var(--saturation, 1)), 95%);
    --secondary: hsl(calc(var(--hue) + 25), calc(15% * var(--saturation, 1)), 80%);
    --on-secondary: hsl(var(--hue), calc(100% * var(--saturation, 1)), 8%);
}
:root[themed][dark] {
    --background: hsl(calc(var(--hue) - 25), calc(10% * var(--saturation, 1)), 10%);
    --on-background: hsl(calc(var(--hue) + 25), calc(100% * var(--saturation, 1)), 95%);
    --primary: hsl(calc(var(--hue) + 25), calc(80% * var(--saturation, 1)), 70%);
    --on-primary: hsl(calc(var(--hue) - 25), calc(20% * var(--saturation, 1)), 25%);
    --secondary: hsl(calc(var(--hue) + 25), calc(15% * var(--saturation, 1)), 40%);
    --on-secondary: hsl(var(--hue), calc(100% * var(--saturation, 1)), 96%);
    --image-filter: brightness(0.7);
    --invertable-image-filter: invert(1) hue-rotate(180deg) contrast(calc(14/16));
}
body {
    margin: 1rem 1rem 0;
}

/* *::selection {
    background-color: #fff4;
    color: #0008;
} */

header {
    width: min-content;
    min-width: calc(min(50rem, 100%));
    max-width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 1rem;
    border-radius: 2rem;
    background: var(--primary);
    color: var(--on-primary);
    text-align: center;
}
header > * {
    animation: header-children 1s cubic-bezier(0, 0, 0, 1) forwards;
}
@keyframes header-children {
    from {
        transform: translateY(-50%);
        opacity: 0.5;
    }
}

nav {
    margin: 1rem 0;
    gap: 1rem;
    flex-direction: column;
}
nav > a {
    padding: 1rem;
    border-radius:  0.2rem 0.2rem 1rem 1rem;
    color: var(--on-secondary);
    background: var(--secondary);
    text-decoration: none;
}
nav > a > h3 {
    margin: 0 0 0.3rem;
}
nav > a > p {
    margin: 0;
    text-wrap: pretty;
}
nav > a {
    position: relative;
    display: block;
    margin: 1rem 0;
    border-radius: 2rem;
    padding: 1rem;
    background: var(--secondary);
    color: var(--on-secondary);
    text-decoration: none;
    text-wrap: nowrap;
}
nav > a:focus {
    outline: none;
}
nav > a::before {
    transition: transform 150ms cubic-bezier(0, 0, 0, 1);
    content: "";
    position: absolute;
    border-radius: inherit;
    inset: 0;
    box-shadow: var(--on-secondary) 0 0.5rem 0 -1px;
    z-index: -1;
}
nav > a:not(:hover, :focus):before {
    transform: translateY(-0.5rem);
}
nav > a::after {
    content: "";
    position: absolute;
    border-radius: inherit;
    inset: 0;
    background: var(--on-secondary);
    transform: scaleX(0);
    opacity: 0.2;
    z-index: 1;
}
nav > a:not(:active)::after {
    transition: transform 150ms cubic-bezier(0, 0, 0, 1),
        opacity 500ms 150ms linear;
    transform: scaleX(1);
    opacity: 0;
}

details.metronome {
    display: flex;
    padding: 0.6rem 0.5rem 0.5rem;
    font-size: 1.5em;
    border-radius: 0.3rem 0.3rem 0.5rem 0.5rem;
    overflow: hidden;
    cursor: pointer;
}
@media not print {
    details.metronome {
        position: sticky;
        top: -0.3rem;
        z-index: 1;
        background: var(--secondary);
        color: var(--on-secondary);
    }
}
details.metronome[open] {
    animation: metronome-beat var(--period) cubic-bezier(1, 0, 1, 1) infinite;
}
@keyframes metronome-beat {
    to {
        background: #fff;
        color: var(--on-secondary);
    }
}
details.metronome summary::marker {
    /* TODO: use clip-path */
    content: "◼";
    display: inline-block;
    width: 1ch;
    line-height: 1;
}
details.metronome[open] summary::marker {
    content: "▶";
}

.chords {
    position: relative;
    min-height: 5rem;
    white-space: pre;
    padding-left: 3rem;
    text-wrap: wrap;
}
.chords:not([chorus]) {
    counter-increment: verse;
}
.chords::before {
    content: attr(verse);
    position: absolute;
    height: 100%;
    inset: 1.3rem auto 0 0;
    font-size: 3rem;
    font-weight: 900;
    font-family: monospace;
    vertical-align: middle;
    color: var(--primary);
    opacity: 0.7;
}
.chords:not([verse], [chorus])::before {
    content: counter(verse);
}
.chords[chorus]:not([verse])::before {
    content: "R";
}
.chords:nth-child(even)::before {
    color: var(--on-background);
}
span[chord] {
    display: inline-block;
}
span[chord]:empty {
    vertical-align: top;
}
span[chord]::before {
    content: attr(chord);
    display: block;
    width: fit-content;
    background: var(--primary);
    color: var(--on-primary);
    padding: 0 0.3rem;
    margin-right: 0.2rem;
    border-radius: 0.5rem;
}
span[chord]:empty:last-child::before {
    padding-right: 0.5rem;
    background: linear-gradient(270deg, transparent, /* #4444 0.3rem, */ var(--primary) 0.7rem);
    border-radius: 0.5em 0 0 0.5em;
}

body.literature {
    width: fit-content;
    height: 100%;
    margin: 0 auto;
    font-size: 12pt;
    font-family: sans-serif;
    letter-spacing: 0.2pt;
    scroll-behavior: smooth;
    background: #fff;
}
body.literature:not([paginated]) {
    width: 595pt;
}
body.literature > section {
    position: relative;
    height: 842pt;
    width: 595pt;
    counter-increment: page;
    outline-offset: -5pt;
    /* To prevent margin collapse */
    overflow: hidden;
}
body.literature > section[page-num] {
    counter-increment: none;
    counter-reset: page var(--page-num);
}
body.literature > section[page-num] {
    page-break-before: always;
}
body.literature > section.title-page {
    display: flex;
    flex-direction: column;
    min-height: 842pt;
    text-align: center;
    justify-items: stretch;
}
body.literature > section.title-page > h1 {
    margin-top: 160pt;
    font-size: 60pt;
}
body.literature > section.title-page > footer {
    margin-top: auto;
}
body.literature > section:not([hidden-page-number])::after {
    content: counter(page);
    position: absolute;
    inset: auto 0 0;
    text-align: center;
}
body.literature > :is(h1, h2) {
    page-break-after: avoid;
}
body.literature > :is(p, img, svg, ul, ol, table) {
    page-break-before: avoid;
    page-break-inside: avoid;
}
body.literature a {
    color: currentColor;
}
body.literature > section.contents a:not(:hover, :focus) {
    text-decoration: none;
}
body.literature table {
    min-width: 150pt;
    border-collapse: collapse;
    vertical-align: middle;
}
body.literature table :is(th, td) {
    border: 1.5pt solid;
    border-color: var(--on-surface);
    padding: 2.5pt;
}
body.literature table th {
    font-weight: inherit;
    padding-inline: 8pt; text-wrap: nowrap;
    font-style: italic;
}
body.literature :is(img, svg) {
    display: block;
    max-width: 100%;
    max-height: 370pt;
    margin: 10pt auto;
    filter: var(--image-filter);
}
body.literature code {
    line-height: 1;
    vertical-align: middle;
}
body.literature img[invertable] {
    filter: var(--invertable-image-filter);
}

@media not print {
    body.literature {
        margin-block: 2rem;
        background: inherit;
    }
    body.literature[paginated] > section {
        margin: 1rem 0;
    }
    body.literature:not([paginated]),
    body.literature[paginated] > section {
        border: solid #fff 36pt;
        background-color: #fff;
    }
}

body > footer {
    position: sticky;
    background: var(--background);
    margin-top: 0.5rem;
    padding: 0.5rem 0;
    text-align: center;
    z-index: 1;
}
@media not print {
    footer {
        bottom: 0;
    }
}
body > footer::before {
    content: "";
    position: absolute;
    inset: 0 5rem auto 5rem;
    height: max(1px, 0.1rem);
    background-color: var(--on-background);
    opacity: 0.5;
}
body > footer p {
    margin: 0;
}
footer a {
    position: relative;
    color: var(--primary);
    text-decoration: none;
}
footer a::before {
    transition: transform 100ms cubic-bezier(0, 0, 0, 1);
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: 1px;
    background-color: var(--primary);
    transform: scaleX(0);
}
footer a:hover:before {
    transform: scaleX(1);
}
