/*
 * Elysicester — diorama UI only: reader panel, controls, title card.
 * The scene itself is drawn on the canvas; this file dresses the HTML around it
 * in the site's cloth (void and amber, EB Garamond and Cormorant).
 */

:root {
    --void: #050506;
    --deep: #0e0e11;
    --smoke: #1a1a1e;
    --stone: #505058;
    --bone: #808088;
    --pale: #a8a8b2;
    --silver: #c8c8d0;
    --ivory: #e8e8ec;
    --rust: #a05020;
    --amber: #c07830;
    --gold: #d89840;
    --honey: #e8b860;

    --font-body: 'EB Garamond', Georgia, serif;
    --font-display: 'Cormorant', Georgia, serif;

    color-scheme: dark;
}

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

html,
body {
    margin: 0;
    height: 100%;
    background: var(--void);
    color: var(--pale);
    font-family: var(--font-body);
    font-size: 18px;
    line-height: 1.6;
    overflow: hidden;
}

a {
    color: var(--amber);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
}

a:hover,
a:focus-visible {
    color: var(--honey);
}

:focus-visible {
    outline: 1px solid var(--honey);
    outline-offset: 3px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/*
 * The site's own paper grain, as every other page lays it (the same fractal
 * noise, the same faintness, the same restless shift), over the scene and its
 * words alike. One difference, for a page that is already drawing WebGL: the
 * site's grain layer is twice the screen each way, this one only a tenth over,
 * with the noise pinned at the site's scale (200vmin, what the site's layer
 * works out to), so it looks the same at a fraction of the memory. Under
 * reduced motion it holds still.
 */
.grain {
    position: fixed;
    top: -5%;
    left: -5%;
    width: 110%;
    height: 110%;
    z-index: 55;
    pointer-events: none;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-size: 200vmin 200vmin;
    animation: grainShift 0.5s steps(10) infinite;
}

@keyframes grainShift {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-2%, -2%); }
    20% { transform: translate(2%, 2%); }
    30% { transform: translate(-1%, 2%); }
    40% { transform: translate(2%, -1%); }
    50% { transform: translate(-2%, 1%); }
    60% { transform: translate(1%, -2%); }
    70% { transform: translate(-1%, -1%); }
    80% { transform: translate(2%, 1%); }
    90% { transform: translate(-2%, 2%); }
}

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

/* The way out, visible at every moment. */
.plainly {
    position: fixed;
    top: max(14px, env(safe-area-inset-top));
    left: max(18px, env(safe-area-inset-left));
    z-index: 50;
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: 0.08em;
    color: var(--bone);
    text-shadow: 0 0 3px rgba(4, 3, 8, 1), 0 0 8px rgba(4, 3, 8, 0.9), 0 0 2px rgba(4, 3, 8, 1);
}

/* A pool of dusk behind the corner words, so they read over whatever the city (or the maze) puts behind them. */
.plainly::before,
.controls::before {
    content: '';
    position: absolute;
    inset: -12px -20px;
    z-index: -1;
    background: radial-gradient(closest-side, rgba(4, 3, 8, 0.62), rgba(4, 3, 8, 0.4) 62%, transparent);
    pointer-events: none;
}

.diorama {
    position: fixed;
    inset: 0;
}

.stage {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
}

[data-mode="still"] .stage {
    display: none;
}

/* The still: the diorama as a plate, when the live scene can't be drawn. */
.fallback {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: var(--void);
}

.fallback[hidden] {
    display: none;
}

.fallback-still,
.fallback-still img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.fallback-note {
    position: relative;
    max-width: 34em;
    margin: 0 auto max(28px, env(safe-area-inset-bottom));
    padding: 18px 24px 20px;
    background: rgba(5, 5, 6, 0.72);
    border: 1px solid var(--smoke);
    color: var(--silver);
}

.fallback-note h2 {
    margin: 0 0 6px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 24px;
    letter-spacing: 0.04em;
    color: var(--ivory);
}

.fallback-note p {
    margin: 0;
}

/*
 * The reading points as a list of real links: out of sight until a keyboard
 * arrives (then it shows, so focus is always visible), always there for screen
 * readers, and shown openly in the still.
 */
