/* Story Burrows: the warren cross-section. Tokens first, then the strata top to bottom. */

@font-face {
    font-family: "Bree Serif";
    src: url("../fonts/BreeSerif-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

:root {
    --night: #0f1b3d;
    --night-deep: #080f24;
    --moon: #e6c65a;
    --star: #eef2f7;
    --turf: #5d876a;
    --turf-shade: #3f6249;
    --earth: #8c4c37;
    --strata: #5f2f25;
    --strata-deep: #43201a;
    --room: #ab9846;
    --room-ink: #3a1e16;
    --room-ink-soft: #3f2317;
    --teal: #126867;
    --teal-deep: #0c4a49;
    --teal-ink: #ffffff;
    --teal-ink-soft: #d6e8e5;
    --paper: #ffffff;
    --wood: #7a4a2e;

    --display: "Bree Serif", "Iowan Old Style", Georgia, serif;
    --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --rim: 10px;
    --shaft: 34px;
    --reach: 40px;
    --turf-height: 36px;
    --rung-pitch: 56px;
    --rung-quarter: 7px;
    --gap: clamp(2.5rem, 5vw, 4.5rem);
    --measure: 34rem;

    color-scheme: dark;
}

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

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--body);
    font-size: 1.0625rem;
    line-height: 1.5;
    color: var(--room-ink);
    background: var(--strata-deep);
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--moon);
    color: var(--strata-deep);
}

:focus-visible {
    outline: 3px solid var(--moon);
    outline-offset: 4px;
}

h1,
h2 {
    font-family: var(--display);
    font-weight: 400;
    text-wrap: balance;
    margin: 0;
}

p {
    margin: 0;
    max-width: var(--measure);
}

/* Props: authored SVG furnishings, decorative, never in the reading order */

.prop {
    position: absolute;
    display: block;
    pointer-events: none;
    user-select: none;
}

/* The sky */

/* The sky's geometry: the moon, the oak, and one unit of the oak's 440 by 320
   viewBox, shared by the moon, the oak, and the owl that perches in it. */

.sky {
    --moon-right: 3rem;
    --moon-top: 0.25rem;
    --moon-size: clamp(52px, 6vw, 84px);
    --tree-right: -0.75rem;
    --tree-bottom: -2px;
    --tree-height: 96px;
    --tree-unit: calc(var(--tree-height) / 320);
    --orbit-rx: var(--moon-size);
    --orbit-ry: calc(var(--moon-size) * 0.3);
    position: relative;
    min-height: clamp(140px, 16vh, 180px);
    padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1.25rem, 5vw, 4rem) 0;
    color: var(--star);
    background-color: var(--night);
    background-image: url("../img/scene/stars.svg"), linear-gradient(180deg, var(--night-deep), var(--night) 70%);
    background-size:
        1600px 220px,
        100% 100%;
    background-position:
        left top,
        0 0;
    background-repeat: repeat-x, no-repeat;
    overflow: hidden;
}

.sign {
    position: relative;
    z-index: 3;
    display: inline-block;
    font-family: var(--display);
    font-size: clamp(1.75rem, 2.6vw, 2.25rem);
    line-height: 1;
    letter-spacing: 0.01em;
    padding: 0.55em 0.9em 0.5em;
    color: var(--star);
    background: var(--strata);
    border: 3px solid var(--strata-deep);
    border-radius: 6px 6px 3px 3px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45);
    max-width: none;
}

.sign::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    width: 12px;
    height: 200px;
    margin-left: -6px;
    background: var(--strata-deep);
}

/* The moon. Double-clicked, the man in the moon fades in; poked in an eye,
   he shuts it, scowls, and fades back out. Each state is an htmx fragment in
   eggs/, and each duration below matches the load delay of its fragment. */

