/* 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 */

.sky {
    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: 1;
    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);
}

.sky::after {
    content: "";
    position: absolute;
    right: 3rem;
    top: 0.25rem;
    width: clamp(52px, 6vw, 84px);
    height: clamp(52px, 6vw, 84px);
    border-radius: 50%;
    background: var(--moon);
    box-shadow: 0 0 48px 14px rgba(230, 198, 90, 0.22);
}

/* Sky furnishings: clouds, twinkling stars, the oak with its owl */

.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: -0.75rem;
    bottom: -2px;
    height: 96px;
    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: static;
    display: block;
    width: min(100%, 520px);
    height: auto;
    margin: 2.5rem auto 0;
}

.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;
    }

    .tree {
        right: 0.9rem;
        height: 130px;
    }

    .sky::after {
        right: clamp(12rem, 18vw, 18rem);
        top: clamp(1rem, 2.5vw, 2rem);
    }

    .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;
    }
}

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

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