/* ==========================================================================
   The desk: the homepage scene, and the same desk under every other page
   (page-head.ghtml / App.deskPage), with its notebook, magnifier and teacups as
   props. Loaded only on those pages (wrapper.ghtml, data.scene).
   Monochrome sepia, one lamp from the upper left, one red accent (the stamp).
   ========================================================================== */

:root {
    --desk:        #15100b;   /* the wood where the lamp doesn't reach */
    --desk-ink:    #efe5d1;   /* cream type on the desk */
    --desk-dim:    #b9a888;
    --sheet:       #efe8da;   /* loose paper on the desk */
    --sheet-edge:  #d9cdb6;
    --pencil:      #2b2118;   /* handwriting on the notebook */
    --stamp:       #8e2420;
    --hand: "Cedarville Cursive", "Bradley Hand", "Segoe Print", cursive;

    /* The notebook is three slices of one 800px-wide photo: the binding and top of the
       page (236px), a band two rules tall (94px) tiled down the middle, and the bottom
       edge (123px). Measured in the notebook's own width (cqw), so it grows with its text. */
    --nb-top: 29.5cqw;         /* 236 / 800 */
    --nb-bottom: 15.375cqw;    /* 123 / 800 */
    --nb-rule: 5.875cqw;       /* one printed rule: 47 / 800 */
    --nb-left: 18.75cqw;       /* writing starts just right of the red margin line */
    --nb-right: 11.75cqw;

    /* magnifier.webp (800×806): the clear glass inside the brass rim */
    --mg-ratio: 800 / 806;
    --mg-lens-l: 4.09%;
    --mg-lens-t: 3.56%;
    --mg-lens-size: 38.38%;
}

/* --- page chrome on desk pages ------------------------------------------ */

body:has(.desk) { background: var(--desk); }
body:has(.desk) > header { display: none; }
body:has(.desk) main { max-width: none; padding: 0; }

/* site menu: a hamburger in the corner opens a paper card (Popover API). The card
   sits right under the fixed button, so it reads as anchored without anchor
   positioning; on phones it becomes a full-screen sheet. */