.points {
    position: fixed;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
    z-index: 40;
    max-width: min(26em, calc(100vw - 36px));
    max-height: 52vh;
    overflow: auto;
    padding: 12px 18px 14px;
    background: rgba(8, 7, 11, 0.9);
    border: 1px solid var(--smoke);
}

.points:not(:focus-within) {
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    border: 0;
}

.points-title {
    margin: 0 0 6px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 18px;
    letter-spacing: 0.08em;
    color: var(--bone);
}

.points-list {
    margin: 0;
    padding-left: 1.4em;
    font-size: 17px;
    line-height: 1.5;
}

.points-list cite {
    font-style: italic;
}

.points-list a[data-read="yes"] {
    color: var(--bone);
}

[data-mode="still"] .points,
[data-mode="still"] .points:not(:focus-within) {
    position: static;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    margin-top: 12px;
    padding: 0;
    overflow: visible;
    clip-path: none;
    background: none;
    border: 0;
}

[data-mode="still"] .fallback-note {
    max-height: 70vh;
    overflow: auto;
}

/* The name of the lit point, floated beside it in the scene. */
.point-label {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 30;
    transform: translate(-50%, calc(-100% - 18px));
    padding: 2px 10px;
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: 0.06em;
    white-space: nowrap;
    color: var(--ivory);
    background: rgba(8, 7, 11, 0.78);
    border: 1px solid var(--smoke);
    pointer-events: none;
}

/* Beside the walking shadow, the name is a way in: a click reads it. */
.point-label.is-near {
    pointer-events: auto;
    cursor: pointer;
    /* A thumb set down on it may be steering (walk.js steersFrom): the page mustn't take the drag for a scroll. */
    touch-action: none;
}

.point-label.is-near:hover {
    color: var(--honey);
    border-color: var(--amber);
}

/*
 * The places' faint names, from far out (a trial, names.js): each a little above its place, drawn light on the
 * dusk, taking no touch. Places read through are fainter still (names.js sets each one's strength).
 */
.place-names {
    position: fixed;
    inset: 0;
    z-index: 20;
    overflow: hidden;
    pointer-events: none;
}

.place-name {
    position: absolute;
    left: 0;
    top: 0;
    transform: translate(-50%, -100%);
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    white-space: nowrap;
    color: #f1e6cc;
    text-shadow: 0 0 6px rgba(3, 2, 6, 0.95), 0 0 2px rgba(3, 2, 6, 1);
    transition: opacity 0.5s linear;
}

/*
 * A whisper over the water, after a long stillness (a trial, whisper.js): one of E's lines, low in the view,
 * rising a little as it comes and sinking as it goes.
 */
.whisper {
    position: fixed;
    left: 50%;
    bottom: 14vh;
    z-index: 25;
    width: min(26em, calc(100vw - 48px));
    margin: 0;
    transform: translate(-50%, 10px);
    font-family: var(--font-display);
    font-size: clamp(19px, 2.5vw, 25px);
    font-style: italic;
    line-height: 1.35;
    letter-spacing: 0.02em;
    text-align: center;
    text-wrap: balance;
    color: #ebe8f8;
    text-shadow: 0 0 14px rgba(160, 150, 230, 0.6), 0 0 3px rgba(3, 2, 6, 0.95);
    opacity: 0;
    pointer-events: none;
    transition: opacity 2.8s ease, transform 7s ease-out;
}

.whisper.is-whispering {
    opacity: 0.84;
    transform: translate(-50%, 0);
    transition: opacity 2.4s ease, transform 7s ease-out;
}

.whisper.is-quick {
    transition: opacity 0.6s ease;
}

@media (prefers-reduced-motion: reduce) {
    .whisper,
    .whisper.is-whispering {
        transform: translate(-50%, 0);
        transition: opacity 0.3s linear;
    }
}

/*
 * A sign's words, floated over its plate: the Danæam above, and beneath it the
 * site's gloss where the site gives one.
 */
