@font-face {
  font-family: "Luciole";
  src: url("fonts/Luciole-Math/Luciole-Regular.woff2") format("woff2");
  font-weight: normal;
  font-display: swap;
}
@font-face {
  font-family: "Luciole";
  src: url("fonts/Luciole-Math/Luciole-Italic.woff2");
  font-weight: normal;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Luciole";
  src: url("fonts/Luciole-Math/Luciole-Bold.woff2");
  font-weight: bold;
  font-display: swap;
}
@font-face {
  font-family: "Luciole";
  src: url("fonts/Luciole-Math/Luciole-BoldItalic.woff2");
  font-weight: bold;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Luciole Math";
  src: url("fonts/Luciole-Math/Luciole-Math.otf") format("opentype");
  font-display: swap;
}

@property --bg {
    syntax: "<color>";
    inherits: true;
    initial-value: white;
}

@property --bg-lum {
    syntax: "<number>";
    inherits: true;
    initial-value: 0.95;
}

@property --bg-chroma {
    syntax: "<number>";
    inherits: true;
    initial-value: 0.05;
}

@property --header-font {
    syntax: "<string>#";
    inherits: true;
    initial-value: "Luciole","sans-serif";
}

@property --text-font {
    syntax: "<string>#";
    inherits: true;
    initial-value: "Luciole","sans-serif";
}

@property --text-color {
    syntax: "<color>";
    inherits: true;
    initial-value: black;
}

@property --text-decoration-color {
    syntax: "<color>";
    inherits: true;
    initial-value: #555;
}

@property --rule-color {
    syntax: "<color>";
    inherits: true;
    initial-value: white;
}

@property --border-color {
    syntax: "<color>";
    inherits: true;
    initial-value: black;
}

@property --border-radius-scalar {
    syntax: "<number>";
    inherits: true;
    initial-value: 0.2;
}

@property --muted-color {
    syntax: "<color>";
    inherits: true;
    initial-value: #333;
}

:root {
    color-scheme: light dark;

    --border-radius: calc(1em * var(--border-radius-scalar));
    --more-border-radius: calc(2 * var(--border-radius));
    --start-bg: oklch(var(--bg-lum) var(--bg-chroma) 210);
    --end-bg: oklch(var(--bg-lum) var(--bg-chroma) 0);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: hsl(203.8, 72.2%, 8%);
        --bg-lum: 0.32;
        --bg-chroma: 0.09;
        --text-color: #fff;
        --text-decoration-color: #aaa;
        --rule-color: black;
        --border-color: white;
        --muted-color: #ddd;
    }
}

* {
    box-sizing: border-box;
    word-break: break-word;
}

html {
    font-size: min(2.5vmax,3.5vmin);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text-color);
    font-family: var(--text-font);
    padding: 0;
}

math {
    font-family: 'Luciole Math', var(--text-font);
}

h1,h2,h3,h4,h5,h6 {
    font-family: var(--header-font);
    margin: 0 0 1rem 0;
}

h2 {
    margin: 0;
    font-size: 1.1em;
}

hr {
    width: 50%;
    border: thick solid var(--rule-color);
    margin-block: 1lh;
}

aside {
    display: none;
}

a {
    color: var(--text-color);
    text-decoration-color: var(--text-decoration-color);
}

header {
    padding: 1rem;
    & #uni svg {
        width: 100%;
    }
}


@media screen and (orientation: landscape) {
    body {
        display: grid;
        grid-template:
            "main header" / 1fr 15svw;
        
        & > header {
            grid-area: header;
            padding: 1svw;
            display: flex;
            flex-direction: column;
            gap: 1em;
            padding-bottom: calc(3 * min(1svw,0.6em));
        }
    }
    
}

* {
    line-height: 1.5em;
}

