/* Library motion in the onboarding — SPEC-ONBOARDING-MOTION-2026-10
   (PLAN-LIBRARY-TEAM-AND-PARITY §B). Loaded by _kai_onboarding_shell.html only
   under the Reading Room theme; driven by static/js/kai/motion.js.

   Rules (each has a test in tests/test_onboarding_motion.py):
   1. Every rule starts with html.rr-theme — flag off, nothing here applies.
   2. prefers-reduced-motion: reduce turns every animation and transition off
      and shows the end state.
   3. Only transform and opacity animate (clip-path for rrRise and rrWrite).
   4. Transitions ≤ 450 ms; loops run only while we are working.
   5. No new words; colours are --rr-* tokens, radii var(--rr-radius-*). */

/* ── 1 · the page turn (direction from [data-nav] on the shell) ───────── */
html.rr-theme .kai-backdrop { overflow-x: clip; }
html.rr-theme .kai-panel { transform-origin: 0 50%; backface-visibility: hidden; }
html.rr-theme [data-nav="fwd"] .kai-panel-exit { animation: rrLeaveF .28s cubic-bezier(.4, 0, 1, 1) both; }
html.rr-theme [data-nav="fwd"] .kai-panel-enter { animation: rrEnterF .42s cubic-bezier(.2, .7, .2, 1) both; }
html.rr-theme [data-nav="back"] .kai-panel-exit { animation: rrLeaveB .28s cubic-bezier(.4, 0, 1, 1) both; }
html.rr-theme [data-nav="back"] .kai-panel-enter { animation: rrEnterB .42s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rrLeaveF { to { transform: perspective(1400px) rotateY(-9deg) translateX(-22px); opacity: 0; } }
@keyframes rrEnterF { from { transform: perspective(1400px) rotateY(6deg) translateX(26px); opacity: 0; } }
@keyframes rrLeaveB { to { transform: perspective(1400px) rotateY(6deg) translateX(26px); opacity: 0; } }
@keyframes rrEnterB { from { transform: perspective(1400px) rotateY(-9deg) translateX(-22px); opacity: 0; } }

/* ── 2 · the lamp-lit desk ─────────────────────────────────────────────── */
html.rr-theme .rr-desk { display: block; width: 100%; max-width: 340px; height: auto; margin: 6px auto 16px; --lit: 0; }
html.rr-theme .rr-desk .d-wall { fill: var(--rr-paper-sunken); }
html.rr-theme .rr-desk .d-shelf { stroke: var(--rr-rule-strong); stroke-width: 2; }
html.rr-theme .rr-desk .d-spine { fill: var(--rr-ink-3); opacity: .5; }
html.rr-theme .rr-desk .d-spine.acc { fill: var(--rr-accent); opacity: .9; }
html.rr-theme .rr-desk .d-ink { fill: var(--rr-ink); }
html.rr-theme .rr-desk .d-ink2 { fill: var(--rr-ink-2); }
html.rr-theme .rr-desk .d-fix { fill: var(--rr-accent); }
html.rr-theme .rr-desk .d-cone { fill: var(--rr-lamp); opacity: calc(var(--lit, 0) * .55); transition: opacity .3s ease; }
html.rr-theme .rr-desk .d-bulb { fill: var(--rr-lamp); opacity: var(--lit, 0); transition: opacity .3s ease; }
html.rr-theme .rr-desk .d-glow { fill: var(--rr-lamp); opacity: calc(var(--lit, 0) * .35); transition: opacity .3s ease; }
html.rr-theme .rr-desk .d-paper { fill: var(--rr-paper-raised); stroke: var(--rr-ink-3); stroke-width: .6; }
html.rr-theme .rr-desk .d-drawer { fill: var(--rr-ink-2); }
html.rr-theme .rr-desk .d-pull { stroke: var(--rr-gold); stroke-width: 2; }
html.rr-theme .rr-desk .d-card { fill: var(--rr-paper-raised); stroke: var(--rr-ink-3); stroke-width: .6; opacity: 0; }
html.rr-theme .rr-desk .d-card.drop { animation: rrCardDrop .6s ease-in-out both; }
html.rr-theme .rr-desk .d-arm { transform-box: fill-box; transform-origin: top left; }
html.rr-theme .rr-desk .writing .d-arm { animation: rrArm .35s ease-in-out infinite alternate; }
html.rr-theme .rr-desk .d-drawerg { transform-box: fill-box; }
html.rr-theme .rr-desk .d-drawerg.pulse { animation: rrDrawer .6s ease-in-out; }
@keyframes rrCardDrop {
  0% { opacity: 0; transform: translateY(-14px); }
  35% { opacity: 1; transform: translateY(-8px); }
  75% { opacity: 1; transform: translateY(4px); }
  100% { opacity: 0; transform: translateY(10px); }
}
@keyframes rrArm { from { transform: rotate(0); } to { transform: rotate(-15deg) translateY(-2px); } }
@keyframes rrDrawer { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(4px); } }
/* the desk on the discovery panel shows only while its progress list does */
html.rr-theme .rr-desk-disc[hidden] { display: none; }