.sign-label {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 31;
    transform: translate(-50%, calc(-100% - 10px));
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 12px 5px;
    line-height: 1.25;
    white-space: nowrap;
    background: rgba(8, 7, 11, 0.82);
    border: 1px solid var(--smoke);
    pointer-events: none;
}

.sign-label[hidden] {
    display: none;
}

.sign-words {
    font-family: var(--font-display);
    font-size: 21px;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: var(--honey);
}

.sign-gloss {
    font-family: var(--font-body);
    font-size: 15px;
    font-style: italic;
    color: var(--pale);
}

/* The signs in the list: words, then gloss, on one line. */
.signs-title {
    margin: 12px 0 4px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 17px;
    letter-spacing: 0.08em;
    color: var(--bone);
}

.signs-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.sign-link {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0 0.6em;
    padding: 1px 0;
    color: inherit;
    text-align: left;
    background: none;
    border: 0;
    cursor: pointer;
}

.sign-link .sign-words {
    font-size: 18px;
}

.sign-link:hover .sign-words,
.sign-link:focus-visible .sign-words {
    color: var(--ivory);
}

/* Top right: the sound switch, and the way back to the whole city. */
.controls {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(18px, env(safe-area-inset-right));
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.control {
    padding: 2px 6px;
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: 0.08em;
    color: var(--amber);
    background: none;
    border: 0;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    text-shadow: 0 0 3px rgba(4, 3, 8, 1), 0 0 8px rgba(4, 3, 8, 0.9), 0 0 2px rgba(4, 3, 8, 1);
    cursor: pointer;
}

.control:hover,
.control:focus-visible {
    color: var(--honey);
}

.control[hidden] {
    display: none;
}

.control[aria-pressed="true"] {
    color: var(--honey);
}

/* One option at the top of the screen (a trial: main.js), in Elm's words: "zoom out", "zoom out", "leave". */
.one-button {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: 50%;
    z-index: 50;
    transform: translateX(-50%);
    padding: 4px 14px;
    font-family: var(--font-display);
    font-size: 19px;
    letter-spacing: 0.1em;
    white-space: nowrap;
    color: var(--amber);
    background: none;
    border: 0;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.22em;
    text-shadow: 0 0 3px rgba(4, 3, 8, 1), 0 0 8px rgba(4, 3, 8, 0.9), 0 0 2px rgba(4, 3, 8, 1);
    cursor: pointer;
}

.one-button::before {
    content: '';
    position: absolute;
    inset: -10px -24px;
    z-index: -1;
    background: radial-gradient(closest-side, rgba(4, 3, 8, 0.62), rgba(4, 3, 8, 0.4) 62%, transparent);
    pointer-events: none;
}

.one-button:hover,
.one-button:focus-visible {
    color: var(--honey);
}

.one-button[hidden] {
    display: none;
}

/*
 * Beside it, the hum's own symbol (the jetty sign's hummingbird, Elm's ask: "a button that's the symbol of the hum so
 * you can recentre on the hum"): there whenever the camera isn't close on the hum, as quiet as the option beside it.
 */
.hum-button {
    position: fixed;
    top: max(7px, env(safe-area-inset-top));
    left: calc(50% - 6.6em);
    z-index: 50;
    width: 44px;
    height: 44px;
    padding: 5px;
    font-size: 19px;
    color: var(--amber);
    background: none;
    border: 0;
    cursor: pointer;
}

.hum-button::before {
    content: '';
    position: absolute;
    inset: -6px;
    z-index: -1;
    background: radial-gradient(closest-side, rgba(4, 3, 8, 0.62), rgba(4, 3, 8, 0.4) 62%, transparent);
    pointer-events: none;
}

.hum-button svg {
    display: block;
    width: 100%;
    height: 100%;
    fill: currentColor;
    filter: drop-shadow(0 0 2px rgba(4, 3, 8, 1));
}

.hum-button:hover,
.hum-button:focus-visible {
    color: var(--honey);
}

.hum-button[hidden] {
    display: none;
}

/*
 * What a giver says (a trial: creatures.js), where a place's name would be: its word, in italics, as Elm wrote them
 * (*squur*, *chirp*); Allison's line is longer, and wraps (allison.js).
 */
.point-label.is-speech {
    font-style: italic;
    letter-spacing: 0.04em;
    white-space: normal;
    width: max-content;
    max-width: min(17em, calc(100vw - 40px));
    text-align: center;
}

/*
 * What's been gathered (with the givers, a trial: inventory.js): a small count high on the right, once there's
 * something in it, as quiet as the one option; it opens the inventory. Won, it glows.
 */
.inventory-toggle {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    z-index: 50;
    padding: 4px 6px;
    font-family: var(--font-display);
    font-size: 17px;
    letter-spacing: 0.08em;
    white-space: nowrap;
    color: var(--bone);
    background: none;
    border: 0;
    cursor: pointer;
}

.inventory-toggle::before {
    content: '';
    position: absolute;
    inset: -8px -16px;
    z-index: -1;
    background: radial-gradient(closest-side, rgba(4, 3, 8, 0.6), rgba(4, 3, 8, 0.36) 62%, transparent);
    pointer-events: none;
}

.inventory-toggle:hover,
.inventory-toggle:focus-visible {
    color: var(--honey);
}

.inventory-toggle.is-won {
    color: var(--honey);
    text-shadow: 0 0 12px rgba(240, 190, 90, 0.75);
}

.inventory-toggle[hidden] {
    display: none;
}

/* (It comes in gently, once the lost pages are counted, rather than appearing at once: inventory.js.) */
.inventory-toggle:not([hidden]) {
    animation: inventory-arrive 0.6s ease both;
}

@keyframes inventory-arrive {
    from { opacity: 0; }
}

.inventory-note {
    margin: 10px 0 12px;
    font-size: 16px;
    color: var(--bone);
}

.inventory-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.inventory-list li {
    margin: 0;
    padding: 6px 0;
    border-top: 1px solid rgba(160, 150, 170, 0.14);
}

.inventory-list li {
    display: grid;
    grid-template-columns: 1.9rem 1fr auto;
    align-items: start;
    gap: 0 0.7rem;
}

.inventory-list li.is-waiting {
    font-family: var(--font-display);
    font-size: 16px;
    letter-spacing: 0.04em;
    color: rgba(200, 190, 175, 0.55);
}

/* Each lost page's number, as the texts number it (read.html): a ring, filled with gold once it's found. */
.inventory-number {
    display: grid;
    place-items: center;
    width: 1.6rem;
    height: 1.6rem;
    border-radius: 50%;
    border: 1px solid rgba(160, 80, 32, 0.8);
    font-family: var(--font-display);
    font-size: 14px;
    color: var(--amber);
}

.inventory-list li.is-found .inventory-number {
    background: var(--gold);
    border-color: var(--gold);
    color: #0a0a0c;
}

.inventory-piece {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    padding: 2px 0;
    font: inherit;
    text-align: left;
    color: var(--silver);
    background: none;
    border: 0;
    cursor: pointer;
}

.inventory-piece:hover,
.inventory-piece:focus-visible {
    color: var(--ivory);
}

.inventory-texts {
    font-family: var(--font-display);
    font-size: 14px;
    letter-spacing: 0.05em;
    color: var(--amber);
    white-space: nowrap;
}

.inventory-waiting {
    grid-column: 2 / -1;
    padding-top: 0.15rem;
}

.inventory-words {
    font-family: var(--font-body);
    font-size: 17px;
    line-height: 1.4;
}

.inventory-where {
    font-family: var(--font-display);
    font-size: 14px;
    letter-spacing: 0.06em;
    color: var(--bone);
}

/* (Won, it stands first, over the list, where the inventory opens.) */
.inventory-win {
    margin: 4px 0 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(217, 174, 95, 0.4);
}

.inventory-win[hidden] {
    display: none;
}

.inventory-win-title {
    margin: 0 0 6px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 24px;
    letter-spacing: 0.08em;
    color: var(--honey);
}

.inventory-win p {
    margin: 0 0 8px;
}

/* (Beside the taking, the page itself, on the site: read at once, in a new tab.) */
.inventory-by-hand {
    margin-left: 0.9em;
}

.inventory-by-hand:hover,
.inventory-by-hand:focus-visible {
    color: var(--honey);
}

.inventory-status {
    min-height: 1.4em;
    font-size: 15px;
    color: var(--bone);
}

/*
 * With the one option (a trial), the rest stands aside: the corner's words go with the first screen (the card),
 * the controls stay for keyboards (Tab brings them into view, as a skip link comes), and sound has a quiet corner
 * of its own, low on the left.
 */
/* (Before the code has come, the card is what shows, and its corner's "Read" with it, from the first paint; unless coming
   back, when the city is what's coming. index.html sets both.) */
html[data-onebutton][data-threshold]:not([data-threshold="card"]) .plainly,
html[data-onebutton][data-returning] .plainly {
    display: none;
}

html[data-onebutton] .controls:not(:focus-within) {
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

html[data-onebutton] .controls:not(:focus-within)::before {
    display: none;
}

.control.sound-corner {
    position: fixed;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 50;
    font-size: 15px;
    color: var(--bone);
}

/*
 * Room for a finger (a review of the site, 2 Oct: "sound: off" was 82 by 22 CSS pixels, the count 54 by 29, "zoom out"
 * 113 by 31): each small control answers a touch over at least 44 pixels each way, drawn just as it was.
 */
.one-button::after,
.inventory-toggle::after,
.control.sound-corner::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: max(100%, 44px);
    height: max(100%, 44px);
    transform: translate(-50%, -50%);
}

.control.sound-corner:hover,
.control.sound-corner:focus-visible,
.control.sound-corner[aria-pressed="true"] {
    color: var(--honey);
}

/*
 * Walking as the shadow (walk.js): where a thumb comes down and drags, a soft
 * ring appears under it, and a knob that follows it, as in Messenger. The ring
 * is placed by its centre (translate); it never takes a pointer itself.
 */
.walk-stick {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: 116px;
    height: 116px;
    margin: -58px 0 0 -58px;
    border: 1px solid rgba(255, 236, 206, 0.34);
    border-radius: 50%;
    background: rgba(255, 236, 206, 0.08);
    pointer-events: none;
}

.walk-stick[hidden] {
    display: none;
}

.walk-stick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 46px;
    height: 46px;
    margin: -23px 0 0 -23px;
    border-radius: 50%;
    background: rgba(255, 236, 206, 0.42);
    box-shadow: 0 0 10px rgba(5, 5, 6, 0.35);
}

