/* AI Copilot, GET /copilot: the question and the field to ask, in the
   middle of the window, and the opening that crosses the page as it opens.
   [D78, D137, D160; mocks docs/mockups/copilot.html and
   docs/mockups/copilot-opening.html]

     .copilot           the page, a container: a phone's layout below 560
                        pixels of it, the wide one from there; as high as
                        the window leaves it; .is-opening while its opening
                        plays (the view marks it without a question, app.js
                        takes the mark away once it has passed)
     .copilot-wash      the opening's tide over the main column, laid before
                        the page: .copilot-wash-sheet twice, Dusk
                        (.copilot-wash-dusk) and Ocean over it
                        (.copilot-wash-ocean)
     .copilot-hero      the question and the field, centred both ways
     .copilot-ask       the field with the light around it (.copilot-glow)
     .copilot-field     the field: a pill of one line, on a phone too, which
                        a longer question of one's own grows line by line
     .copilot-hint      the example questions over the empty field, which
                        app.js types one after the other (.copilot-hint-line,
                        .copilot-caret), each measured first, unseen
                        (.copilot-hint-probe); without script the
                        placeholder shows the first one's short form
     .copilot-tab       the Tab key, which takes the example shown, beside
                        the arrow while it does (.can-take, app.js)
     .copilot-soon      under the field once a question was sent: nothing
                        answers yet */

/* As high as the window leaves the page (--main-room, layout.css), so the
   question and the field stand in its middle, as an assistant's first
   screen does, lifted a little over the true middle. A page with the
   banner of viewing as someone scrolls by the banner's height. [D137] */
.copilot {
    container: copilot / inline-size;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: var(--main-room);
}

/* ------------------------------------------------------------------------
   The opening (D160). Each time the page opens without a question, the
   mark's tide (D136) crosses the main column once: Dusk rises from its
   foot, Ocean takes over as it crosses the middle, and it leaves through
   the top. The question, then the field, come out of a blur behind it, and
   the light around the field comes as it leaves; app.js starts typing the
   examples once it has passed. It plays from the first paint, in
   --opening-time (app.js's COPILOT_OPENING, the same 1.2 seconds), and
   leaves everything as it stands without it, so it ends cleanly without
   script too. Its colours are tokens (--copilot-wash-*), a step lighter in
   the light theme.
   ------------------------------------------------------------------------ */

.copilot-wash,
.copilot {
    --opening-time: 1200ms;
}

/* Over the main column alone, as the cover of a page on its way stands
   (components.css, .page-cover): from the sidebar's edge, the rail's
   where it is folded or the window is narrower than 1024 pixels, and the
   window's left edge on a phone, to the right edge, the window's whole
   height. Fixed, and outside the page's container, so the window places
   it. Below everything of the page in the root's stacking context and
   above its canvas (z-index -1): whatever has a ground of its own, the
   field, a flash, the banner of viewing as someone, stands above it, and
   so do the sidebar, the phone's title and its bar, which shows it through
   its glass. */
.copilot-wash {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -1;
    overflow: hidden;
    container-type: size;
    pointer-events: none;
}

@media (min-width: 640px) {
    .copilot-wash {
        left: var(--rail-width);
    }
}

@media (min-width: 1024px) {
    .copilot-wash {
        left: var(--sidebar-width);
    }

    html[data-sidebar="collapsed"] .copilot-wash {
        left: var(--rail-width);
    }
}

/* A sheet two and a half times as high as the column, its colour
   strongest in its upper half, a little wider than it so that no edge
   shows: it comes in at the column's foot, crosses it, and is gone above
   its top when the time is up. */
.copilot-wash-sheet {
    position: absolute;
    top: 100%;
    left: -15%;
    width: 130%;
    height: 250%;
    opacity: var(--copilot-wash-strength);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 16%, black 40%, color-mix(in srgb, black 55%, transparent) 62%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, black 16%, black 40%, color-mix(in srgb, black 55%, transparent) 62%, transparent 100%);
    animation: copilot-wash-rise var(--opening-time) cubic-bezier(0.5, 0.05, 0.35, 1) both;
    will-change: transform;
}

@keyframes copilot-wash-rise {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(calc(-100% - 100cqh));
    }
}

/* Dusk, the mark's ::after (base.css, .icon-copilot): its ground blended
   with its violet, a little of its orange and violet in its upper half. */
.copilot-wash-dusk {
    background:
        radial-gradient(30% 7% at 70% 14%, color-mix(in srgb, var(--copilot-dusk-1) 16%, transparent), transparent),
        radial-gradient(45% 12% at 62% 30%, color-mix(in srgb, var(--copilot-dusk-2) 40%, transparent), transparent),
        linear-gradient(to bottom, var(--copilot-wash-dusk-a) 0%, var(--copilot-wash-dusk-b) 20%, var(--copilot-wash-dusk-b) 36%, var(--copilot-wash-dusk-c) 60%);
}

