/* =====================================================================
   The Library — a walk-through bookshelf room, Apple style (black / white / greys).
   Designed at a fixed size (a bookcase is 560 × 860 px) and scaled to the window by JS (--k).
   Light = white gallery with daylight; dark = black room with warm-white lamps.
   ===================================================================== */
:root {
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --bg: #fbfbfd; --wall: #f5f5f7; --wall2: #ececf0;
    --case: #ffffff; --case-in: #e8e8ed; --case-edge: #d2d2d7; --case-dark: #c7c7cc;
    --floor: #e9e9ee; --floor-line: rgba(0,0,0,.06);
    --text: #1d1d1f; --muted: #6e6e73; --faint: #86868b; --line: rgba(0,0,0,.08);
    --ui-bg: rgba(251, 251, 253, .78);
    --page: #ffffff; --page-ink: #1d1d1f;
    --accent: #0071e3;
    --shade: .2;
}
:root[data-theme="dark"] {
    --bg: #000; --wall: #0b0b0c; --wall2: #000;
    --case: #1c1c1e; --case-in: #0a0a0b; --case-edge: #2c2c2e; --case-dark: #3a3a3c;
    --floor: #111113; --floor-line: rgba(255,255,255,.05);
    --text: #f5f5f7; --muted: #a1a1a6; --faint: #6e6e73; --line: rgba(255,255,255,.1);
    --ui-bg: rgba(22, 22, 23, .78);
    --page: #1c1c1e; --page-ink: #f5f5f7;
    --accent: #2997ff;
    --shade: .82;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }

/* ---------- top bar (Apple glass) ---------- */
.topbar {
    position: fixed; z-index: 50; top: 0; left: 0; right: 0; height: 52px;
    display: flex; align-items: center; gap: 16px; padding: 0 20px;
    background: var(--ui-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--line);
}
.topbar .back { color: var(--text); text-decoration: none; font-size: 14px; opacity: .8; white-space: nowrap; }
.topbar .back:hover { opacity: 1; }
.brand { font-size: 17px; font-weight: 600; letter-spacing: -.01em; margin: 0 auto; }
.tools { display: flex; align-items: center; gap: 10px; }
.ask { display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 9px; background: var(--line); }
.ask svg { width: 15px; height: 15px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.ask input { border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 14px; width: 190px; }
.ask input::placeholder { color: var(--faint); }
.lights { width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer; background: var(--line); position: relative; }
.lights::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--text); transition: all .4s var(--ease); }
:root[data-theme="dark"] .lights::before { background: transparent; box-shadow: inset -4px -2px 0 0 var(--text); transform: rotate(-20deg); }
@media (max-width: 640px) {
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar .back { font-size: 0; } .topbar .back::before { content: "‹ CV"; font-size: 15px; }
    .brand { font-size: 16px; }
    .ask input { width: 92px; }
    .ask input:focus { width: 140px; }
}