main {
    overflow: hidden scroll;
    height: 100svh;
    scroll-snap-type: y mandatory;
            border-left: min(1em, 1svw) solid;
            border-image: 
                linear-gradient(
                    in oklch longer hue to bottom,
                    var(--start-bg),
                    var(--end-bg)
                )
                1 100%
            ;

    & > section {
        container-type: inline-size;
        width: 100%;
        height: 100svh;
        display: grid;
        position: relative;
        align-items: center;
        justify-items: center;
        text-align: center;
        padding: 0;
        scroll-snap-align: center;
        grid-auto-rows: max-content;
        align-content: center;
        overflow-y: hidden;
        --background-color: color-mix(in oklch longer hue,  var(--start-bg), var(--end-bg) calc(100% * var(--slide-number)));      
        background-color: var(--background-color);
        padding: 1svw;

        & mjx-container * {
            line-height: revert;
        }

        &:focus {
            outline: none;
        }

        & > :is(h1, h2) {
            align-self: start;
            padding: 0 1em;
            line-height: 1.2em;
        }

        &:not(#start):has(> h1:first-child) {
            display: flex;
            flex-direction: column;
            & > h1:first-child {
                flex-grow: 1;
                align-self: center;
            }
            
            &::after {
                content: ' ';
                flex-grow: 1;
            }
        }
        
        
        & h2 {
            margin: 1rem 0 0 0;
        }

        & math[display="block"] {
            margin: 2em 0;
        }

        & > details {

            & summary {
                position: absolute;
                left: 0;
                width: 100%;
                text-align: start;
                color: transparent;
                
                &::marker {
                    color: var(--text-color);
                }
            }
        }


        & pre {
            padding: 0.5rem;
            max-width: 100%;
            text-align: start;
            overflow: auto;
            max-height: 8rem;
            font-size: 0.8em;
            background: color-mix(in oklab, var(--background-color), var(--bg) 50%);
        }

        & :is(textarea,[contenteditable]) {
            width: 100%;
            flex-grow: 10;
            padding: 0.5em;
            resize: none;
            font-size: inherit;
            font-family: inherit;
            display: flex;
            flex-wrap: wrap;
            gap: 1em 3em;
            background: Canvas;
            
            align-content: start;
                    & > * {
                flex-grow: 0;
            }
        }

        & :is(ul,ol) {
            width: 100%;
            padding-left: 2em;

            &.markers {
                list-style-position: inside;

                & li {
                    list-style-type: var(--marker);

                    &::marker {
                        font-size: 1.5em;
                        font-family: sans-serif;
                    }
                }
            }

            & li {
                text-align: left;
            }

            &:has(li > img.bullet) {
                list-style: none;
                padding-left: 0;
                
                
                & li {
                    position: relative;
                    padding-left: 6em;
                    min-height: 2em;
                    
                    & img.bullet {
                        height: 3em;
                        width: calc(16 / 9 * 3em);
                        position: absolute;
                        left: 0;
                        top: -0.5em;
                    }
                }
            }


            & > li ~ li {
                margin-top: 0.5lh;
            }

            &.row {
                display: flex;
                column-gap: 2em;
                flex-wrap: wrap;

                & > li ~ li {
                    margin: 0;
                }
            }
        }

        & .gallery {
            list-style: none;
            padding: 0;
            display: grid;
            grid-template-columns: repeat(3, min(calc((100svw - 15svw - 4em) / 3), calc(40svh - 1em)));
            gap: 1em;
            align-items: end;
            justify-content: center;
            font-size: min(calc(30svw/11),1em);
            
            & > li {
                margin: 0;
            }

            & figure {
                display: flex;
                flex-direction: column;
                justify-content: center;
            }

            & figcaption {
                font-size: 1.6svw;
                text-align: center;
                text-wrap: balance;
                height: 3em;
            }
        }

        & p:has(img, svg, video, iframe) {
            max-width: 90%;
            max-height: 60svh;
            display: grid;
            align-items: center;
            justify-items: center;
            margin: 1rem 0;
            
            grid-template: 1fr / auto;
        }

        & img.big {
            height: calc(100svh - 5em);
        }

        & :is(img, svg, video, iframe):not(.inline, .bullet) {
            max-width: 100%;
            max-height: 60svh;
            border-radius: var(--border-radius) var(--more-border-radius) var(--border-radius) var(--more-border-radius);
        }

        & .inline {
            height: 2ex;
        }
        
        & :is(figure, p, blockquote) {
            margin: 0;
        }
        
        & figure {
            width: 100%;
        }

        & p:not(:has(numbas-exam)) {
            text-wrap: balance;
            word-break: keep-all;
        }
        & :is(figure, p, blockquote) + :is(figure, p, blockquote) {
            margin-top: 1lh;
        }

        & .full-height {
            max-height: 90svh;
        }

        & blockquote {
            line-height: 1.8em;
        }
        & iframe {
          width: 80%;
          height: 60svh;
        }

        & dl {
            text-align: left;

            & dt {
                font-weight: bold;
            }
            & dd ~ dt {
                margin-top: 1lh;
            }
        }

        & table {
            border-collapse: collapse;
            margin-block: 1lh;

            & :is(td,th):not(:first-child) {
                border-left: thin solid;
            }
            
            & tr:not(:first-child) :is(td,th) {
                border-top: thin solid;
            }

            & thead tr:last-child th {
                border-bottom: thin solid;
            }

            & :is(td,th) {
                vertical-align: top;
                padding: 0.25em;
            }
            
            & tbody th {
                text-align: end;
            }

            & ul {
                margin: 0;
            }
        }
    }

    & #start {
        --slide-number: 0;

        & > * {
            margin: 1rem 0;
        }
        & img {
            border-radius: 0;
            border: none;
        }
        
        & #logo {
            width: 50%;
        }

        & .event {
            font-style: italic;
        }
    }

    & #config {
        --slide-number: 0;

        & #controls {
            display: flex;
            flex-wrap: wrap;
            gap: 1em;

            & > div {
                display: flex;
                gap: 0.5em;
            }
        }
    }    
}

