/* ==========================================================================
   simple-demos.css: the four looping demo drawings on index.html.

   Modelled on zotero.org's "Collect with a click" drawings: a grey,
   line-drawn window with only the words the eye should land on, and a
   cursor that does ONE thing per loop.

   - .sl-demo--search  query -> databases light up -> results -> Add AI
                       column -> criteria typed -> Create -> Yes/No fill
                       -> star one (one cursor for the whole loop)
   - .sl-demo--cols    click "Add AI column" -> cells fill row by row
   - .sl-demo--chat    question -> answer -> click its source -> sentence
                       highlighted in the PDF
   - .sl-demo--write   Cite -> search the library -> pick -> superscript
                       and reference list entry appear

   Rules that keep this maintainable:
   - BASE styles are the FINAL frame. Keyframes start hidden and end
     visible, so with reduced motion (animation: none) every drawing simply
     shows its finished state.
   - Each drawing has ONE loop length (--loop) and every animated part of
     it uses that length, so the parts stay in step. Timing lives in the
     keyframe percentages.
   - The cursor sits INSIDE the element it clicks, so it lands on target
     whatever the text wrapping or screen width.
   - Paused until on screen: index.html adds .js-demos to <html> and
     .is-playing to a drawing while it is visible.
   - Colour: grey everywhere; violet only on the one thing that is the
     point (the AI mark, the saved state, the source number). The yellow
     PDF highlight is a datum, so it is exempt.
   ========================================================================== */

/* --- Rows: text on one side, drawing on the other -------------------- */
.sl-rows { max-width: 1080px; margin: 72px auto 0; display: grid; gap: 112px; }
.sl-row { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 64px; align-items: center; }
/* Alternate sides by mirroring the columns too, so every drawing gets the
   same (wider) column and all four windows come out the same width. */
.sl-row:nth-child(even) { grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr); }
.sl-row:nth-child(even) .sl-row-text { order: 2; }
.sl-row-text svg { width: 28px; height: 28px; color: var(--violet); }
.sl-row-text h3 { font-size: clamp(30px, 3.4vw, 42px); line-height: 1.12; margin: 16px 0 16px; }
.sl-row-text p { font-size: 18px; line-height: 1.65; color: var(--ink-2); }
.sl-grid--rest { margin-top: 120px; }

/* --- Shared drawing frame ------------------------------------------- */
.sl-demo {
  position: relative; margin: 0; height: 440px; overflow: hidden; display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  box-shadow: 0 1px 2px rgb(17 24 39 / 0.04), 0 28px 56px -32px rgb(17 24 39 / 0.3);
  font-size: 13.5px; line-height: 1.45; color: var(--ink-2); text-align: start;
}
.d-bar { flex: none; height: 34px; display: flex; align-items: center; gap: 7px; padding: 0 14px;
  background: var(--paper-band); border-bottom: 1px solid var(--line); }
.d-bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.d-body { padding: 20px; }
.sk { display: block; height: 8px; border-radius: 4px; background: var(--line-soft); }
:root[data-theme="dark"] .sk { background: var(--line); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sk { background: var(--line); } }

/* The cursor: tip at the centre of its (position: relative) target. */
.d-cursor { position: absolute; left: 50%; top: 50%; width: 18px; height: 22px; z-index: 3;
  pointer-events: none; transform-origin: 0 0; filter: drop-shadow(0 1px 1.5px rgb(0 0 0 / 0.3)); }
.d-cursor path { fill: var(--ink); stroke: var(--card); stroke-width: 1.5; stroke-linejoin: round; }

/* --- 1. Search: one query, many databases, screened by an AI column -- */
/* Loop (14s): type the query -> databases light up -> results arrive ->
   ONE cursor clicks "Add AI column" -> the dialog opens and the criteria
   are typed -> the cursor clicks "Create column" -> each result gets its
   Yes/No -> the cursor stars the first result.
   The cursor lives on the figure and moves by left/top between measured
   waypoints (the window is a fixed 440px tall on desktop, so they hold).
   On phones the layout reflows, so the cursor is hidden there and the rest
   still plays. */
