/* Book Tree — the site: the stack from lab 15 over the whole window, a settings panel hidden behind a corner button.
   The tree is one SVG in the 1000 × 1250 world (xMidYMid meet — always whole, centred on any screen shape);
   CSS lengths on SVG elements are user units, so 34px below = 34 world units at any size.
   The page colour is --site-bg, set by app.js from the picker; the white gaps of the poster become that colour. */

:root {
  --site-bg: #c8f69f; /* the lime ref (measured); the lavender preset is #969add — both live in app.js PRESETS */
  --site-ink: #0b1517;
  --site-text: var(--site-ink); /* the third colour: the caption and the About block (app.js TEXTS; auto = the books') */ /* the books' colour: plain blocks (design off), the star with them, the words — app.js INKS */
  --site-gutter: var(--s-4);
  --spectrum: linear-gradient(to right, #f00 0%, #ff0 16.66%, #0f0 33.33%, #0ff 50%, #00f 66.66%, #f0f 83.33%, #f00 100%);
  --cp-white: #fff;
  --cp-black: #000;
}

/* Droid 1997 (Ray Larabie, Typodermic, CC0 — fonts/LICENSE-droid-1997.txt): not on Google Fonts, so it ships with the
   site; Latin + full Cyrillic. Used only by the words beside the tree. */
@font-face {
  font-family: 'Droid 1997';
  src: url('fonts/droid-1997.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

html, body { height: 100%; }
body.ui { margin: 0; overflow: hidden; background: var(--site-bg); transition: background-color var(--base) var(--ease); }
/* the page scrolls down when the Tree size runs the scene past the screen; the chrome stays pinned (position: fixed) */
.site { position: fixed; inset: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
/* since the intro text made the page scroll, Chrome treats .site as a keyboard-focusable scroller and a click on the
   background focused it — with the kit's ring around the whole window. It isn't a control: no ring (keys still scroll it) */
.site:focus, .site:focus-visible { outline: none; }

/* ── the tree, full window ── */
.bt {
  position: absolute; inset: var(--site-gutter);
  width: calc(100% - 2 * var(--site-gutter)); height: calc(100% - 2 * var(--site-gutter));
  display: block; overflow: visible;
}

/* no entrance motion: the stack is simply there. Moves: one animation at a time (Look → Animation) — the turns (turn.js,
   each book a prism turning about a vertical axis) or the impulse (pulse.js, the stack re-proportioned pose to pose) —
   plus the hover nudge, the pull-out and the tear. */

.bt-book { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.bt-slide { transition: translate var(--base) var(--ease); }
/* no sideways nudge on hover (Сергей, 2026-11-29): the hovered book stays in its place — it turns spine-left and opens
   instead (app.js / turn.js); only keyboard focus still nudges it out, as the cue for where focus is */
.bt-book:focus-visible .bt-slide { translate: calc(var(--dir) * 34px) 0; }
.bt-book[aria-pressed='true'] .bt-slide { translate: calc(var(--dir) * 150px) 0; }
.bt-book:focus-visible .bt-ring { stroke: var(--x-ink); stroke-width: 5px; }
.bt-book text { pointer-events: none; }

/* edit one book: no nudge, no pull-out; the chosen book stays, the rest step back */
.bt[data-editing] .bt-book .bt-slide { translate: none; }
.bt-book { transition: opacity var(--base) var(--ease), translate 340ms cubic-bezier(0.34, 1.3, 0.64, 1); }
.bt-trunk { transition: translate 340ms cubic-bezier(0.34, 1.3, 0.64, 1); } /* the hover: books part around the one under the cursor (app.js spread) */
.bt[data-editing='pick'] .bt-book:hover { opacity: 0.7; }
.bt[data-editing='book'] .bt-book:not([data-sel]) { opacity: 0.28; }
.bt[data-editing='book'] .bt-book:not([data-sel]):hover { opacity: 0.55; }
/* the palette reveal from the star (app.js revealFromStar): no cross-fade — the new page shows only through the growing
   star mask, the old one stays whole underneath */
:root[data-reveal='two'] .site { view-transition-name: bt-scene; } /* two stars (app.js REVEAL.stars 2): the content, captured apart from the background */
:root[data-reveal]::view-transition-group(*), :root[data-reveal]::view-transition-image-pair(*),
:root[data-reveal]::view-transition-old(*), :root[data-reveal]::view-transition-new(*) { animation: none; mix-blend-mode: normal; }
:root[data-reveal] *, :root[data-reveal] body.ui { transition: none !important; } /* the new page arrives in its colours at once */

/* the hover tease (Сергей, 2026-11-28): hinting at the click — the core (the small inner star) takes the next
   palette's background colour and swells (no turn), as if about to fly out; the whole star leans in a touch */
.bt-star path { transition: transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1), fill 220ms ease; transform-box: view-box; transform-origin: 0 0; }
.bt-star:hover .bt-star-core, .bt-star:focus-visible .bt-star-core { fill: var(--star-next, currentColor) !important; animation: star-tease 1.1s cubic-bezier(0.45, 0, 0.55, 1) 120ms infinite; }
.bt-star:hover .bt-star-ring, .bt-star:focus-visible .bt-star-ring { transform: scale(1.06); }
@keyframes star-tease {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.38); }
  70% { transform: scale(1.22); }
}
@media (prefers-reduced-motion: reduce) { .bt-star:hover .bt-star-core, .bt-star:focus-visible .bt-star-core { animation: none; } .bt-star:hover .bt-star-ring { transform: none; } }
.bt-star { transition: opacity var(--base) var(--ease); cursor: pointer; outline: none; } /* a click = the next palette (app.js) */
.bt-star:focus-visible path { stroke: var(--site-ink); stroke-width: 4; stroke-opacity: 0.35; }
.bt[data-editing='book'] .bt-star, .bt[data-editing='book'] .bt-trunk { opacity: 0.28; }

/* ── gift wrap (gift.js) and the tear ──
   on → tearing → open. The tear, 0.9 s in all, in four beats:
   1. the gift draws a breath (scale 1 → 1.03 → 1, 220 ms), the ribbon slips up and off (280 ms);
   2. a white torn edge appears along the jagged line;
   3. from 150 ms the two halves part outward and drop a little, each turning on its outer end, fading in the last half;
   4. the book underneath breathes in (0.965 → 1 with the kit's small overshoot).
   px on SVG = world units, so the halves travel ~46 units whatever the screen size. */
.gw, .gw-half, .gw-ribbon, .bt-art { transform-box: fill-box; transform-origin: 50% 50%; }
.gw-l { transform-origin: 0% 50%; }
.gw-r { transform-origin: 100% 50%; }
.gw-edge { opacity: 0; }
/* at rest the wrap is one whole sheet; the torn halves take over only while it tears (no hairline along the tear) */
.bt-book:not([data-wrap='tearing']) .gw-paper { display: none; }
.bt-book[data-wrap='tearing'] .gw-whole { display: none; }
.bt-book[data-wrap='open'] .gw { display: none; }
.bt-book[data-wrap='tearing'] { pointer-events: none; }
.bt-book[data-wrap='tearing'] .gw { animation: gw-breath 220ms var(--ease) both; }
.bt-book[data-wrap='tearing'] .gw-edge { opacity: 1; }
.bt-book[data-wrap='tearing'] .gw-ribbon { animation: gw-ribbon 280ms var(--ease) both; }
.bt-book[data-wrap='tearing'] .gw-l { animation: gw-tear-l 680ms var(--ease) 150ms both; }
.bt-book[data-wrap='tearing'] .gw-r { animation: gw-tear-r 680ms var(--ease) 150ms both; }
.bt-book[data-wrap='tearing'] .bt-art { animation: gw-reveal 620ms var(--ease-pop) 260ms both; }
@keyframes gw-breath { 50% { scale: 1.03; } }
@keyframes gw-ribbon { to { translate: 0 -18px; opacity: 0; } }
@keyframes gw-tear-l {
  45% { opacity: 1; }
  to { translate: -46px 10px; rotate: 6deg; opacity: 0; }
}
@keyframes gw-tear-r {
  45% { opacity: 1; }
  to { translate: 46px 10px; rotate: -6deg; opacity: 0; }
}
@keyframes gw-reveal { from { scale: 0.965; } }

/* ── chrome in the corner: full screen + settings ── */
.site-corner {
  position: fixed; z-index: 3;
  top: max(var(--site-gutter), env(safe-area-inset-top)); right: max(var(--site-gutter), env(safe-area-inset-right));
  display: flex; gap: var(--s-3);
}
.site-corner .ui-btn[aria-expanded='true'] { --btn-bg: var(--ink); --btn-fg: var(--bg); --btn-hover: var(--ink); }
.site-ico-close, :root:fullscreen .site-ico-open { display: none; }
:root:fullscreen .site-ico-close { display: block; }

/* ── the panel: a sheet that drops out of the corner ── */
.site-panel {
  position: fixed; z-index: 2;
  top: calc(max(var(--site-gutter), env(safe-area-inset-top)) + var(--h-md) + var(--s-3));
  right: max(var(--site-gutter), env(safe-area-inset-right));
  width: min(340px, calc(100vw - 2 * var(--site-gutter)));
  max-height: calc(100dvh - var(--h-md) - var(--s-3) - 2 * var(--site-gutter));
  overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--s-7);
  transform-origin: top right;
  animation: site-pop var(--base) var(--ease-pop) both;
}
.site-panel[hidden] { display: none; }
@keyframes site-pop { from { opacity: 0; transform: translateY(-6px) scale(0.96); } }
.site-panel-head { align-items: flex-start; }
.site-panel-head .ui-pair { font-size: var(--text-xl); }
.site-group { display: flex; flex-direction: column; gap: var(--s-5); }
.site-row { display: flex; flex-direction: column; gap: var(--s-2); }
.site-row label { font-weight: var(--weight-ui); }
.site-actions { gap: var(--s-3); }
.site-hints { margin: 0; color: var(--muted); }
.site-toggle { align-items: center; font-weight: var(--weight-ui); cursor: pointer; }

/* the two words beside the tree (app.js) — one block per side: text, font, size, distance */
.site-words { display: flex; flex-direction: column; gap: var(--s-6); }
.site-word { display: flex; flex-direction: column; gap: var(--s-4); }
.site-word-head { display: flex; gap: var(--s-3); }
.site-word-head .ui-input { flex: 1 1 0; min-width: 0; }
.site-word-head .ui-select { flex: 0 0 auto; width: 11.5em; }
.bt-words text { pointer-events: none; user-select: none; }
.bt-hang { pointer-events: none; } /* the hanging ornaments: clicks go through to the books… */
.bt-hang .bb-body { pointer-events: auto; cursor: grab; touch-action: none; } /* …except on a bauble, which you can grab */
.bt[data-grab], .bt[data-grab] * { cursor: grabbing; }

/* ── the book editor: a card in the bottom-left corner (empty beside the tree) while you edit one book ── */
.site-editor {
  position: fixed; z-index: 2; left: max(var(--site-gutter), env(safe-area-inset-left)); bottom: max(var(--site-gutter), env(safe-area-inset-bottom));
  width: min(320px, calc(100vw - 2 * var(--site-gutter)));
  display: flex; flex-direction: column; gap: var(--s-5);
  animation: site-up var(--base) var(--ease) both;
}
@keyframes site-up { from { opacity: 0; translate: 0 10px; } }
.site-editor[hidden], .site-editor [hidden] { display: none; }
.site-editor .site-panel-head .ui-pair { font-size: var(--text-lg); }

/* preset swatches carry their colour in --c; a hairline keeps the light ones visible on paper */
.site-presets span { width: var(--h-md); height: var(--h-md); box-shadow: inset 0 0 0 1px var(--sheet-edge); }
.site-presets span[data-auto] { background: linear-gradient(135deg, var(--site-ink) 50%, var(--site-bg) 50%) !important; } /* 'as the books' */
.site-presets input:checked + span { box-shadow: inset 0 0 0 1px var(--sheet-edge), 0 0 0 2px var(--tile), 0 0 0 4px var(--ink); }

/* ── colour picker: saturation × brightness square, hue strip, hex ── */
.cp { display: flex; flex-direction: column; gap: var(--s-4); }
.cp-area {
  --hue: 0;
  position: relative; aspect-ratio: 16 / 10; border-radius: var(--r-md); cursor: crosshair; touch-action: none;
  background:
    linear-gradient(to top, var(--cp-black), transparent),
    linear-gradient(to right, var(--cp-white), rgb(255 255 255 / 0)),
    hsl(var(--hue) 100% 50%);
}
.cp-hue {
  position: relative; height: 14px; border-radius: var(--r-pill); background: var(--spectrum); cursor: pointer; touch-action: none;
}
.cp-dot, .cp-knob {
  position: absolute; width: 18px; height: 18px; border-radius: 50%; pointer-events: none;
  translate: -50% -50%; background: var(--c, transparent);
  box-shadow: 0 0 0 2px var(--cp-white), 0 1px 4px 1px rgb(0 0 0 / 0.25);
}
.cp-knob { top: 50%; }
.cp-area:focus-visible, .cp-hue:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.cp-row { display: flex; align-items: center; gap: var(--s-3); }
#cp-target { align-self: flex-start; }

/* palettes: one swatch per (background, books) pair, split on the diagonal; a click sets both */
.site-pairs { display: flex; flex-wrap: wrap; gap: var(--s-3); }
.site-pairs label { position: relative; cursor: pointer; }
.site-pairs input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.site-pairs span {
  display: block; width: var(--h-md); height: var(--h-md); border-radius: 50%;
  background: linear-gradient(135deg, var(--a) 50%, var(--b) 50%);
  box-shadow: inset 0 0 0 1px var(--sheet-edge);
}
.site-pairs input:checked + span { box-shadow: inset 0 0 0 1px var(--sheet-edge), 0 0 0 2px var(--tile), 0 0 0 4px var(--ink); }
.site-pairs input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 3px; }
.cp-chip { flex: none; width: var(--h-md); height: var(--h-md); border-radius: var(--r-md); background: var(--cp-now, var(--site-bg)); box-shadow: inset 0 0 0 1px var(--sheet-edge); }
.cp-hex { flex: 1; display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.cp-hex .ui-input { flex: 1; min-width: 0; text-transform: uppercase; }
.cp-hex .ui-input[aria-invalid='true'] { box-shadow: inset 0 0 0 1.5px var(--danger); }

/* ── the About text (Сергей, 2026-11-28): a small block about the project in the bottom-right corner, Inter, in the
   books' colour; size, offsets, leading and tracking come from the settings as custom properties (app.js) ── */
.site-foot {
  position: fixed; z-index: 1; pointer-events: none;
  right: max(var(--about-right, 16px), env(safe-area-inset-right)); bottom: max(var(--about-bottom, 16px), env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: flex-end; gap: var(--s-4);
}
.site-about {
  margin: 0;
  max-width: min(32ch, calc(100vw - var(--about-right, 16px) - var(--site-gutter))); /* never past the left edge, whatever the right offset */
  font-family: Inter, 'Helvetica Neue', Arial, sans-serif; font-weight: 400;
  font-size: var(--about-size, 13px); line-height: var(--about-lead, 1.35); letter-spacing: var(--about-track, 0em);
  color: var(--site-text); white-space: pre-line; text-wrap: pretty;
}
.site-about:empty { display: none; }
/* the library button under the About block (Сергей, 2026-11-29): Inter, flat — the text colour as its fill and the page
   colour as its label, so it follows every palette. REMOVED from index.html the same day (the library is reached from
   a book on the tree); the styles stay for a #lib link should it come back */
.site-lib {
  pointer-events: auto; align-self: flex-start; /* left edge on the text block's */
  --btn-bg: var(--site-text); --btn-fg: var(--site-bg); --btn-hover: color-mix(in srgb, var(--site-text) 84%, var(--site-bg));
  font-family: Inter, 'Helvetica Neue', Arial, sans-serif; font-weight: 500;
  /* nothing on it animates (Сергей, 2026-11-29: the wipe blinked again): the kit button's press scale + transitions
     promoted it to its own layer right as the star wipe starts — the same layer churn under the stars' clip-paths that
     made the page flicker on retina before (star-wipe.js). The press shows as a colour step instead. */
  transition: none; will-change: auto;
}
.site-lib:active { transform: none; background: color-mix(in srgb, var(--site-text) 72%, var(--site-bg)); }
.site-lib:focus-visible { outline: 2px solid var(--site-text); outline-offset: 3px; }
/* the tooltip over a book (app.js showTip, Сергей 2026-11-29): the library button's chip — text colour fill, page colour
   type, Inter, the kit's button radius; flat, no shadow, no motion. The date on top, softer; the title under it. Placed
   by app.js (translate, following the cursor). */
.site-tip {
  position: fixed; left: 0; top: 0; z-index: 3; pointer-events: none;
  display: flex; flex-direction: column; gap: 1px;
  width: max-content; max-width: min(28ch, calc(100vw - 24px));
  padding: 7px 12px 8px; border-radius: var(--r-md);
  background: var(--site-text); color: var(--site-bg);
  /* a page-coloured rim, like the gaps between the books: the chip is the books' colour and would melt into the book
     under it otherwise */
  outline: 2px solid var(--site-bg);
  font-family: Inter, 'Helvetica Neue', Arial, sans-serif; font-size: 13px; line-height: 1.3; text-wrap: balance;
}
.site-tip[hidden] { display: none; }
.site-tip-date { font-weight: 400; color: color-mix(in srgb, var(--site-bg) 70%, var(--site-text)); }
.site-tip-title { font-weight: 500; }
.site-tip-date:only-child { color: inherit; font-weight: 500; } /* a closed book: the date alone, at full strength */
.site-about-input { min-height: 88px; resize: vertical; font-family: Inter, 'Helvetica Neue', Arial, sans-serif; }

/* ── the reader (Сергей, 2026-11-28): the traced line drawing in the bottom-left corner, same inset as the About block;
   width from the settings (--reader-w, app.js), never wider than 60% of a phone; lines in the third colour, the
   insides open to the page ── */
.site-reader {
  position: fixed; z-index: 1; pointer-events: none;
  left: max(16px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom));
  width: min(var(--reader-w, 300px), 60vw); height: auto;
  color: var(--site-text);
}

/* ── the pulled-out book: a dark chip at the bottom ── */
.site-note {
  position: fixed; z-index: 1; left: 50%; bottom: max(var(--site-gutter), env(safe-area-inset-bottom));
  translate: -50% 0; width: max-content; max-width: min(52ch, calc(100vw - 2 * var(--site-gutter)));
  padding: var(--s-4) var(--s-6); border-radius: var(--r-lg);
  background: var(--chrome); color: var(--on-chrome); box-shadow: var(--shadow-float);
  display: grid; gap: var(--s-2); text-align: center;
  animation: site-rise var(--base) var(--ease) both;
}
.site-note[hidden] { display: none; }
.site-note .ui-pair { font-size: var(--text-lg); }
.site-note .ui-pair > :first-child { color: var(--on-chrome-muted); }
.site-note .ui-pair > :not(:first-child) { color: var(--on-chrome); }
.site-note p { margin: 0; font-size: var(--text-sm); color: var(--on-chrome-muted); }
@keyframes site-rise { from { opacity: 0; translate: -50% 10px; } }

@media (max-width: 600px) {
  :root { --site-gutter: var(--s-3); }
  .site-panel { gap: var(--s-6); }
}

@media (prefers-reduced-motion: reduce) {
  .site-panel, .site-note, .site-editor, .bt-book[data-wrap='tearing'] * { animation: none !important; }
  body { transition: none; }
}

/* phones: the reader (left) and the About text (right) share the bottom edge — each keeps to its own half */
@media (max-width: 600px) {
  .site-reader { width: min(var(--reader-w, 300px), 42vw); }
  .site-about { max-width: calc(50vw - 24px); }
}

/* cross-document view transition (Сергей, 2026-11-29): between the tree and the library the browser keeps the old page's
   last frame until the new one has rendered and crossfades them — the star wipe's last frame and the library are the
   same picture, so the swap cannot blink (star-wipe.js). Browsers without it simply navigate. */
@view-transition { navigation: auto; }

/* ── the intro under the tree (Сергей, 2026-11-29): Alina's letter, very large, edge to edge (the page gutter only),
   in the third colour. It starts where the tree ends (--tree-h from intro.js, which follows Tree size). Every word is
   a mask (.iw) its inner span rises out of — expo-out, staggered by intro.js through --d. Flat: no blur, no glow. ── */
.site-intro {
  position: relative;
  margin-top: calc(var(--tree-h, calc(100dvh - 2 * var(--site-gutter))) + 2 * var(--site-gutter));
  /* the bottom leaves room for the reader drawing that comes back into the corner at the end (--reader-h, intro.js) */
  padding: clamp(48px, 10vh, 160px) var(--site-gutter) max(24vh, calc(var(--reader-h, 200px) + 96px));
  color: var(--site-text);
  font-family: Inter, 'Helvetica Neue', Arial, sans-serif; font-weight: 500;
  font-size: clamp(32px, 6.2vw, 150px); line-height: 1.04; letter-spacing: -0.04em;
  font-feature-settings: 'ss01' on; /* Inter's open digits: calmer at display size */
  hyphens: manual; overflow-wrap: break-word;
}
.site-intro p { margin: 0; }
.site-intro p + p { margin-top: 0.62em; }
.site-intro-vis p { text-wrap: pretty; }
.site-intro .iw {
  display: inline-block; overflow: clip; vertical-align: baseline;
  /* room for Cyrillic breves and descenders inside the mask, given back by the margins so the lines don't move */
  padding: 0.1em 0.04em 0.16em; margin: -0.1em -0.04em -0.16em;
}
.site-intro .iw > span {
  display: inline-block;
  transform: translate3d(0, 108%, 0) rotate(3deg); transform-origin: 0 100%; opacity: 0;
  transition: transform 1000ms cubic-bezier(0.16, 1, 0.3, 1) var(--d, 0ms), opacity 520ms cubic-bezier(0.33, 1, 0.68, 1) var(--d, 0ms);
}
.site-intro .iw.is-in > span { transform: none; opacity: 1; }
/* scrolling back up: the words sink faster than they rose */
.site-intro .iw:not(.is-in) > span { transition-duration: 520ms, 300ms; transition-timing-function: cubic-bezier(0.7, 0, 0.84, 0), ease-in; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* the pinned corner pieces step aside once the page leaves the tree (intro.js sets --scrolled 0 → 1 on .site); the
   reader sinks out of its corner as it fades, and at the very end of the page (.is-end) drives back in — expo-out,
   like the words */
.site-foot { opacity: calc(1 - var(--scrolled, 0)); }
.site-reader {
  opacity: calc(1 - var(--scrolled, 0)); translate: 0 calc(var(--scrolled, 0) * 60%);
  transition: opacity 360ms cubic-bezier(0.33, 1, 0.68, 1), translate 420ms cubic-bezier(0.7, 0, 0.84, 0);
}
/* the first screen (.is-top, intro.js): the reader is a way into the text — a pointer, a tooltip, a click scrolls down */
.site.is-top:not(.is-end) .site-reader { pointer-events: auto; cursor: pointer; }
.site-reader:focus-visible { outline: 2px solid var(--site-text); outline-offset: 6px; border-radius: var(--r-md); }
#reader-tip { z-index: 2; }
.site.is-end .site-reader {
  opacity: 1; translate: 0 0;
  transition: opacity 600ms cubic-bezier(0.33, 1, 0.68, 1), translate 1100ms cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-reduced-motion: reduce) {
  .site-intro .iw > span { transform: none; opacity: 1; transition: none; }
  .site-reader, .site.is-end .site-reader { translate: none; transition: none; }
}