/*
 * The threshold. First the Mega-Screen: a dark screen in the red desert air,
 * enormous upright letters rolling in from the right, a short step left with
 * each flicker (the flicker stays gentle, under three a second). Then, above
 * the flight, E's lines surface one at a time.
 */
.threshold {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity 0.9s ease;
}

/*
 * The door's picture, from the page's first paint (the opener should come straight away, and not flicker as it opens,
 * 6 Oct): the Mega-Screen scene's first frame, baked (tools/bake-door.mjs: the desert under the red sky, the screen
 * still past the view's right edge), fitted to the screen's height and centred, as the scene itself frames its shot
 * (with the same vertical angle, a narrower view is that one cropped at its sides); the corners darkened as the ink
 * darkens them; beneath it, the sky in plain colour, for a screen wider than the picture and the moment before it has
 * arrived. Once the scene's own first frame is on the canvas beneath (is-scene: main.js), it fades, and the scene goes
 * on from just where it showed.
 */
.threshold::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse farthest-corner at 50% 50%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.019) 25%, rgba(0, 0, 0, 0.075) 50%, rgba(0, 0, 0, 0.169) 75%, rgba(0, 0, 0, 0.3) 100%),
        url('assets/door-wide.webp') center / auto 100% no-repeat,
        linear-gradient(to bottom, #a42520 0%, #c23823 30%, #cb3c24 50%, #df5d33 60%, #f17f50 70%, #f38152 72.3%, #aa1d00 72.4%, #a31300 100%);
    transition: opacity 0.35s ease;
    pointer-events: none;
}