/* ── 3 · results out of the drawer ─────────────────────────────────────── */
html.rr-theme #discResults { position: relative; }
html.rr-theme #discResults:not(:empty) { padding-bottom: 16px; }
html.rr-theme #discResults:not(:empty)::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 10px;
  border-radius: var(--rr-radius-stamp); background: var(--rr-ink-2);
}
html.rr-theme .rr-rise { animation: rrRise .38s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rrRise {
  from { transform: translateY(18px); opacity: 0; clip-path: inset(0 0 60% 0); }
  to { transform: none; opacity: 1; clip-path: inset(0 0 0 0); }
}
html.rr-theme .disc-card, html.rr-theme .disc-link-row { transition: opacity .25s ease; }
html.rr-theme .disc-card:not(.is-selected), html.rr-theme .disc-link-row:not(.is-selected) { opacity: .55; }

/* ── 4 · the small shelf in the top bar ────────────────────────────────── */
html.rr-theme .rr-shelf {
  display: inline-flex; align-items: flex-end; gap: 2px; height: 30px; min-width: 12px;
  padding: 0 4px 3px; border-bottom: 2px solid var(--rr-ink-2);
}
html.rr-theme .rr-shelf[hidden] { display: none; }
html.rr-theme .rr-sp {
  display: block; width: 6px; flex: none; background: var(--rr-ink-2);
  border-radius: var(--rr-radius-stamp) var(--rr-radius-stamp) var(--rr-radius-none) var(--rr-radius-none);
}
html.rr-theme .rr-sp.acc { background: var(--rr-accent); }
html.rr-theme .rr-sp.gold { background: var(--rr-gold); }
html.rr-theme .rr-sp.rr-drop { animation: rrSpDrop .36s cubic-bezier(.2, .7, .2, 1) both; }
html.rr-theme .rr-more { align-self: center; margin-left: 3px; font-family: var(--rr-font-mono); font-size: .68rem; color: var(--rr-ink-3); }
html.rr-theme .kai-topbar-count { font-family: var(--rr-font-mono); font-size: .74rem; font-variant-numeric: tabular-nums; }
@keyframes rrSpDrop {
  from { transform: translateY(-18px); opacity: 0; }
  70% { transform: translateY(1px); opacity: 1; }
  to { transform: none; opacity: 1; }
}

/* ── 5 · the catalogue card (organize "Draft them for me") ─────────────── */
html.rr-theme #kaiOrganizeModal .disc-import-bar { display: none; }
html.rr-theme .rr-catcard {
  margin-top: 14px; padding: 14px 16px; text-align: left;
  background: var(--rr-paper-sunken); border: 1px solid var(--rr-rule-strong); border-radius: var(--rr-radius-media);
}
html.rr-theme .rr-catcard-h {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding-bottom: 6px; margin-bottom: 10px; border-bottom: 1px solid var(--rr-stamp-received);
  font-family: var(--rr-font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--rr-ink-3);
}
html.rr-theme .rr-catcard-title { display: inline-block; margin: 0 0 8px; font-family: var(--rr-font-display); font-size: 1.1rem; color: var(--rr-ink); }
html.rr-theme .rr-catcard-title.rr-write { animation: rrWrite .8s ease-out both; }
html.rr-theme .rr-cattabs { display: grid; gap: 4px; max-height: 40vh; overflow-y: auto; }
html.rr-theme .rr-cattab {
  display: grid; grid-template-columns: auto 1fr auto; gap: 2px 9px; align-items: center;
  padding: 6px 8px; border-bottom: 1px dashed var(--rr-rule); font-size: .86rem; color: var(--rr-ink);
}
html.rr-theme .rr-cattab svg { width: 16px; height: 16px; color: var(--rr-accent); }
html.rr-theme .rr-cattab-n { font-family: var(--rr-font-mono); font-size: .72rem; color: var(--rr-ink-3); }
html.rr-theme .rr-cattab-sub { grid-column: 2 / -1; font-size: .74rem; color: var(--rr-ink-3); }
html.rr-theme .rr-cattab.rr-tabin { animation: rrTabIn .32s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rrWrite { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes rrTabIn { from { transform: translateX(-10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── 6 · publish: the shelf is set, and stamped open ───────────────────── */
html.rr-theme .rr-pub {
  position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: color-mix(in srgb, var(--rr-paper) 85%, transparent);
}
html.rr-theme .rr-pub[hidden] { display: none; }
html.rr-theme .rr-pub-card {
  width: min(460px, 100%); padding: 22px 22px 18px;
  background: var(--rr-paper-raised); border: 1px solid var(--rr-rule-strong); border-radius: var(--rr-radius-card);
}
html.rr-theme .rr-pub-h { margin: 0 0 6px; font-family: var(--rr-font-display); font-weight: 500; font-size: 1.4rem; color: var(--rr-ink); }
html.rr-theme .rr-pub-shelf { position: relative; height: 196px; }
html.rr-theme .rr-pub-plank { position: absolute; left: 0; right: 0; bottom: 18px; height: 10px; border-radius: var(--rr-radius-stamp); background: var(--rr-ink-2); }
html.rr-theme .rr-pub-covers { position: absolute; left: 6%; bottom: 28px; display: flex; gap: 12px; align-items: flex-end; }
html.rr-theme .rr-cover {
  width: 92px; height: 132px; padding: 8px; display: flex; flex-direction: column; justify-content: space-between;
  background: var(--rr-paper); border: 1px solid var(--rr-rule-strong);
  border-radius: var(--rr-radius-stamp) var(--rr-radius-media) var(--rr-radius-media) var(--rr-radius-stamp);
  box-shadow: inset 6px 0 0 var(--rr-accent); overflow: hidden;
}
html.rr-theme .rr-cover:nth-child(2) { height: 120px; box-shadow: inset 6px 0 0 var(--rr-gold); }
html.rr-theme .rr-cover:nth-child(3) { height: 126px; box-shadow: inset 6px 0 0 var(--rr-ink-2); }
html.rr-theme .rr-cover b { padding-left: 6px; font-family: var(--rr-font-display); font-weight: 500; font-size: .78rem; line-height: 1.15; color: var(--rr-ink); overflow-wrap: break-word; hyphens: auto; }
html.rr-theme .rr-cover small { padding-left: 6px; font-family: var(--rr-font-mono); font-size: .62rem; color: var(--rr-ink-3); }
html.rr-theme .rr-cover.rr-slidein { animation: rrSlideIn .5s cubic-bezier(.2, .7, .2, 1) both; }
html.rr-theme .rr-stamp {
  position: absolute; right: 8%; top: 22px; padding: .2rem .6rem .2rem .8rem;
  font-family: var(--rr-font-mono); font-weight: 500; font-size: 1.05rem; letter-spacing: .2em; color: var(--rr-stamp-received);
  border: 2px solid var(--rr-stamp-received); border-radius: var(--rr-radius-stamp);
  transform: rotate(-2deg); opacity: .88;
}
html.rr-theme .rr-stamp.rr-land { animation: rrLand .42s cubic-bezier(.3, 1.4, .5, 1) both; }
@keyframes rrSlideIn { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rrLand { from { transform: rotate(-2deg) scale(1.25); opacity: 0; } to { transform: rotate(-2deg) scale(1); opacity: .88; } }
@media (max-width: 560px) {
  html.rr-theme .rr-cover { width: 76px; height: 112px; }
  html.rr-theme .rr-cover:nth-child(2) { height: 102px; }
  html.rr-theme .rr-cover:nth-child(3) { height: 106px; }
  html.rr-theme .rr-stamp { right: 4%; }
}

/* ── reduced motion: nothing moves; the end state shows ────────────────── */
@media (prefers-reduced-motion: reduce) {
  html.rr-theme [data-nav] .kai-panel-exit, html.rr-theme [data-nav] .kai-panel-enter,
  html.rr-theme .rr-desk .d-card, html.rr-theme .rr-desk .writing .d-arm, html.rr-theme .rr-desk .d-drawerg,
  html.rr-theme .rr-rise, html.rr-theme .rr-sp, html.rr-theme .rr-catcard-title, html.rr-theme .rr-cattab,
  html.rr-theme .rr-cover, html.rr-theme .rr-stamp { animation: none; }
  html.rr-theme .rr-desk .d-cone, html.rr-theme .rr-desk .d-bulb, html.rr-theme .rr-desk .d-glow,
  html.rr-theme .disc-card, html.rr-theme .disc-link-row { transition: none; }
}

/* ── the stage (Ramy 2026-10-03) ────────────────────────────────────────
   Desktop: the reading room on the left, pinned, the wizard on the right —
   what is happening shows without scrolling. One desk for the whole flow
   (kai/_desk_vignette.html, lit by motion.js) and a line saying what it is
   doing. Below 1024 px there is no stage; below 900 px no animation at all. */
html.rr-theme .rr-stage { display: none; }
@media (min-width: 1024px) {
  html.rr-theme .rr-stage {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: fixed; left: 0; top: 0; bottom: 0; width: min(36vw, 560px);
    padding: 88px 32px 32px; background: var(--rr-paper-sunken);
    border-right: 1px solid var(--rr-rule); z-index: 1;
  }
  html.rr-theme .rr-stage .rr-desk { max-width: 420px; margin: 0; }
  html.rr-theme .rr-stage-cap {
    margin: 18px 0 0; max-width: 34ch; text-align: center; text-wrap: balance;
    font-family: var(--rr-font-display); font-size: 1.05rem; line-height: 1.4; color: var(--rr-ink-2);
  }
  html.rr-theme .kai-backdrop > .kai-panel,
  html.rr-theme .kai-backdrop > .kai-resume-card { margin-left: min(36vw, 560px); }
}
@media (max-width: 899px) {
  html.rr-theme .rr-stage, html.rr-theme .rr-shelf, html.rr-theme .rr-pub { display: none !important; }
  html.rr-theme [data-nav] .kai-panel-exit, html.rr-theme [data-nav] .kai-panel-enter,
  html.rr-theme .rr-rise, html.rr-theme .rr-catcard-title.rr-write, html.rr-theme .rr-cattab.rr-tabin { animation: none; }
}
