/*
 * Howdyline's example call on a phone screen (call.js): the number calling,
 * labelled as an example, then the words coming in as they're said over a
 * waveform that moves with whoever is speaking, Howdyline in Neon and the
 * caller in white. Any page can show one: a .voice with data-call, its
 * script in .voice-lines.
 *
 * The page holds the call as it ends, so without call.js, or with reduced
 * motion, every line shows, the phone grows to hold them, and nothing
 * moves. call.js marks where the call is with data-state; only then does
 * the screen keep to the lines said so far, the latest at its foot.
 */

/* As shaped as a phone, with the status and the pause button across its
   top and the lines filling the rest. */
.voice {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    grid-template-areas:
        "state pause"
        "number number"
        "tag tag"
        "wave wave"
        "lines lines";
    align-items: center;
    column-gap: var(--space-4);
    inline-size: min(var(--container-xs), 100%);
    aspect-ratio: 9 / 19.5;
    padding-block: var(--space-16) var(--space-8);
    padding-inline: var(--space-6);
    border: var(--border-width) solid var(--border-strong);
    border-radius: var(--radius-4xl);
    background: var(--card);
    box-shadow: var(--shadow-lg);
}

/* The camera, in its pill at the top. */
.voice::before {
    content: "";
    position: absolute;
    inset-block-start: var(--space-4);
    inset-inline: 0;
    inline-size: var(--space-24);
    block-size: var(--space-6);
    margin-inline: auto;
    border-radius: var(--radius-full);
    background: var(--background);
}

/* The whole call, for screen readers; the screen itself is hidden from them. */
.voice-script {
    position: absolute;
    inset: 0;
    margin: 0;
    overflow: hidden;
    clip-path: inset(50%);
}

.voice-state {
    grid-area: state;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    margin: 0;
    font-size: var(--text-ui);
    font-weight: var(--weight-medium);
}

.voice-live {
    flex: none;
    inline-size: var(--space-2);
    aspect-ratio: 1;
    border-radius: var(--radius-full);
    background: var(--green);
}

.voice-time {
    color: var(--muted-foreground);
    font-weight: var(--weight-normal);
    font-variant-numeric: tabular-nums;
}

.voice-pause {
    grid-area: pause;
    display: inline-grid;
    place-items: center;
    inline-size: var(--tap-target);
    block-size: var(--tap-target);
    padding: 0;
    border: var(--border-width) solid var(--border-strong);
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--foreground);
    cursor: pointer;
}

.voice-pause:hover {
    border-color: var(--muted-foreground);
}

.voice-pause[hidden],
.voice-pause .i-play,
.voice-pause.is-paused .i-pause {
    display: none;
}

.voice-pause.is-paused .i-play {
    display: block;
}

.voice-pause svg {
    inline-size: var(--icon-size);
    block-size: var(--icon-size);
}

.voice-number {
    grid-area: number;
    margin-block: var(--space-6) 0;
    font-family: var(--font-heading);
    font-size: var(--text-2xl);
    font-weight: var(--weight-medium);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-snug);
    font-variant-numeric: tabular-nums;
}

.voice-tag {
    grid-area: tag;
    margin-block: var(--space-1) 0;
    color: var(--muted-foreground);
    font-size: var(--text-ui);
}

/* The bars, which call.js draws, each as loud as its height: grey while
   nobody speaks. Without call.js there are none, and no room is kept. */
.voice-wave {
    grid-area: wave;
    display: flex;
    align-items: center;
    gap: var(--space-0-5);
    block-size: var(--space-16);
    margin-block: var(--space-6);
    color: var(--muted-foreground);
}

.voice-wave:empty {
    display: none;
}

.voice-wave i {
    flex: 1;
    border-radius: var(--radius-full);
    background: currentColor;
    scale: 1 0.7;
}

.voice[data-who="howdy"] .voice-wave {
    color: var(--green);
}

.voice[data-who="caller"] .voice-wave {
    color: var(--foreground);
}

.voice-lines {
    grid-area: lines;
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: var(--space-6);
    margin: 0;
    padding: 0;
    list-style: none;
}

.voice-lines li {
    display: grid;
    justify-items: start;
    gap: var(--space-1);
}

.voice-who {
    color: var(--muted-foreground);
    font-size: var(--text-ui);
    font-weight: var(--weight-semibold);
}

.voice-lines [data-who="howdy"] .voice-who {
    color: var(--green-text);
}

.voice-say {
    font-size: var(--text-body);
    font-weight: var(--weight-medium);
    line-height: var(--leading-normal);
}

.voice-lines .is-past .voice-say {
    color: var(--muted-foreground);
}

/* Without call.js, or with reduced motion, the phone is at least as tall
   as its shape and grows to hold every line. It drops aspect-ratio to grow,
   so that, grown, it doesn't widen what holds it. */
.voice:not([data-state]),
.voice[data-state="still"] {
    aspect-ratio: auto;
    min-block-size: calc(var(--container-xs) * 19.5 / 9);
}

/* While it plays, the phone keeps its shape and the lines so far rise up
   the screen, fading out at its top. */
.voice[data-state]:not([data-state="still"]) {
    min-block-size: 0;
}

.voice[data-state]:not([data-state="still"]) .voice-lines {
    overflow: hidden;
    mask-image: linear-gradient(transparent, var(--background) 35%);
}

.voice[data-state] .voice-lines li:not(.is-past, .is-now) {
    display: none;
}

.voice[data-state] .voice-say span:not(.is-said) {
    opacity: 0;
}

/* The bars idle while nobody speaks, talk while someone does, and stop
   where they are while the call is paused or resting. call.js sets each
   bar's own pace. */
@media (prefers-reduced-motion: no-preference) {
    .voice[data-state="playing"] .voice-live {
        animation: voice-pulse var(--duration-loop) var(--ease-in-out) infinite;
    }

    .voice-wave {
        transition: color var(--duration-medium) var(--ease-out);
    }

    .voice-wave i {
        animation: voice-idle var(--duration-slower) var(--ease-in-out) infinite alternate both;
    }

    .voice[data-who] .voice-wave i {
        animation-name: voice-talk;
    }

    .voice:not([data-state="playing"]) .voice-wave i {
        animation-play-state: paused;
    }

    .voice-say span {
        transition: opacity var(--duration-base) var(--ease-out);
    }
}

@keyframes voice-pulse {
    50% {
        opacity: 0.35;
    }
}

@keyframes voice-talk {
    from {
        scale: 1 0.15;
    }

    to {
        scale: 1 1;
    }
}

@keyframes voice-idle {
    from {
        scale: 1 0.06;
    }

    to {
        scale: 1 0.18;
    }
}