@media (max-aspect-ratio: 4/5) {
    .threshold::before {
        background:
            radial-gradient(ellipse farthest-corner at 50% 50%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.019) 25%, rgba(0, 0, 0, 0.075) 50%, rgba(0, 0, 0, 0.169) 75%, rgba(0, 0, 0, 0.3) 100%),
            url('assets/door-tall.webp') center / auto 100% no-repeat,
            linear-gradient(to bottom, #881623 0%, #b63221 30%, #cb3c24 50%, #d24a29 60%, #f07e4f 70%, #f38152 72.3%, #aa1d00 72.4%, #a41400 100%);
    }
}

.threshold.is-scene::before {
    opacity: 0;
}

/* Where the scene can't be drawn (no WebGL2, its trial off, or its drawing failed: main.js), the card is the flat one:
 * a dark band across which the letters roll. */
.threshold.is-flat {
    background:
        radial-gradient(ellipse 120% 60% at 50% 115%, rgba(150, 40, 24, 0.42), transparent 62%),
        #040305;
}

.threshold.is-flat::before {
    display: none;
}

.threshold:not(.is-flat) .mega-screen {
    visibility: hidden;
}

.threshold.is-leaving {
    opacity: 0;
    pointer-events: none;
}

/* The Mega-Screen as a still shot in the desert (a trial: megascreen.js): once its first frame is on the canvas
 * beneath, the card lets it show through, keeping only its words. */
