/*
:filename: wexa_statics/css/book.css
:author: Brigitte Bigi
:contact: contact@sppas.org
:summary: a CSS framework to make reports from web content

-------------------------------------------------------------------------

This file is part of Whakerexa: https://github.com/brigitte-bigi/Whakerexa

Copyright (C) 2023-2026 Brigitte Bigi, CNRS
Laboratoire Parole et Langage, Aix-en-Provence, France

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

This banner notice must not be removed.

-------------------------------------------------------------------------

Architecture:
  - Unlayered rules: structural invariants that must always win (layout, sizing,
    counters, positioning, transitions). These cannot be overridden by themes.
  - @layer theme block at the bottom: visual defaults (colors, accent borders,
    backgrounds, shadows). Theme files injected later in <head> override these
    within the same layer by source order.

*/

:root {
    --toc-width: 0;
    --toc-aside-width: 0;
}


@media screen {
    html {
        margin-left: var(--toc-width);
    }

    html:has(aside.book-toc-aside) {
        margin-left: var(--toc-aside-width);
        transition: margin-left var(--transition, 0.25s ease-in-out);
    }

    html:has(aside.book-toc-aside.open) {
        margin-left: calc(var(--toc-aside-width) + var(--toc-width));
    }
}

body {
    width: 100%;
    counter-reset: chapter;
}

/* ----------------------------------------------------------------------- */
/* ------------------------------- Titles  ------------------------------- */
/* ----------------------------------------------------------------------- */

/* A new numbered chapter in the document */
.chapter {
    counter-increment: chapter;
    counter-reset: ssection;
    text-align: left;
    min-height: 100vh;
}

.chapter > h1 {
    width: 100%;
    padding-top: 2rem;
    padding-bottom: 2rem;
    margin-bottom: 4rem;
    line-height: calc(4 * var(--font-size));
    font-size: calc(3 * var(--font-size));

    /* a chapter title is a box for 2 items: number + title */
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: start;
    text-align: left;
}

.chapter > h1::before {
    content: counter(chapter) ".";
    padding-top: 1rem;
    padding-bottom: 2rem;
    padding-left: 2rem;
    padding-right: 2rem;
    font-size: calc(3 * var(--font-size));
    margin-top: 0;
    margin-right: 1rem;
    margin-bottom: 4rem;
    text-align: right;
    width: 10rem;
}

/* A new numbered section in the chapter */
.ssection {
    counter-increment: ssection;
    counter-reset: subssection;
    padding-left: 0;
    padding-right: 0;
}

.ssection h2 {
    font-size: calc(1.6 * var(--font-size));
}

.ssection h2::before {
    content: counter(chapter) "." counter(ssection) " ";
    font-size: calc(1.6 * var(--font-size));
}

/* A new numbered sub-section in the section */
.subssection {
    counter-increment: subssection;
    padding-left: 0;
    padding-right: 0;
}

.subssection h3 {
    font-size: calc(1.4 * var(--font-size));
}

.subssection h3::before {
    content: counter(chapter) "." counter(ssection) "." counter(subssection) " ";
    font-size: calc(1.4 * var(--font-size));
}

/* ----------------------------------------------------------------------- */
/* ---------------------- BOOK NAVIGATION: Table of Content -------------- */
/* ----------------------------------------------------------------------- */

/* The nav element is used to create the book ToC. */

nav.book-toc {
    z-index: 9;
    width: var(--toc-width);
    height: 100%;
    position: fixed;
    top: var(--typography-spacing-vertical);
    left: 0;
    padding-bottom: 3rem;
    margin-top: calc(-1 * var(--typography-spacing-vertical));
    font-size: 90%;
    overflow-x: hidden;
    display: block;
}

body:has(nav.nav-wexa.top) nav.book-toc {
    top: var(--nav-min-height);
}

/* Reset any previous nav margin/padding */
nav.book-toc * {
    margin: auto;
    padding: 0;
    font-size: calc(0.8*var(--font-size));
}
nav.book-toc > ul, nav.book-toc > hr, nav.book-toc > h1, nav.book-toc > h2 {
    margin-top: 1rem;
    margin-bottom: 2rem;
}