.site-menu {
    position: fixed;
    z-index: 50;
    /* --menu-offset: on phones, the launch banner's visible height (scene.js) */
    top: calc(0.75rem + env(safe-area-inset-top, 0px) + var(--menu-offset, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
    /* blend the fixed layer itself (the open panel lives in the top layer, untouched):
       cream over the desk, near-black over paper */
    mix-blend-mode: difference;
    transition: transform 220ms ease, opacity 220ms ease;
}
.site-menu.is-hidden:not(:focus-within):not(:has(:popover-open)) { transform: translateY(calc(-100% - 1.5rem)); opacity: 0; pointer-events: none; }
.site-menu__button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: none;
    color: #f3e9d4;
    cursor: pointer;
}
.site-menu__button svg { width: 28px; height: 28px; }
.site-menu__button:hover { opacity: 0.7; }
.site-menu__button:focus-visible { outline: 2px solid #f3e9d4; outline-offset: 2px; }

.site-menu__panel {
    position: fixed;
    inset: auto;
    top: calc(3.6rem + env(safe-area-inset-top, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
    width: 15.5rem;
    margin: 0;
    padding: 0.9rem 0 0.7rem;
    color: var(--ink);
    background:
        repeating-linear-gradient(0deg, rgba(60, 44, 28, 0.025) 0 1px, transparent 1px 5px),
        radial-gradient(120% 90% at 20% 0%, #f6f1e6, var(--sheet) 60%, #e6dcc8);
    border: 0;
    box-shadow: 0 1px 0 var(--sheet-edge), 10px 18px 30px -8px rgba(0, 0, 0, 0.6), 2px 3px 4px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 160ms ease, transform 160ms ease, overlay 160ms allow-discrete, display 160ms allow-discrete;
}
.site-menu__panel:popover-open { opacity: 1; transform: none; }
@starting-style { .site-menu__panel:popover-open { opacity: 0; transform: translateY(-6px); } }
/* browsers without the Popover API: scene.js toggles .is-open instead */
@supports not selector(:popover-open) {
    .site-menu__panel { display: none; }
    .site-menu__panel.is-open { display: block; opacity: 1; transform: none; }
}
.site-menu__close { display: none; }

.site-menu__list { list-style: none; margin: 0; padding: 0; }
.site-menu__list + .site-menu__list { margin-top: 0.6rem; padding-top: 0.6rem; border-top: 1px dashed var(--sheet-edge); }
.site-menu__list a {
    display: block;
    padding: 0.5rem 1.3rem;
    font-family: var(--display);
    font-size: 1.05rem;
    color: var(--ink);
    text-decoration: none;
}
.site-menu__list--account a { font-family: var(--serif); font-size: 0.98rem; color: var(--ink-dim); }
.site-menu__list a:hover, .site-menu__list a:focus-visible { color: var(--oxblood); background: rgba(142, 36, 32, 0.06); outline: none; }

@media (max-width: 44rem) {
    .site-menu__panel {
        inset: 0;
        width: auto;
        height: 100%;
        max-height: none;
        padding: calc(5rem + env(safe-area-inset-top, 0px)) 1.5rem 2rem;
        transform: translateY(-2%);
    }
    .site-menu__close {
        display: grid;
        place-items: center;
        position: absolute;
        top: calc(0.75rem + env(safe-area-inset-top, 0px));
        right: calc(0.75rem + env(safe-area-inset-right, 0px));
        width: 44px;
        height: 44px;
        border: 0;
        background: none;
        color: var(--ink);
        cursor: pointer;
    }
    .site-menu__close svg { width: 26px; height: 26px; }
    .site-menu__list a { padding: 0.8rem 0.4rem; font-size: 1.5rem; }
    .site-menu__list--account a { font-size: 1.15rem; }
    .site-menu__list + .site-menu__list { margin-top: 1.2rem; padding-top: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
    .site-menu, .site-menu__panel { transition: none; }
}

/* --- the desk (homepage) ------------------------------------------------- */

.desk {
    position: relative;
    isolation: isolate;
    color: var(--desk-ink);
    background: var(--desk);
    overflow-x: clip;
}
/* the lamp-lit wood fills the first screen and fades into the dark below */
.desk::after {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: max(100svh, 780px);
    background: url("/assets/img/scene/desk.webp") center top / cover no-repeat;
    mask-image: linear-gradient(to bottom, #000 72%, transparent);
    z-index: -1;
}
@media (orientation: portrait) {
    .desk::after { background-image: url("/assets/img/scene/desk-tall.webp"); }
}
/* Reveal the homepage in one smooth fade, without a lamp-flicker reversal. */
.desk::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--desk);
    opacity: 0;
    pointer-events: none;
    z-index: 5;
}
.lamp-on .desk:not(.desk--page)::before { animation: lamp-on 1.1s ease-out both; }   /* homepage only */
@keyframes lamp-on {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* both are <header>s: undo the site header's padding and double rule */
.desk__masthead, .page-head { border-bottom: 0; padding: 0; }
/* on wide screens the notebook rises beside the masthead, under its box: let the
   pointer through to the notebook (and the magnifier) except on the masthead's links */
.desk__masthead { pointer-events: none; }
.desk__masthead a, .desk__masthead button { pointer-events: auto; }
.desk__masthead {
    position: relative;
    z-index: 2;
    padding: calc(4.5rem + env(safe-area-inset-top, 0px)) 1.25rem 0;
    text-align: center;
}
.desk__eyebrow {
    font-size: 0.8rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--desk-dim);
    /* lifts it off the lit wood behind it */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.8), 0 0 22px rgba(0, 0, 0, 0.6);
}
.desk__logo {
    display: block;
    width: clamp(270px, 34vw, 500px);
    height: auto;
    margin: 0.8rem auto 0;
    filter: invert(0.93) sepia(0.35) brightness(1.02);
}
/* the way in, right under the masthead (the stamp on the notebook goes to the same place) */
.desk__cta { margin-top: 1.7rem; }
.desk__play {
    padding: 1.05rem 2.1rem;
    font-size: 1.05rem;
    box-shadow: 0 12px 26px -12px rgba(0, 0, 0, 0.85), 0 2px 4px rgba(0, 0, 0, 0.4);
}
.desk__lede {
    max-width: 40ch;
    margin: 2rem auto 2rem;
    font-size: clamp(1.05rem, 1.4vw, 1.3rem);
    line-height: 1.55;
    color: var(--desk-ink);
    font-style: italic;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85), 0 0 14px rgba(0, 0, 0, 0.6);
    font-size: larger;
}

/* the stage holds the notebook, the magnifier and the teacup */
.desk__stage {
    position: relative;
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: 1.6rem 1rem 3rem;
}
/* the notebook and the magnifier move as one, tilted a little counterclockwise;
   scene.js does the lens maths in this group's own (unrotated) frame */
.desk__group {
    --nb-w: clamp(300px, 44vw, 460px);
    position: relative;
    z-index: 3; /* above the masthead copy and play button; the glass lets clicks through */
    width: var(--nb-w);
    margin-left: calc(50% - var(--nb-w) * 0.95);
    transform: rotate(-6deg);
}
/* wide screens: the notebook moves off to the left and rises alongside the masthead.
   The stage goes full width so the notebook is placed against the viewport, clear of the logo. */
@media (min-width: 75rem) {
    .desk__stage .teacup { right: max(0vw, calc(48% - 630px)); top: 1.5rem; }   /* beats the later base rule */
    .desk__stage { width: 100%; margin-top: -17rem; }
    .desk__group {
        --nb-w: clamp(330px, 27vw, 520px);
        /* right edge meets the logo boundary (half its clamp() width either side of centre) */
        margin-left: max(1.5rem, calc(50% - clamp(135px, 17vw, 250px) - 0rem - var(--nb-w)));
        max-width: 375px;
    }
}

/* --- notebook ------------------------------------------------------------ */

.notebook {
    position: relative;
    container-type: inline-size;
    filter: drop-shadow(14px 22px 18px rgba(0, 0, 0, 0.55)) drop-shadow(3px 4px 3px rgba(0, 0, 0, 0.45));
}
.notebook__paper {
    position: relative;
    padding: var(--nb-top) 0 var(--nb-bottom);
    background: url("/assets/img/scene/notebook-mid.webp") 0 0 / 100% auto repeat-y;
    background-origin: content-box;
    background-clip: content-box;
}
.notebook__paper::before,
.notebook__paper::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    background: 0 0 / 100% 100% no-repeat;
}
.notebook__paper::before { top: 0; height: var(--nb-top); background-image: url("/assets/img/scene/notebook-top.webp"); }
.notebook__paper::after { bottom: 0; height: var(--nb-bottom); background-image: url("/assets/img/scene/notebook-bottom.webp"); }

/* handwriting sits on the printed rules: every line box is exactly one rule tall
   (the stamp takes two), so the bottom slice always meets the tiled band on a rule */
.hand {
    position: relative;
    z-index: 1;
    margin: 0 var(--nb-right) 0 var(--nb-left);
    min-height: var(--nb-rule);
    color: var(--pencil);
    font-family: var(--hand);
    font-weight: 400;
    font-size: calc(var(--nb-rule) * 0.86);
    line-height: var(--nb-rule);
}
.hand p, .hand dl, .hand div, .hand dd { margin: 0; }
.hand__no {font-weight: 700;font-family: var(--mono);padding-bottom: var(--nb-rule);font-size: 79%;}   /* one whole rule, so the writing stays on the lines */
.hand__title { font-weight: 400; font-size: 1em; line-height: var(--nb-rule); }   /* Cedarville has one weight */
.hand__place { font-style: normal; opacity: 0.8; }
.hand__opening {
    display: -webkit-box;
    max-height: calc(var(--nb-rule) * 7);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 7;
    line-clamp: 7;
    overflow: hidden;
}
/* a blank ruled line after the place and before the facts, and one above the stamp */
.hand .hand__opening, .hand .hand__facts, .hand .hand__action { margin-top: var(--nb-rule); }
.hand__facts { display: flex; flex-wrap: wrap; gap: 0 1.1em; }
.hand__facts div:nth-child(3) { flex-basis: 100%; }   /* Clues starts the next ruled line */
.hand__facts div { display: flex; gap: 0.25em; }
.hand__facts dt, .hand__facts dd { font-size: inherit; font-weight: inherit; }
.hand__facts dt::after { content: ":"; }
.hand__progress { opacity: 0.8; }

/* a rubber stamp is the only colour on the desk; its line is two rules tall */
.hand__action { height: calc(var(--nb-rule) * 2); display: flex; align-items: center; }
.stamp {
    display: inline-block;
    padding: 0.45em 0.7em 0.25em;
    font-family: var(--mono);
    font-size: max(0.8rem, calc(var(--nb-rule) * 0.62));
    letter-spacing: 0.08em;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--stamp);
    text-decoration: none;
    border: 2px solid var(--stamp);
    border-radius: 4px;
    transform: rotate(-3deg);
    mix-blend-mode: multiply;
    opacity: 0.92;
    transition: transform 160ms ease, opacity 160ms ease;
}
.stamp:hover, .stamp:focus-visible { transform: rotate(-3deg) scale(1.04); opacity: 1; }
.stamp:focus-visible { outline: 2px solid var(--stamp); outline-offset: 3px; }


/* a finger resting on the notebook brings the glass (scene.js); vertical swipes still scroll */
.desk__group .notebook { touch-action: pan-y pinch-zoom; }

/* --- magnifier: the lens shows a magnified live copy of what's beneath --- */

.magnifier {
    position: absolute;
    z-index: 2;
    aspect-ratio: var(--mg-ratio);
    pointer-events: none;
}
.magnifier__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    filter: drop-shadow(18px 26px 14px rgba(0, 0, 0, 0.5)) drop-shadow(4px 6px 4px rgba(0, 0, 0, 0.4));
}
.magnifier__lens {
    position: absolute;
    left: var(--mg-lens-l);
    top: var(--mg-lens-t);
    width: var(--mg-lens-size);
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: hidden;
}
.magnifier__lens > .notebook {
    position: absolute;
    left: 0;
    top: 0;
    transform-origin: 0 0;
}
.magnifier__lens > .notebook { filter: none; }