.threshold.is-scene {
    background: none;
}

.threshold.is-scene .mega-screen {
    visibility: hidden;
}

.threshold.is-scene .threshold-prompt {
    text-shadow: 0 0 14px rgba(24, 4, 4, 0.85), 0 0 3px rgba(24, 4, 4, 0.9);
}

/* Waiting for the Mega-Screen to settle (a trial, settle: threshold.js): its words wait unseen and the card takes no
 * tap; as it stands, they fade in. */
html[data-settling] .threshold-prompt.is-ready {
    opacity: 0;
}

html[data-settling] .threshold-begin {
    cursor: default;
}

/* Diving into the Mega-Screen (a trial, dive: megascreen.js): its words step aside as the eye goes in. And leaving for
   the swirl without a dive, they go at once, not with the card (its fade let the prompt's box, a keyboard's focus
   outline, sit over the swirl's first line: the playtester, 3 Oct, "a button prompt in the middle of a trance"). */
.threshold.is-diving .threshold-prompt,
.threshold.is-leaving .threshold-prompt {
    opacity: 0;
    transition: opacity 0.35s ease;
}

.threshold.is-diving .threshold-begin {
    cursor: default;
}

.threshold[hidden] {
    display: none;
}

/* Back within the same visit: no card, only the dark the city lifts out of (main.js takes it from there). */
html[data-returning] .threshold {
    display: none;
}

html[data-returning] .veil {
    opacity: 1;
    transition: none;
}

.mega-screen {
    position: relative;
    height: min(64vh, 76vw);
    overflow: hidden;
    background: rgba(10, 10, 14, 0.94);
    border-block: 1px solid rgba(200, 200, 208, 0.1);
}

.mega-screen::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.3) 0 2px, transparent 2px 5px);
    pointer-events: none;
}

.mega-track {
    position: absolute;
    top: 50%;
    left: 0;
    display: flex;
    gap: 0.1em;
    font-family: var(--font-display);
    font-weight: 300;
    font-size: min(54vh, 64vw);
    line-height: 1;
    white-space: nowrap;
    color: #eaedf7;
    text-shadow: 0 0 0.05em rgba(200, 220, 255, 0.55);
    transform: translate(100vw, -50%);
    animation: mega-roll 24s steps(96) infinite, mega-flicker 0.42s steps(2) infinite;
}

.mega-gap {
    width: 0.45em;
}

@keyframes mega-roll {
    from { transform: translate(100vw, -50%); }
    to { transform: translate(-100%, -50%); }
}

@keyframes mega-flicker {
    0% { opacity: 1; }
    50% { opacity: 0.84; }
}