nav.book-toc h1 {
    font-size: calc(1.5*var(--font-size));
    font-weight: var(--font-weight-black);
}

nav.book-toc h2 {
    font-size: calc(1.5*var(--font-size));
    font-weight: var(--font-weight-bold);
}

nav.book-toc a[role=button], nav.book-toc button {
    width: calc(0.75*var(--toc-width));
    height: calc(3*var(--font-size));
    border-radius: calc(3*(var(--border-width)));
    display: flex;
    justify-content: center;
    flex-direction: column;
    margin-bottom: 0.5rem;
}

/* Table of content automatically generated from <h*> of the document. */
/* The element tags in the HTML document became automatically a class name
   into the toc thanks to a script. */

nav.book-toc ul {
    display: initial;
}

nav.book-toc a:not([role=button],[role=menuitem]) {
    display: initial;
}

nav.book-toc li.h1,
nav.book-toc li.h2,
nav.book-toc li.h3,
nav.book-toc li.h4,
nav.book-toc li.h5,
nav.book-toc li.h6 {
    display: block;
    margin-bottom: 0.5rem;
    text-align: left;
}

nav.book-toc li.h1 {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    padding-left: 0;
}
nav.book-toc li.h2 {
    margin-top: 1rem;
    padding-left: 0.5rem;
}
nav.book-toc li.h3 {
    padding-left: 1.5rem;
}
nav.book-toc li.h4 {
    padding-left: 2rem;
}
nav.book-toc li.h5 {
    padding-left: 3rem;
}
nav.book-toc li.h6 {
    padding-left: 4rem;
}

nav.book-toc li.h2::before {
    content: "■";
    padding-right: calc(0.4*var(--typography-spacing-horizontal));
}
nav.book-toc li.h3::before {
    content: "◇";
    padding-right: calc(0.4*var(--typography-spacing-horizontal));
}
nav.book-toc li.h4::before {
    content: "-";
    padding-right: calc(0.4*var(--typography-spacing-horizontal));
}
nav.book-toc li.h5::before {
    content: "□";
    padding-right: calc(0.4*var(--typography-spacing-horizontal));
}

nav.book-toc li.h1 a {
    text-decoration: none;
    font-variant-caps: small-caps;
    font-weight: var(--font-weight-bold);
    font-size: calc(1.2*var(--font-size));
}
nav.book-toc li.h2 a {
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    text-overflow: ellipsis;
    font-size: var(--font-size);
}
nav.book-toc li.h3 a {
    text-decoration: none;
    font-weight: var(--font-weight-normal);
    text-overflow: ellipsis;
    font-size: calc(0.9*var(--font-size));
}
nav.book-toc li.h4 a {
    text-decoration: none;
    font-weight: var(--font-weight-semithin);
    white-space: nowrap;
    text-overflow: ellipsis;
}
nav.book-toc li.h5 a {
    text-decoration: none;
    font-weight: var(--font-weight-thin);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: calc(0.75*var(--font-size));
}
nav.book-toc li.h6 a {
    text-decoration: none;
    font-weight: var(--font-weight-thin);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: calc(0.7*var(--font-size));
}

/* ----------------------------------------------------------------------- */
/* -------------- BOOK NAVIGATION: Toggleable aside ToC ------------------ */
/* ----------------------------------------------------------------------- */

/* Usage: <aside class="book-toc-aside" id="book-toc-aside">
             <h1>Table des matières</h1>
             <ul id="toc"></ul>
          </aside>
   book.js detects the class and injects button.book-toc-toggle before the aside. */

aside.book-toc-aside {
    width: var(--toc-width);
    display: block;
    padding: var(--typography-spacing-vertical) var(--typography-spacing-horizontal);
    padding-bottom: 3rem;
}