.moon {
    position: absolute;
    z-index: 1;
    right: var(--moon-right);
    top: var(--moon-top);
    width: var(--moon-size);
    height: var(--moon-size);
    border-radius: 50%;
    background: var(--moon);
    box-shadow: 0 0 48px 14px rgba(230, 198, 90, 0.22);
    transform-origin: 50% 0;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.moon-face,
.moon-glints,
.moon-pupil {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Each ball is the white inside its drawn outline, and clips its pupil.
   The pupil is a disc on a sphere the size of the ball, turned toward
   (--gaze-x, --gaze-y, --roll-forward + --gaze-y): it slides toward the rim
   and flattens as it turns, and is gone once it faces away. */

.moon-ball {
    position: absolute;
    top: 33.5%;
    width: 13%;
    height: 13%;
    border-radius: 50%;
    overflow: hidden;
}

.moon-jolly .moon-ball-left {
    left: 27.5%;
}

.moon-jolly .moon-ball-right {
    left: 59.5%;
}

.moon-scowl .moon-ball {
    top: 37.8%;
    width: 10.4%;
    height: 10.4%;
}

.moon-scowl .moon-ball-left {
    left: 28.8%;
}

.moon-scowl .moon-ball-right {
    left: 60.8%;
}

.moon-pupil {
    --pupil-radius: 28;
    --roll-forward: 0.6;
    --roll-z: calc(var(--roll-forward) + var(--gaze-y));
    --roll-length: sqrt(var(--gaze-x) * var(--gaze-x) + var(--gaze-y) * var(--gaze-y) + var(--roll-z) * var(--roll-z));
    --roll-arm: calc(sqrt(50 * 50 - var(--pupil-radius) * var(--pupil-radius)) * 1%);
    --roll-turn: atan2(var(--gaze-y), var(--gaze-x));
    transform: translate(
            calc(var(--gaze-x) / var(--roll-length) * var(--roll-arm)),
            calc(var(--gaze-y) / var(--roll-length) * var(--roll-arm))
        )
        rotate(var(--roll-turn)) scaleX(max(0, var(--roll-z) / var(--roll-length))) rotate(calc(var(--roll-turn) * -1));
}

.moon-eye {
    position: absolute;
    top: 22%;
    width: 32%;
    height: 36%;
}

.moon-eye-left {
    left: 18%;
}

.moon-eye-right {
    right: 18%;
}

.moon-jolly,
.moon-scowl {
    transform: scale(1.4);
}

.moon-jolly {
    animation: moon-rise 1.2s ease-out both;
}

.moon-jolly .moon-face,
.moon-jolly .moon-ball,
.moon-jolly .moon-glints {
    animation: face-in 1.2s ease-out both;
}

.moon-scowl {
    animation: moon-set 1.1s ease-in 1.5s both;
}

.moon-scowl .moon-face,
.moon-scowl .moon-ball,
.moon-scowl .moon-glints {
    animation: face-out 1.1s ease-in 1.5s both;
}

@keyframes moon-rise {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.4);
    }
}

@keyframes moon-set {
    from {
        transform: scale(1.4);
    }

    to {
        transform: scale(1);
    }
}

@keyframes face-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes face-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* The owl on the oak's right branch. Its box is the viewBox of the owl
   drawings (270 80 88 70) inside sky-tree.svg's 440 by 320, placed from the
   sky's top so a flight can carry it to the moon. Clicked, it blinks and
   stays blinked; clicked again, it flies and lands back at rest. Each state
   is an htmx fragment in eggs/, and the flight's duration below matches the
   load delay of its fragment.

   The flight is 8s: 1.4s from the branch to the orbit's right point, two
   2.6s orbits of the moon, 1.4s back. .owl-flight carries the travel and the
   stacking: z-index 0 puts it behind the moon (z-index 1) across the top of
   each orbit, 2 in front across the bottom, each flip where the owl is clear
   of the moon's side. The signpost (z-index 3) stands in front of it all
   the way round, as it does on phones where the orbit's left end reaches
   behind the board. .owl-orbit traces the ellipse, resting at its right
   point, so the travel is offset by one radius.

   While the owl flies, .sky runs moon-gaze on the orbit's own clock,
   holding in --gaze-x and --gaze-y the direction from the moon to the
   owl, and the eyes of whatever face the moon shows, whenever it shows
   it, roll toward it. */

.owl {
    --perch-right: calc(var(--tree-right) + 82 * var(--tree-unit));
    --perch-top: calc(100% - var(--tree-bottom) - 240 * var(--tree-unit));
    --center-right: calc(var(--moon-right) + var(--moon-size) / 2 - 44 * var(--tree-unit));
    --center-top: calc(var(--moon-top) + var(--moon-size) / 2 - 35 * var(--tree-unit));
    position: absolute;
    right: var(--perch-right);
    top: var(--perch-top);
    width: calc(88 * var(--tree-unit));
    height: calc(70 * var(--tree-unit));
    pointer-events: none;
    user-select: none;
}