/* Ocean, the mark's ::before, over Dusk: its cyan, violet and sky. It
   comes in as the tide crosses the middle, from 38 to 80 hundredths of the
   time, so the tide turns from Dusk to Ocean on its way up. */
.copilot-wash-ocean {
    background:
        radial-gradient(30% 8% at 78% 22%, color-mix(in srgb, var(--copilot-ocean-1) 42%, transparent), transparent),
        radial-gradient(40% 10% at 26% 30%, var(--copilot-ocean-2), transparent),
        radial-gradient(30% 8% at 55% 44%, color-mix(in srgb, var(--copilot-ocean-3) 30%, transparent), transparent),
        linear-gradient(to bottom, var(--copilot-wash-ocean-a) 0%, var(--copilot-wash-ocean-b) 24%, var(--copilot-wash-ocean-b) 40%, var(--copilot-wash-ocean-c) 62%);
    animation:
        copilot-wash-rise var(--opening-time) cubic-bezier(0.5, 0.05, 0.35, 1) both,
        copilot-wash-turn var(--opening-time) ease-in-out both;
}

@keyframes copilot-wash-turn {
    0%, 38% {
        opacity: 0;
    }
    80%, 100% {
        opacity: var(--copilot-wash-strength);
    }
}

/* The question, then the field, out of a blur as the tide passes them. */
.copilot.is-opening .copilot-title,
.copilot.is-opening .copilot-ask {
    animation: copilot-come-in calc(var(--opening-time) * 0.62) cubic-bezier(0.2, 0.7, 0.2, 1) calc(var(--opening-time) * 0.3) both;
}

.copilot.is-opening .copilot-ask {
    animation-delay: calc(var(--opening-time) * 0.38);
}

@keyframes copilot-come-in {
    from {
        opacity: 0;
        filter: blur(16px);
        transform: translateY(18px) scale(0.985);
    }
    to {
        opacity: 1;
        filter: none;
        transform: none;
    }
}

/* The light around the field, as the tide leaves. */
.copilot.is-opening .copilot-glow {
    animation: copilot-glow-in calc(var(--opening-time) * 0.9) ease-out calc(var(--opening-time) * 0.55) both;
}

@keyframes copilot-glow-in {
    from {
        opacity: 0;
        transform: scale(0.92);
    }
}

/* A page that took over the cover of a page on its way (D110; wait.js,
   html.is-arriving) would play its opening unseen under it. So the opening
   holds its first frame there, the question and the field not yet shown and
   the tide below the column's foot, and plays once the cover has gone and
   the class with it; app.js starts its timers then too. Under the whole
   cover the column is the page's ground; under the dimmed one of another
   view of the same page (html.is-arriving-dim, from /copilot?q= to
   /copilot) the empty column shows through it until then. wait.js takes
   the class away a second after the cover should have faded even where its
   fade never ends, so the opening never stays held. */
html.is-arriving .copilot-wash-sheet,
html.is-arriving .copilot.is-opening .copilot-title,
html.is-arriving .copilot.is-opening .copilot-ask,
html.is-arriving .copilot.is-opening .copilot-glow {
    animation-play-state: paused;
}

/* Nothing moves with reduced motion: no tide, the page there at once, the
   light around the field with it. In forced colours, which leave out the
   gradients, there is no tide and no light. */
@media (prefers-reduced-motion: reduce) {
    .copilot-wash {
        display: none;
    }

    .copilot.is-opening .copilot-title,
    .copilot.is-opening .copilot-ask,
    .copilot.is-opening .copilot-glow {
        animation: none;
    }
}

@media (forced-colors: active) {
    .copilot-wash,
    .copilot-glow {
        display: none;
    }
}

/* ------------------------------------------------------------------------
   The question and the field
   ------------------------------------------------------------------------ */

.copilot-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: var(--space-12);
    text-align: center;
}

.copilot-title {
    max-width: 18ch;
    font-size: var(--text-3xl);
    letter-spacing: -0.03em;
    line-height: 1.12;
    text-wrap: balance;
}

/* The field and its light, the question's distance above them, so the
   light stands centred on the field. Its own stacking context keeps the
   light behind the field and in front of the page. */
.copilot-ask {
    position: relative;
    width: 100%;
    max-width: 720px;
    margin-top: var(--space-6);
    isolation: isolate;
}

/* The light around the field (D160): the mark's Dusk, violet and Ocean
   from left to right, blurred, as wide as the field and slimmer above and
   below it, soft (--copilot-glow-strength) and still. It stays when a
   question was sent; the opening brings it in. */
.copilot-glow {
    position: absolute;
    inset: -4px 3%;
    z-index: -1;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg,
        var(--copilot-dusk) 0%,
        var(--copilot-dusk-2) 50%,
        color-mix(in oklab, var(--copilot-ocean) 55%, var(--copilot-ocean-1)) 100%);
    filter: blur(16px);
    opacity: var(--copilot-glow-strength);
    pointer-events: none;
    scale: 1 0.7;
}