dl.grid {
    display: grid;
    
    & dt {
        grid-row: 1;
        justify-self: center;
        align-self: end;
    }
    & dd {
        grid-row: 2;
    }
}


footer {
    position: absolute;
    bottom: 0;
    font-size: min(1svw,0.6em);
    text-align: center;
    right: 0;
    background: var(--bg);
    padding: 0.5em;
}

header {
    font-size: 0.5rem;

    & hr {
        flex-grow: 1;
    }

    & a {
        text-decoration: none;
    }
}

footer #url {
    color: var(--muted-color);
    text-decoration: none;
}

@media (orientation: portrait), print {
    header {
        margin-bottom: 10svh;
        justify-content: center;
        
        & svg {
            width: 50vw;
            max-height: 30svh;
        }
        & #qrcode {
            display: flex;
            justify-content: center;
        }
        
        display: flex;
        flex-direction: column;
    }
    
    main {
        overflow: initial;
        height: auto;

        & > section {
            height: auto;
            scroll-snap-align: none;
            padding: 5em 1em;

            & + section {
                border-top: 0.5svh dashed white;
            }

            & details > summary {
                display: none;
            }

            & .gallery {
                font-size: 1em;

                & figcaption {
                    font-size: smaller;
                }
            }
        }
        
        & dl.grid {
            grid-auto-flow: row;
            gap: 1em;

            & dt {
                grid-row: initial;
                grid-column: 1;
                justify-self: end;
                align-self: center;
                margin: 0;
            }
            & dd {
                grid-row: initial;
                grid-column: 2;
                margin: 0;
                & :is(img, svg, video) {
                    max-width: 30vw;
                }
            }
        }    
    }

    footer {
        position: initial;
        padding: 1em;
        margin-top: 10svh;
    }
}

@media (orientation: portrait) {
    main {
        & > section {
            & .gallery {
                grid-template-columns: repeat(auto-fit, 25svh);
            }
        }
    }
}

@media print {
    header {
        height: 100svh;
        break-after: page;
    }
    footer {
        display: none;
    }
    main {
        border-left: none;

        & section {
            height: 100svh;

            &:not(:first-child) {
                border-top: none;
                break-before: page;
            }

            &:last-child {
                display: none;
            }
        }
    }
}

@page {
    margin: 0;
    padding: 10mm;
}

#slide-0 svg {
    width: 100%;
    height: 80svh;
}