@media screen {
    aside.book-toc-aside {
        z-index: 10;
        height: 100%;
        position: fixed;
        top: 0;
        left: var(--toc-aside-width);
        overflow-x: hidden;
        transform: translateX(calc(-1 * (var(--toc-aside-width) + var(--toc-width))));
        transition: transform var(--transition, 0.25s ease-in-out);
    }

    aside.book-toc-aside.open {
        transform: translateX(0);
    }

    body:has(nav.nav-wexa.top) aside.book-toc-aside {
        top: var(--nav-min-height);
    }

    /* Toggle button injected by book.js */
    button.book-toc-toggle {
        position: fixed;
        top: 50vh;
        left: 0;
        z-index: 10;
        writing-mode: vertical-rl;
        transform: translateY(-50%) rotate(180deg);
        padding: var(--typography-spacing-vertical) calc(0.5 * var(--typography-spacing-horizontal));
        border-radius: var(--border-radius) 0 0 var(--border-radius);
        cursor: pointer;
        font-size: calc(0.75 * var(--font-size));
        font-family: inherit;
        transition: left var(--transition, 0.25s ease-in-out);
    }

    body:has(aside.book-toc-aside.open) button.book-toc-toggle {
        left: 0;
    }
}

/* Inner content — mirrors nav.book-toc styles */
aside.book-toc-aside * {
    margin: auto;
    padding: 0;
    font-size: calc(0.8 * var(--font-size));
    background-color: transparent;
}

aside.book-toc-aside > ul,
aside.book-toc-aside > hr,
aside.book-toc-aside > h1,
aside.book-toc-aside > h2 {
    margin-top: 1rem;
    margin-bottom: 2rem;
}

aside.book-toc-aside h1 {
    font-size: calc(1.5 * var(--font-size));
    font-weight: var(--font-weight-black);
}

aside.book-toc-aside h2 {
    font-size: calc(1.5 * var(--font-size));
    font-weight: var(--font-weight-bold);
}

aside.book-toc-aside ul { display: initial; }

aside.book-toc-aside a:not([role=button],[role=menuitem]) { display: initial; }

aside.book-toc-aside li.h1,
aside.book-toc-aside li.h2,
aside.book-toc-aside li.h3,
aside.book-toc-aside li.h4,
aside.book-toc-aside li.h5,
aside.book-toc-aside li.h6 {
    display: block;
    margin-bottom: 0.5rem;
    text-align: left;
}

aside.book-toc-aside li.h1 { margin-top: 1.5rem; margin-bottom: 1rem; padding-left: 0; }
aside.book-toc-aside li.h2 { margin-top: 1rem; padding-left: 0.5rem; }
aside.book-toc-aside li.h3 { padding-left: 1.5rem; }
aside.book-toc-aside li.h4 { padding-left: 2rem; }
aside.book-toc-aside li.h5 { padding-left: 3rem; }
aside.book-toc-aside li.h6 { padding-left: 4rem; }

aside.book-toc-aside li.h2::before { content: "■"; padding-right: calc(0.4 * var(--typography-spacing-horizontal)); }
aside.book-toc-aside li.h3::before { content: "◇"; padding-right: calc(0.4 * var(--typography-spacing-horizontal)); }
aside.book-toc-aside li.h4::before { content: "-"; padding-right: calc(0.4 * var(--typography-spacing-horizontal)); }
aside.book-toc-aside li.h5::before { content: "□"; padding-right: calc(0.4 * var(--typography-spacing-horizontal)); }

aside.book-toc-aside li.h1 a {
    text-decoration: none;
    font-variant-caps: small-caps;
    font-weight: var(--font-weight-bold);
    font-size: calc(1.2 * var(--font-size));
}
aside.book-toc-aside li.h2 a {
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    text-overflow: ellipsis;
    font-size: var(--font-size);
}
aside.book-toc-aside li.h3 a {
    text-decoration: none;
    font-weight: var(--font-weight-normal);
    text-overflow: ellipsis;
    font-size: calc(0.9 * var(--font-size));
}
aside.book-toc-aside li.h4 a {
    text-decoration: none;
    font-weight: var(--font-weight-semithin);
    white-space: nowrap;
    text-overflow: ellipsis;
}
aside.book-toc-aside li.h5 a {
    text-decoration: none;
    font-weight: var(--font-weight-thin);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: calc(0.75 * var(--font-size));
}
aside.book-toc-aside li.h6 a {
    text-decoration: none;
    font-weight: var(--font-weight-thin);
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: calc(0.7 * var(--font-size));
}

