/* color.css is linked from the layout, ahead of this file: an @import would
   have made the browser parse this stylesheet before discovering it, and load
   the two in series. */

/* titillium-web-regular - latin_latin-ext */
@font-face {
  font-family: 'Titillium Web';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Titillium Web Regular'), local('TitilliumWeb-Regular'),
       url('../fonts/titillium-web-v7-latin_latin-ext-regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
       url('../fonts/titillium-web-v7-latin_latin-ext-regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}

/* titillium-web-700 - latin_latin-ext */
@font-face {
  font-family: 'Titillium Web';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: local('Titillium Web Bold'), local('TitilliumWeb-Bold'),
       url('../fonts/titillium-web-v7-latin_latin-ext-700.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
       url('../fonts/titillium-web-v7-latin_latin-ext-700.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
}

/* The script toggles [hidden] to reveal the notices, and several of them are
   flex containers: without this their display would win over the one the user
   agent stylesheet attaches to the attribute, and they would never hide. */
[hidden] {
    display: none !important;
}

html {
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    flex-direction: column;
    /* min-height, not height: a long paste has to be able to push the page
       further than one screen. dvh, so the retractable browser bars of a phone
       do not add a screenful of emptiness below a short page. */
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    font-family: 'Titillium Web', sans-serif;
}

/* Reachable by a screen reader, invisible on screen. Used for the labels that
   would be redundant next to what is already displayed. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* One visible focus ring for the whole service, on every interactive element.
   The fields used to drop the outline for a one pixel border, and buttons and
   links kept whatever the browser drew. */
:focus-visible {
    outline: 2px solid var(--primary-action-background-color);
    outline-offset: 2px;
}

header {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    color: var(--secondary-text-color);
    background: var(--secondary-background-gradiant);
    background-color: var(--secondary-background-color);
    box-shadow: 1px 1px 5px 1px var(--secondary-background-color);

    .logo {
        margin-inline-end: 1rem;

        /* The logo is a link: its focus ring has to clear the drawing. */
        a {
            display: inline-flex;
        }
    }

    /* Long translations wrap here rather than pushing the header wider. */
    .title {
        min-width: 0;
    }

    h1 {
        margin: 0;

        .title {
            color: var(--primary-action-background-color);
        }
    }

    .tagline {
        margin: 0;
    }
}

main {
    flex: 1;
    margin-top: var(--default-margin-top);
    padding: 0 5%;
}

/* Notices: the banner of the created link, the expiry information, and the
   errors. They share a shape, not a meaning, hence the separate colours. */
#link,
.paste-information,
.notice {
    padding: 1rem;
    margin-block-end: var(--default-margin-top);
    color: var(--primary-action-text-color);
    background-color: var(--primary-action-background-color);
    border: 1px solid var(--primary-action-background-color);
    border-radius: 0.5rem;
    /* A paste url is one long unbreakable token, and a translated sentence can
       hold one too: neither may widen the page. */
    overflow-wrap: break-word;
    opacity: 0;
    transition: opacity 250ms cubic-bezier(0.22, 1, 0.36, 1);

    &.show {
        opacity: 1;
    }
}

.notice {
    margin-block-start: 0;

    /* Failures the visitor can act on: a link cut short, a quota, a paste that
       could not be encrypted. */
    &.notice--error {
        color: var(--error-text-color, var(--primary-action-text-color));
        background-color: var(--error-background-color, #a3241c);
        border-color: var(--error-background-color, #a3241c);
    }

    /* The service cannot be used at all: no JavaScript, or no encryption
       available. Rendered by <noscript>, so it is never faded in. */
    &.notice--blocking {
        opacity: 1;
    }
}

.paste-information {
    font-weight: bold;
}

#link {
    display: flex;
    flex-wrap: wrap;
    align-items: center;

    .title {
        width: 100%;
        margin-block-end: var(--default-margin-top);
        font-weight: bold;
    }

    .link {
        /* The basis has to stay above zero: the title above takes the whole
           first line, and a flex item whose basis is 0 always fits on the line
           in progress — the link kept being pinned to the end of the title row
           at zero width, with its url overflowing off screen. */
        flex: 1 1 60%;
        /* Without this a flex item refuses to shrink below the width of its
           content, and a paste url is a single 200 character word. */
        min-width: 0;
        overflow-x: auto;
        white-space: nowrap;
    }

    .link-actions {
        display: flex;
        position: relative;
        gap: 0.5rem;
        margin-inline-start: var(--default-margin-top);

        /* The outcome of a copy belongs under the button that was pressed: at
           the bottom of the block the eye had already left it. Out of flow so
           appearing and disappearing never shifts the form below, and anchored
           to the end of the row so a long message grows towards the inside of
           the page rather than off screen. */
        .copy-feedback {
            position: absolute;
            z-index: 1;
            inset-block-start: calc(100% + 0.25rem);
            /* An absolutely positioned box takes its width from its containing
               block, and that block is two buttons wide: without max-content the
               message came out as a 96px column of stacked words. */
            width: max-content;
            inset-inline-end: 0;
            max-width: min(20rem, 70vw);
            padding: 0.5rem;
            font-size: 0.8rem;
            background-color: rgb(0 0 0 / 0.7);
            border-radius: 0.5rem;

            /* A live region stays in the page while it waits for something to
               say, and an empty box is still a box: without this a dark
               rectangle hangs under the buttons at all times. */
            &:empty {
                display: none;
            }
        }
    }

    /* The key lives in the link: losing it loses the paste, which is worth
       saying next to the link rather than in the documentation. */
    .link-warning {
        width: 100%;
        margin-block: var(--default-margin-top) 0;
        font-size: 0.9rem;
    }

    a {
        color: inherit;
        text-decoration: none;

        &:hover,
        &:visited {
            color: inherit;
        }

        &:hover {
            text-decoration: underline;
        }
    }
}

/* Copy and send. Sized to stay comfortable under a thumb, with the icon left at
   its drawn size inside. */
#copy-link,
#send-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    color: inherit;
    background: none;
    border: 0;
    border-radius: 0.2rem;
    cursor: pointer;

    svg {
        width: 24px;
        height: 24px;
        fill: currentColor;
    }

    &:hover {
        background-color: rgb(255 255 255 / 0.15);
    }
}

form {
    display: flex;
    flex: 1 0 auto;
    flex-wrap: wrap;

    fieldset {
        display: flex;
        flex-wrap: wrap;
        /* Each item keeps its own height: the one carrying a hint is taller,
           and stretching its neighbours pushed their centred contents down. */
        align-items: flex-start;
        gap: 0 1rem;
        width: 100%;
        min-width: 0;
        padding: 0;
        margin: 0;
        border: 0;
    }
}

.form-item {
    display: flex;
    align-items: center;
    /* Three across, gap included. */
    width: calc((100% - 2rem) / 3);
    margin: 0;

    label {
        margin-inline-end: 1rem;
        font-size: 1.1rem;
        font-weight: bold;
    }

    input,
    select,
    textarea {
        /* Otherwise min-height applies to the content box and the padding adds
           to it: the input stood 56px tall next to 44px selects. */
        box-sizing: border-box;
        outline: none;
        /* A field has to be discernible from the page behind it: #ddd on white
           was a ratio of 1.27:1. */
        border: 1px solid var(--field-border-color, #8a8391);
        border-radius: 0.2rem;
        font-family: 'Titillium Web', sans-serif;
        font-size: 1.1rem;
    }

    input,
    select {
        flex: 2;
        min-width: 0;
        min-height: 44px;
    }

    input,
    textarea {
        padding: 0.3rem;
    }

    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--primary-action-background-color);
    }

    @media screen and (max-width: 768px) {
        width: 100%;
        margin-block-end: 0.5rem;

        label {
            width: 50%;
        }
    }

    /* A field whose meaning needs a word. Two columns rather than a wrapping
       row: the hint belongs under the field it explains, on the same edge, and
       a wrapped flex line would have started it under the label instead. */
    &.form-item--with-hint {
        display: grid;
        grid-template-columns: auto 1fr;
        column-gap: 1rem;
        row-gap: 0.25rem;

        label {
            /* The column gap already separates the pair. */
            margin-inline-end: 0;
        }

        .hint {
            grid-column: 2;
            font-size: 0.85rem;
        }

        @media screen and (max-width: 768px) {
            grid-template-columns: 50% 1fr;

            label {
                /* The column carries the width here. */
                width: auto;
            }
        }
    }
}

.form-paste {
    flex-direction: column;
    align-items: unset;
    width: 100%;
    height: 50vh;
    min-height: 300px;
    margin-top: var(--default-margin-top);

    textarea {
        height: 100%;
    }
}

.form-action {
    align-items: unset;
    justify-content: flex-end;
    width: 100%;
    margin-top: var(--default-margin-top);
}

button {
    box-sizing: border-box;
    min-height: 44px;
    padding: 0.5rem 0.8rem;
    color: var(--primary-action-text-color);
    background-color: var(--primary-action-background-color);
    border: 0;
    border-radius: 0.2rem;
    font-family: 'Titillium Web', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;

    &:disabled {
        cursor: not-allowed;
        opacity: 0.6;
    }
}

/* The form ships disabled and app.js unlocks it once it has checked that the
   browser can encrypt. Saying so beats letting the fields look broken. */
fieldset:disabled {
    opacity: 0.6;
}

#paste-content {
    padding: 0.5rem;
    border-radius: 0.2rem;
    white-space: pre-wrap;
    /* A decrypted paste is arbitrary text: a single long line, a url, a base64
       blob. None of them may widen the document. */
    overflow-wrap: break-word;

    &:not(.hljs) {
        background: #eee;
    }

    &.hljs {
        white-space: pre;
        /* Highlighted code keeps its columns, so it gets its own scroller
           rather than pushing the page sideways. */
        overflow-x: auto;
    }

    &.markdown {
        white-space: normal;
    }
}

.markdown {
    h1, h2, h3, h4, h5, h6, p {
        margin: 1rem 0;
    }

    /* A wide table or an image in a paste stays inside the page. */
    img {
        max-width: 100%;
        height: auto;
    }

    pre {
        overflow-x: auto;
    }
}

footer {
    padding: 1%;
    margin-top: var(--default-margin-top);
    color: var(--secondary-text-color);
    background: var(--secondary-background-gradiant);
    background-color: var(--secondary-background-color);
    font-size: 0.8rem;

    a {
        color: inherit;

        &:hover,
        &:visited,
        &:link {
            color: inherit;
        }
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