/* A pill of one line on a phone as on a wide screen (D160), the arrow a
   little closer to its edge. */
.copilot-field {
    display: flex;
    align-items: flex-end;
    gap: var(--space-2);
    width: 100%;
    padding: 7px 7px 7px var(--space-5);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    background: var(--color-surface);
    box-shadow: var(--shadow-ask);
    text-align: left;
    cursor: text;
    transition: border-color var(--duration-fast) var(--ease-in-out),
                box-shadow var(--duration-normal) var(--ease-out);
}

/* A question of one's own, which wraps soonest on a phone: corners of its
   own rather than a pill's round ends, so more lines never read as a
   capsule. */
.copilot-field.has-text {
    border-radius: 26px;
}

/* A field's border while it is used, calmer than a form field's black:
   the control border, at 3:1 on the surface. */
.copilot-field:focus-within {
    border-color: var(--color-control-border);
    box-shadow: var(--shadow-ask-focus);
}

.copilot-field-text {
    position: relative;
    flex: 1 1 auto;
    align-self: center;
    min-width: 0;
}

/* One line while it is empty, so it never jumps as the examples change;
   app.js grows it with a longer question. */
.copilot-input {
    display: block;
    width: 100%;
    min-height: 1.5em;
    max-height: 12em;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--text-md);
    line-height: 1.5;
    resize: none;
    outline: none;
}

.copilot-input::placeholder {
    color: var(--color-text-subtle);
    opacity: 1;
}

.copilot-hint {
    position: absolute;
    inset: 0 0 auto;
    height: 1.5em;
    overflow: hidden;
    color: var(--color-text-subtle);
    font-size: var(--text-md);
    line-height: 1.5;
    pointer-events: none;
}

.copilot-field.has-text .copilot-hint {
    visibility: hidden;
}

/* One line: app.js shows an example's short form where the whole one does
   not fit, and on a screen narrower than 360 pixels a short form may end
   in an ellipsis. */
.copilot-hint-line {
    position: absolute;
    inset: 0 0 auto;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* An example measured before it is typed, in the hint's own type, on one
   line and unseen. */
.copilot-hint-probe {
    position: absolute;
    visibility: hidden;
    white-space: nowrap;
}

/* A question read leaves upwards, a little blurred, as the next one is
   typed. With reduced motion it goes at once (base.css). */
.copilot-hint-line.is-out {
    animation: copilot-hint-out 520ms var(--ease-out) both;
}

@keyframes copilot-hint-out {
    to {
        opacity: 0;
        filter: blur(4px);
        transform: translateY(-0.7em);
    }
}

/* The caret after the letters typed, gone while the field has the
   browser's own. */
.copilot-caret {
    display: inline-block;
    width: 1.5px;
    height: 1.15em;
    margin-left: 1px;
    background: currentColor;
    vertical-align: -0.2em;
    animation: copilot-blink 1.05s steps(1) infinite;
}

.copilot-field:focus-within .copilot-caret {
    display: none;
}

@keyframes copilot-blink {
    50% {
        opacity: 0;
    }
}

/* The Tab key, where there is a keyboard, while Tab takes the example:
   after a click or a key in the empty field (app.js). */
.copilot-tab {
    display: none;
    flex: none;
    align-self: center;
    padding: 2px 7px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-subtle);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.5;
}

@media (hover: hover) and (pointer: fine) {
    .copilot-field.can-take:not(.has-text) .copilot-tab:not([hidden]) {
        display: block;
    }
}

.copilot-send {
    display: grid;
    flex: none;
    place-items: center;
    width: var(--control-height);
    height: var(--control-height);
    padding: 0;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: var(--color-on-primary);
    cursor: pointer;
    transition: background-color var(--duration-fast) var(--ease-in-out),
                transform var(--duration-fast) var(--ease-in-out);
}

.copilot-send .icon {
    stroke-width: 2.25;
}

@media (hover: hover) {
    .copilot-send:hover {
        background: var(--color-primary-hover);
    }
}

.copilot-send:active {
    transform: scale(0.94);
}

.copilot-send:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.copilot-soon {
    max-width: 44ch;
    margin-top: var(--space-3);
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    text-wrap: balance;
}

/* From the width of a tablet: the question larger, more room around the
   field and its light, the pill's round ends kept with more lines too. */
@container copilot (min-width: 560px) {
    .copilot-title {
        max-width: none;
        font-size: 2.25rem;
    }

    .copilot-ask {
        margin-top: var(--space-8);
    }

    .copilot-glow {
        inset: -6px 2%;
        filter: blur(24px);
    }

    .copilot-field,
    .copilot-field.has-text {
        padding: 9px 9px 9px 26px;
        border-radius: var(--radius-full);
    }
}