.sl-demo--search { --loop: 14s; }
.ds-field { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 9px; color: var(--ink); font-size: 14.5px; }
.ds-field svg { width: 16px; height: 16px; color: var(--ink-3); flex: none; }
.ds-q { white-space: nowrap; animation: ds-type var(--loop) steps(22) infinite; }
@keyframes ds-type { 0%, 2% { clip-path: inset(0 100% 0 0); } 12%, 96% { clip-path: inset(0 0 0 0); } 100% { clip-path: inset(0 100% 0 0); } }

.ds-src { list-style: none; padding: 0; margin: 10px 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.ds-src li { font-size: 12px; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--ink-2); }
.ds-src li:nth-child(1) { animation: ds-s1 var(--loop) infinite; }
.ds-src li:nth-child(2) { animation: ds-s2 var(--loop) infinite; }
.ds-src li:nth-child(3) { animation: ds-s3 var(--loop) infinite; }
.ds-src li:nth-child(4) { animation: ds-s4 var(--loop) infinite; }
.ds-src li:nth-child(5) { animation: ds-s5 var(--loop) infinite; }
@keyframes ds-s1 { 0%, 13% { opacity: 0.3; } 14%, 96% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes ds-s2 { 0%, 15% { opacity: 0.3; } 16%, 96% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes ds-s3 { 0%, 17% { opacity: 0.3; } 18%, 96% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes ds-s4 { 0%, 19% { opacity: 0.3; } 20%, 96% { opacity: 1; } 100% { opacity: 0.3; } }
@keyframes ds-s5 { 0%, 21% { opacity: 0.3; } 22%, 96% { opacity: 1; } 100% { opacity: 0.3; } }

/* Results: a small table. Columns: paper | AI answer | save. */
.ds-tool { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-3); }
.ds-btn { font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap;
  padding: 5px 11px; border: 1px solid var(--line); border-radius: 8px; animation: ds-press var(--loop) infinite; }
@keyframes ds-press { 0%, 37% { background: transparent; } 38%, 41% { background: var(--line-soft); } 43%, 100% { background: transparent; } }
.ds-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px 26px; gap: 12px; align-items: center; }
.ds-hrow { padding: 0 12px 6px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.ds-colh { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; animation: ds-colh var(--loop) infinite; }
.ds-colh svg { width: 13px; height: 13px; color: var(--violet); }
@keyframes ds-colh { 0%, 60% { opacity: 0; transform: translateX(10px); } 63%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.ds-res { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ds-res li { position: relative; padding: 7px 12px; border: 1px solid var(--line-soft); border-radius: 8px; }
.ds-res li > span:first-child { display: grid; gap: 6px; min-width: 0; }
.ds-res b { font-weight: 600; color: var(--ink); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ds-res li:nth-child(1) { animation: ds-r1 var(--loop) infinite; }
.ds-res li:nth-child(2) { animation: ds-r2 var(--loop) infinite; }
.ds-res li:nth-child(3) { animation: ds-r3 var(--loop) infinite; }
.ds-res li:nth-child(4) { animation: ds-r4 var(--loop) infinite; }
@keyframes ds-r1 { 0%, 22% { opacity: 0; transform: translateY(8px); } 24%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes ds-r2 { 0%, 24% { opacity: 0; transform: translateY(8px); } 26%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes ds-r3 { 0%, 26% { opacity: 0; transform: translateY(8px); } 28%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }
@keyframes ds-r4 { 0%, 28% { opacity: 0; transform: translateY(8px); } 30%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* The AI column dialog: opens under the button, the criteria type in,
   "Create column" is pressed, and it closes. Base = closed (final frame). */
.ds-pop {
  position: absolute; z-index: 4; inset-inline-end: 20px; top: 178px; width: 300px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 18px 40px -16px rgb(17 24 39 / 0.35); opacity: 0; pointer-events: none;
  animation: ds-pop var(--loop) infinite;
}
@keyframes ds-pop { 0%, 41% { opacity: 0; transform: translateY(-4px); } 43%, 59% { opacity: 1; transform: none; } 62%, 100% { opacity: 0; transform: translateY(-4px); } }
.ds-pop-type { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--ink);
  padding: 2px 8px; border-radius: 6px; background: var(--line-soft); }
.ds-pop-type svg { width: 11px; height: 11px; }
.ds-pop-q { margin: 8px 0 10px; min-height: 36px; font-size: 12.5px; line-height: 1.45; color: var(--ink); }
.ds-pop-q span { display: block; animation: ds-pop-type var(--loop) steps(6) infinite; }
@keyframes ds-pop-type { 0%, 44% { clip-path: inset(0 0 100% 0); } 54%, 100% { clip-path: inset(0 0 0 0); } }
.ds-pop-foot { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); }
.ds-pop-go { font-size: 12px; font-weight: 600; color: #fff; background: var(--violet); padding: 4px 10px; border-radius: 7px;
  animation: ds-go var(--loop) infinite; }
@keyframes ds-go { 0%, 57% { filter: none; } 58%, 60% { filter: brightness(0.85); } 61%, 100% { filter: none; } }

/* The AI answer cell: a pulsing bar while it reads, then the pill. The
   pill colours are the value itself (yes/no cells are exempt from the
   one-accent rule), matching the app's Yes/No column. */
.ds-ai { position: relative; height: 22px; display: flex; align-items: center; }
.ds-ai .sk { position: absolute; inset-inline-start: 0; width: 64px; opacity: 0; }
.ds-pill { font-style: normal; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 6px; }
.ds-pill--yes { color: var(--yes); background: color-mix(in srgb, var(--yes) 14%, transparent); }
.ds-pill--no { color: var(--pdf); background: color-mix(in srgb, var(--pdf) 12%, transparent); }
.ds-res li:nth-child(1) .ds-ai .sk { animation: ds-k1 var(--loop) infinite; }
.ds-res li:nth-child(2) .ds-ai .sk { animation: ds-k2 var(--loop) infinite; }
.ds-res li:nth-child(3) .ds-ai .sk { animation: ds-k3 var(--loop) infinite; }
.ds-res li:nth-child(4) .ds-ai .sk { animation: ds-k4 var(--loop) infinite; }
.ds-res li:nth-child(1) .ds-pill { animation: ds-v1 var(--loop) infinite; }
.ds-res li:nth-child(2) .ds-pill { animation: ds-v2 var(--loop) infinite; }
.ds-res li:nth-child(3) .ds-pill { animation: ds-v3 var(--loop) infinite; }
.ds-res li:nth-child(4) .ds-pill { animation: ds-v4 var(--loop) infinite; }
@keyframes ds-k1 { 0%, 61% { opacity: 0; } 62%, 64% { opacity: 1; } 65%, 100% { opacity: 0; } }
@keyframes ds-k2 { 0%, 61% { opacity: 0; } 62%, 67% { opacity: 1; } 68%, 100% { opacity: 0; } }
@keyframes ds-k3 { 0%, 61% { opacity: 0; } 62%, 70% { opacity: 1; } 71%, 100% { opacity: 0; } }
@keyframes ds-k4 { 0%, 61% { opacity: 0; } 62%, 73% { opacity: 1; } 74%, 100% { opacity: 0; } }
@keyframes ds-v1 { 0%, 64% { opacity: 0; } 65%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes ds-v2 { 0%, 67% { opacity: 0; } 68%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes ds-v3 { 0%, 70% { opacity: 0; } 71%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes ds-v4 { 0%, 73% { opacity: 0; } 74%, 96% { opacity: 1; } 100% { opacity: 0; } }

/* The favourite star, the app's own (AgGridTable's fav cell): grey outline
   until the click, then filled amber. No box around it, as in the app. */
.ds-fav { width: 26px; height: 26px; display: grid; place-items: center; color: var(--ink-4); }
.ds-fav svg { grid-area: 1 / 1; width: 16px; height: 16px; }
.ds-star-full { color: #f59e0b; }
.ds-res li:first-child .ds-star-empty { animation: ds-plus var(--loop) infinite; }
.ds-res li:first-child .ds-star-full { animation: ds-tick var(--loop) infinite; }
.ds-res li:not(:first-child) .ds-star-full, .ds-res li:first-child .ds-star-empty { opacity: 0; }
@keyframes ds-plus { 0%, 82% { opacity: 1; } 83%, 100% { opacity: 0; } }
@keyframes ds-tick { 0%, 82% { opacity: 0; transform: scale(0.6); } 84% { opacity: 1; transform: scale(1.15); } 86%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* The one cursor. Waypoints are the measured centres of: the Add AI column
   button (A), the dialog's Create column button (C), the first result's
   favourite star (S); left/top are the cursor's tip. */
.ds-cursor { left: var(--ax); top: var(--ay); transform: none; animation: ds-cur var(--loop) infinite; }
/* Measured at 543-559px wide: x from the right edge, y from the top. */
.sl-demo--search { --ax: calc(100% - 76px); --ay: 155px; --cx: calc(100% - 85px); --cy: 274px; --sx: calc(100% - 47px); --sy: 234px; }
@keyframes ds-cur {
  0%, 30% { opacity: 0; left: calc(var(--ax) - 160px); top: calc(var(--ay) + 140px); }
  32% { opacity: 1; left: calc(var(--ax) - 150px); top: calc(var(--ay) + 130px); }
  37% { left: var(--ax); top: var(--ay); transform: none; }
  38.5% { left: var(--ax); top: var(--ay); transform: scale(0.82); }
  40% { left: var(--ax); top: var(--ay); transform: none; }
  45% { left: var(--ax); top: var(--ay); }
  56% { left: var(--cx); top: var(--cy); transform: none; }
  58% { left: var(--cx); top: var(--cy); transform: scale(0.82); }
  60% { left: var(--cx); top: var(--cy); transform: none; }
  76% { left: var(--cx); top: var(--cy); }
  81% { left: var(--sx); top: var(--sy); transform: none; }
  82% { left: var(--sx); top: var(--sy); transform: scale(0.82); }
  83.5%, 90% { opacity: 1; left: var(--sx); top: var(--sy); transform: none; }
  94%, 100% { opacity: 0; left: var(--sx); top: var(--sy); }
}

/* --- 2. AI columns: ask once, answered for every paper -------------- */
.sl-demo--cols { --loop: 8s; }
.dc-tool { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dc-tool strong { color: var(--ink); font-size: 14px; }
.dc-btn { position: relative; font-size: 12.5px; font-weight: 600; color: var(--ink); white-space: nowrap;
  padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; animation: dc-press var(--loop) infinite; }
@keyframes dc-press { 0%, 12% { background: transparent; } 13%, 16% { background: var(--line-soft); } 18%, 100% { background: transparent; } }
.dc-btn .d-cursor { animation: dc-cur var(--loop) infinite; }
@keyframes dc-cur {
  0%, 2% { opacity: 0; transform: translate(-160px, 120px); }
  5% { opacity: 1; }
  11% { transform: translate(0, 0); }
  13% { transform: translate(0, 0) scale(0.82); }
  15%, 20% { opacity: 1; transform: translate(0, 0) scale(1); }
  26%, 100% { opacity: 0; transform: translate(-40px, 70px); }
}

.dc-t { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.dc-row { display: grid; grid-template-columns: minmax(0, 1.5fr) 44px minmax(0, 1fr); gap: 12px; align-items: center;
  height: 38px; padding: 0 12px; border-top: 1px solid var(--line-soft); }
.dc-row:first-child { border-top: 0; background: var(--paper-band); font-size: 12px; font-weight: 600; color: var(--ink-3); }
.dc-row > span:first-child { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dc-row > span:first-child b { font-weight: 600; color: var(--ink); font-size: 12.5px; white-space: nowrap; }
/* The app's PDF glyph (Acrobat swirl in a page, red): every paper here has its file. */
.dc-pdf { width: 15px; height: 15px; flex: none; color: var(--pdf); margin-inline-end: -2px; }
.dc-th { padding-inline-start: 23px; }
.dc-row > span:first-child .sk { flex: 1; }
.dc-new { display: inline-flex; align-items: center; gap: 6px; animation: dc-head var(--loop) infinite; }
.dc-new svg { width: 13px; height: 13px; color: var(--violet); }
@keyframes dc-head { 0%, 16% { opacity: 0; transform: translateX(14px); } 22%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* One answer cell: a pulsing bar while "thinking", then the value. */
.dc-cell { position: relative; color: var(--ink); font-variant-numeric: tabular-nums; }
.dc-cell .sk { position: absolute; inset-inline-start: 0; top: 50%; width: 70%; margin-top: -4px; opacity: 0; }
.dc-row:nth-child(2) .dc-cell .sk { animation: dc-k1 var(--loop) infinite; }
.dc-row:nth-child(3) .dc-cell .sk { animation: dc-k2 var(--loop) infinite; }
.dc-row:nth-child(4) .dc-cell .sk { animation: dc-k3 var(--loop) infinite; }
.dc-row:nth-child(5) .dc-cell .sk { animation: dc-k4 var(--loop) infinite; }
.dc-row:nth-child(6) .dc-cell .sk { animation: dc-k5 var(--loop) infinite; }
.dc-row:nth-child(7) .dc-cell .sk { animation: dc-k6 var(--loop) infinite; }
.dc-row:nth-child(8) .dc-cell .sk { animation: dc-k7 var(--loop) infinite; }
.dc-row:nth-child(2) .dc-cell em { animation: dc-v1 var(--loop) infinite; }
.dc-row:nth-child(3) .dc-cell em { animation: dc-v2 var(--loop) infinite; }
.dc-row:nth-child(4) .dc-cell em { animation: dc-v3 var(--loop) infinite; }
.dc-row:nth-child(5) .dc-cell em { animation: dc-v4 var(--loop) infinite; }
.dc-row:nth-child(6) .dc-cell em { animation: dc-v5 var(--loop) infinite; }
.dc-row:nth-child(7) .dc-cell em { animation: dc-v6 var(--loop) infinite; }
.dc-row:nth-child(8) .dc-cell em { animation: dc-v7 var(--loop) infinite; }
.dc-cell em { font-style: normal; }
@keyframes dc-k1 { 0%, 23% { opacity: 0; } 25%, 31% { opacity: 1; } 33%, 100% { opacity: 0; } }
@keyframes dc-k2 { 0%, 23% { opacity: 0; } 25%, 38% { opacity: 1; } 40%, 100% { opacity: 0; } }
@keyframes dc-k3 { 0%, 23% { opacity: 0; } 25%, 45% { opacity: 1; } 47%, 100% { opacity: 0; } }
@keyframes dc-k4 { 0%, 23% { opacity: 0; } 25%, 52% { opacity: 1; } 54%, 100% { opacity: 0; } }
@keyframes dc-k5 { 0%, 23% { opacity: 0; } 25%, 59% { opacity: 1; } 61%, 100% { opacity: 0; } }
@keyframes dc-k6 { 0%, 23% { opacity: 0; } 25%, 66% { opacity: 1; } 68%, 100% { opacity: 0; } }
@keyframes dc-k7 { 0%, 23% { opacity: 0; } 25%, 73% { opacity: 1; } 75%, 100% { opacity: 0; } }
@keyframes dc-v1 { 0%, 32% { opacity: 0; } 34%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v2 { 0%, 39% { opacity: 0; } 41%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v3 { 0%, 46% { opacity: 0; } 48%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v4 { 0%, 53% { opacity: 0; } 55%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v5 { 0%, 60% { opacity: 0; } 62%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v6 { 0%, 67% { opacity: 0; } 69%, 96% { opacity: 1; } 100% { opacity: 0; } }
@keyframes dc-v7 { 0%, 74% { opacity: 0; } 76%, 96% { opacity: 1; } 100% { opacity: 0; } }

/* --- 3. Chat: every claim carries its source ------------------------ */
.sl-demo--chat { --loop: 10s; }
.dch { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.dch-chat { display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.dch-q { align-self: flex-end; max-width: 78%; padding: 9px 12px; color: var(--ink);
  background: var(--paper-band); border: 1px solid var(--line); border-radius: 12px 12px 4px 12px;
  animation: dch-q var(--loop) infinite; }
@keyframes dch-q { 0%, 3% { opacity: 0; transform: translateY(6px); } 7%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.dch-dots { display: flex; gap: 4px; height: 0; opacity: 0; overflow: visible; animation: dch-dots var(--loop) infinite; }
.dch-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-4); }
@keyframes dch-dots { 0%, 10% { opacity: 0; } 12%, 24% { opacity: 1; } 26%, 100% { opacity: 0; } }
.dch-a { color: var(--ink); animation: dch-a var(--loop) steps(4) infinite; }
@keyframes dch-a { 0%, 26% { clip-path: inset(0 0 100% 0); } 38%, 96% { clip-path: inset(0 0 0 0); } 100% { clip-path: inset(0 0 100% 0); } }
.dch-src { position: relative; align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 6px; font-size: 12px; border: 1px solid var(--line); border-radius: 8px;
  animation: dch-src var(--loop) infinite; }
.dch-src b { display: grid; place-items: center; width: 18px; height: 18px; font-size: 11px; color: var(--violet); }
@keyframes dch-src { 0%, 40% { opacity: 0; background: transparent; } 43%, 57% { opacity: 1; background: transparent; } 58%, 61% { opacity: 1; background: var(--line-soft); } 63%, 96% { opacity: 1; background: transparent; } 100% { opacity: 0; } }
.dch-src .d-cursor { animation: dch-cur var(--loop) infinite; }
@keyframes dch-cur {
  0%, 45% { opacity: 0; transform: translate(-120px, 70px); }
  48% { opacity: 1; }
  56% { transform: translate(0, 0); }
  58% { transform: translate(0, 0) scale(0.82); }
  60%, 88% { opacity: 1; transform: translate(0, 0) scale(1); }
  92%, 100% { opacity: 0; transform: translate(0, 0); }
}

.dch-pdf { padding: 18px; background: var(--paper-band); border-inline-start: 1px solid var(--line);
  animation: dch-pdf var(--loop) infinite; }
@keyframes dch-pdf { 0%, 60% { opacity: 0; transform: translateX(16px); } 65%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.dch-page { display: grid; gap: 9px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.dch-page .sk--title { height: 11px; width: 80%; margin-bottom: 6px; }
.dch-hl { font-size: 12px; line-height: 1.55; color: var(--ink); padding: 1px 0;
  background-image: linear-gradient(rgb(250 204 21 / 0.42), rgb(250 204 21 / 0.42));
  background-repeat: no-repeat; background-size: 100% 100%; animation: dch-hl var(--loop) infinite; }
@keyframes dch-hl { 0%, 68% { background-size: 0% 100%; } 76%, 96% { background-size: 100% 100%; } 100% { background-size: 0% 100%; } }

/* --- 4. Writer: cite from the library, references follow ------------ */
.sl-demo--write { --loop: 10s; }
.dw-tool { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line-soft); }
.dw-tool .sk { width: 16px; height: 16px; border-radius: 4px; }
.dw-tool .dw-gap { flex: 1; }
.dw-cite { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--ink); animation: dw-press var(--loop) infinite; }
.dw-cite svg { width: 14px; height: 14px; }
@keyframes dw-press { 0%, 8% { background: transparent; } 9%, 13% { background: var(--line-soft); } 15%, 100% { background: transparent; } }
.dw-style { font-size: 12px; color: var(--ink-3); padding: 3px 9px; border: 1px solid var(--line); border-radius: 99px; }
.dw-doc { position: relative; padding: 22px 26px 24px; display: grid; gap: 10px; }
.dw-h { font: 500 21px/1.2 var(--font-display); color: var(--ink); margin-bottom: 4px; }
.dw-p { color: var(--ink); font-size: 14px; line-height: 1.6; }
.dw-p sup { color: var(--violet); font-weight: 700; font-size: 10.5px; animation: dw-sup var(--loop) infinite; }
@keyframes dw-sup { 0%, 49% { opacity: 0; } 51%, 96% { opacity: 1; } 100% { opacity: 0; } }

/* The picker: opens under the sentence, searches the library, closes on pick. */
.dw-pick { position: absolute; inset-inline: 46px 26px; top: 112px; z-index: 2; padding: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 18px 40px -16px rgb(17 24 39 / 0.35); opacity: 0; animation: dw-pick var(--loop) infinite; }
@keyframes dw-pick { 0%, 13% { opacity: 0; transform: translateY(-4px); } 16%, 47% { opacity: 1; transform: none; } 50%, 100% { opacity: 0; transform: translateY(-4px); } }
.dw-find { display: flex; align-items: center; gap: 8px; padding: 6px 8px 8px; border-bottom: 1px solid var(--line-soft); color: var(--ink); }
.dw-find svg { width: 14px; height: 14px; color: var(--ink-3); }
.dw-find span { animation: dw-type var(--loop) steps(7) infinite; }
@keyframes dw-type { 0%, 17% { clip-path: inset(0 100% 0 0); } 27%, 100% { clip-path: inset(0 0 0 0); } }
.dw-pick ul { list-style: none; margin: 6px 0 0; padding: 0; }
.dw-pick li { position: relative; display: grid; gap: 2px; padding: 7px 8px; border-radius: 7px; font-size: 12px; }
.dw-pick li b { color: var(--ink); font-weight: 600; }
.dw-pick li span { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-pick li:nth-child(1) { animation: dw-l1 var(--loop) infinite; }
.dw-pick li:nth-child(2) { animation: dw-l2 var(--loop) infinite; }
@keyframes dw-l1 { 0%, 28% { opacity: 0; background: transparent; } 30%, 43% { opacity: 1; background: transparent; } 44%, 100% { opacity: 1; background: var(--line-soft); } }
@keyframes dw-l2 { 0%, 30% { opacity: 0; } 32%, 100% { opacity: 1; } }
.dw-pick li:first-child .d-cursor { left: 40%; animation: dw-cur var(--loop) infinite; }
@keyframes dw-cur {
  0%, 30% { opacity: 0; transform: translate(-90px, 90px); }
  33% { opacity: 1; }
  41% { transform: translate(0, 0); }
  43% { transform: translate(0, 0) scale(0.82); }
  45%, 47% { opacity: 1; transform: translate(0, 0) scale(1); }
  50%, 100% { opacity: 0; transform: translate(0, 0); }
}

.dw-refs { margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--line-soft); animation: dw-refs var(--loop) infinite; }
.dw-refs b { display: block; font-size: 12px; font-weight: 600; color: var(--ink-3); letter-spacing: 0.04em; margin-bottom: 6px; }
.dw-refs p { font-size: 12.5px; line-height: 1.55; color: var(--ink); }
@keyframes dw-refs { 0%, 54% { opacity: 0; transform: translateY(6px); } 60%, 96% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* --- Playback control ----------------------------------------------- */
/* !important on purpose: every `animation:` shorthand above resets the play
   state to running, and the more specific ones (`.ds-res li:nth-child(1)
   .ds-pill` and the like) outranked this rule, so those parts kept running
   off screen and played seconds ahead of the rest of their drawing. */
.js-demos .sl-demo:not(.is-playing) *,
.js-demos .sl-demo:not(.is-playing) *::before { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
  .sl-demo *, .sl-demo *::before { animation: none !important; }
  .sl-demo .d-cursor, .sl-demo .dch-dots { display: none; }
}

/* --- Narrow screens ------------------------------------------------- */
@media (max-width: 900px) {
  .sl-rows { gap: 80px; margin-top: 56px; }
  .sl-row { grid-template-columns: 1fr; gap: 28px; }
  .sl-row:nth-child(even) { grid-template-columns: 1fr; }
  .sl-row:nth-child(even) .sl-row-text { order: 0; }
  .sl-row-text p { font-size: 17px; }
  .sl-grid--rest { margin-top: 88px; }
}
@media (max-width: 520px) {
  .sl-demo { height: auto; min-height: 0; font-size: 13px; }
  .dch { grid-template-columns: 1fr; }
  .dch-pdf { border-inline-start: 0; border-top: 1px solid var(--line); }
  .dc-row { grid-template-columns: minmax(0, 1.4fr) 40px minmax(0, 1fr); gap: 8px; padding: 0 10px; }
  .ds-row { grid-template-columns: minmax(0, 1fr) 112px 26px; gap: 8px; }
  .ds-cursor { display: none; }
  .ds-pop { inset-inline: 16px; width: auto; top: 222px; }
  .ds-colh { font-size: 11px; }
  .dw-doc { padding: 18px 16px 20px; }
  .dw-pick { inset-inline: 16px; top: 176px; }
  .dw-tool .sk:nth-child(n+4) { display: none; }
}