/* at rest the glass lies off to the right, its lens over the page's right margin */
.desk__group .magnifier {
    width: 96%;
    left: 72%;
    top: 30%;
}

/* --- teacup -------------------------------------------------------------- */

/* 25% larger than the first pass; on medium screens it bleeds off the right edge
   (.desk clips the overflow), on wide ones it stays inside the frame */
.teacup {
    position: absolute;
    width: clamp(238px, 30.5vw, 425px);
    height: auto;
    right: -7vw;
    top: 3rem;
    filter: drop-shadow(12px 18px 14px rgba(0, 0, 0, 0.55));
    transform: rotate(14deg);
    pointer-events: none;
}
/* medium screens (stacked layout): a smaller notebook and glass, a bigger cup,
   and more room under the Play button */
@media (44rem < width < 75rem) {
    .desk__stage {padding-top: 4.5rem;}
    .desk__group { --nb-w: clamp(350px, 34vw, 380px); }
    .teacup { width: clamp(380px, 38vw, 470px); right: -9vw; top: -4rem; z-index: 2; }
}


/* the assignment status line under the masthead (assignment-home.js): off for now */
.desk__masthead .home-assignment { display: none; }

/* --- papers on the desk ---------------------------------------------------- */

.desk__papers {
    position: relative;
    width: min(1000px, 100%);
    margin: 80px auto 30px;
    padding: 0 3rem 4rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8rem 2rem;
    align-items: start;
    color: var(--ink);
}
.sheet {
    position: relative;
    padding: 2.6rem 2.6rem 2.7rem;
    background:
        repeating-linear-gradient(0deg, rgba(60, 44, 28, 0.025) 0 1px, transparent 1px 5px),
        radial-gradient(120% 90% at 20% 0%, #f6f1e6, var(--sheet) 60%, #e6dcc8);
    box-shadow: 0 1px 0 var(--sheet-edge), 10px 18px 24px -8px rgba(0, 0, 0, 0.6), 2px 3px 4px rgba(0, 0, 0, 0.35);
}
.sheet h2 {
    font-family: var(--display);
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1.2;
    margin-bottom: 0.7rem;
}
.sheet > p + p, .sheet > p + ul, .sheet > ul + p { margin-top: 0.8rem; }

/* the index card: ruled, with a red top line */
.sheet--card {
    transform: rotate(-1.2deg);
    background:
        linear-gradient(to bottom, transparent 3.15rem, rgba(142, 36, 32, 0.45) 3.15rem, rgba(142, 36, 32, 0.45) calc(3.15rem + 1px), transparent calc(3.15rem + 1px)),
        repeating-linear-gradient(to bottom, transparent 0 calc(1.75rem - 1px), rgba(70, 90, 110, 0.18) calc(1.75rem - 1px) 1.75rem),
        #f4efe4;
    background-position: 0 0, 0 3.15rem, 0 0;
}
/* every line of the card sits on one of its printed rules */
.sheet--card {padding-top: 1.5rem;line-height: 1.75rem;}
.sheet--card h2 { line-height: 1.75rem; margin: 0; }
.sheet--card .steps {gap: 0;margin-top: 1.7rem;}
.sheet--card .steps li {border-bottom: 0;padding: 0;line-height: 1.7rem;gap: 0 1.1rem;}
.sheet--card .steps .verb { color: var(--ink); }

/* the typed memo */
.sheet--memo { transform: rotate(0.9deg); margin-top: 2.5rem; font-family: var(--mono); font-size: 0.95rem; line-height: 1.65; }
.sheet--memo h2 { font-family: var(--mono); font-weight: 400; font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.06em; }
.memo-rules { list-style: none; margin-top: 0.9rem; display: grid; gap: 0.3rem; }
.memo-rules li::before { content: "— "; }

/* Four notes share the memo's soft paper and typewriter face. */
.desk-notes-wrap { grid-column: 1 / -1; min-width: 0; }
.desk-notes-hint { display: none; }
.desk-notes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2.2rem; }
.desk-notes:focus-visible { outline: 1px solid var(--desk-dim); outline-offset: 8px; }

