/* Longnose */

:root {
    --cream: #F3EEDB;
    --cream-hi: #F9F6EA;
    --cream-lo: #E6DFC8;
    --ink: #211F19;
    --black: #0D0C09;
    --olive: #515042;
    --sage: #726F5D;
    --sage-lt: #91917E;
    --tan: #AA936F;
    --tan-lt: #C2B495;

    /* character width */
    --img: clamp(170px, min(34vw, 38vh), 300px);

    /* crawl typography */
    --crawl-size: clamp(14.5px, 0.5vw + 12.5px, 17px);
    --crawl-width: min(720px, 90vw);

    /* space kept free under the crawl for the player (0 on wide screens) */
    --reserve: 0px;
}

@supports (height: 1svh) {
    :root {
        --img: clamp(170px, min(34vw, 38svh), 300px);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

html {
    background: var(--cream);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    background: var(--cream);
    color: var(--ink);
    font-family: "Courier New", Courier, "Nimbus Mono PS", "Liberation Mono", "Cousine", monospace;
    -webkit-tap-highlight-color: transparent;
}

/* page-wide dither / facet texture */
body::after {
    content: "";
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    pointer-events: none;
    background: url("./texture.svg") repeat 0 0;
    background-size: 300px 300px;
}

/* ---------- layout ---------- */

.stage {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

.figure {
    /* the render already carries its own dither, keep it above the overlay */
    position: relative;
    z-index: 21;
    flex: none;
    width: var(--img);
    margin: 0;
    padding-top: clamp(4px, 2.5vh, 36px);
}

.longnose {
    display: block;
    width: 100%;
    height: auto;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    animation: drift 11s ease-in-out infinite;
}

@keyframes drift {
    0%, 100% { transform: translate3d(0, 0, 0); }
    50%      { transform: translate3d(0, -3px, 0); }
}

/* ---------- crawl ---------- */

.crawl {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    width: var(--crawl-width);
    /* tuck under the transparent margin at the bottom of the image */
    margin-top: calc(var(--img) * -0.035);
    margin-bottom: var(--reserve);
    overflow-x: hidden;
    overflow-y: auto;
    outline: none;
    font-size: var(--crawl-size);
}

.js .crawl {
    overflow-y: hidden;
    cursor: default;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.js .crawl.is-static {
    overflow-y: auto;
    touch-action: auto;
    -webkit-user-select: text;
    user-select: text;
    scrollbar-width: thin;
    scrollbar-color: var(--sage) transparent;
}

.crawl:focus-visible {
    outline: 1px dotted var(--sage);
    outline-offset: -1px;
}

.crawl-text {
    padding: 0 2px;
    text-align: center;
    color: var(--ink);
    line-height: 1.62;
    letter-spacing: 0.01em;
    text-shadow: 0.5px 0.5px 0 rgba(33, 31, 25, 0.26);
}

.js .crawl-text {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    visibility: hidden;
    backface-visibility: hidden;
}

.js .crawl-text.is-ready {
    visibility: visible;
}

.js .crawl.is-static .crawl-text {
    position: static;
    padding-top: 1.2em;
    padding-bottom: 2em;
    transform: none;
}

.crawl-text p {
    margin: 0 0 1.55em;
    overflow-wrap: break-word;
}

.crawl-text p:last-child {
    margin-bottom: 0;
}

/* tiny, uneven ink density like an old display */
.crawl-text p:nth-child(3n + 2) { opacity: 0.93; }
.crawl-text p:nth-child(7n + 4) { opacity: 0.88; }
.crawl-text p:nth-child(11n + 6) { opacity: 0.96; }

/* ---------- player ---------- */

.player {
    display: none;
}

.js .player {
    position: fixed;
    right: 20px;
    bottom: 20px;
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 7px;
    height: 44px;
    padding: 0 8px 0 5px;
    background: var(--cream-lo) url("./texture.svg") repeat 0 0;
    background-size: 300px 300px;
    border: 2px solid var(--ink);
    box-shadow:
        inset 2px 2px 0 var(--cream-hi),
        inset -2px -2px 0 var(--tan-lt),
        2px 2px 0 var(--olive);
    -webkit-user-select: none;
    user-select: none;
}

.btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 2px solid var(--ink);
    border-radius: 0;
    font: inherit;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.btn:active {
    transform: translate(1px, 1px);
}

.btn:focus {
    outline: none;
}

.btn:focus-visible,
.slider:focus-visible {
    outline: 2px dotted var(--ink);
    outline-offset: 2px;
}

.icon {
    display: block;
    fill: currentColor;
}

.btn-play {
    width: 30px;
    height: 30px;
    background: var(--ink);
    color: var(--cream);
    box-shadow: inset 1px 1px 0 var(--olive);
}

.btn-play:hover {
    background: var(--olive);
    box-shadow: inset 1px 1px 0 var(--sage);
}

.btn-play .icon {
    width: 14px;
    height: 14px;
}

.btn-play .icon-pause,
.is-playing .btn-play .icon-play {
    display: none;
}

.is-playing .btn-play .icon-pause {
    display: block;
}

.btn-mute {
    width: 26px;
    height: 26px;
    background: var(--cream-hi);
    color: var(--ink);
}

.btn-mute:hover {
    background: var(--tan-lt);
}

.btn-mute .icon {
    width: 16px;
    height: 16px;
}

.btn-mute .icon-muted,
.is-muted .btn-mute .icon-vol {
    display: none;
}

.is-muted .btn-mute .icon-muted {
    display: block;
}

/* custom sliders */

.slider {
    --p: 0;
    --thumb: 8px;
    position: relative;
    flex: none;
    height: 26px;
    cursor: pointer;
    touch-action: none;
}

.slider-seek {
    width: 128px;
}

.slider-vol {
    --thumb: 6px;
    width: 50px;
}

.slider-track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 10px;
    margin-top: -5px;
    border: 2px solid var(--ink);
    background: var(--cream-hi);
    overflow: hidden;
}

.slider-fill {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    background: var(--sage) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' shape-rendering='crispEdges'%3E%3Cpath fill='%2391917E' d='M0 0h1v1H0zM2 2h1v1H2z'/%3E%3Cpath fill='%23515042' d='M3 1h1v1H3zM1 3h1v1H1z'/%3E%3C/svg%3E") repeat 0 0;
    transform-origin: 0 50%;
    transform: scaleX(var(--p));
}

.slider-thumb {
    position: absolute;
    top: 50%;
    left: calc(var(--p) * (100% - var(--thumb)));
    width: var(--thumb);
    height: 16px;
    margin-top: -8px;
    background: var(--tan-lt);
    border: 2px solid var(--ink);
    box-shadow: inset 1px 1px 0 var(--cream-hi);
}

.slider:hover .slider-thumb,
.slider.is-dragging .slider-thumb {
    background: var(--tan);
}

.is-muted .slider-vol .slider-fill,
.is-muted .slider-vol .slider-thumb {
    opacity: 0.55;
}

/* ---------- responsive ---------- */

@media (min-width: 1600px) and (min-height: 940px) {
    :root {
        --img: clamp(170px, min(34vw, 38vh), 330px);
    }
}

/* keep the crawl clear of the player once they would overlap */
@media (max-width: 1240px) {
    :root {
        --reserve: 72px;
    }
}

@media (max-width: 600px) {
    :root {
        --img: clamp(160px, min(58vw, 32vh), 240px);
        --crawl-width: 88vw;
        --reserve: calc(62px + env(safe-area-inset-bottom));
    }

    @supports (height: 1svh) {
        :root {
            --img: clamp(160px, min(58vw, 32svh), 240px);
        }
    }

    .js .player {
        right: 12px;
        bottom: 12px;
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
        height: 40px;
        gap: 6px;
        padding: 0 6px 0 4px;
    }

    .btn-play {
        width: 28px;
        height: 28px;
    }

    .slider-seek {
        width: 104px;
    }
}

/* short landscape screens (phones on their side) */
@media (max-height: 500px) and (min-width: 601px) {
    :root {
        --img: clamp(120px, 34vh, 200px);
        --reserve: 0px;
        --crawl-width: min(560px, 70vw);
    }

    .figure {
        padding-top: 4px;
    }

    /* the top corner is free here, the bottom one is not */
    .js .player {
        top: 12px;
        bottom: auto;
        top: max(12px, env(safe-area-inset-top));
        right: 12px;
        right: max(12px, env(safe-area-inset-right));
    }
}

/* touch devices: volume is usually hardware-only, keep just mute */
@media (hover: none) and (pointer: coarse), (max-width: 600px) {
    .slider-vol {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .longnose {
        animation: none;
    }
}