/* ---------- entrance: glass doors ---------- */
.entrance {
    position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
    background: radial-gradient(120% 90% at 50% 20%, var(--bg), var(--wall2) 80%);
    perspective: 1600px; transition: opacity .9s ease .5s, visibility 0s linear 1.5s;
}
.doorway {
    position: relative; width: min(520px, 84vw); height: min(70vh, 660px); margin-bottom: 8vh;
    display: flex; gap: 6px; padding: 6px; border-radius: 6px 6px 0 0; transform-style: preserve-3d;
    background: linear-gradient(180deg, #fafafa, #f0f0f3); box-shadow: 0 0 0 1px var(--case-edge), 0 40px 80px rgba(0,0,0,.12);
    transition: transform 1.5s var(--ease);
}
:root[data-theme="dark"] .doorway { background: linear-gradient(180deg, #1c1c1e, #0b0b0c); box-shadow: 0 0 0 1px #2c2c2e, 0 40px 80px rgba(0,0,0,.6); }
.doorway::before { content: ""; position: absolute; inset: 6px; border-radius: 2px; background: linear-gradient(180deg, #ffffff, #f2f2f5); }
:root[data-theme="dark"] .doorway::before { background: radial-gradient(80% 60% at 50% 40%, #2a2a2c, #0b0b0c); }
.door {
    flex: 1; position: relative; border-radius: 2px; transition: transform 1.4s var(--ease);
    background: linear-gradient(115deg, rgba(255,255,255,.55), rgba(230,232,238,.35) 40%, rgba(255,255,255,.6) 60%, rgba(220,222,230,.4));
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.08), 0 1px 0 rgba(255,255,255,.8);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
:root[data-theme="dark"] .door { background: linear-gradient(115deg, rgba(255,255,255,.08), rgba(255,255,255,.02) 40%, rgba(255,255,255,.1) 60%, rgba(255,255,255,.03)); box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.door.left { transform-origin: left center; } .door.right { transform-origin: right center; }
.door .panel { display: none; }
.door .handle { position: absolute; top: 38%; width: 6px; height: 120px; border-radius: 3px; background: linear-gradient(90deg, #b9b9be, #f5f5f7 50%, #a1a1a6); box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.door.left .handle { right: 16px; } .door.right .handle { left: 16px; }
.plaque {
    position: absolute; left: 50%; top: 18%; transform: translateX(-50%); z-index: 2; text-align: center; white-space: nowrap;
    font-size: 40px; font-weight: 600; letter-spacing: -.03em; color: var(--text); transition: opacity .5s;
}
.plaque small { display: block; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: #bf4800; margin-bottom: 8px; }
.plaque em { display: block; font-style: normal; font-size: 15px; font-weight: 400; letter-spacing: 0; color: var(--muted); margin-top: 6px; }
.enter {
    position: absolute; bottom: 8vh; padding: 12px 24px; border-radius: 980px; border: 0; cursor: pointer;
    background: var(--accent); color: #fff; font-size: 17px; transition: transform .3s var(--ease), opacity .4s;
}
.enter:hover { transform: scale(1.04); }
.entrance.open .door.left { transform: rotateY(-100deg); }
.entrance.open .door.right { transform: rotateY(100deg); }
.entrance.open .plaque, .entrance.open .enter { opacity: 0; }
.entrance.open .doorway { transform: translateZ(900px); }
.entrance.open { opacity: 0; visibility: hidden; pointer-events: none; }
.entrance.gone { display: none; }
html.locked, html.locked body { overflow: hidden; }

/* ---------- the hall: tall scroll space, the room sticks ---------- */
.hall { position: relative; }
.stage { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; }
.room { position: absolute; inset: 0; perspective: 1500px; perspective-origin: 50% 45%; background: linear-gradient(180deg, var(--bg), var(--wall) 60%); }
.wall { position: absolute; inset: 0; }
.aisle { position: absolute; left: 0; bottom: var(--floor-h, 14vh); display: flex; align-items: flex-end; transform-origin: 0 100%; transform-style: preserve-3d; will-change: transform; }
.floor {
    position: absolute; left: -60%; width: 220%; height: 140vh; top: calc(100% - var(--floor-h, 14vh));
    transform-origin: 50% 0; transform: rotateX(84deg);
    background:
        repeating-linear-gradient(90deg, transparent 0 calc(var(--plank, 420px) - 1px), var(--floor-line) calc(var(--plank, 420px) - 1px) var(--plank, 420px)),
        repeating-linear-gradient(180deg, transparent 0 139px, var(--floor-line) 139px 140px),
        linear-gradient(180deg, var(--wall2), var(--floor) 30%);
    background-position: var(--walk, 0) 0, 0 0, 0 0;
}
.fore { position: absolute; left: 0; top: 0; bottom: 0; pointer-events: none; will-change: transform; }
/* the reading cart: books you open land here */
.cart {
    position: absolute; z-index: 6; left: 0; bottom: 10px; will-change: transform; width: 210px; padding: 9px 8px 6px; border-radius: 18px; color: var(--case-dark);
    background: var(--ui-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    box-shadow: 0 0 0 1px var(--line), 0 12px 30px rgba(0,0,0,.1);
}
:root[data-theme="dark"] .cart { color: #48484a; }
.cart-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 8px 6px; font-size: 12px; color: var(--muted); }
.cart-head b { font-weight: 600; color: var(--text); }
.cart-clear { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12px; cursor: pointer; opacity: 0; transition: opacity .3s; }
.cart.has .cart-clear { opacity: 1; }
.cart-pile { display: flex; flex-direction: column-reverse; align-items: center; min-height: 26px; padding: 0 10px; }
.pile-book {
    display: block; height: 20px; width: var(--w); max-width: 196px; margin-top: 1px; padding: 0 10px; border: 0; border-radius: 2px; cursor: pointer;
    background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(0,0,0,.12)), var(--c); color: #f5f5f7; box-shadow: inset 0 0 0 .5px rgba(0,0,0,.15);
    font-size: 9.5px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: transform .35s var(--ease);
}
.pile-book[data-ink="light"] { color: #1d1d1f; }
.pile-book:hover { transform: translateX(8px); }
.pile-book.drop { animation: drop .7s var(--ease); }
@keyframes drop { from { transform: translateY(-60px) rotate(-6deg); opacity: 0; } }
.pile-empty { font-size: 11px; color: var(--faint); padding: 4px 0; }
.cart-frame { display: block; width: 100%; height: auto; margin-top: -2px; overflow: visible; }
.vignette { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 100% at 50% 45%, transparent 60%, rgba(0,0,0,.05)); }
:root[data-theme="dark"] .vignette { background: radial-gradient(110% 95% at 50% 40%, transparent 35%, rgba(0,0,0,.75)); }
.dust { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.hint {
    position: absolute; left: 50%; transform: translateX(-50%); bottom: 72px; margin: 0; z-index: 7;
    padding: 8px 16px; border-radius: 980px; font-size: 13px; color: var(--text); white-space: nowrap;
    background: var(--ui-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    box-shadow: 0 0 0 1px var(--line); transition: opacity .8s;
}
.hint.off { opacity: 0; }
.minimap { position: absolute; right: 18px; bottom: 18px; z-index: 5; display: flex; gap: 4px; padding: 5px; border-radius: 980px; background: var(--ui-bg); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); box-shadow: 0 0 0 1px var(--line); scrollbar-width: none; }
.minimap::-webkit-scrollbar { display: none; }
.minimap button { border: 0; padding: 5px 11px; border-radius: 980px; background: none; color: var(--muted); font-size: 12px; cursor: pointer; white-space: nowrap; transition: background .3s, color .3s; }
.minimap button.on { background: var(--text); color: var(--bg); }
@media (max-width: 1240px) { .cart { bottom: 104px; } .minimap { left: 12px; right: 12px; bottom: 60px; justify-content: space-between; overflow-x: auto; } .hint { font-size: 12px; bottom: 14px; left: 50%; transform: translateX(-50%); } }
@media (max-width: 700px) { .cart { display: none; } .minimap { bottom: 14px; } .hint { bottom: 64px !important; white-space: normal; width: calc(100% - 32px); text-align: center; border-radius: 14px; } .minimap button { font-size: 11px; padding: 4px 8px; } }

/* ---------- a bookcase: white (light) / graphite (dark) ---------- */
.bay { position: relative; width: 560px; height: 860px; flex: none; transform-style: preserve-3d; }
.bay .crown { position: absolute; left: -8px; right: -8px; top: 22px; height: 36px; border-radius: 10px 10px 0 0; z-index: 3; background: var(--case); box-shadow: 0 0 0 1px var(--case-edge), 0 10px 20px rgba(0,0,0,.05); }
.bay .sign { position: absolute; z-index: 4; top: 30px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 15px; font-weight: 600; letter-spacing: -.01em; color: var(--text); }
.bay .case { position: absolute; left: 0; right: 0; top: 58px; bottom: 44px; padding: 0 18px; transform-style: preserve-3d; background: linear-gradient(90deg, rgba(0,0,0,.07), transparent 7%, transparent 93%, rgba(0,0,0,.07)), var(--case-in); }
:root[data-theme="dark"] .bay .case { background: linear-gradient(90deg, rgba(0,0,0,.6), transparent 8%, transparent 92%, rgba(0,0,0,.6)), var(--case-in); }
.bay .case::before, .bay .case::after { content: ""; position: absolute; top: 0; bottom: 0; width: 18px; z-index: 3; background: var(--case); box-shadow: 0 0 0 1px var(--case-edge); }
.bay .case::before { left: 0; } .bay .case::after { right: 0; }
.bay .plinth { position: absolute; left: -4px; right: -4px; bottom: 0; height: 44px; background: var(--case); box-shadow: 0 0 0 1px var(--case-edge), 0 12px 24px rgba(0,0,0,.06); }
.shelf { position: relative; height: 189.5px; display: flex; align-items: flex-end; padding: 0 6px 12px; gap: 2px; transform-style: preserve-3d; }
.shelf::after { content: ""; position: absolute; left: -2px; right: -2px; bottom: 0; height: 12px; z-index: 2; background: linear-gradient(180deg, var(--case-edge) 0 1px, var(--case) 1px); box-shadow: 0 6px 12px rgba(0,0,0,.07); }
:root[data-theme="dark"] .shelf::after { box-shadow: 0 6px 12px rgba(0,0,0,.5); }
.shelf::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 34px; pointer-events: none; z-index: 1; background: linear-gradient(180deg, rgba(0,0,0,.1), transparent); transform: translateZ(60px); }
:root[data-theme="dark"] .shelf::before { background: linear-gradient(180deg, rgba(0,0,0,.6), transparent); }
.bay .shade { position: absolute; inset: 0; z-index: 6; pointer-events: none; opacity: var(--shade); background: radial-gradient(80% 60% at 50% 20%, rgba(0,0,0,.75), rgba(0,0,0,.95)); transition: opacity .7s ease; }
:root:not([data-theme="dark"]) .bay .shade { top: 22px; background: linear-gradient(180deg, rgba(60,60,67,.9), rgba(60,60,67,.7)); }
.bay.lit .shade { opacity: 0; }
.bay .glow { position: absolute; z-index: 5; left: -20%; right: -20%; top: 30px; height: 75%; pointer-events: none; background: radial-gradient(50% 55% at 50% 0%, rgba(255,226,150,.13), rgba(255,226,150,.035) 55%, transparent 75%); opacity: 0; transition: opacity .7s ease; }
:root:not([data-theme="dark"]) .room { background: linear-gradient(180deg, #ededf0, #e3e3e8 70%); }
:root:not([data-theme="dark"]) .bay .glow { background: radial-gradient(48% 52% at 50% 0%, rgba(255,247,214,.75), rgba(255,246,212,.25) 55%, transparent 76%); }
:root:not([data-theme="dark"]) .lamp::after { mix-blend-mode: normal; filter: blur(6px); background: radial-gradient(50% 70% at 50% 0%, rgba(255,246,206,.95), rgba(255,247,215,.45) 50%, transparent 78%); }
:root:not([data-theme="dark"]) .bay.lit .lamp::after { opacity: 1; }
.lamp::after {        /* the cone of light under the shade */
    content: ""; position: absolute; left: 50%; top: 104px; width: 220px; height: 160px; margin-left: -110px; pointer-events: none; opacity: 0; transition: opacity .5s;
    background: radial-gradient(50% 60% at 50% 0%, rgba(255,205,90,.55), rgba(255,215,120,.18) 55%, transparent 75%);
    clip-path: polygon(38% 0, 62% 0, 100% 100%, 0 100%); filter: blur(4px); mix-blend-mode: multiply;
}
:root[data-theme="dark"] .lamp::after { mix-blend-mode: screen; background: radial-gradient(50% 60% at 50% 0%, rgba(255,214,120,.4), rgba(255,214,120,.1) 55%, transparent 75%); }
:root[data-theme="dark"] .bay.lit .lamp::after { opacity: 1; }
:root[data-theme="dark"] .bay.lit .glow { opacity: 1; }

/* pendant lamp (click to switch) */
.lamp { position: absolute; z-index: 8; top: -150px; left: 50%; width: 120px; height: 150px; margin-left: -60px; cursor: pointer; border: 0; background: none; padding: 0; }
.lamp .cord { position: absolute; left: 50%; top: -400px; height: 470px; width: 1px; background: var(--faint); }
.lamp .shade-top { position: absolute; left: 30px; right: 30px; top: 70px; height: 34px; border-radius: 60px 60px 4px 4px; background: linear-gradient(180deg, #ffffff, #e5e5ea); box-shadow: 0 0 0 1px var(--case-edge); }
:root[data-theme="dark"] .lamp .shade-top { background: linear-gradient(180deg, #2c2c2e, #1c1c1e); box-shadow: 0 0 0 1px #3a3a3c; }
.lamp .bulb { position: absolute; left: 50%; top: 102px; width: 26px; height: 6px; margin-left: -13px; border-radius: 0 0 8px 8px; background: #c7c7cc; transition: background .4s, box-shadow .4s; }
.bay.lit .lamp .bulb { background: #fff8de; box-shadow: 0 0 10px 3px rgba(255,243,196,1), 0 6px 22px 6px rgba(255,236,170,.25); }
:root[data-theme="dark"] .bay.lit .lamp .bulb { background: #ffe9a0; box-shadow: 0 0 12px 5px rgba(255,208,90,.9), 0 0 40px 14px rgba(255,214,110,.45); }
:root[data-theme="dark"] .bay.lit .lamp .shade-top { box-shadow: 0 0 0 1px #3a3a3c, inset 0 -6px 10px -6px rgba(255,214,110,.6); }
.lamp:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 8px; }

/* ---------- books ---------- */
.book { position: relative; flex: none; height: var(--h); width: var(--w); transform-style: preserve-3d; transition: transform .55s var(--ease), opacity .4s; cursor: pointer; outline: none; }
.book .spine {
    position: absolute; inset: 0; border-radius: 2px; overflow: hidden;
    background: linear-gradient(90deg, rgba(0,0,0,.14), rgba(255,255,255,.1) 22%, transparent 50%, rgba(0,0,0,.08) 85%, rgba(0,0,0,.18)), var(--c);
    display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 10px 0 8px;
    color: var(--ink, #f5f5f7); box-shadow: inset 0 0 0 .5px rgba(0,0,0,.12);
}
.book .t { writing-mode: vertical-rl; font-size: 9.5px; line-height: 1.12; font-weight: 600; max-height: 74%; max-width: 86%; overflow: hidden; margin-top: 10%; text-align: center; }
.book .a { writing-mode: vertical-rl; font-size: 7px; letter-spacing: .06em; text-transform: uppercase; opacity: .6; margin-bottom: 8%; white-space: nowrap; max-height: 20%; overflow: hidden; }
.book[data-ink="light"] .spine { --ink: #1d1d1f; }
.book .side { position: absolute; top: 0; left: 100%; width: var(--d); height: 100%; transform-origin: 0 50%; transform: rotateY(90deg); background: var(--img, none) center / cover no-repeat, var(--c); backface-visibility: hidden; border-radius: 0 3px 3px 0; box-shadow: inset 4px 0 8px rgba(0,0,0,.2); }
.book .top { position: absolute; left: 0; top: 0; width: 100%; height: var(--d); transform-origin: 50% 0; transform: rotateX(-90deg); background: repeating-linear-gradient(90deg, #f5f5f7 0 1px, #e0e0e5 1px 2px); }
.book.real:hover, .book.real:focus-visible, .book.real.pulled { transform: translate3d(0, -12px, 70px) rotateY(-58deg); z-index: 4; }
.book.real:focus-visible .spine { box-shadow: 0 0 0 2px var(--accent); }
.book.filler { cursor: default; }
.book.filler:hover { transform: translate3d(0, -3px, 8px); }
.book.lean { transform: rotate(-9deg) translateX(6px); transform-origin: 0 100%; margin-right: 14px; }
.book.lean:hover { transform: rotate(-9deg) translate3d(6px, -3px, 8px); }
.book.secret { cursor: pointer; }
.book.secret .t { font-size: 7px; letter-spacing: .16em; margin-top: 30%; }
.book.secret:hover { transform: translate3d(0, -4px, 14px) rotateX(-12deg); }
.aisle.searching .book.real:not(.match) { opacity: .25; }
.aisle.searching .book.real.match { transform: translate3d(0, -12px, 70px) rotateY(-58deg); z-index: 4; }
.aisle.searching .book.real.match .spine, .aisle.searching .book.real.match .side { box-shadow: 0 0 0 2px var(--accent), 0 0 24px rgba(0,113,227,.45); }

/* floating label over a pulled book */
.tag {
    position: fixed; z-index: 30; pointer-events: none; max-width: 280px; padding: 10px 14px; border-radius: 14px;
    background: var(--ui-bg); color: var(--text); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    box-shadow: 0 10px 30px rgba(0,0,0,.14), 0 0 0 1px var(--line);
    opacity: 0; transform: translate(-50%, calc(-100% - 10px)) scale(.96); transition: opacity .25s, transform .35s var(--ease);
}
.tag.show { opacity: 1; transform: translate(-50%, calc(-100% - 16px)) scale(1); }
.tag b { display: block; font-size: 15px; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
.tag span { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }
.tag i { display: inline-block; margin-top: 6px; font-style: normal; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 980px; background: rgba(0,113,227,.12); color: var(--accent); }
.tag i.soon { background: var(--line); color: var(--muted); }

/* objects on the shelves */
.obj { flex: none; position: relative; margin: 0 8px; color: var(--text); }
.obj svg { display: block; overflow: visible; }
.stack { display: flex; flex-direction: column-reverse; align-items: center; margin: 0 10px; }
.stack .lying { height: var(--t); width: var(--l); border-radius: 2px; margin-left: var(--o, 0); background: linear-gradient(180deg, rgba(255,255,255,.12), rgba(0,0,0,.12)), var(--c); box-shadow: inset 0 0 0 .5px rgba(0,0,0,.15); }
.bookend { width: 14px; height: 64px; flex: none; border-radius: 2px 2px 0 0; background: linear-gradient(90deg, #a1a1a6, #f5f5f7 50%, #a1a1a6); margin: 0 4px; box-shadow: 1px 0 3px rgba(0,0,0,.2); }

/* ---------- windows ---------- */
.window { position: relative; width: 330px; height: 860px; flex: none; }
.window .frame {
    position: absolute; left: 40px; right: 40px; top: 90px; height: 560px; border-radius: 4px;
    border: 8px solid var(--case); box-shadow: 0 0 0 1px var(--case-edge), 0 10px 30px rgba(0,0,0,.08);
    background: linear-gradient(90deg, transparent calc(50% - 2px), var(--case) calc(50% - 2px) calc(50% + 2px), transparent calc(50% + 2px)), linear-gradient(180deg, #cfe3f7, #eef5fb 60%, #ffffff);
    overflow: hidden;
}
:root[data-theme="dark"] .window .frame {
    background:
        linear-gradient(90deg, transparent calc(50% - 2px), var(--case) calc(50% - 2px) calc(50% + 2px), transparent calc(50% + 2px)),
        radial-gradient(circle at 70% 16%, #f5f5f7 0 14px, rgba(245,245,247,.15) 15px 28px, transparent 29px),
        radial-gradient(1px 1px at 20% 30%, #fff, transparent), radial-gradient(1px 1px at 40% 12%, #fff, transparent), radial-gradient(1.5px 1.5px at 30% 50%, #fff, transparent),
        radial-gradient(1px 1px at 80% 45%, #fff, transparent), radial-gradient(1px 1px at 60% 60%, #fff, transparent), radial-gradient(1px 1px at 15% 70%, #fff, transparent),
        linear-gradient(180deg, #050608, #12141a);
}
.window .sill { position: absolute; left: 32px; right: 32px; top: 650px; height: 10px; border-radius: 2px; background: var(--case); box-shadow: 0 0 0 1px var(--case-edge), 0 8px 12px rgba(0,0,0,.08); }
.window .beam { position: absolute; left: 60px; top: 120px; width: 420px; height: 900px; pointer-events: none; z-index: 7; background: linear-gradient(180deg, rgba(255,255,255,.55), rgba(255,255,255,.1) 70%, transparent); clip-path: polygon(0 0, 48% 0, 100% 100%, 40% 100%); filter: blur(8px); }
:root[data-theme="dark"] .window .beam { background: linear-gradient(180deg, rgba(220,225,255,.08), rgba(220,225,255,.02) 70%, transparent); }
.window .plant { position: absolute; left: 50%; top: 556px; transform: translateX(-50%); }
.obj.big svg { width: 100px; height: 150px; }

/* ---------- reading nook at the end ---------- */
.nook { position: relative; width: 760px; height: 860px; flex: none; }
.nook .note { position: absolute; left: 64%; top: 150px; transform: translateX(-50%); width: 360px; padding: 28px 28px 24px; text-align: center; color: var(--text); background: var(--case); border-radius: 18px; box-shadow: 0 0 0 1px var(--line), 0 20px 40px rgba(0,0,0,.08); }
.nook .note h2 { margin: 0 0 8px; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.nook .note p { margin: 0; font-size: 15px; line-height: 1.45; color: var(--muted); }
.nook .note a { color: var(--accent); text-decoration: none; }
.nook .desk-scene {        /* original pixel workstation, same pixel size as the librarian (10 px) */
    position: absolute; left: 160px; bottom: 0; width: 600px; height: 460px; image-rendering: pixelated; image-rendering: crisp-edges;
    border-radius: 6px 6px 0 0; box-shadow: 0 0 0 1px rgba(79,216,255,.15), 0 0 60px rgba(255,79,216,.18), 0 20px 50px rgba(20,27,56,.35);
}

/* ---------- the secret bookcase ---------- */
.secret-bay .case { transition: transform 1.6s cubic-bezier(.6,0,.2,1); z-index: 2; }
.secret-bay.open .case { transform: translateX(82%); }
.passage {
    position: absolute; left: 0; right: 0; top: 58px; bottom: 44px; z-index: 1; transform: translateZ(2px);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-decoration: none; padding-right: 18%;
    background: radial-gradient(50% 50% at 41% 55%, #ffffff, #e8e8ed 70%, #c7c7cc); color: #1d1d1f; opacity: 0; transition: opacity .8s ease .3s;
}
:root[data-theme="dark"] .passage { background: radial-gradient(50% 50% at 41% 55%, #3a3a3c, #0b0b0c 80%); color: #f5f5f7; }
.secret-bay.open .passage { opacity: 1; }
.passage span { font-size: 12px; font-weight: 600; color: #bf4800; }
.passage b { font-size: 19px; font-weight: 500; padding: 11px 22px; border-radius: 980px; background: var(--accent); color: #fff; white-space: nowrap; }
.secret-bay:not(.open) .passage { pointer-events: none; }

/* ---------- reading desk overlay ---------- */
.desk-ov { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(245, 245, 247, .6); backdrop-filter: blur(24px) saturate(160%); -webkit-backdrop-filter: blur(24px) saturate(160%); opacity: 0; transition: opacity .45s ease; perspective: 2200px; }
:root[data-theme="dark"] .desk-ov { background: rgba(0, 0, 0, .6); }
.desk-ov.show { opacity: 1; }
.desk-ov[hidden] { display: none; }
.desk-top, .lamp-glow { display: none; }
.open-book { --P: min(380px, 44vw); --H: min(560px, 76vh); position: relative; width: calc(var(--P) * 2); height: var(--H); transform-style: preserve-3d; transition: transform .8s var(--ease), opacity .4s; }
.leaf { position: absolute; top: 0; width: var(--P); height: 100%; background: var(--page); color: var(--page-ink); overflow: auto; }
.left-page { left: 0; border-radius: 14px 0 0 14px; box-shadow: -10px 30px 60px rgba(0,0,0,.18); }
.right-page { left: var(--P); border-radius: 0 14px 14px 0; padding: clamp(24px, 4vh, 44px) clamp(22px, 3vw, 40px); background: linear-gradient(90deg, rgba(0,0,0,.06), transparent 8%), var(--page); box-shadow: 10px 30px 60px rgba(0,0,0,.18); display: flex; flex-direction: column; }
.right-page .kicker { font-size: 12px; font-weight: 600; color: #bf4800; }
:root[data-theme="dark"] .right-page .kicker { color: #ff9f0a; }
.right-page h2 { font-size: clamp(24px, 2.6vw, 32px); line-height: 1.1; letter-spacing: -.025em; font-weight: 700; margin: 10px 0; }
.right-page .by { font-size: 16px; color: var(--muted); }
.right-page .yr { font-size: 13px; color: var(--faint); margin-top: 4px; }
.right-page .rule { height: 1px; background: var(--line); margin: 20px 0; }
.right-page p { font-size: 17px; line-height: 1.5; margin: 0 0 18px; letter-spacing: -.01em; }
.right-page .acts { margin-top: auto; display: flex; flex-wrap: wrap; gap: 10px; }
.right-page .acts a, .right-page .acts span { display: inline-flex; align-items: center; gap: 6px; padding: 11px 20px; border-radius: 980px; font-size: 15px; text-decoration: none; background: var(--accent); color: #fff; transition: transform .3s var(--ease); }
.right-page .acts a:hover { transform: scale(1.04); }
.right-page .acts a.ghost { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.right-page .acts span.soon { background: var(--line); color: var(--muted); }
.front { position: absolute; top: 0; left: var(--P); width: var(--P); height: 100%; transform-origin: 0 50%; transform-style: preserve-3d; transition: transform 1.1s var(--ease); z-index: 3; }
.front-out, .front-in { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 0 14px 14px 0; overflow: hidden; }
.front-out { background: var(--img, none) center / cover no-repeat, var(--c); box-shadow: inset 6px 0 12px rgba(0,0,0,.25), 10px 30px 60px rgba(0,0,0,.25); }
.front-in { transform: rotateY(180deg); border-radius: 14px 0 0 14px; display: grid; place-items: center; background: var(--page); box-shadow: inset -20px 0 30px -20px rgba(0,0,0,.12); }
.exlibris { width: 72%; padding: 28px 20px; text-align: center; color: var(--page-ink); border-radius: 18px; box-shadow: 0 0 0 1px var(--line); }
.exlibris small { display: block; font-size: 12px; font-weight: 600; color: var(--faint); letter-spacing: .02em; }
.exlibris b { display: block; font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin: 8px 0 2px; }
.exlibris em { font-style: normal; font-size: 14px; color: var(--muted); }
.exlibris-me { width: 84px; height: 84px; margin: 16px auto 0; display: block; border-radius: 14px; image-rendering: pixelated; image-rendering: crisp-edges; }
.open-book.closed .front { transform: rotateY(0deg); }
.open-book.opened .front { transform: rotateY(-180deg); }
.open-book.closed { transform: translateX(calc(var(--P) * -.5)); }
.desk-close { position: absolute; top: 70px; right: 24px; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer; font-size: 15px; background: var(--line); color: var(--text); }
.desk-close:hover { background: rgba(127,127,127,.25); }
.desk-nav { position: absolute; bottom: 4vh; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; }
.desk-nav button { width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer; font-size: 22px; background: var(--line); color: var(--text); }
.desk-nav button:hover { background: rgba(127,127,127,.25); }

@media (max-width: 700px) {
    .open-book { --P: min(340px, calc(100vw - 40px)); --H: min(39vh, 360px); width: var(--P); height: calc(var(--H) * 2); }
    .leaf { width: 100%; height: var(--H); }
    .left-page { top: 0; left: 0; border-radius: 14px 14px 0 0; }
    .right-page { top: var(--H); left: 0; border-radius: 0 0 14px 14px; background: linear-gradient(180deg, rgba(0,0,0,.06), transparent 6%), var(--page); padding: 18px 20px; }
    .right-page h2 { font-size: 22px; margin: 6px 0 4px; } .right-page p { font-size: 15px; margin-bottom: 12px; } .right-page .rule { margin: 12px 0; }
    .front { top: var(--H); left: 0; width: 100%; height: var(--H); transform-origin: 50% 0; }
    .front-out { border-radius: 0 0 14px 14px; background-size: contain, auto; }
    .front-in { transform: rotateX(180deg); border-radius: 14px 14px 0 0; }
    .open-book.closed { transform: translateY(calc(var(--H) * -.5)); }
    .open-book.opened .front { transform: rotateX(180deg); }
    .desk-close { top: 62px; right: 12px; }
    .desk-nav { bottom: 2vh; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------- the pixel librarian ---------- */
.librarian { position: absolute; left: 0; bottom: 0; width: 320px; height: 480px; z-index: 9; pointer-events: none; transform-style: preserve-3d; }
.librarian canvas { width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; display: block; filter: drop-shadow(0 6px 4px rgba(0,0,0,.18)); }
.librarian .bubble {
    position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%) scale(.9); margin-bottom: 6px; white-space: nowrap;
    padding: 6px 10px; border-radius: 12px; font-size: 13px; color: var(--text); background: var(--ui-bg); box-shadow: 0 0 0 1px var(--line), 0 6px 16px rgba(0,0,0,.1);
    opacity: 0; transition: opacity .3s, transform .3s var(--ease);
}
.librarian .bubble.show { opacity: 1; transform: translateX(-50%) scale(1); }
.book.filler.tidy { animation: tidy 1.1s var(--ease); }
@keyframes tidy { 0% { transform: none; } 35% { transform: translate3d(0, -6px, 34px) rotateY(-14deg); } 70% { transform: translate3d(0, 0, -6px); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .librarian { display: none; } }

/* ---------- lite mode (phones / tablets): same look, far less work for the GPU ---------- */
.lite .room { perspective: none; }
.lite .aisle, .lite .bay, .lite .case, .lite .shelf, .lite .book, .lite .librarian { transform-style: flat; }
.lite .shelf::before { transform: none; }
.lite .book { transition: none; }
.lite .window .beam { filter: none; opacity: .6; }
.lite .lamp::after { filter: none; }
.lite .dust { display: none; }
.lite .topbar, .lite .hint, .lite .minimap, .lite .tag, .lite .cart { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
.lite .desk-ov { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(245,245,247,.94); }
:root.lite[data-theme="dark"] .desk-ov { background: rgba(0,0,0,.92); }
.lite .nook .desk-scene { box-shadow: 0 0 0 1px rgba(79,216,255,.15); }
.lite .door { backdrop-filter: none; -webkit-backdrop-filter: none; }
.librarian { will-change: transform; }

/* sound toggle (button made by the CV's sfx.js) */
#sfx-toggle { width: 32px; height: 32px; border-radius: 50%; border: 0; padding: 0; display: grid; place-items: center; cursor: pointer; background: var(--line); color: var(--text); }
#sfx-toggle svg { width: 16px; height: 16px; }
#sfx-toggle[aria-pressed="false"] { opacity: .5; }

/* ---------- typography pass: balanced headings, no lone last words, kerning, aligned numbers ---------- */
h1, h2, h3, h4 { text-wrap: balance; font-kerning: normal; }
p, li, dd, figcaption, blockquote { text-wrap: pretty; hanging-punctuation: first; }
body { text-rendering: optimizeLegibility; font-feature-settings: "kern" 1; }
table, time, .num, [data-num] { font-variant-numeric: tabular-nums; }