.threshold-begin {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0 24px max(11vh, 60px);
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

.threshold-begin:focus-visible {
    outline: none;
}

.threshold-prompt {
    font-family: var(--font-display);
    font-size: 24px;
    letter-spacing: 0.08em;
    color: #d4dbec;
    opacity: 0;
    transition: opacity 0.8s ease;
}

/* The prompt shows once its own words have arrived, so no stand-in flashes first. */
.threshold-prompt.is-ready {
    opacity: 1;
}

.threshold-begin:focus-visible .threshold-prompt {
    outline: 1px solid var(--honey);
    outline-offset: 8px;
}

.threshold-voice {
    position: fixed;
    left: 50%;
    bottom: 20vh;
    z-index: 46;
    width: min(30em, calc(100vw - 48px));
    margin: 0;
    padding: 0.7em 1.4em;
    transform: translateX(-50%);
    font-family: var(--font-display);
    font-size: clamp(21px, 3.2vw, 30px);
    font-weight: 500;
    line-height: 1.35;
    text-align: center;
    text-wrap: balance;
    color: #f4f5fb;
    text-shadow: 0 0 10px rgba(3, 2, 6, 0.95), 0 0 2px rgba(3, 2, 6, 1);
    /* A pool of shade under each line, so it reads over the brightest gate. */
    background: radial-gradient(closest-side, rgba(4, 3, 8, 0.72), rgba(4, 3, 8, 0.5) 55%, transparent);
    opacity: 0;
    pointer-events: none;
}

.threshold-voice.is-speaking {
    animation: voice 1.3s ease both;
}

/* Quick to arrive and to go, so each line holds at full strength for most of its time. */
@keyframes voice {
    0% { opacity: 0; }
    12% { opacity: 1; }
    88% { opacity: 1; }
    100% { opacity: 0; }
}

/* A dark veil the city lifts out of, after the flight. */
.veil {
    position: fixed;
    inset: 0;
    z-index: 44;
    background: #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.2s ease;
}

.veil.is-dark {
    opacity: 1;
    transition: none;
}

@media (prefers-reduced-motion: reduce) {
    .mega-track {
        left: 50%;
        font-size: min(22vh, 11vw);
        transform: translate(-50%, -50%);
        animation: none;
    }

    .threshold-voice.is-speaking {
        animation: none;
        opacity: 1;
    }
}

/* The reader: the only place long text appears. */
.reader {
    width: min(34em, calc(100vw - 32px));
    max-height: min(82vh, 46em);
    padding: 0;
    color: var(--silver);
    background: rgba(10, 9, 14, 0.95);
    border: 1px solid var(--stone);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
}

/* A giver's passage stands to the left on a wide screen, so its giver can be seen beside it with its shade, framed in
   the open part (a trial, ?frame=off: frame.js, Elm's "B"). On a phone it rises from the bottom as ever. */
@media (min-width: 900px) {
    .reader.is-beside {
        margin-left: max(24px, 4vw);
        margin-right: auto;
    }
}

.reader::backdrop {
    background: rgba(5, 5, 6, 0.35);
}

.reader-body {
    padding: 20px 26px 24px;
}

.reader-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1em;
}

.reader-place {
    margin: 0;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 26px;
    letter-spacing: 0.04em;
    color: var(--honey);
}

.reader-close {
    padding: 2px 8px;
    font-size: 30px;
    line-height: 1;
    color: var(--bone);
    background: none;
    border: 0;
    cursor: pointer;
}

.reader-close:hover,
.reader-close:focus-visible {
    color: var(--ivory);
}

.reader-text {
    margin: 14px 0 16px;
    font-size: 21px;
    line-height: 1.6;
    color: var(--ivory);
    white-space: pre-line;
}

.reader-text:focus {
    outline: none;
}

.reader-text p {
    margin: 0 0 0.8em;
}

/* A flower's part, whole, as President Oedipus's page sets it (its lines kept by their own breaks). */
.reader-text.is-whole {
    white-space: normal;
}

.reader-text.is-whole blockquote {
    margin: 0 0 0.9em 0.9em;
    padding-left: 0.9em;
    border-left: 1px solid var(--stone);
    font-size: 0.92em;
}

.reader-text.is-whole .footnote {
    font-size: 0.8em;
    color: var(--bone);
}

