  /* The library (AP-1322, library.js): Simple, as what the person has made.
     Colours are app.css's tokens, so both themes follow. */

  /* At Simple the library is the home: no Sessions and no rail. Talk stays,
     an easy thing anyone can use (Nate, 2026-11-16). Standard and Expert
     have no Library. */
  body[data-level="simple"] #nav-sessions { display: none; }
  body:not([data-level="simple"]) #nav-library { display: none; }

  main.library { max-width: 60rem; }
  main.library .banner { margin: 0 0 1rem; }
  .lib-new h2 { margin: 0 0 0.6rem; }
  .lib-new textarea, .lib-change-box textarea { width: 100%; resize: vertical; font: inherit; }
  .lib-new-foot { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; }
  .lib-new-foot > :first-child { flex: 1; font-size: 0.88rem; }
  .lib-new-foot button { margin: 0; }

  .lib-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin: 1.4rem 0 0.7rem; }
  .lib-bar h2 { margin: 0; font: 600 1.05rem/1.3 var(--display); }
  .lib-bar .segmented button { margin: 0; padding: 0.2rem 0.75rem; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); font-size: 0.82rem; font-weight: 500; }
  .lib-bar .segmented button[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }

  /* Gallery: each item's cover over its name. */
  .lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 0.9rem; }
  .lib-card { display: flex; flex-direction: column; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; color: var(--ink); text-decoration: none; }
  .lib-card:hover, .lib-card:focus-visible { border-color: var(--accent); box-shadow: var(--shadow); }
  .lib-cover { display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: var(--paper); border-bottom: 1px solid var(--line); flex: none; }
  .lib-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .lib-cover.page img { object-position: top center; }
  .lib-cover.none .lib-mark { width: 3.4rem; height: 3.4rem; border-radius: 12px; font-size: 1.6rem; }
  .lib-card-text { display: grid; gap: 0.3rem; min-width: 0; padding: 0.7rem 0.85rem 0.8rem; }
  .lib-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
  .lib-card-name { font: 600 1rem/1.3 var(--display); overflow-wrap: anywhere; }
  .lib-card-marks { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.35rem 0.6rem; flex: none; }
  /* Changed since it was last opened here (AP-1343): the card's edge and a chip, until it is opened. */
  .lib-card.updated { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .lib-updated { padding: 0.05rem 0.5rem; border-radius: 99px; background: var(--accent); color: var(--card); font-size: 0.74rem; font-weight: 600; }
  .lib-card-meta { font-size: 0.82rem; }

  /* List: the same card as a row, its cover a thumbnail. */
  .lib-grid.list { grid-template-columns: 1fr; gap: 0.4rem; }
  .lib-grid.list .lib-card { flex-direction: row; align-items: center; }
  .lib-grid.list .lib-cover { width: 6rem; border-bottom: 0; border-right: 1px solid var(--line); }
  .lib-grid.list .lib-cover.none .lib-mark { width: 2.2rem; height: 2.2rem; border-radius: 8px; font-size: 1.1rem; }
  .lib-grid.list .lib-card-text { flex: 1; padding: 0.5rem 0.85rem; }
  .lib-grid.list .lib-card-top { align-items: center; }

  /* AP-1345: a card slides left over its Archive and Delete (a swipe on a
     phone, the ··· button with a mouse). The tile is the grid's cell; the
     slide carries the card and the button; the actions wait behind it. */
  .lib-swipe { position: relative; min-width: 0; border-radius: 8px; overflow: hidden; --lib-actions: 10.5rem; }
  .lib-slide { position: relative; z-index: 1; height: 100%; touch-action: pan-y; transition: transform 0.18s ease; }
  .lib-swipe.dragging .lib-slide { transition: none; }
  .lib-swipe.open .lib-slide { transform: translateX(calc(-1 * var(--lib-actions))); }
  .lib-slide > .lib-card { height: 100%; }
  .lib-swipe-actions { position: absolute; inset: 0 0 0 auto; width: var(--lib-actions); display: flex; }
  .lib-swipe:not(.open):not(.dragging) .lib-swipe-actions { visibility: hidden; }
  .lib-swipe-actions button { flex: 1; margin: 0; border: 0; border-radius: 0; padding: 0 0.4rem; font-size: 0.86rem; font-weight: 600; }
  .lib-swipe-archive { background: var(--accent-soft); color: var(--accent); }
  .lib-swipe-delete { background: var(--fail); color: var(--card); }
  .lib-options { position: absolute; top: 0.4rem; right: 0.4rem; margin: 0; padding: 0.1rem 0.5rem; border: 1px solid var(--line); border-radius: 99px; background: var(--card); color: var(--ink); font-size: 0.85rem; line-height: 1.2; opacity: 0; transition: opacity 0.12s; }
  .lib-swipe:hover .lib-options, .lib-options:focus-visible, .lib-swipe.open .lib-options { opacity: 1; }
  /* Touch screens swipe; the button is for a mouse and the keyboard. */
  @media (hover: none) { .lib-options { display: none; } }
  .lib-grid.list .lib-options { top: 50%; transform: translateY(-50%); }
  @media (hover: hover) { .lib-grid.list .lib-card-text { padding-right: 3.2rem; } }

  .lib-archived { margin-top: 1.6rem; }
  .lib-archived > summary { cursor: pointer; margin-bottom: 0.7rem; font: 600 1rem/1.3 var(--display); color: var(--muted); }
  .lib-archived > summary .count { font: 500 0.85rem var(--body); margin-left: 0.3rem; }
  .lib-archived .lib-cover { opacity: 0.75; }

  /* The item's thing, large: a page's cover (a button to Preview), or its picture, PDF, model, video or sound. */
  .lib-hero { margin-bottom: 0.9rem; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
  .lib-hero > .muted { padding: 1rem; }
  .lib-hero-shot { display: block; width: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; background: none; cursor: pointer; }
  div.lib-hero-shot { cursor: default; }
  .lib-hero-shot img { display: block; width: 100%; height: auto; }
  .lib-hero .fv-image { min-height: 0; }
  .lib-hero .fv-image img { max-height: 70vh; }
  .lib-hero .fv-pdf { height: 75vh; }
  .lib-hero .glb-view { height: 60vh; min-height: 18rem; }
  .lib-hero .fv-media { display: grid; place-items: center; padding: 1rem; }
  .lib-hero.audio .fv-media audio { width: 100%; }
  .lib-hero-name { display: block; width: 100%; margin: 0; padding: 0.45rem 0.8rem; border-top: 1px solid var(--line); border-radius: 0; text-align: left; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .lib-mark { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 8px; font: 600 1.1rem/1 var(--display); flex: none; }
  .lib-mark.t0 { background: var(--accent-soft); color: var(--accent); }
  .lib-mark.t1 { background: var(--done-soft); color: var(--done); }
  .lib-mark.t2 { background: var(--warn-soft); color: var(--warn); }
  .lib-mark.t3 { background: var(--fail-soft); color: var(--fail); }
  .lib-mark.t4 { background: var(--code); color: var(--ink); }
  .lib-mark.t5 { background: var(--user); color: var(--muted); }

  .lib-state { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; font-weight: 600; color: var(--muted); }
  .lib-state:empty { display: none; }
  .lib-state.live { color: var(--done); }
  .lib-state.running { color: var(--accent); }
  .lib-state.awaiting_user_input { color: var(--warn); }
  .lib-state.failed { color: var(--fail); }

  .lib-item-head { position: relative; display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
  .lib-item-head button { margin: 0; }
  .lib-item-head .popover.menu { top: 2.2rem; bottom: auto; }
  .lib-title { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.8rem; margin-bottom: 1rem; }
  .lib-title h2 { display: flex; align-items: center; gap: 0.6rem; margin: 0; overflow-wrap: anywhere; }

  .lib-panel { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 0.9rem 1.1rem; margin-bottom: 0.9rem; }
  .lib-panel h3 { margin: 0 0 0.5rem; font: 600 1rem/1.3 var(--display); }
  .lib-panel p { margin: 0 0 0.5rem; }
  .lib-page { border-left: 3px solid var(--accent); }
  .lib-page .sched { font-size: 0.88rem; margin-top: 0.3rem; }
  .lib-fresh-note { margin-bottom: 0.9rem; padding: 0.55rem 0.9rem; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent-soft); color: var(--ink); font-size: 0.9rem; }
  .lib-draft-note { color: var(--warn); font-size: 0.9rem; margin-top: 0.3rem; }
  .lib-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
  .lib-actions button { margin: 0; }
  .lib-working { display: flex; align-items: center; gap: 0.8rem; }
  .lib-working button { margin: 0 0 0 auto; }
  .lib-now { display: flex; align-items: center; gap: 0.5rem; min-width: 0; overflow-wrap: anywhere; }
  .lib-question { border-left: 3px solid var(--warn); }
  .lib-answer .md { overflow-wrap: anywhere; }

  /* minmax(0, 1fr): a file's or a change's one-line name is cut short with an
     ellipsis; an auto column would widen to the whole name instead. */
  .lib-files { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.35rem; }
  .lib-file { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
  .lib-file button { margin: 0; }
  .lib-file-name { flex: 1; min-width: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lib-thumb { display: inline-grid; place-items: center; width: 3.2rem; height: 3.2rem; border-radius: 4px; overflow: hidden; background: var(--paper); flex: none; font-size: 0.7rem; }
  .lib-thumb img { width: 100%; height: 100%; object-fit: cover; }

  .lib-change-box { margin: 0.4rem 0 1.4rem; }
  .lib-changes-title { margin: 0 0 0.4rem; font: 600 1rem/1.3 var(--display); }
  .lib-changes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.35rem; }
  .lib-change { border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
  .lib-change summary { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.8rem; cursor: pointer; }
  .lib-change-ask { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lib-change .when { font-size: 0.82rem; flex: none; }
  .lib-change-body { display: grid; gap: 0.6rem; padding: 0 0.8rem 0.8rem; }
  .lib-said { overflow-wrap: anywhere; }
  .lib-said.you { background: var(--user); border-radius: 6px; padding: 0.5rem 0.7rem; white-space: pre-wrap; }

  @media (max-width: 760px) {
    .lib-grid { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
    .lib-grid.list .lib-cover { width: 4.5rem; }
    .lib-hero .fv-pdf { height: 65vh; }
    .lib-new-foot { flex-wrap: wrap; }
    .lib-working { flex-wrap: wrap; }
  }
  @media (max-width: 420px) {
    .lib-grid { grid-template-columns: 1fr; }
  }