.owl img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.owl-hit {
    position: absolute;
    inset: 0;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.owl-lids {
    opacity: 0;
}

.owl-blinked .owl-lids {
    animation: owl-blink 0.3s ease-in-out both;
}

.owl-flight {
    animation: owl-flight 8s linear both;
}

.owl-orbit,
.owl-wings {
    position: absolute;
    inset: 0;
}

.owl-orbit {
    animation: owl-orbit 2.6s linear 1.4s 2 both;
}

.owl-flight .owl-perched {
    animation: owl-perch 8s linear both;
}

.owl-wings {
    animation: owl-aloft 8s linear both;
}

.owl-wings img {
    animation: owl-flap 0.3s step-end infinite;
}

.owl-wings .owl-wings-up {
    animation-delay: -0.15s;
}

@property --gaze-x {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

@property --gaze-y {
    syntax: "<number>";
    inherits: true;
    initial-value: 0;
}

.sky:has(.owl-flight) {
    animation: moon-gaze 2.6s linear 1.4s 2 both;
}

@keyframes owl-flight {
    0% {
        right: calc(var(--perch-right) + var(--orbit-rx));
        top: var(--perch-top);
        z-index: 2;
        animation-timing-function: ease-out;
    }

    3% {
        right: calc(var(--perch-right) + var(--orbit-rx));
        top: calc(var(--perch-top) - 14 * var(--tree-unit));
        animation-timing-function: ease-in;
    }

    10% {
        right: calc((var(--perch-right) + var(--orbit-rx) + var(--center-right)) / 2);
        top: calc((var(--perch-top) + var(--center-top)) / 2 - 20 * var(--tree-unit));
        animation-timing-function: ease-out;
    }

    17.5% {
        right: var(--center-right);
        top: var(--center-top);
        z-index: 2;
    }

    17.6%,
    33.75% {
        z-index: 0;
    }

    33.85%,
    50% {
        z-index: 2;
    }

    50.1%,
    66.25% {
        z-index: 0;
    }

    66.35% {
        z-index: 2;
    }

    82.5% {
        right: var(--center-right);
        top: var(--center-top);
        animation-timing-function: ease-in;
    }

    90% {
        right: calc((var(--perch-right) + var(--orbit-rx) + var(--center-right)) / 2);
        top: calc((var(--perch-top) + var(--center-top)) / 2 - 20 * var(--tree-unit));
        animation-timing-function: ease-out;
    }

    97% {
        right: calc(var(--perch-right) + var(--orbit-rx));
        top: calc(var(--perch-top) - 8 * var(--tree-unit));
        animation-timing-function: ease-in-out;
    }

    100% {
        right: calc(var(--perch-right) + var(--orbit-rx));
        top: var(--perch-top);
        z-index: 2;
    }
}

@keyframes owl-orbit {
    0%,
    100% {
        transform: translate(var(--orbit-rx), 0) scale(1);
    }

    6.25% {
        transform: translate(calc(var(--orbit-rx) * 0.9239), calc(var(--orbit-ry) * -0.3827)) scale(0.9426);
    }

    12.5% {
        transform: translate(calc(var(--orbit-rx) * 0.7071), calc(var(--orbit-ry) * -0.7071)) scale(0.8939);
    }

    18.75% {
        transform: translate(calc(var(--orbit-rx) * 0.3827), calc(var(--orbit-ry) * -0.9239)) scale(0.8614);
    }

    25% {
        transform: translate(0, calc(var(--orbit-ry) * -1)) scale(0.85);
    }

    31.25% {
        transform: translate(calc(var(--orbit-rx) * -0.3827), calc(var(--orbit-ry) * -0.9239)) scale(0.8614);
    }

    37.5% {
        transform: translate(calc(var(--orbit-rx) * -0.7071), calc(var(--orbit-ry) * -0.7071)) scale(0.8939);
    }

    43.75% {
        transform: translate(calc(var(--orbit-rx) * -0.9239), calc(var(--orbit-ry) * -0.3827)) scale(0.9426);
    }

    50% {
        transform: translate(calc(var(--orbit-rx) * -1), 0) scale(1);
    }

    56.25% {
        transform: translate(calc(var(--orbit-rx) * -0.9239), calc(var(--orbit-ry) * 0.3827)) scale(1.0383);
    }

    62.5% {
        transform: translate(calc(var(--orbit-rx) * -0.7071), calc(var(--orbit-ry) * 0.7071)) scale(1.0707);
    }

    68.75% {
        transform: translate(calc(var(--orbit-rx) * -0.3827), calc(var(--orbit-ry) * 0.9239)) scale(1.0924);
    }

    75% {
        transform: translate(0, var(--orbit-ry)) scale(1.1);
    }

    81.25% {
        transform: translate(calc(var(--orbit-rx) * 0.3827), calc(var(--orbit-ry) * 0.9239)) scale(1.0924);
    }

    87.5% {
        transform: translate(calc(var(--orbit-rx) * 0.7071), calc(var(--orbit-ry) * 0.7071)) scale(1.0707);
    }

    93.75% {
        transform: translate(calc(var(--orbit-rx) * 0.9239), calc(var(--orbit-ry) * 0.3827)) scale(1.0383);
    }
}

@keyframes owl-perch {
    0%,
    3% {
        opacity: 1;
    }

    3.1%,
    96.9% {
        opacity: 0;
    }

    97%,
    100% {
        opacity: 1;
    }
}

@keyframes owl-aloft {
    0%,
    3% {
        opacity: 0;
    }

    3.1%,
    96.9% {
        opacity: 1;
    }

    97%,
    100% {
        opacity: 0;
    }
}

@keyframes owl-flap {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

@keyframes owl-blink {
    0%,
    100% {
        opacity: 0;
    }

    40%,
    60% {
        opacity: 1;
    }
}

@keyframes owl-away {
    0% {
        opacity: 1;
    }

    10%,
    90% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

@keyframes moon-gaze {
    0%,
    100% {
        --gaze-x: 1;
        --gaze-y: 0;
    }

    6.25% {
        --gaze-x: 0.9239;
        --gaze-y: -0.3827;
    }

    12.5% {
        --gaze-x: 0.7071;
        --gaze-y: -0.7071;
    }

    18.75% {
        --gaze-x: 0.3827;
        --gaze-y: -0.9239;
    }

    25% {
        --gaze-x: 0;
        --gaze-y: -1;
    }

    31.25% {
        --gaze-x: -0.3827;
        --gaze-y: -0.9239;
    }

    37.5% {
        --gaze-x: -0.7071;
        --gaze-y: -0.7071;
    }

    43.75% {
        --gaze-x: -0.9239;
        --gaze-y: -0.3827;
    }

    50% {
        --gaze-x: -1;
        --gaze-y: 0;
    }

    56.25% {
        --gaze-x: -0.9239;
        --gaze-y: 0.3827;
    }

    62.5% {
        --gaze-x: -0.7071;
        --gaze-y: 0.7071;
    }

    68.75% {
        --gaze-x: -0.3827;
        --gaze-y: 0.9239;
    }

    75% {
        --gaze-x: 0;
        --gaze-y: 1;
    }

    81.25% {
        --gaze-x: 0.3827;
        --gaze-y: 0.9239;
    }

    87.5% {
        --gaze-x: 0.7071;
        --gaze-y: 0.7071;
    }

    93.75% {
        --gaze-x: 0.9239;
        --gaze-y: 0.3827;
    }
}

/* Sky furnishings: clouds, twinkling stars, the oak */

.cloud {
    width: clamp(160px, 22vw, 320px);
    height: auto;
    opacity: 0.9;
}

.cloud-a {
    left: 34%;
    top: 12px;
}

.cloud-b {
    right: 22%;
    top: 46px;
    width: clamp(120px, 16vw, 240px);
}

.star {
    width: 14px;
    height: 14px;
    animation: twinkle 3.6s ease-in-out infinite;
}

.star-a {
    left: 28%;
    top: 22px;
    animation-delay: 0s;
}

.star-b {
    left: 52%;
    top: 58px;
    width: 10px;
    height: 10px;
    animation-delay: 1.1s;
}

.star-c {
    left: 63%;
    top: 18px;
    animation-delay: 2.2s;
}

.star-d {
    right: 12%;
    top: 90px;
    width: 10px;
    height: 10px;
    animation-delay: 0.6s;
}

.star-e {
    left: 41%;
    top: 96px;
    width: 8px;
    height: 8px;
    animation-delay: 1.7s;
}

@keyframes twinkle {
    0%,
    100% {
        opacity: 0.45;
        transform: scale(0.8);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

.tree {
    right: var(--tree-right);
    bottom: var(--tree-bottom);
    height: var(--tree-height);
    width: auto;
}

@media (max-width: 479px) {
    .cloud-b {
        display: none;
    }
}

/* The turf line */

.turf {
    position: relative;
    height: 28px;
    background: var(--turf);
    border-bottom: 8px solid var(--turf-shade);
    background-image: repeating-linear-gradient(90deg, var(--turf-shade) 0 3px, transparent 3px 11px);
    background-size: 11px 12px;
    background-repeat: repeat-x;
    background-position: 0 -4px;
}

.turf::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -40px;
    height: 44px;
    background: url("../img/scene/grass.svg") repeat-x left bottom / 1600px 44px;
}

/* The earth */

.earth {
    position: relative;
    padding: var(--gap) clamp(1rem, 4vw, 3rem) calc(var(--gap) * 1.5);
    color: var(--room-ink);
    background-color: var(--earth);
    background-image: url("../img/scene/earth-tile.svg"), url("../img/scene/strata.svg");
    background-size:
        1200px 600px,
        1200px 520px;
}

/* Earth furnishings */

.roots {
    right: clamp(3rem, 14vw, 14rem);
    top: -6px;
    width: clamp(150px, 20vw, 300px);
    height: auto;
    opacity: 0.95;
}

.left-earth {
    position: relative;
    display: block;
    width: min(100%, 520px);
    height: auto;
    margin: 2.5rem auto 0;
}

.left-earth > img,
.sleeper img {
    display: block;
    width: 100%;
    height: auto;
}

/* The sleeping rabbit in the earth scene's hollow. Its box is the viewBox of
   the rabbit drawings (290 20 230 170) inside left-earth.svg's 520 by 640.
   A poke snuggles it; three pokes, each within the 450ms window of the one
   before, sit it up in a rage before it lies back down. Each state is an
   htmx fragment in eggs/, and each duration below matches its fragment. */

.sleeper {
    position: absolute;
    left: calc(290 / 520 * 100%);
    top: calc(20 / 640 * 100%);
    width: calc(230 / 520 * 100%);
}

.sleeper img {
    transform-origin: 50% 90%;
}

.poke-window {
    display: contents;
}

.poke {
    position: absolute;
    left: 18%;
    top: 18%;
    width: 66%;
    height: 70%;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.sleeper-return img {
    animation: face-in 0.35s ease-out both;
}

.sleeper-snuggle img {
    animation: snuggle 0.9s ease-in-out both;
}

.sleeper-rage img {
    transform-origin: 50% 95%;
    animation: rage 2.4s ease-in-out both;
}

.sleeper-settle img {
    animation: settle 0.7s ease-out both;
}

@keyframes snuggle {
    0%,
    100% {
        transform: none;
    }

    20% {
        transform: translateX(-2%) scale(1.03, 0.96) rotate(-2deg);
    }

    45% {
        transform: translateX(1.5%) scale(0.98, 1.02) rotate(1.5deg);
    }

    70% {
        transform: translateX(-0.5%) scale(1.01, 0.99);
    }
}

@keyframes rage {
    0% {
        opacity: 0.4;
        transform: translateY(18%) scaleY(0.6);
    }

    10% {
        opacity: 1;
        transform: translateY(-6%) scaleY(1.08);
    }

    16%,
    52%,
    82% {
        opacity: 1;
        transform: none;
    }

    20%,
    28%,
    36%,
    44% {
        transform: translateX(-2%);
    }

    24%,
    32%,
    40%,
    48% {
        transform: translateX(2%);
    }

    100% {
        opacity: 0.6;
        transform: translateY(14%) scaleY(0.7);
    }
}

@keyframes settle {
    from {
        opacity: 0.6;
        transform: translateY(-6%) scaleY(1.06);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.climber {
    left: calc(50% - 15px);
    top: calc(var(--gap) * -1 + 2px);
    width: 30px;
    height: auto;
    z-index: 1;
}

.warren {
    position: relative;
    isolation: isolate;
    max-width: 1240px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
}

/* The entrance shaft from the turf to the first room */

.warren::before {
    content: "";
    position: absolute;
    z-index: -1;
    left: 50%;
    top: calc(var(--gap) * -1);
    width: var(--shaft);
    height: calc(var(--gap) + var(--reach));
    margin-left: calc(var(--shaft) / -2);
    background: var(--strata);
}

/* The ladder is its own layer above the rooms: it stands a quarter rung above the turf and hangs a quarter rung into the book room */

.warren::after {
    content: "";
    position: absolute;
    left: 50%;
    top: calc(var(--gap) * -1 - var(--turf-height) - var(--rung-quarter));
    width: var(--shaft);
    height: calc(var(--gap) + var(--turf-height) + var(--rung-quarter) * 2 + var(--rim));
    margin-left: calc(var(--shaft) / -2);
    background: url("../img/scene/ladder.svg") repeat-y center top / var(--shaft) var(--rung-pitch);
    pointer-events: none;
}

/* Rooms */

.room {
    position: relative;
    padding: clamp(1.75rem, 3.5vw, 3rem) clamp(1.75rem, 4vw, 3.25rem);
    background: var(--room);
    border: var(--rim) solid var(--strata);
    border-radius: 44% 56% 48% 52% / 20% 20% 22% 22%;
    box-shadow: inset 0 10px 24px rgba(0, 0, 0, 0.22);
}

/* The Bedrock outline sits on a layer behind the tunnels, so a passage cuts through it and the room's own interior ends the passage exactly on the curve */

.room::before {
    content: "";
    position: absolute;
    z-index: -2;
    inset: calc(var(--rim) * -1);
    border-radius: inherit;
    box-shadow: 0 0 0 6px var(--strata-deep);
    pointer-events: none;
}

/* Tunnels: each starts inside the room it leaves and ends inside the next, both rooms painting over its ends; the throat darkens toward each room */

.room-book::after,
.room-game::after,
.room-paperback::after {
    content: "";
    position: absolute;
    z-index: -1;
    left: 50%;
    top: calc(100% + var(--rim) - var(--reach));
    width: var(--shaft);
    height: calc(var(--reach) * 2 + var(--gap));
    margin-left: calc(var(--shaft) / -2);
    background:
        linear-gradient(to bottom, rgba(67, 32, 26, 0.45) var(--reach), transparent calc(var(--reach) + 28px)) center
        top / var(--shaft) 100% no-repeat,
        linear-gradient(to top, rgba(67, 32, 26, 0.45) var(--reach), transparent calc(var(--reach) + 28px)) center top /
        var(--shaft) 100% no-repeat,
        url("../img/scene/tunnel.svg") center top / var(--shaft) 240px repeat-y;
}

.room h2 {
    font-size: clamp(1.75rem, 2.6vw, 2.375rem);
    line-height: 1.05;
    color: var(--strata-deep);
    margin-bottom: 0.5rem;
}

/* Room furnishings */

.lantern {
    right: 12%;
    top: calc(var(--rim) * -1);
    width: 48px;
    height: auto;
    z-index: 1;
}

.rug {
    position: static;
    order: 3;
    width: 80%;
    height: auto;
    justify-self: center;
    margin-top: 0.5rem;
}

.books {
    position: static;
    order: 2;
    width: 55%;
    height: auto;
    margin-top: 1.25rem;
}

.pennants {
    left: 8%;
    top: calc(var(--rim) * -1 + 4px);
    width: 84%;
    height: auto;
}

.board {
    position: static;
    order: 9;
    width: 88px;
    height: auto;
    align-self: flex-end;
    margin-top: 1rem;
}

.papers {
    right: 6%;
    bottom: 8%;
    width: 120px;
    height: auto;
}

.desk {
    position: static;
    order: 9;
    width: 62%;
    height: auto;
    align-self: flex-end;
    margin-top: 1.25rem;
}

/* The book room: the only teal room, the largest, first */

.room-book {
    background: var(--teal);
    color: var(--teal-ink);
    padding-top: clamp(4.5rem, 8vw, 5.5rem);
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1.25rem, 3vw, 2.5rem);
    align-items: center;
}

.room-book h1 {
    font-size: clamp(2.125rem, 3.4vw, 3.25rem);
    line-height: 1.02;
    letter-spacing: -0.01em;
    color: var(--teal-ink);
}

.byline {
    margin-top: 0.85rem;
    font-size: clamp(1.0625rem, 1.3vw, 1.25rem);
    color: var(--teal-ink-soft);
}

.aside {
    margin-top: 0.75rem;
    font-size: 0.9375rem;
    color: var(--teal-ink-soft);
}

/* The typographic cover panel, until the cover file arrives */

.cover {
    position: relative;
    order: 0;
    aspect-ratio: 3 / 4;
    width: 100%;
    background: var(--teal-deep);
    border: 3px solid var(--moon);
    outline: 3px solid var(--teal-deep);
    border-radius: 3px;
    box-shadow: 6px 10px 22px rgba(0, 0, 0, 0.4);
    color: var(--teal-ink);
    overflow: hidden;
    transform: rotate(-2deg);
}

.cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* The book room's cover sits small on phones, beside the text from 600px */

.room-book .cover {
    max-width: 170px;
}

@media (min-width: 600px) {
    .room-book {
        grid-template-columns: minmax(150px, 220px) 1fr;
    }

    .room-book .cover {
        max-width: none;
    }
}

/* Buttons: signboards */

.button {
    display: inline-block;
    margin-top: 1.5rem;
    white-space: nowrap;
    font-family: var(--display);
    font-size: 1.1875rem;
    line-height: 1;
    padding: 0.9em 1.3em 0.85em;
    color: var(--strata-deep);
    background: var(--moon);
    text-decoration: none;
    border: 3px solid var(--strata-deep);
    border-radius: 6px;
    box-shadow: 0 5px 12px rgba(0, 0, 0, 0.32);
    transition:
        transform 0.35s var(--ease-out),
        box-shadow 0.35s var(--ease-out);
}

.button:hover {
    transform: translateY(-2px);
    box-shadow: 0 9px 18px rgba(0, 0, 0, 0.36);
}

.button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.32);
}

.button-game {
    background: var(--teal);
    color: var(--teal-ink);
}

/* The game room: portraits peeking from holes */

.room-game {
    padding-top: clamp(3.25rem, 6vw, 4rem);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.room-imprint {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.room-paperback {
    padding-right: clamp(8rem, 30vw, 10rem);
}

.holes {
    list-style: none;
    margin: 1.5rem 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: clamp(0.5rem, 1.5vw, 1rem);
    max-width: 30rem;
}

.hole {
    position: relative;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--strata-deep);
    box-shadow:
        inset 0 6px 12px rgba(0, 0, 0, 0.5),
        0 0 0 5px var(--strata);
    overflow: hidden;
}

.hole img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: translateY(34%);
    transition: transform 0.6s var(--ease-out);
}

.hole:hover img,
.room-game:focus-within .hole img {
    transform: translateY(0);
}

@media (hover: none) {
    .hole img {
        transform: translateY(0);
    }
}

/* The paperback nook and the imprint room */

.room-paperback p {
    font-size: 1.125rem;
    color: var(--room-ink-soft);
}

.room-imprint p {
    color: var(--room-ink-soft);
}

/* The depth rule: a diagram scale that names and reaches each room */

.depth {
    display: none;
}

/* Bedrock */

.bedrock {
    position: relative;
    padding: 1.5rem clamp(1.25rem, 5vw, 4rem) 6rem;
    color: var(--star);
    background:
        url("../img/scene/bones.svg") space no-repeat left calc(100% - 60px) / 1200px 34px,
        url("../img/scene/stream.svg") repeat-x left bottom / 600px 60px,
        var(--strata-deep);
    font-size: 0.9375rem;
}

@media (max-width: 479px) {
    .bedrock {
        background-image: url("../img/scene/bones-narrow.svg"), url("../img/scene/stream.svg");
        background-size:
            360px 34px,
            600px 60px;
    }
}

/* The wide cutaway */

@media (min-width: 900px) {
    .earth {
        padding-top: 5rem;
        padding-left: clamp(7rem, 12vw, 11rem);
    }

    .warren::before {
        top: -5rem;
        height: calc(5rem + 90px);
    }

    .warren::after {
        top: calc(-5rem - var(--turf-height) - var(--rung-quarter));
        height: calc(5rem + var(--turf-height) + var(--rung-quarter) * 2 + var(--rim));
    }

    .warren {
        --row-gap: clamp(1.5rem, 2.5vw, 2.5rem);
        --col-gap: clamp(2rem, 3vw, 3rem);
        --tunnel-top: 190px;
        max-width: 1100px;
        margin-left: 0;
        grid-template-columns: repeat(12, minmax(0, 1fr));
        grid-template-rows: auto auto auto;
        gap: var(--row-gap) var(--col-gap);
        align-items: start;
    }

    .warren::before,
    .warren::after {
        left: 33%;
    }

    .room {
        border-radius: 46% 54% 50% 50% / 58% 42% 58% 42%;
    }

    .room-book {
        grid-column: 1 / 8;
        grid-row: 1 / 3;
        align-self: start;
        grid-template-columns: minmax(170px, 215px) 1fr;
        padding: clamp(2.5rem, 4vw, 3.5rem) clamp(2.75rem, 4.5vw, 4rem);
        border-radius: 48% 52% 46% 54% / 42% 40% 44% 42%;
    }

    .room-game {
        grid-column: 8 / 13;
        grid-row: 1;
        margin-top: 0;
        padding: 2.25rem clamp(3.25rem, 5.5vw, 4.75rem);
        border-radius: 44% 56% 48% 52% / 34% 34% 38% 38%;
    }

    .room-game .holes {
        max-width: 15rem;
        margin-top: 1.25rem;
    }

    .room-paperback {
        grid-column: 8 / 13;
        grid-row: 2;
        padding: 1.5rem 3rem 1.75rem;
        border-radius: 54% 46% 52% 48% / 46% 54% 50% 50%;
    }

    .room-imprint {
        grid-column: 5 / 13;
        grid-row: 3;
        border-radius: 50% 50% 46% 54% / 56% 56% 44% 44%;
    }

    /* Tunnels on the wide cutaway: the book room reaches the game room across the column gap; the shafts drop down the right-hand column */

    .room-book::after {
        left: calc(100% + var(--rim) - var(--reach));
        top: var(--tunnel-top);
        width: calc(var(--reach) * 2 + var(--col-gap));
        height: var(--shaft);
        margin-left: 0;
        background:
            linear-gradient(to right, rgba(67, 32, 26, 0.45) var(--reach), transparent calc(var(--reach) + 28px)) left
            top / 100% var(--shaft) no-repeat,
            linear-gradient(to left, rgba(67, 32, 26, 0.45) var(--reach), transparent calc(var(--reach) + 28px)) left
            top / 100% var(--shaft) no-repeat,
            url("../img/scene/tunnel-across.svg") left top / 240px var(--shaft) repeat-x;
    }

    .room-game::after {
        left: 47%;
    }

    .room-paperback::after {
        left: 31%;
    }

    .room-game::after,
    .room-paperback::after {
        height: calc(var(--reach) * 2 + var(--row-gap));
    }

    .left-earth {
        position: absolute;
        left: clamp(6rem, 10vw, 9rem);
        bottom: -10px;
        width: clamp(300px, 26vw, 420px);
        margin: 0;
    }

    .roots {
        right: 1.75rem;
        width: 150px;
    }

    .sky {
        --moon-right: clamp(12rem, 18vw, 18rem);
        --moon-top: clamp(1rem, 2.5vw, 2rem);
        --tree-right: 0.9rem;
        --tree-height: 130px;
    }

    .moon {
        transform-origin: 50% 50%;
    }

    .cloud-b {
        display: block;
    }

    .climber {
        left: calc(33% - 15px);
        top: calc(-5rem + 34px);
        width: 28px;
    }

    .lantern {
        width: 48px;
        right: auto;
        left: 40%;
    }

    .rug {
        position: absolute;
        left: 52%;
        bottom: calc(var(--rim) + 30px);
        width: min(46%, 300px);
        margin: 0;
        transform: translateX(-50%);
    }

    .books {
        position: absolute;
        left: 15%;
        bottom: calc(var(--rim) + 26px);
        width: 130px;
        margin: 0;
    }

    .board {
        position: absolute;
        right: 4%;
        bottom: 11%;
        width: 72px;
        margin: 0;
    }

    .pennants {
        left: 14%;
        width: 72%;
    }

    .desk {
        position: absolute;
        right: 7%;
        bottom: calc(var(--rim) + 4px);
        width: 220px;
        margin: 0;
    }

    .papers {
        right: 8%;
        bottom: 12%;
        width: 140px;
    }

    .room-book {
        padding-bottom: clamp(6rem, 9vw, 7.5rem);
    }

    .room-imprint {
        padding-right: clamp(15rem, 22vw, 18rem);
    }

    .depth {
        display: block;
        position: absolute;
        left: clamp(1.5rem, 3vw, 3rem);
        top: 0;
        bottom: 0;
        width: 2px;
        background: var(--strata-deep);
    }

    .depth::before {
        content: "";
        position: absolute;
        left: -4px;
        top: 0;
        bottom: 0;
        width: 10px;
        background: repeating-linear-gradient(180deg, var(--strata-deep) 0 2px, transparent 2px 24px);
        opacity: 0.85;
    }

    .depth ol {
        list-style: none;
        margin: 0;
        padding: 0;
        position: sticky;
        top: 1.5rem;
        display: grid;
        gap: 2.75rem;
        padding-top: var(--gap);
    }

    .depth li {
        position: relative;
        padding-left: 1.25rem;
    }

    .depth li::before {
        content: "";
        position: absolute;
        left: -6px;
        top: 0.65em;
        width: 14px;
        height: 2px;
        background: var(--strata-deep);
    }

    .depth a {
        font-family: var(--display);
        font-size: 1rem;
        line-height: 1.3;
        color: var(--star);
        text-decoration: none;
        white-space: nowrap;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .depth a:hover {
        text-decoration: underline;
        text-underline-offset: 0.2em;
        text-decoration-thickness: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .button,
    .hole img {
        transition: none;
    }

    .star {
        animation: none;
        opacity: 0.9;
    }

    .hole img {
        transform: translateY(0);
    }

    .button:hover {
        transform: none;
    }

    .moon-jolly,
    .moon-scowl {
        animation: none;
        transform: none;
    }

    .sleeper-snuggle img,
    .sleeper-rage img,
    .sleeper-settle img {
        animation: none;
    }

    .owl-flight {
        animation: owl-away 8s ease-in-out both;
    }

    .owl-orbit,
    .owl-flight .owl-perched {
        animation: none;
    }

    .owl-wings {
        display: none;
    }

    .sky:has(.owl-flight) {
        animation: none;
    }
}

@media print {
    .sky,
    .earth,
    .bedrock,
    .room {
        background: none;
        color: #000;
        box-shadow: none;
    }

    .moon,
    .depth,
    .sign::after {
        display: none;
    }
}
