/* ============================================
   THE FRAME EVERY PAGE SHARES
   The bar at the top, the theme switch in it, and the footer. It reads the colours and the type
   of the page it is on under the names main.css gives them (--bg, --text, --text-muted,
   --border, --bg-secondary, --accent, --font), and resets what it needs itself, so that a page
   with its own stylesheet, like the statistics app, can use it too.
   ============================================ */

.navbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--navbar-height, 56px);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-family: var(--font);
    line-height: 1.6;
}

.navbar .container,
.site-footer .container {
    width: min(100% - 4rem, var(--container-max, 72rem));
    margin: 0 auto;
}

.navbar .container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.navbar .navbar-brand {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.015em;
    color: var(--text);
    text-decoration: none;
    white-space: nowrap;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.navbar .nav-link {
    padding: 0.35rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.navbar .nav-link:hover,
.navbar .nav-link.active {
    color: var(--text);
}

.navbar .nav-link.active {
    border-bottom-color: var(--accent);
}

/* On the app pages: the way back to the list of apps. */
.nav-back::before {
    content: "\2190\00a0";
}

/* Mobile menu, on the homepage */
.navbar-toggler {
    display: none;
    background: none;
    border: 1px solid var(--text);
    border-radius: 0;
    padding: 0.3rem 0.6rem;
    color: var(--text);
    font: 500 0.875rem var(--font);
    line-height: 1.2;
    cursor: pointer;
}

/* Theme switch: a painter's palette, drawn by theme.js, which opens the list of themes. The
   icon's right edge is the column's. */
.theme-switch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    margin: 0 -0.4375rem;
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s ease;
}

.theme-switch:hover,
.theme-switch[aria-expanded="true"] {
    color: var(--text);
}

.theme-switch svg {
    display: block;
    width: 1.125rem;
    height: 1.125rem;
}

/* The list of themes hangs from the bar's lower rule, its right edge on the column's. Each theme
   is shown by a sample: its page, with a letter in its ink and its type. */
.theme-picker {
    position: relative;
    display: inline-flex;
}

.theme-menu {
    position: absolute;
    top: calc(100% + (var(--navbar-height, 56px) - 2rem) / 2 - 1px);
    right: 0;
    z-index: 2;
    min-width: 11rem;
    padding: 0.375rem 0;
    background: var(--bg);
    border: 1px solid var(--text);
    font: 500 0.875rem/1.4 var(--font);
}

.theme-menu[hidden] {
    display: none;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.375rem 0.875rem;
    background: none;
    border: 0;
    border-radius: 0;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.theme-option:hover,
.theme-option:focus-visible {
    background: var(--bg-secondary);
    outline: 0;
}

.theme-option[aria-checked="true"]::after {
    content: "\2713";
    margin-left: auto;
    padding-left: 1rem;
    color: var(--accent);
}

.theme-sample {
    display: grid;
    place-items: center;
    flex: none;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid var(--border);
    font: 600 0.8125rem/1 Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

[data-value="light"] > .theme-sample { background: #fff; color: oklch(0.18 0.006 260); }
[data-value="dark"] > .theme-sample { background: #000; color: oklch(0.95 0.003 260); }
[data-value="colour"] > .theme-sample { background: oklch(0.52 0.22 264); color: #fff; }
[data-value="khaki"] > .theme-sample {
    background: oklch(0.85 0.03 95);
    color: oklch(0.33 0.02 90);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-weight: 500;
}

/* Khaki: the page is a dotted grid in a frame, the window's, with a square at each corner; the
   bar ends on a dashed rule over a solid one, and its links are boxes with a square before them,
   filled with the ink when chosen, as is text selected. */
:root[data-theme="khaki"] {
    background-color: var(--bg);
    background-image: radial-gradient(circle, var(--border) 0.75px, transparent 1.1px);
    background-size: 8px 8px;
}

:root[data-theme="khaki"] body {
    background: transparent;
}

:root[data-theme="khaki"] body::after {
    content: "";
    position: fixed;
    inset: 0.375rem;
    z-index: 1001;
    border: 1px solid var(--faint);
    background:
        linear-gradient(var(--text) 0 0) top left / 5px 5px no-repeat border-box,
        linear-gradient(var(--text) 0 0) top right / 5px 5px no-repeat border-box,
        linear-gradient(var(--text) 0 0) bottom left / 5px 5px no-repeat border-box,
        linear-gradient(var(--text) 0 0) bottom right / 5px 5px no-repeat border-box;
    pointer-events: none;
}

:root[data-theme="khaki"] ::selection {
    background: var(--text);
    color: var(--bg);
}

:root[data-theme="khaki"] .navbar {
    border-bottom-color: var(--text);
    background-image: linear-gradient(90deg, var(--text) 0 4px, transparent 4px);
    background-position: left bottom 4px;
    background-size: 8px 1px;
    background-repeat: repeat-x;
}

:root[data-theme="khaki"] .navbar .navbar-brand {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

:root[data-theme="khaki"] .nav-right {
    gap: 1.25rem;
}

:root[data-theme="khaki"] .navbar-nav {
    gap: 0.5rem;
}

:root[data-theme="khaki"] .navbar .nav-link,
:root[data-theme="khaki"] .navbar-toggler {
    padding: 0.2rem 0.5rem;
    background: var(--bg-secondary);
    border: 0;
    color: var(--text);
    font-size: 0.6875rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

:root[data-theme="khaki"] .navbar .nav-link:not(.nav-back)::before {
    content: "";
    display: inline-block;
    width: 0.5em;
    height: 0.5em;
    margin-right: 0.6em;
    background: currentColor;
}

:root[data-theme="khaki"] .navbar .nav-link:hover,
:root[data-theme="khaki"] .navbar .nav-link.active,
:root[data-theme="khaki"] .navbar-toggler:hover,
:root[data-theme="khaki"] .navbar-toggler[aria-expanded="true"] {
    background: var(--text);
    color: var(--bg);
}

:root[data-theme="khaki"] .site-footer .container {
    border-top-style: dashed;
}

/* Footer */
.site-footer {
    padding: 3rem 0 2.5rem;
    font: 0.8125rem/1.6 var(--font);
    color: var(--text-muted);
}

.site-footer .container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.site-footer p {
    margin: 0;
}

@media (max-width: 820px) {
    .navbar .container,
    .site-footer .container {
        width: min(100% - 2.5rem, var(--container-max, 72rem));
    }

    .nav-right { gap: 1rem; }

    .navbar-toggler { display: block; }

    /* The homepage's links drop under the bar, opened by the Menu button. */
    .navbar-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0.5rem 1.25rem 1rem;
        background: var(--bg);
        border-bottom: 1px solid var(--text);
    }

    .navbar-nav.show { display: flex; }

    .navbar-nav .nav-link {
        display: block;
        padding: 0.5rem 0;
        border-bottom: 0;
    }

    .navbar-nav .nav-link.active { color: var(--accent); }

    :root[data-theme="khaki"] .navbar-nav { gap: 0.375rem; }

    :root[data-theme="khaki"] .navbar-nav .nav-link { padding: 0.45rem 0.6rem; }
}

@media (max-width: 480px) {
    .nav-back .wide { display: none; }
}
