:target {
    scroll-margin-top: 5rem;
}

@layer layout {
    :root {
        --padding: 0.5rem 1rem;
    }

    body {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        min-width: min-content;
        margin: 0;
        padding: 0;
    }

    body > header,
    body > footer {
        flex: 0;
        padding: var(--padding);
    }

    body > main {
        flex: 1 0 auto;
        align-self: center;
        max-width: 140ch;
        padding: var(--padding);
    }
}

@layer general {
    :root {
        --color: #373c44;
        --bg-color: white;
        --heading-color: #2d3138;
        --border-color: lightslategray;
        --muted-border-color: #e7eaf0;
        --shadow-color: lightgray;
        --outline-color: black;
        --primary-color: black;
        --primary-bg-color: #ccc6b4;
        --primary-bg-color-hover: #beb8a7;
        --secondary-color: white;
        --secondary-bg-color: #525f7a;
        --secondary-bg-color-hover: #48536b;
        --input-color: #23262c;
        --input-bg-color: #fbfcfc;
        --link-color: #6e6a60;
        --link-hover-color: #55524a;
        --success: green;
        --danger: red;

        --border: 1px solid var(--border-color);
        --muted-border: 1px solid var(--muted-border-color);
        --shadow: 0px 0px 4px 1px var(--shadow-color);

        font-family: sans-serif;
        color: var(--color);
    }

    :focus {
        outline: thin solid var(--outline-color);
    }

    body {
        background-color: var(--bg-color);
    }

    h1, h2, h3, h4, h5, h6, th {
        color: var(--heading-color);
    }

    table {
        border-collapse: separate;
        border-spacing: 0;

        & thead > tr:first-child th {
            width: min-content;
            border-bottom: var(--border);
        }

        & tfoot > tr:first-child {
            & th, td {
                border-top: var(--border);
            }
        }

        & tr:not(:last-child) {
            & th, td {
                border-bottom: var(--muted-border);
            }
        }

        & th, td {
            padding: 0.6em 0.3em;
            text-align: center;
        }
    }

    table.sticky {
        & > thead {
            position: sticky;
            top: 0;
            background-color: var(--bg-color);
        }

        & > tfoot {
            position: sticky;
            bottom: 0;
            background-color: var(--bg-color);
        }
    }

    form:not(.flat) {
        display: flex;
        flex-direction: column;

        & > label {
            display: flex;
            flex-direction: column;
            margin-bottom: 1em;
        
            & input, select {
                display: block;
                margin-top: 0.2em;
                flex: 1;
            }
        }

        & button[type="submit"] {
            flex: 1;
        }
    }

    input, button, select {
        box-sizing: border-box;
        padding: 0.75rem 0.5rem;
        font-size: 1rem;
        border: var(--border);
        border-radius: 0.25rem;
    }

    input, select {
        color: var(--input-color);
        background-color: var(--input-bg-color);
    }

    button {
        --color: var(--primary-color);
        --bg-color: var(--primary-bg-color);

        font-size: 1.1rem;
        color: var(--color);
        background-color:  var(--bg-color);
        border-color: var(--bg-color);
        cursor: pointer;

        &:hover {
            --bg-color: var(--primary-bg-color-hover);
        }
    }

    button.secondary {
        --color: var(--secondary-color);
        --bg-color: var(--secondary-bg-color);
        
        &:hover {
            --bg-color: var(--secondary-bg-color-hover);
        }
    }

    a {
        color: var(--link-color);

        &:hover {
            color: var(--link-hover-color);
        }
    }

    img {
        max-width: 100%;
        max-height: 100%;
    }

    body > header {
        border-bottom: var(--border);
        box-shadow: var(--shadow);

        & a {
            text-decoration: none;
        }

        & a:hover {
            text-decoration: underline;
            text-underline-offset: 0.25em;
        }
    }

    nav a {
        font-size: 1.2rem;
    }

    body > footer {
        border-top: var(--border);
        box-shadow: var(--shadow);
    }
}

@layer responsive {
    :root {
        --gap: 1rem;

        font-size: clamp(0.75rem, 1.5vw, 1rem)
    }

    .responsive {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: start;
        gap: var(--gap);
    }

    .responsive > *,
    .small {
        flex: 2;
    }

    .medium {
        flex: 4;
    }

    .large {
        flex: 8;
    }

    @media (max-width: 768px) {
        .break-at-wide {
            flex: unset;
            width: 100%;
        }

        .reorder-at-wide {
            order: unset !important;
        }
    }

    @media (max-width: 1200px) {
        .break-at-widest {
            flex: unset;
            width: 100%;
        }
    }
}