/* ----------------------------------------------------------------------- */
/* ----------------------------- Abstract -------------------------------- */
/* ----------------------------------------------------------------------- */

.abstract {
    margin-left: 10%;
    margin-right: 10%;
    margin-top: var(--typography-spacing-vertical);
    margin-bottom: var(--typography-spacing-vertical);
    padding: var(--typography-spacing-vertical) var(--typography-spacing-horizontal);
    border-radius: var(--border-radius);
    font-size: calc(0.9 * var(--font-size));
    font-style: italic;
}

.abstract * {
    background-color: transparent;
    color: inherit;
}

.abstract h2 {
    font-style: normal;
}

/* ----------------------------------------------------------------------- */
/* ---------------------- Chapters without numbering --------------------- */
/* ----------------------------------------------------------------------- */

.chapter.nonumber {
    counter-increment: none;
}

.chapter.nonumber > h1 {
    display: block;
}

.chapter.nonumber > h1::before {
    display: none;
}

.chapter.nonumber .ssection h2::before {
    /* book.js #get_headings() includes a heading in the ToC only if
       getComputedStyle(el, '::before').content differs from 'none', '""'
       and "''". Using content: none would exclude these headings from the ToC.
       A zero-size non-breaking space (\00a0) passes the JS filter while
       remaining invisible and taking no space. */
    content: "\00a0";
    color: transparent;
    font-size: 0;
    padding: 0;
    margin: 0;
}

.chapter.nonumber .subssection h3::before {
    /* Same reason as h2::before above. */
    content: "\00a0";
    color: transparent;
    font-size: 0;
    padding: 0;
    margin: 0;
}

/* ----------------------------------------------------------------------- */
/* ------------- VISUAL DEFAULTS — @layer theme, overrideable ------------ */
/*                                                                         */
/* Theme files injected by ThemeManager are appended to <head> after this  */
/* stylesheet. Within @layer theme, later source order wins, so any theme  */
/* file that defines the same selectors will automatically override these  */
/* defaults without specificity tricks.                                    */
/* ----------------------------------------------------------------------- */

@layer theme {

    /* Chapter title: accent border and number badge */
    .chapter > h1 {
        border-top: calc(4 * var(--border-width)) solid var(--custom-color1);
        border-bottom: calc(4 * var(--border-width)) solid var(--custom-color1);
    }

    .chapter > h1::before {
        background-color: var(--custom-color1);
        color: var(--custom-color2);
    }

    /* Section / sub-section numbering and underline */
    .ssection h2 {
        border-bottom: var(--border-width) solid var(--h2-color);
    }

    .ssection h2::before {
        color: var(--custom-color1);
    }

    .subssection h3::before {
        color: var(--custom-color1);
    }

    /* Table of content: text color */
    nav.book-toc *:not([role=button]) {
        color: var(--nav-fg-color);
    }

    aside.book-toc-aside *:not([role=button]) {
        color: var(--nav-fg-color);
    }

    /* Toggleable aside ToC: panel and toggle button decoration */
    @media screen {
        aside.book-toc-aside {
            background: var(--nav-bg-color);
            box-shadow: 0.3rem 0 1.2rem var(--shadow-color);
        }

        button.book-toc-toggle {
            background: var(--nav-bg-color);
            color: var(--nav-fg-color);
            border: var(--border-width) solid var(--border-color);
        }
    }

    /* Abstract block */
    .abstract {
        background-color: var(--bg-color-alt);
        color: var(--fg-color-alt);
        box-shadow: 0 0.2rem 0.8rem var(--shadow-color);
    }

}