/* The notes use a quiet desk-coloured scrollbar, including non-overlay systems. */
.desk-notes { scrollbar-width: thin; scrollbar-color: #8c7b60 #211a12; }
@supports selector(::-webkit-scrollbar) {
    .desk-notes { scrollbar-width: auto; scrollbar-color: auto; }
    .desk-notes::-webkit-scrollbar { height: 10px; }
    .desk-notes::-webkit-scrollbar-track { background: #211a12; border-radius: 999px; margin-inline: 2rem; }
    .desk-notes::-webkit-scrollbar-thumb { background: #8c7b60; border: 2px solid #211a12; border-radius: 999px; }
    .desk-notes::-webkit-scrollbar-thumb:hover { background: #b9a888; }
    .desk-notes::-webkit-scrollbar-thumb:active { background: #d2c2a5; }
    .desk-notes::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
    .desk-notes::-webkit-scrollbar-corner { background: transparent; }
}
@media (forced-colors: active) {
    .desk-notes { scrollbar-color: auto; }
    .desk-notes::-webkit-scrollbar-track { background: Canvas; }
    .desk-notes::-webkit-scrollbar-thumb { background: ButtonText; border-color: Canvas; }
    .desk-notes::-webkit-scrollbar-thumb:hover, .desk-notes::-webkit-scrollbar-thumb:active { background: Highlight; }
}

.desk-note {
    --note-turn: -.65deg;
    padding: 2rem 2rem 2.3rem;
    font-family: var(--mono);
    font-size: .95rem;
    line-height: 1.65;
    transform: rotate(var(--note-turn));
    transition: transform 220ms ease, box-shadow 220ms ease;
}
.desk-note:nth-child(2) { --note-turn: .5deg; }
.desk-note:nth-child(3) { --note-turn: .4deg; }
.desk-note:nth-child(4) { --note-turn: -.5deg; }
.desk-note__number { display: block; margin-bottom: 1.1rem; color: var(--ink-dim); font-size: .8rem; letter-spacing: .12em; }
.desk-note h2 { font: inherit; font-size: 1.05rem; line-height: 1.4; text-transform: uppercase; letter-spacing: .045em; margin-bottom: 1rem; }
.desk-note p + p { margin-top: .85rem; }
.desk-note__steps { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.desk-note__steps strong { font-weight: 400; text-decoration: underline; text-underline-offset: .18em; }
.desk-note__steps + p { margin-top: 1rem; }
.desk-note .desk-note__link { margin-top: 1.2rem; }
.desk-note__link a { color: var(--oxblood); text-underline-offset: .25em; }
.desk-note__link a:focus-visible { outline: 2px solid var(--oxblood); outline-offset: 5px; }
@media (hover: hover) and (pointer: fine) {
    .desk-note:hover { transform: translateY(-5px) rotate(0deg); box-shadow: 0 1px 0 var(--sheet-edge), 12px 24px 30px -8px rgba(0, 0, 0, .55), 2px 4px 5px rgba(0, 0, 0, .3); }
}
.desk-note:focus-within { transform: translateY(-3px) rotate(0deg); }
@media (max-width: 44rem) {
    .desk-notes-hint { display: block; color: var(--desk-dim); font-size: .8rem; margin-bottom: .5rem; }
    .desk-notes {
        display: flex;
        gap: 1.2rem;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scroll-padding-inline: 2rem;
        overscroll-behavior-x: contain;
        padding: 1rem 2rem 2rem;
        margin-inline: -2rem;
    }
    .desk-note { flex: 0 0 calc(100vw - 5rem); min-width: 0; padding: 1.6rem 1.5rem 2rem; scroll-snap-align: start; }
}
@media (prefers-reduced-motion: reduce) {
    .desk-note { transition: none; }
    .desk-note:hover, .desk-note:focus-within { transform: rotate(var(--note-turn)); }
}

/* The homepage casebook reads as a case list, with one quiet rule per entry. */
.desk__casebook { grid-column: 1 / -1; color: var(--desk-ink); }
.desk__casebook h2 { font-family: var(--display); font-weight: 700; font-size: 1.6rem; line-height: 1.2; }
.desk__casebook > p { margin-top: 0.6rem; color: var(--desk-dim); max-width: 60ch; }
.desk__casebook .casebook-list { margin: 1.6rem 0 0.4rem; gap: 0; grid-template-columns: minmax(0, 1fr); }
.desk__casebook .casebook-item a {
    grid-template-columns: 5rem minmax(0, 1fr) auto;
    grid-template-areas: "number title tag" ". meta meta";
    gap: .25rem 1rem;
    padding: 1rem 0;
    color: var(--desk-ink);
    border: 0;
    border-top: 1px solid rgba(239, 229, 209, 0.2);
    background: transparent;
}
.desk__casebook .casebook-item:last-child a { border-bottom: 1px solid rgba(239, 229, 209, 0.2); }
.desk__casebook .casebook-item a:hover .casebook-title { text-decoration: underline; text-underline-offset: .2em; }
.desk__casebook .casebook-item a:focus-visible { outline: 2px solid var(--desk-ink); outline-offset: 4px; }
.desk__casebook .casebook-no { grid-area: number; color: var(--desk-dim); font-family: var(--mono); letter-spacing: .02em; font-size: .85rem; }
.desk__casebook .casebook-title { grid-area: title; font-weight: 600; font-size: 1.15rem; line-height: 1.4; }
.desk__casebook .casebook-meta { grid-area: meta; color: var(--desk-dim); font-size: .9rem; }
.desk__casebook .casebook-tag { grid-area: tag; color: #d9a39b; align-self: baseline; font-size: .8rem; letter-spacing: .02em; text-transform: none; }
.desk__casebook .casebook-item.is-locked .casebook-tag { color: var(--desk-dim); }
.desk__casebook .commands { justify-content: flex-start; margin-top: 1.6rem; }
.desk__casebook .desk__casebook-open { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; font-family: var(--mono); font-weight: 400; letter-spacing: .04em; line-height: 1.2; }
/* the casebook itself, on the desk beside its list (desktop only) */
.desk__casebook-aside { display: none; }
@media (min-width: 60rem) {
    /* only the homepage's section has the book; /cases and /account share the class */
    .desk__casebook:has(> .desk__casebook-aside) { display: grid; grid-template-columns: minmax(0, 1fr) clamp(260px, 30vw, 330px); column-gap: 3.5rem; align-items: start; }
    .desk__casebook:has(> .desk__casebook-aside) > * { grid-column: 1; }
    .desk__casebook > .desk__casebook-aside {
        display: flex; flex-direction: column; align-items: center; gap: 2.4rem;
        grid-column: 2; grid-row: 1 / span 4; margin-top: 2.6rem;
    }
    .desk__casebook-art { display: block; width: 100%; }
    .desk__casebook-art img {
        display: block; width: 100%; height: auto;
        transform: rotate(4deg);
        filter: drop-shadow(10px 16px 16px rgba(0, 0, 0, 0.55)) drop-shadow(2px 3px 3px rgba(0, 0, 0, 0.4));
        transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    .desk__casebook-art:hover img { transform: rotate(3deg) translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) { .desk__casebook-art img { transition: none; } }
/* Special Elite's capitals sit high in their line box. Center the visible ink. */
.desk__casebook-open > span { transform: translateY(.12em); }
.desk__casebook .cmd:not(.cmd-primary) { color: var(--desk-ink); border-color: var(--desk-ink); }
.desk__casebook .cmd:not(.cmd-primary):hover, .desk__casebook .cmd:not(.cmd-primary):focus-visible { background: var(--desk-ink); color: var(--desk); }
@media (max-width: 44rem) {
    .desk__casebook .casebook-item a { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "number tag" "title title" "meta meta"; gap: .3rem .75rem; }
}

.desk__next {
    text-align: center;
    color: var(--desk-dim);
    font-size: 0.92rem;
}
.desk__next { margin-top: -3.2rem; position: relative; z-index: 2; }

/* --- phones: notebook full width, magnifier tucked onto its corner ----------- */

@media (max-width: 44rem) {
    .desk__stage {min-height: 0;padding: 5rem max(2rem, 5%)  1rem;}
    .desk__masthead {padding-top: calc(4.5rem + env(safe-area-inset-top, 0px));}
    /* two balanced lines, leaving the top-right corner to the menu button */
    .desk__eyebrow {max-width: 18em;margin-inline: auto;text-wrap: balance;font-size: 100%;}
    /* the menu no longer sits on the banner, so it can use the full width
       (its padding is inline in wrapper.ghtml, hence !important) */
    .launch-notice { padding-right: 24px !important; }
    .desk__logo { width: min(78vw, 360px); }
    .desk__group { --nb-w: min(85vw, 420px); margin: 0 0 0 1vw; transform: rotate(-4deg); }
    .hand__opening { -webkit-line-clamp: 5; line-clamp: 5; max-height: calc(var(--nb-rule) * 5); }
    .desk__group .magnifier {width: 102%;left: 70%;top: 47%;}
    .teacup { display: none; }   /* no room for the cup beside the notebook on a phone */
    .desk__papers {grid-template-columns: 1fr;gap: 4rem;padding-inline: 2rem;margin-top: 7rem;}
    .sheet--memo { margin-top: 0; }
    .desk__next { margin-top: -2.4rem; }
}

/* --- every other page: the desk, with a shared header (page-head.ghtml) ---- */

.page-head {
    position: relative;
    z-index: 2;
    width: min(1120px, 100%);
    margin: 0 auto;
    padding: calc(3.2rem + env(safe-area-inset-top, 0px)) 3rem 0;   /* the homepage papers sit 3rem in */
    /* flush left, its left edge on the page body's below (that column is 120px narrower, centred on this one) */
    padding-left: calc(3rem + (min(1120px, 100vw) - min(1000px, 100vw)) / 2);
    text-align: left;
}
.page-head__home { display: inline-block; }
.page-head__home img {
    display: block;
    width: clamp(120px, 13vw, 160px);
    height: auto;
    margin: 0 0 2rem -10px;   /* the wordmark's own inset, so its letters line up with the copy */
    filter: invert(0.93) sepia(0.35) brightness(1.02);
}
.page-head__home:focus-visible { outline: 2px solid var(--desk-ink); outline-offset: 6px; }
.page-head__eyebrow {
    font-size: 0.8rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--desk-dim);
    /* lifts it off the lit wood behind it, as on the homepage */
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.8), 0 0 22px rgba(0, 0, 0, 0.6);
}
.page-head__title {
    margin-top: 0.5rem;
    font-family: var(--display);
    font-weight: 700;
    font-size: clamp(2.2rem, 5.5vw, 3.4rem);
    line-height: 1.1;
    color: var(--desk-ink);
    text-wrap: balance;
}
.page-head__lede {
    max-width: 46ch;
    margin: 0.9rem 0 0;
    font-style: italic;
    font-size: clamp(1.02rem, 1.3vw, 1.15rem);
    color: var(--desk-ink);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
    overflow-wrap: anywhere;
}

/* head.aside: who is signed in, top right on wide screens, under the title on a phone */
.page-head__aside {
    margin-top: 0.9rem;
    font-style: italic;
    color: var(--desk-ink);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
    overflow-wrap: anywhere;
}
.page-head__aside span {
    display: block;
    margin-bottom: 0.3rem;
    font-style: normal;
    font-size: 0.75rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--desk-dim);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.8), 0 0 22px rgba(0, 0, 0, 0.6);
}
@media (min-width: 60rem) {
    .page-head__aside {
        position: absolute;
        top: calc(3.2rem + env(safe-area-inset-top, 0px));
        right: calc(3rem + (min(1120px, 100vw) - min(1000px, 100vw)) / 2);   /* the page body's right edge */
        max-width: 22rem;
        margin: 0;
        text-align: right;
    }
}

/* one prop lying on the desk beside the title, on wide screens only */
.page-prop { position: absolute; pointer-events: none; display: none; }
@media (min-width: 60rem) {
    .page-prop { display: block; }
    .page-prop--magnifier {
        width: clamp(200px, 19vw, 270px);
        height: auto;
        right: max(1rem, calc(50% - 540px));
        top: 4.5rem;
        transform: rotate(16deg);
        filter: drop-shadow(18px 26px 14px rgba(0, 0, 0, 0.5)) drop-shadow(4px 6px 4px rgba(0, 0, 0, 0.4));
    }
    .page-prop--teacup {
        width: clamp(210px, 20vw, 290px);
        height: auto;
        right: max(0rem, calc(50% - 570px));
        top: 3rem;
        transform: rotate(14deg);
        filter: drop-shadow(12px 18px 14px rgba(0, 0, 0, 0.55));
    }
    .page-prop--notebook {
        width: clamp(190px, 17vw, 240px);
        right: max(1rem, calc(50% - 540px));   /* the right side: the header's copy is flush left */
        top: 5rem;
        transform: rotate(8deg);
    }
}
.page-prop--notebook .hand__title { font-size: 1em; white-space: nowrap; }
.page-prop--notebook .hand { min-height: calc(var(--nb-rule) * 6); }   /* a few blank rules, so it reads as a notebook */

.page-body {
    position: relative;
    z-index: 1;
    width: min(1000px, 100%);
    margin: 0 auto;
    padding: 3rem;
    color: var(--desk-ink);
}
.page-body--narrow { width: min(470px, 100%); }
.page-body--center { text-align: center; }
.page-body--center .commands { justify-content: center; }
.page-body--split { display: grid; gap: 2.4rem; align-items: start; }
@media (min-width: 52rem) { .page-body--split { grid-template-columns: 1.1fr 1fr; gap: 3rem; } }
.page-body--split .sheet--memo { margin-top: 0; }
.page-intro { text-align: center; font-style: italic; color: var(--desk-ink); opacity: 0.85; }
.page-empty { text-align: center; font-style: italic; color: var(--desk-dim); }
.page-notice { margin: 0 auto 1.8rem; max-width: 560px; padding: 0.8rem 1rem; border: 1px solid rgba(239, 229, 209, 0.3); color: var(--desk-ink); }
/* buttons straight on the desk read cream; inside paper sheets they keep their ink */
.page-body > .commands .cmd:not(.cmd-primary) { color: var(--desk-ink); border-color: var(--desk-ink); }
.page-body > .commands .cmd:not(.cmd-primary):hover,
.page-body > .commands .cmd:not(.cmd-primary):focus-visible { background: var(--desk-ink); color: var(--desk); }

/* on the other pages the lamp is turned down a little, so text on the desk reads */
.desk--page::after { opacity: 0.55; }

/* forms and offers on paper: ink on the sheet, not the desk's cream */
.page-body .sheet { color: var(--ink); }
.sheet.auth { max-width: none; margin: 0; }
.sheet--form { transform: rotate(-0.4deg); }
.sheet--form h2 { margin-bottom: 0.6rem; }
.sheet--form h2.sheet__typed { font-family: var(--mono); font-weight: 400; letter-spacing: 0.02em; }
.sheet--form > p + p { margin-top: 0.6rem; }
.sheet--form .commands { justify-content: flex-start; margin-top: 1rem; }
.sheet--form form + .auth-hint, .sheet--form .commands + .auth-hint { margin-top: 0.8rem; }
/* the account: the membership card on the left, the record on the desk beside it */
.page-body--account { display: grid; gap: 3rem; align-items: start; }
@media (min-width: 52rem) { .page-body--account { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); } }
.page-body--account > .page-notice { grid-column: 1 / -1; max-width: none; margin: 0; }
.page-body .account-card { max-width: none; margin: 0; }   /* outranks .sheet.auth */
.account-card a:not(.cmd) { color: var(--oxblood); }
.account-card .commands { flex-wrap: wrap; }
.account-record { grid-column: auto; }
.account-record .commands { margin-top: 1.2rem; }

/* the casebook and the record: shelves of cases on the desk */
.shelf + .shelf { margin-top: 3.4rem; }
.shelf--today .casebook-list { grid-template-columns: 1fr; }
.shelf--today .casebook-title { font-size: 1.3rem; }
.desk__casebook > p a { color: var(--desk-ink); text-decoration-color: var(--desk-dim); text-underline-offset: 0.15em; }
.desk__casebook > p a:hover { color: #d9a39b; }
.casebook-mark { color: #d9a39b; }
.casebook-mark::before { content: " \00B7  "; color: var(--desk-dim); }
.casebook-mark:not(.is-solved) { color: var(--desk-dim); }
.record-item:not(.is-solved) .casebook-tag { color: var(--desk-dim); }

@media (max-width: 44rem) {
    .page-head { padding-top: calc(2.2rem + env(safe-area-inset-top, 0px)); }
    .page-head__home img { margin-bottom: 1.4rem; }
    .page-body { padding-top: 2.2rem; }
    .page-head, .page-body { padding-inline: 2rem; }
}

/* casebook: today's case on one of the homepage's linen notes (.desk-note), with a
   smaller note beside it for the time left and the way in */
.today-pair { display: grid; gap: 1.6rem; max-width: 920px; margin-top: 1.4rem; align-items: start; }
@media (min-width: 52rem) { .today-pair { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } }
.today-note h3 { font: inherit; font-size: 1.05rem; line-height: 1.4; text-transform: uppercase; letter-spacing: .045em; margin-bottom: .35rem; }
.today-note__place { color: var(--ink-dim); margin-bottom: 1rem; }
.today-pair .today-clock {
    --note-turn: 1.2deg;
    display: grid;
    gap: 1rem;
    justify-items: center;
    text-align: center;
    padding: 2rem 1.5rem 2.1rem;
    max-width: 390px;
    margin-inline: auto;
}
@media (min-width: 52rem) { .today-pair .today-clock { margin-top: 2.4rem; } }
.today-pair .today-clock p { margin: 0; }
.today-clock__time { font-size: 2rem; line-height: 1.1; letter-spacing: .02em; }
.today-clock__time--static { font-size: 1.4rem; }
.today-clock__label { display: block; margin-top: .5rem; font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-dim); }
.today-clock__progress { font-size: .85rem; color: var(--ink-dim); }
.today-clock__play { width: 100%; text-align: center; }

/* the casebook's prop: a pocket watch that keeps the viewer's time, its chain drawn
   on a canvas over the header and dragged around in scene.js (wide screens only) */
.watch-chain { display: none; }
@media (min-width: 60rem) {
    .watch-chain { display: block; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
    .page-prop--watch {
        z-index: 1;
        width: clamp(190px, 18vw, 250px);
        right: max(6rem, calc(50% - 460px));
        top: 4rem;
        transform: rotate(-12deg);
    }
    .page-prop--watch .watch__case {
        display: block;
        width: 100%;
        height: auto;
        filter: drop-shadow(14px 20px 14px rgba(0, 0, 0, 0.5)) drop-shadow(3px 5px 4px rgba(0, 0, 0, 0.4));
    }
    .watch__hands { position: absolute; inset: 0; width: 100%; height: 100%; }
    .watch__hands path { fill: #1d1812; }
    .watch__hands g[data-hand="hour"] circle { stroke: #1d1812; }
    .watch__cap { fill: #8c7650; stroke: #3a2e1c; stroke-width: 1.5; }
}

/* the gift page's prop: a parcel tag on red-and-cream twine. The twine is drawn on a
   canvas over the header and dragged in scene.js; the tag echoes the form (wide screens only) */
.tag-twine { display: none; }
@media (min-width: 60rem) {
    .tag-twine { display: block; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
    .page-prop--tag {
        z-index: 1;
        width: clamp(112px, 9.75vw, 135px);
        right: max(7rem, calc(50% - 440px));
        top: 6.5rem;
        rotate: 9deg;
        container-type: inline-size;
    }
    .gift-tag__card {
        display: block;
        width: 100%;
        height: auto;
        filter: drop-shadow(12px 18px 14px rgba(0, 0, 0, 0.5)) drop-shadow(2px 4px 3px rgba(0, 0, 0, 0.4));
    }
    .gift-tag__writing { position: absolute; left: 13%; right: 13%; top: 30%; display: grid; gap: 14cqw; color: #2a2118; }
    .gift-tag__writing p { display: grid; margin: 0; border-bottom: 1px solid rgba(60, 42, 24, 0.35); }
    .gift-tag__writing span { font-family: var(--mono); font-size: 7.5cqw; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(42, 33, 24, 0.7); }
    .gift-tag__writing b {
        font-family: var(--hand); font-weight: 400; font-size: 14cqw; line-height: 1.15;
        overflow-wrap: anywhere;
        display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
    }
}

/* --- the backlog's desk calendar: a 1930s brass perpetual calendar (calendar.webp)
       whose card is live; the brass buttons step the month (scene.js) --------- */
.backlog { display: grid; gap: 2.4rem; margin-top: 1.8rem; align-items: start; }
@media (min-width: 52rem) {
    .backlog { grid-template-columns: minmax(250px, 330px) minmax(0, 1fr); gap: 3.2rem; }
    .backlog__calendar { position: sticky; top: 1.5rem; }
}
.backlog__calendar { width: min(100%, 330px); margin-inline: auto; }
.desk-calendar {
    position: relative;
    transform: rotate(-2deg);
    filter: drop-shadow(14px 22px 18px rgba(0, 0, 0, 0.55)) drop-shadow(3px 4px 3px rgba(0, 0, 0, 0.4));
}
.desk-calendar__frame { display: block; width: 100%; height: auto; }
/* the two bakelite-capped push buttons, measured from the image */
.desk-calendar__btn {
    position: absolute;
    width: 11%;
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    transform: translate(-50%, -50%);
    transition: background 90ms ease;
}
.desk-calendar__btn--prev { left: 19.5%; top: 6.75%; }
.desk-calendar__btn--next { left: 81.25%; top: 6.4%; }
.desk-calendar__btn:active,
.desk-calendar__btn.is-pressed { background: radial-gradient(circle, rgba(10, 6, 2, 0.5) 0 50%, transparent 64%); }
.desk-calendar__btn:focus-visible { outline: 2px solid var(--desk-ink); outline-offset: 2px; }
.desk-calendar__btn[aria-disabled="true"] { cursor: default; }
/* the card in the window */
.desk-calendar__card { position: absolute; left: 23.875%; top: 20.43%; width: 53.375%; height: 60.835%; perspective: 700px; container-type: size; }
.desk-calendar__face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 7cqh 7cqw 5cqh;
    color: var(--ink);
    text-align: center;
    transform-origin: 50% 0;
    transition: transform 170ms ease-in;
    backface-visibility: hidden;
}
.desk-calendar__face.is-turning { transform: rotateX(90deg); }
.desk-calendar__face.is-landing { transition: none; transform: rotateX(-90deg); }
.desk-calendar__month { font-family: var(--display); font-weight: 700; font-size: 14cqw; line-height: 1.05; }
.desk-calendar__year { margin-top: 1.5cqh; font-family: var(--mono); font-size: 7cqw; letter-spacing: 0.12em; color: var(--ink-dim); }
.desk-calendar__week, .desk-calendar__days { display: grid; grid-template-columns: repeat(7, 1fr); width: 100%; }
.desk-calendar__week {
    margin-top: 5cqh;
    padding-bottom: 1.4cqh;
    border-bottom: 1px solid rgba(32, 24, 15, 0.25);
    font-family: var(--mono);
    font-size: 5.6cqw;
    color: var(--ink-dim);
}
.desk-calendar__days { margin-top: 1.6cqh; row-gap: 0.6cqh; font-family: var(--mono); font-size: 6.4cqw; }
.desk-calendar__days > * { display: grid; place-items: center; aspect-ratio: 1; color: var(--ink); text-decoration: none; }
/* a case on that day: the date ringed by hand, in red ink */
.desk-calendar__days .is-case { position: relative; color: var(--stamp); font-weight: 700; }
.desk-calendar__days .is-case::after {
    content: "";
    position: absolute;
    inset: -4%;
    border: 1.5px solid var(--stamp);
    border-radius: 52% 46% 50% 44%;
    transform: rotate(-9deg);
    opacity: 0.85;
}
.desk-calendar__days .is-case:hover::after,
.desk-calendar__days .is-case:focus-visible::after { border-width: 2.5px; }
.desk-calendar__days .is-case:focus-visible { outline: none; }
.desk-calendar__count { margin-top: auto; font-family: var(--mono); font-size: 6cqw; color: var(--ink-dim); }
/* at the end of its range the mechanism won't turn: a small shake instead */
.backlog__calendar.is-stuck .desk-calendar { animation: desk-calendar-stuck 240ms ease; }
@keyframes desk-calendar-stuck {
    25% { transform: rotate(-2deg) translateX(-3px); }
    75% { transform: rotate(-2deg) translateX(3px); }
}
@media (prefers-reduced-motion: reduce) {
    .desk-calendar__face, .desk-calendar__btn { transition: none; }
    .backlog__calendar.is-stuck .desk-calendar { animation: none; }
}
.backlog__month-title { font-family: var(--mono); font-weight: 400; font-size: 0.9rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--desk-dim); }
.backlog__month + .backlog__month { margin-top: 2.2rem; }
.backlog__list .casebook-list { margin-top: 0.6rem; grid-template-columns: minmax(0, 1fr); }
.backlog__empty { color: var(--desk-dim); font-style: italic; }

/* --- /how-to-play: a sketch and its step, swapping sides down the page ------ */
.howto__steps { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: 4rem; }
.howto__step { display: grid; gap: 1.6rem; align-items: center; }
.howto__sketch {
    margin: 0;
    width: min(100%, 360px);
    justify-self: center;
    padding: 0.7rem;
    background: #efe6d2;
    transform: rotate(-1.5deg);
    box-shadow: 0 18px 30px -16px rgba(0, 0, 0, 0.85), 0 2px 4px rgba(0, 0, 0, 0.4);
}
.howto__sketch img { display: block; width: 100%; height: auto; }
.howto__no { margin: 0 0 0.3rem; font-family: var(--mono); font-size: 0.85rem; letter-spacing: 0.04em; color: var(--desk-dim); }
.howto__text h2 { font-family: var(--display); font-weight: 700; font-size: 1.6rem; line-height: 1.2; margin: 0 0 0.7rem; }
.howto__text p:last-child { max-width: 46ch; font-size: 1.05rem; line-height: 1.7; }
.howto .commands { justify-content: center; margin-top: 4.5rem; }
.howto__text a { color: inherit; text-decoration-color: var(--oxblood); text-underline-offset: .2em; }
.howto__decisive { max-width: 44rem; margin: 5rem auto 0; color: var(--ink); scroll-margin-top: 2rem; }
.howto__decisive .memo-rules { gap: 0.9rem; }
.howto__decisive .memo-rules li { padding-left: 2ch; text-indent: -2ch; }
.howto__decisive strong { font-weight: 700; }
@media (min-width: 52rem) {
    .howto__steps { gap: 5.5rem; }
    .howto__step { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4rem; }
    .howto__step:nth-child(even) .howto__sketch { order: 2; transform: rotate(1.5deg); }
}