.reader-text.is-whole a {
    color: var(--honey);
}

/* A lost page of Numbers by Paint, whole (whole, a trial), as the texts set it: its headings, its page marks, its
   paragraphs run on (p.in) or set apart (p.sp), its section marks, its verse and its bibliography. */
.reader-text.is-whole h2,
.reader-text.is-whole h3 {
    margin: 1.4em 0 0.8em;
    font-size: 1.05em;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-align: center;
    color: var(--honey);
}

.reader-text.is-whole .pg {
    float: right;
    margin: 0 0 0 0.6em;
    font-size: 0.62em;
    line-height: 2.4;
    letter-spacing: 0.04em;
    color: var(--bone);
}

.reader-text.is-whole p.in {
    text-indent: 1.6em;
}

.reader-text.is-whole p.sp {
    margin-top: 1.2em;
}

.reader-text.is-whole p.in,
.reader-text.is-whole .work-body p {
    margin-bottom: 0;
}

.reader-text.is-whole p.dropcap-centered,
.reader-text.is-whole p.part-sub,
.reader-text.is-whole p.scene-year {
    text-align: center;
    color: var(--bone);
}

.reader-text.is-whole p.bib {
    padding-left: 1.6em;
    text-indent: -1.6em;
    font-size: 0.86em;
}

.reader-text.is-whole p.lines,
.reader-text.is-whole p.signed,
.reader-text.is-whole p.ed {
    font-size: 0.92em;
}

.reader-text.is-whole p.signed {
    text-align: right;
}

.reader-text.is-whole .figure,
.reader-text.is-whole nav.contents {
    margin: 0.8em 0;
    font-size: 0.9em;
}

.reader-text.is-whole ol {
    margin: 0 0 0.8em;
    padding: 0 0 0 1.2em;
}

/* The thesis's contents, as its page sets them: each entry's page, then its title. */
.reader-text.is-whole nav.contents ol {
    list-style: none;
    padding: 0;
}

.reader-text.is-whole nav.contents li.sub {
    padding-left: 1.6em;
}

.reader-text.is-whole .contents-page {
    display: inline-block;
    min-width: 2.2em;
    color: var(--bone);
}

.reader-source {
    margin: 0 0 6px;
    font-size: 16px;
    color: var(--bone);
}

.reader-read-on {
    margin: 0;
    font-family: var(--font-display);
    font-size: 19px;
    letter-spacing: 0.06em;
}

.reader-also-title {
    margin: 18px 0 4px;
    font-family: var(--font-display);
    font-weight: 400;
    font-size: 16px;
    letter-spacing: 0.1em;
    color: var(--bone);
}

.reader-also ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

/* The thread on: the nearest place not yet read, and a quiet count of how many are. */
.reader-onward {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px 1.2em;
    margin: 20px 0 0;
    padding-top: 12px;
    border-top: 1px solid rgba(160, 150, 170, 0.18);
}

.reader-onward[hidden] {
    display: none;
}

.reader-on {
    padding: 2px 0;
    font-family: var(--font-display);
    font-size: 19px;
    letter-spacing: 0.06em;
    color: var(--amber);
    background: none;
    border: 0;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    cursor: pointer;
}

.reader-on:hover,
.reader-on:focus-visible {
    color: var(--honey);
}

.reader-on[hidden] {
    display: none;
}

.reader-count {
    font-family: var(--font-display);
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--bone);
}

@media (max-width: 600px) {
    .reader {
        width: 100vw;
        max-width: 100vw;
        max-height: 74vh;
        margin: auto 0 0;
        border-width: 1px 0 0;
    }

    .reader-text {
        font-size: 19px;
    }
}

.debug-readout {
    position: fixed;
    right: 10px;
    bottom: 10px;
    z-index: 60;
    padding: 3px 8px;
    font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
    color: var(--honey);
    background: rgba(5, 5, 6, 0.7);
    pointer-events: none;
}

.noscript {
    position: fixed;
    inset: auto 0 40% 0;
    max-width: 32em;
    margin: 0 auto;
    padding: 0 24px;
    text-align: center;
    color: var(--silver);
}
