/* Rug Research: "mill sample book" interface.
   Cool card-stock pages, a dark bookcloth board for the shell, and research
   themes carried as bookcloth colours on every record's label. */

:root {
  --ground: #e6e8e3;
  --surface: #f7f7f4;
  --surface-2: #dcdfd9;
  --ink: #181c1a;
  --ink-2: #4f5652;
  --ink-3: #6b726e;
  --line: #c6cbc4;
  --line-strong: #a9afa8;
  --board: #1d2521;
  --board-2: #2a332e;
  --board-ink: #e8ebe6;
  --board-ink-2: #a9b3ad;
  --primary: #7a2e2a;          /* oxblood bookcloth */
  --primary-hover: #66241f;
  --primary-ink: #fbf6f4;
  --focus: #2d5f8a;
  --select: #c9d6e2;
  --danger: #9b2c22;

  /* bookcloth: one per research theme */
  --cloth-oxblood: #7a2e2a;
  --cloth-moss: #56662c;
  --cloth-navy: #253b5f;
  --cloth-rose: #94566a;
  --cloth-ochre: #a87a22;
  --cloth-teal: #1e6767;
  --cloth-slate: #4e5966;
  --cloth-umber: #6a4a2e;
  --cloth-plum: #5a3e6b;
  --cloth-grey: #5d6460;
  --cloth-indigo: #3a3f78;
  --cloth-rust: #9a4a26;

  --r: 6px;
  --r-lg: 10px;
  --shadow-1: 0 1px 2px rgb(24 28 26 / .08), 0 2px 6px rgb(24 28 26 / .06);
  --shadow-2: 0 2px 4px rgb(24 28 26 / .08), 0 10px 24px rgb(24 28 26 / .12);
  --shadow-3: 0 8px 20px rgb(24 28 26 / .18), 0 28px 60px rgb(24 28 26 / .22);
  --ease: cubic-bezier(.16, 1, .3, 1);
  --font: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  --t-xs: .75rem; --t-sm: .8125rem; --t-md: .9375rem; --t-lg: 1.125rem; --t-xl: 1.375rem; --t-2xl: 1.75rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #131715; --surface: #1b201d; --surface-2: #252b27; --ink: #e5e9e5; --ink-2: #a6aea9; --ink-3: #8a928d;
    --line: #313834; --line-strong: #47504b; --board: #0c0f0d; --board-2: #1b211e; --board-ink: #e5e9e5; --board-ink-2: #98a29c;
    --primary: #b0544c; --primary-hover: #c2645b; --primary-ink: #fff; --focus: #8bb6dc; --select: #2a3d50; --danger: #e0786c;
    --cloth-oxblood: #9a4842; --cloth-moss: #6f8040; --cloth-navy: #3d5884; --cloth-rose: #a86a7e; --cloth-ochre: #b98d36;
    --cloth-teal: #2e8181; --cloth-slate: #67727f; --cloth-umber: #85613f; --cloth-plum: #765a88; --cloth-grey: #6c736f; --cloth-indigo: #5a60a4; --cloth-rust: #b5643b;
    --shadow-1: 0 1px 2px rgb(0 0 0 / .4); --shadow-2: 0 4px 16px rgb(0 0 0 / .45); --shadow-3: 0 16px 50px rgb(0 0 0 / .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line-strong) transparent; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 400 var(--t-md)/1.5 var(--font); font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
::selection { background: var(--select); color: var(--ink); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
p { text-wrap: pretty; }
a { color: var(--focus); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { accent-color: var(--primary); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .count, time { font-variant-numeric: tabular-nums; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.ic.sm { width: 14px; height: 14px; }
.ic.fill { fill: currentColor; }
.spacer { flex: 1; }
.skip { position: absolute; left: 12px; top: -40px; background: var(--surface); padding: 8px 12px; border-radius: var(--r); z-index: 100; }
.skip:focus { top: 12px; }

/* ---------- shell (the board) ---------- */
.shell { background: var(--board); color: var(--board-ink); position: sticky; top: 0; z-index: 20; }
.shell-inner { max-width: 1520px; margin: 0 auto; padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 28px; }
.wordmark { display: flex; flex-direction: column; text-decoration: none; color: inherit; line-height: 1.05; }
.wordmark-name { font-size: 1.0625rem; font-weight: 750; font-variation-settings: "wdth" 125; text-transform: uppercase; letter-spacing: .04em; }
.wordmark-sub { font-size: var(--t-xs); color: var(--board-ink-2); font-variation-settings: "wdth" 88; }
.tabs { display: flex; height: 100%; gap: 2px; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; color: var(--board-ink-2); text-decoration: none;
  font-weight: 500; font-size: var(--t-md); box-shadow: inset 0 -3px 0 transparent; transition: color .15s, box-shadow .2s var(--ease);
}
.tab:hover { color: var(--board-ink); }
.tab[aria-current="page"] { color: var(--board-ink); box-shadow: inset 0 -3px 0 var(--cloth-ochre); }
.count-pill { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--board-2); color: var(--board-ink); font-size: var(--t-xs); line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.count-pill:empty { display: none; }
.shell-actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap;
  font-weight: 550; font-size: var(--t-md); text-decoration: none; transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { border-color: var(--ink-3); background: color-mix(in srgb, var(--surface) 70%, var(--surface-2)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.on-board { background: var(--board-ink); color: var(--board); border-color: var(--board-ink); }
.btn.on-board:hover { background: #fff; }
.btn.on-board.ghost { background: transparent; color: var(--board-ink); border-color: var(--board-2); }
.btn.on-board.ghost:hover { background: var(--board-2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: var(--t-sm); }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r); border: 1px solid transparent;
  background: transparent; color: var(--ink-2); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.link-btn { border: 0; background: none; padding: 4px 2px; color: var(--ink-2); cursor: pointer; font-size: var(--t-sm); font-weight: 550; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: .2em; }
.link-btn:hover { color: var(--ink); text-decoration-color: currentColor; }
.link-btn.danger { color: var(--danger); text-decoration-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 8px); width: 300px; padding: 6px; z-index: 40; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-3);
  animation: pop .18s var(--ease);
}
.menu-pop button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: none; padding: 9px 10px; border-radius: var(--r); cursor: pointer; text-align: left; }
.menu-pop button:hover, .menu-pop button:focus-visible { background: var(--surface-2); }
.menu-pop strong { font-weight: 600; }
.menu-pop span { font-size: var(--t-sm); color: var(--ink-2); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- layout ---------- */
main { max-width: 1520px; margin: 0 auto; padding: 24px 24px 80px; }
.view-head { margin: 8px 0 20px; max-width: 70ch; }
.view-head h1 { font-size: var(--t-2xl); margin-bottom: 4px; }
.view-head p { margin: 0; color: var(--ink-2); }
.view-head.row { max-width: none; display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; }

.searchbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search {
  flex: 1 1 380px; display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 14px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s; color: var(--ink-3);
}
.search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 1.0625rem; color: var(--ink); }
.search input::placeholder { color: var(--ink-3); }
/* Native option lists: give them the theme's colours. Without this, a select with a transparent
   background (the chapter picker) opens a white list with light dark-mode text. */
select option, select optgroup { background-color: var(--surface); color: var(--ink); }
select optgroup { color: var(--ink-2); font-weight: 650; }
.search kbd { font: 500 var(--t-xs) var(--font); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; color: var(--ink-3); }
.search-tools { display: flex; gap: 8px; align-items: center; }
.select select, .h1-select, .form-grid select {
  appearance: none; height: 36px; padding: 0 34px 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' stroke='%236b726e' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; cursor: pointer; font-weight: 500;
}
.seg { display: flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: var(--r); }
.seg-btn { display: grid; place-items: center; width: 32px; height: 30px; border: 0; border-radius: 4px; background: transparent; color: var(--ink-2); cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.syntax { margin: 10px 0 22px; font-size: var(--t-sm); color: var(--ink-3); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tip { border: 0; background: none; padding: 1px 4px; border-radius: 4px; color: var(--ink-2); cursor: pointer; font-size: var(--t-sm); font-variant-numeric: tabular-nums; text-decoration: underline dotted var(--line-strong); text-underline-offset: .25em; }
.tip:hover { background: var(--surface-2); color: var(--ink); }
.mobile-only { display: none; }

.browse { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; align-items: start; }

/* ---------- facets (the book's spine index) ---------- */
.facets { position: sticky; top: 84px; max-height: calc(100dvh - 104px); overflow: auto; padding: 2px 6px 2px 0; scrollbar-width: thin; }
.facet + .facet { margin-top: 22px; }
.facet h2 { font-size: var(--t-sm); font-weight: 650; color: var(--ink); margin-bottom: 6px; letter-spacing: 0; }
.facet label { display: flex; align-items: center; gap: 9px; min-height: 30px; padding: 3px 6px; margin: 0 -6px; border-radius: var(--r); cursor: pointer; font-size: var(--t-md); color: var(--ink-2); }
.facet label:hover { background: var(--surface-2); color: var(--ink); }
.facet input { width: 15px; height: 15px; margin: 0; flex: none; }
.facet input:checked ~ .fl { color: var(--ink); font-weight: 600; }
.facet .fl { min-width: 0; line-height: 1.3; }
.facet .count { margin-left: auto; font-size: var(--t-xs); color: var(--ink-3); }
.facet .zero { opacity: .55; }
.facet .more { border: 0; background: none; color: var(--focus); cursor: pointer; padding: 4px 0; font-size: var(--t-sm); font-weight: 550; }
.cloth-dot { width: 12px; height: 16px; border-radius: 2px; flex: none; background: var(--c, var(--cloth-grey)); box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
.flag-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c); }

/* ---------- fore-edge: results laid out by date, like a sample book's page edges ---------- */
.foreedge-wrap { margin-bottom: 20px; }
.foreedge-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; min-height: 28px; }
#result-count { font-size: var(--t-md); color: var(--ink-2); font-variant-numeric: tabular-nums; }
#result-count b { color: var(--ink); font-weight: 650; }
.foreedge { position: relative; height: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.foreedge .leaf {
  position: absolute; top: 5px; bottom: 5px; width: 6px; margin-left: -3px; border: 0; padding: 0; border-radius: 1px; cursor: pointer;
  background: var(--c, var(--cloth-grey)); opacity: .85; transition: transform .2s var(--ease), opacity .15s;
}
.foreedge .leaf.span { width: auto; margin-left: 0; height: 6px; top: auto; bottom: 5px; opacity: .35; pointer-events: none; }
.foreedge .leaf:hover, .foreedge .leaf:focus-visible { opacity: 1; transform: scaleY(1.15); z-index: 2; }
.foreedge-axis { position: relative; height: 18px; font-size: var(--t-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.foreedge-axis span { position: absolute; top: 3px; transform: translateX(-50%); }
.foreedge-axis span::before { content: ""; position: absolute; left: 50%; top: -4px; height: 3px; border-left: 1px solid var(--line-strong); }
.foreedge-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: var(--t-sm); }
.chips { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 4px 0 10px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line); font-size: var(--t-sm); }
.chip button { display: grid; place-items: center; width: 20px; height: 20px; border: 0; border-radius: 50%; background: none; cursor: pointer; color: var(--ink-3); }
.chip button:hover { background: var(--surface-2); color: var(--ink); }
.chip .ic { width: 12px; height: 12px; }

/* ---------- cards: a swatch page ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 28px 20px; }
.card { position: relative; display: flex; flex-direction: column; min-width: 0; }
.card-open { display: flex; flex-direction: column; text-align: left; border: 0; padding: 0; background: none; cursor: pointer; color: inherit; border-radius: var(--r); }
.plate {
  position: relative; aspect-ratio: 4 / 5; border-radius: var(--r); overflow: hidden; background: var(--surface-2);
  box-shadow: var(--shadow-1); transition: box-shadow .3s var(--ease), transform .3s var(--ease);
}
.card-open:hover .plate, .card-open:focus-visible .plate { box-shadow: var(--shadow-2); transform: translateY(-3px); }
.plate img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--surface-2); }
/* honest empty plate: a sample-book label with a strip of the theme's bookcloth, never a fake picture */
.board-plate { position: absolute; inset: 0; display: flex; flex-direction: column; background: color-mix(in srgb, var(--c, var(--cloth-grey)) 7%, var(--surface)); }
.bp-tape {
  display: flex; align-items: flex-end; height: 28%; min-height: 34px; padding: 10px 14px; flex: none;
  background-color: var(--c, var(--cloth-grey)); color: rgb(255 255 255 / .94);
  background-image: repeating-linear-gradient(0deg, rgb(255 255 255 / .05) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgb(0 0 0 / .07) 0 1px, transparent 1px 3px);
}
.bp-type { font-size: var(--t-xs); font-weight: 650; font-variation-settings: "wdth" 115; text-transform: uppercase; letter-spacing: .08em; }
.bp-title { padding: 14px 14px 0; font-size: var(--t-lg); font-weight: 600; line-height: 1.25; color: var(--ink); font-variation-settings: "wdth" 92; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.bp-note { margin-top: auto; padding: 0 14px 12px; font-size: var(--t-xs); color: var(--ink-3); }
.plate-flags { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; }
.plate-flags .flag-dot { width: 12px; height: 12px; box-shadow: 0 0 0 2px rgb(255 255 255 / .9); }
.label { padding: 12px 2px 0; display: grid; gap: 3px; }
.label-top { display: flex; align-items: center; gap: 8px; font-size: var(--t-xs); color: var(--ink-3); font-weight: 550; font-variant-numeric: tabular-nums; }
.colorway { display: inline-flex; gap: 2px; }
.colorway i { width: 9px; height: 12px; border-radius: 1.5px; background: var(--c); }
.label h3 { font-size: var(--t-md); font-weight: 620; line-height: 1.3; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.label .meta { font-size: var(--t-sm); color: var(--ink-2); line-height: 1.4; }
.label .meta .num { color: var(--ink-3); }
.verified { display: inline-flex; align-items: center; gap: 3px; color: var(--cloth-moss); }
.verified .ic { width: 13px; height: 13px; stroke-width: 2.25; }
.card-actions {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; padding: 3px; border-radius: 8px;
  background: rgb(250 250 248 / .92); box-shadow: var(--shadow-1); opacity: 0; transform: translateY(-2px);
  transition: opacity .18s, transform .25s var(--ease);
}
.card:hover .card-actions, .card:focus-within .card-actions, .card-actions.has-on { opacity: 1; transform: none; }
/* Flagged or listed cards keep a small marker, not the whole toolbar: only the "on" buttons show until hover. */
@media (hover: hover) { .card:not(:hover):not(:focus-within) .card-actions.has-on .act:not(.on) { display: none; } }
.act { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: #3b423e; cursor: pointer; }
.act:hover { background: rgb(0 0 0 / .07); }
.act.on { color: #fff; background: var(--c); }
.act.on .ic { fill: currentColor; }
@media (hover: none) { .card-actions { opacity: 1; transform: none; } }

mark { background: color-mix(in srgb, var(--cloth-ochre) 32%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }

.grid.list { grid-template-columns: 1fr; gap: 0; border-top: 1px solid var(--line); }
.grid.list .card { border-bottom: 1px solid var(--line); }
.grid.list .card-open { flex-direction: row; gap: 16px; padding: 12px 120px 12px 0; align-items: center; }
.grid.list .plate { width: 72px; flex: none; aspect-ratio: 1; }
.grid.list .bp-tape, .citem .bp-tape { height: 100%; }
.grid.list .bp-type, .grid.list .bp-title, .grid.list .bp-note, .citem .bp-type, .citem .bp-title, .citem .bp-note, .grid.list .plate-flags { display: none; }
.grid.list .act.on { color: #fff; }
.grid.list .label { padding: 0; }
.grid.list .label h3 { -webkit-line-clamp: 2; }
.grid.list .card-actions { top: 50%; transform: translateY(-50%); opacity: 1; background: none; box-shadow: none; }
.grid.list .act { color: var(--ink-2); }
.grid.list .act:hover { background: var(--surface-2); }

.empty { grid-column: 1 / -1; padding: 48px 24px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--ink-2); }
.empty h2 { font-size: var(--t-lg); color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 auto 14px; max-width: 46ch; }
.empty .btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* skeleton */
.skel .plate { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface) 50%, var(--surface-2) 70%) 0 0 / 300% 100%; animation: shimmer 1.4s linear infinite; }
.skel .bar { height: 12px; border-radius: 3px; background: var(--surface-2); margin-top: 10px; }
.skel .bar.short { width: 55%; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgb(12 15 13 / .45); animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51; width: min(640px, 100vw); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); box-shadow: var(--shadow-3); animation: slide .32s var(--ease); outline: none;
}
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.drawer-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 10px 14px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.drawer-bar .label-top { font-size: var(--t-sm); }
.drawer-plate { position: relative; background: var(--surface-2); display: flex; justify-content: center; }
.drawer-plate img { display: block; max-width: 100%; max-height: 62vh; object-fit: contain; }
.drawer-plate .plate-board { position: relative; width: 100%; height: 150px; }
.drawer-plate .plate-board .bp-tape { height: 46px; min-height: 0; }
.drawer-plate .plate-board .bp-title { display: none; }
.drawer-plate .plate-board .bp-note { margin-top: auto; font-size: var(--t-sm); }
.credit { padding: 6px 22px 0; font-size: var(--t-xs); color: var(--ink-3); }
.drawer-body { padding: 18px 22px 48px; }
.drawer h2 { font-size: var(--t-2xl); line-height: 1.15; }
.drawer .sub { margin: 6px 0 14px; color: var(--ink-2); }
.drawer .desc { max-width: 65ch; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 6px; }
.fields { display: grid; grid-template-columns: 140px 1fr; gap: 0; margin: 18px 0 0; border-top: 1px solid var(--line); font-size: var(--t-md); }
.fields dt, .fields dd { padding: 8px 0; border-bottom: 1px solid var(--line); margin: 0; }
.fields dt { color: var(--ink-3); font-size: var(--t-sm); padding-top: 9px; }
.fields dd { font-variant-numeric: tabular-nums; }
.unverified-note { display: flex; gap: 10px; align-items: flex-start; margin-top: 16px; padding: 10px 12px; border-radius: var(--r); background: color-mix(in srgb, var(--cloth-ochre) 14%, var(--surface)); font-size: var(--t-sm); color: var(--ink); }
.dsec { margin-top: 26px; }
.dsec h3 { font-size: var(--t-md); font-weight: 650; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-size: var(--t-sm); font-weight: 550; transition: background .15s, color .15s, border-color .15s; }
.toggle:hover { border-color: var(--ink-3); }
.toggle[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }
.toggle[aria-pressed="true"] .flag-dot { background: #fff; }
.list-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.list-add select { height: 32px; border-radius: 16px; padding: 0 30px 0 12px; font-size: var(--t-sm); }
.notes { width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--ground); resize: vertical; line-height: 1.5; }
.notes:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.saved { font-size: var(--t-xs); color: var(--ink-3); font-weight: 400; transition: opacity .3s; }
.citation { padding: 12px 14px; border-radius: var(--r); background: var(--ground); font-size: var(--t-md); line-height: 1.55; overflow-wrap: anywhere; }
.searchlinks { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--t-sm); }

/* ---------- timeline ---------- */
.decade { display: grid; grid-template-columns: 100px minmax(0, 1fr); gap: 20px; padding: 22px 0; border-top: 1px solid var(--line); }
.decade-label { position: sticky; top: 84px; align-self: start; font-size: var(--t-xl); font-weight: 700; font-variation-settings: "wdth" 115; font-variant-numeric: tabular-nums; color: var(--ink); }
.decade-label small { display: block; font-size: var(--t-xs); font-weight: 500; color: var(--ink-3); font-variation-settings: "wdth" 100; }
.decade .grid { grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 22px 16px; }
.era { margin-top: 28px; }
.era:first-child { margin-top: 0; }
.era-head { padding: 22px 0 18px; border-top: 2px solid var(--ink); display: grid; gap: 10px; }
.era-head h2 { font-size: var(--t-2xl); font-weight: 700; line-height: 1.2; text-wrap: balance; }
.era-years { font-weight: 500; color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 6px; }
.era-summary { margin: 0; max-width: 72ch; color: var(--ink-2); font-size: var(--t-md); line-height: 1.6; text-wrap: pretty; }
.era-meta { display: flex; justify-content: flex-start; align-items: center; gap: 12px; flex-wrap: wrap; font-size: var(--t-sm); color: var(--ink-3); max-width: 72ch; }
.era-meta .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.era-input { width: 100%; max-width: 72ch; min-height: 120px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--t-md); line-height: 1.6; resize: vertical; }
.era-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.gap-note { margin: 0; padding: 10px 0; color: var(--ink-3); font-size: var(--t-sm); border-top: 1px dashed var(--line); }

/* ---------- compile ---------- */
.list-pick { display: grid; gap: 4px; }
.h1-select { height: auto; padding: 2px 34px 2px 0; border: 0; background-color: transparent; font-size: var(--t-2xl); font-weight: 650; background-position: right 4px center; max-width: 100%; }
.list-actions { display: flex; gap: 14px; }
.export-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.export-label { font-size: var(--t-sm); color: var(--ink-3); margin-right: 2px; }
.intro-label { display: block; font-size: var(--t-sm); font-weight: 650; margin-bottom: 6px; }
.list-intro { width: 100%; min-height: 96px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); background: var(--surface); margin-bottom: 24px; resize: vertical; line-height: 1.55; }
.list-intro:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.citem { display: grid; grid-template-columns: 34px 88px minmax(0, 1fr) auto; gap: 16px; align-items: start; padding: 16px 0; border-top: 1px solid var(--line); }
.citem .n { font-size: var(--t-xl); font-weight: 700; font-variation-settings: "wdth" 115; color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; line-height: 1; padding-top: 4px; }
.citem .plate { aspect-ratio: 1; }
.citem h3 { font-size: var(--t-lg); }
.citem h3 button { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.citem h3 button:hover { text-decoration: underline; text-underline-offset: .2em; }
.citem .ccite { font-size: var(--t-sm); color: var(--ink-2); margin-top: 6px; max-width: 80ch; overflow-wrap: anywhere; }
.citem .cnote { margin-top: 10px; padding: 10px 12px; border-radius: var(--r); background: color-mix(in srgb, var(--cloth-ochre) 12%, var(--surface)); font-size: var(--t-md); white-space: pre-wrap; max-width: 80ch; }
.citem .cact { display: flex; gap: 2px; }

/* ---------- discover & sources ---------- */
.status { min-height: 24px; color: var(--ink-2); margin: 14px 0 16px; }
.status.error { color: var(--danger); }
.add-btn { position: absolute; top: 8px; right: 8px; }
.src-group { margin-top: 30px; }
.src-group h2 { font-size: var(--t-lg); margin-bottom: 10px; }
.src-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.src-link { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; color: var(--ink); transition: border-color .15s, box-shadow .2s; }
.src-link:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); }
.src-link strong { font-weight: 600; display: block; }
.src-link small { color: var(--ink-3); font-size: var(--t-sm); }
.src-link .ic { color: var(--ink-3); }

/* ---------- dialog ---------- */
dialog { width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); padding: 0; border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3); }
dialog[open] { animation: pop .22s var(--ease); }
dialog::backdrop { background: rgb(12 15 13 / .5); }
#edit-form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: var(--t-xl); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 18px 20px; overflow: auto; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: var(--t-sm); font-weight: 600; color: var(--ink); }
.form-grid small { font-weight: 400; color: var(--ink-3); font-size: var(--t-xs); }
.form-grid .span2 { grid-column: span 2; }
.form-grid input:not([type=file]), .form-grid textarea, .form-grid select { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background-color: var(--ground); font-weight: 400; font-size: var(--t-md); }
.form-grid textarea { height: auto; padding: 8px 10px; line-height: 1.5; }
.form-grid input:focus, .form-grid textarea:focus, .form-grid select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.form-grid input:user-invalid { border-color: var(--danger); }
.dialog-foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); }

/* ---------- publish ---------- */
.pub-count { min-width: 1.35rem; height: 1.35rem; padding: 0 .35rem; margin-left: 2px; border-radius: 999px; background: var(--board-ink); color: var(--board); font-size: var(--t-xs); font-weight: 700; line-height: 1.35rem; text-align: center; font-variant-numeric: tabular-nums; }
.publish-dialog[open] { display: flex; flex-direction: column; }
.pub-body { flex: 1; overflow: auto; padding: 16px 20px 20px; font-size: var(--t-md); line-height: 1.5; }
.pub-body > p { margin: 0 0 12px; max-width: 64ch; }
.pub-body h3 { margin: 18px 0 6px; font-size: var(--t-md); font-weight: 700; }
.pub-body h3:first-child { margin-top: 0; }
.pub-steps { margin: 0 0 14px; padding-left: 1.3rem; display: grid; gap: 6px; max-width: 64ch; }
.pub-token { display: flex; flex-direction: column; gap: 5px; max-width: 32rem; margin: 0 0 12px; font-size: var(--t-sm); font-weight: 600; }
.pub-token input { height: 38px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--ground); font: 400 var(--t-md) ui-monospace, SFMono-Regular, Menlo, monospace; }
.pub-token input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
.pub-note { color: var(--ink-2); font-size: var(--t-sm); }
.pub-err { padding: 10px 12px; border-radius: var(--r); background: color-mix(in srgb, var(--danger) 10%, var(--surface)); color: var(--danger); font-weight: 500; }
.pub-status { color: var(--ink-2); }
.pub-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.pub-row { border-bottom: 1px solid var(--line); }
.pub-row > label, .pub-row > span { display: flex; gap: 10px; align-items: flex-start; padding: 8px 2px; cursor: pointer; }
.pub-row > span { cursor: default; padding-left: 26px; }
.pub-row input { margin-top: 3px; accent-color: var(--primary); }
.pub-kind { display: inline-block; margin-right: 4px; color: var(--ink-3); font-size: var(--t-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.pub-fields { display: block; color: var(--ink-3); font-size: var(--t-sm); overflow-wrap: anywhere; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: var(--r-lg); background: var(--board); color: var(--board-ink); box-shadow: var(--shadow-3); font-weight: 500; animation: rise .3s var(--ease); }
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } }

.print-only { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .shell-inner { gap: 16px; }
  .wordmark-sub { display: none; }
}
@media (max-width: 860px) {
  .shell { position: static; }
  .shell-inner { height: auto; flex-wrap: wrap; padding: 12px 16px 0; gap: 10px 12px; }
  .shell-actions { margin-left: auto; }
  .tabs { order: 3; width: calc(100% + 32px); margin: 0 -16px; padding: 0 8px; height: 44px; overflow-x: auto; scrollbar-width: none; border-top: 1px solid var(--board-2); }
  .tab { flex: none; }
  main { padding: 16px 16px 64px; }
  .browse { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .mobile-only { display: inline-flex; }
  .facets { position: static; max-height: none; display: none; grid-template-columns: 1fr 1fr; gap: 18px 20px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
  .facets.open { display: grid; }
  .facet + .facet { margin-top: 0; }
  .search-tools { width: 100%; }
  .search-tools .select { flex: 1; }
  .search-tools .select select { width: 100%; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px 12px; }
  .bp-title { font-size: var(--t-md); padding: 10px 10px 0; }
  .bp-tape { padding: 8px 10px; }
  .bp-note { padding: 0 10px 10px; }
  .decade { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .decade-label { position: static; }
  .decade .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .citem { grid-template-columns: 26px 64px minmax(0, 1fr); gap: 12px; }
  .citem .cact { grid-column: 3; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: auto; }
  .fields { grid-template-columns: 1fr; }
  .fields dt { border-bottom: 0; padding-bottom: 0; }
  .grid.list .card-open { padding-right: 0; padding-bottom: 46px; }
  .grid.list .card-actions { top: auto; bottom: 8px; left: 88px; right: auto; transform: none; }
}
@media (max-width: 480px) {
  .wordmark-name { font-size: .9375rem; }
  .shell-actions .btn { padding: 0 10px; }
  .shell-actions .btn-label { display: none; }
  .facets { grid-template-columns: 1fr; }
}

@media print {
  .shell, .export-row, .list-actions, .citem .cact, .intro-label, .list-intro, #view-browse, #view-timeline, #view-discover, #view-sources, .drawer, .scrim, .toast, .skip { display: none !important; }
  body:not(.print-ms) #view-compile { display: block !important; }
  body:not(.print-ms) #view-manuscript, body.print-ms #view-compile { display: none !important; }
  body.print-ms #view-manuscript { display: block !important; }
  .ms-toc, .ms-actions, .ms-ch-meta .linkish { display: none !important; }
  .ms-layout { display: block; }
  .ms { max-width: none; font-size: 11pt; }
  .ms-chapter { break-before: page; border: 0; }
  .ms-sources[open] summary, .ms-sources summary { list-style: none; }
  .ms-sources { display: block; }
  .ms-sources > ol { display: block; }
  .ms-cite { color: #000; }
  body { background: #fff; color: #000; font-size: 11pt; }
  main { padding: 0; }
  .print-only { display: block; }
  #print-title { font-size: 20pt; margin-bottom: 8pt; }
  #print-intro { white-space: pre-wrap; margin-bottom: 18pt; }
  .h1-select { display: none; }
  .citem { break-inside: avoid; grid-template-columns: 24pt 60pt 1fr; }
  .plate { box-shadow: none; }
}

/* browser-drawn details, themed */
input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; cursor: pointer; background: var(--ink-3);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6.5 6.5l11 11M17.5 6.5l-11 11'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6.5 6.5l11 11M17.5 6.5l-11 11'/%3E%3C/svg%3E") center / contain no-repeat;
}
input[type="search"]::-webkit-search-cancel-button:hover { background: var(--ink); }
.foreedge-axis span:first-child { transform: none; }
.foreedge-axis span:first-child::before { left: 0; }
.foreedge-axis span:last-child { transform: translateX(-100%); }
.foreedge-axis span:last-child::before { left: auto; right: 0; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 5px; border: 2px solid var(--ground); }
::-webkit-scrollbar-track { background: transparent; }

/* confidence grades */
.conf { display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; height: 18px; border-radius: 9px; font-size: 11px; font-weight: 650; letter-spacing: .01em; }
.conf::before, .conf-dot { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.conf-solid { color: var(--cloth-moss); background: color-mix(in srgb, var(--cloth-moss) 14%, transparent); }
.conf-suggestive { color: var(--cloth-ochre); background: color-mix(in srgb, var(--cloth-ochre) 16%, transparent); }
.conf-unverified { color: var(--ink-3); background: color-mix(in srgb, var(--ink-3) 14%, transparent); }
.conf-refuted { color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, transparent); }
.conf-dot { width: 10px; height: 10px; }
.conf-dot.conf-solid { background: var(--cloth-moss); } .conf-dot.conf-suggestive { background: var(--cloth-ochre); }
.conf-dot.conf-unverified { background: var(--ink-3); } .conf-dot.conf-refuted { background: var(--danger); }
.conf-line { display: flex; gap: 8px; align-items: center; font-size: var(--t-sm); color: var(--ink-2); margin: 10px 0 0; }

/* original-language quotation */
.quote { margin: 16px 0 0; padding: 14px 16px; border-radius: var(--r); background: var(--ground); }
.quote blockquote { margin: 0; font-size: var(--t-lg); line-height: 1.6; font-family: var(--font), "Noto Sans CJK SC", "Hiragino Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans Devanagari", "Nirmala UI", sans-serif; }
.quote figcaption { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: var(--t-md); }
.citem .ctrans { margin: 6px 0 0; font-size: var(--t-md); color: var(--ink); max-width: 80ch; }

/* write view */
.write-kicker { font-size: var(--t-sm); color: var(--ink-3); font-weight: 550; font-variant-numeric: tabular-nums; }
.intro-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.intro-head .intro-label { margin: 0; }
.list-intro.draft { min-height: 340px; overflow: hidden; font-size: 1.0625rem; line-height: 1.7; padding: 18px 20px; max-width: 78ch; display: block; }
.evidence-label { font-size: var(--t-lg); margin: 8px 0 4px; }
.list-actions { flex-wrap: wrap; gap: 6px 14px; }
.link-btn:disabled { opacity: .4; cursor: not-allowed; }
/* Original-language quote with its English translation beneath, on cards. */
.bp-bi { display: flex; flex-direction: column; gap: 8px; -webkit-line-clamp: unset; min-height: 0; }
.bp-orig, .bp-en { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.bp-orig { font-size: var(--t-md); font-weight: 500; line-height: 1.5; -webkit-line-clamp: 4; font-variation-settings: normal; font-family: var(--font), "Noto Sans CJK SC", "Hiragino Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans Devanagari", "Nirmala UI", sans-serif; }
.bp-en { padding-top: 8px; border-top: 1px solid color-mix(in srgb, var(--c, var(--cloth-grey)) 30%, var(--line)); font-size: var(--t-sm); font-weight: 450; line-height: 1.45; color: var(--ink-2); -webkit-line-clamp: 5; }
@media (max-width: 640px) { .bp-orig { font-size: var(--t-sm); -webkit-line-clamp: 3; } .bp-en { font-size: var(--t-xs); -webkit-line-clamp: 4; } }
.bp-quote { font-weight: 500; font-size: var(--t-md); line-height: 1.55; -webkit-line-clamp: 7; font-variation-settings: normal; font-family: var(--font), "Noto Sans CJK SC", "Hiragino Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans Devanagari", "Nirmala UI", sans-serif; }
.h1-select { field-sizing: content; }
.label-top { flex-wrap: wrap; row-gap: 3px; min-width: 0; }
.view-head.row > .list-pick { flex: 1 1 320px; min-width: 0; }
.h1-select { max-width: 100%; text-overflow: ellipsis; }
@media (max-width: 860px) { .h1-select { font-size: var(--t-xl); } }
.list-pick { grid-template-columns: minmax(0, 1fr); }

/* photo strip in the detail panel */
.gallery { display: flex; gap: 8px; padding: 10px 22px 0; overflow-x: auto; scrollbar-width: thin; }
.gthumb { flex: none; width: 64px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: var(--r); overflow: hidden; background: var(--surface-2); cursor: pointer; opacity: .75; transition: opacity .15s, border-color .15s; }
.gthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gthumb:hover { opacity: 1; }
.gthumb[aria-pressed="true"] { border-color: var(--ink); opacity: 1; }

:root { --cloth-jade: #2f6b55; --cloth-wheat: #9a7f45; }
@media (prefers-color-scheme: dark) { :root { --cloth-jade: #4a8a72; --cloth-wheat: #ad9257; } }
.credit.rights { color: var(--cloth-ochre); font-weight: 550; }
.credit.rights-granted { color: var(--cloth-moss); }
.credit.rights-declined { color: var(--danger); }

/* ---------- manuscript ---------- */
.ms-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 48px; align-items: start; }
.ms-toc { position: sticky; top: 84px; max-height: calc(100vh - 110px); overflow: auto; padding-top: 8px; }
.ms-toc-title { margin: 0 0 8px; font-size: var(--t-sm); font-weight: 650; color: var(--ink-2); }
.ms-toc ol { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.ms-toc li { counter-increment: ch; }
.ms-toc a { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 6px; padding: 6px 8px; border-radius: var(--r); color: var(--ink-2); text-decoration: none; font-size: var(--t-sm); line-height: 1.35; }
.ms-toc a::before { content: counter(ch) "."; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ms-toc a:hover { background: var(--surface); color: var(--ink); }
.ms-toc small { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ms { max-width: none; min-width: 0; }
.ms-head { padding-bottom: 20px; border-bottom: 2px solid var(--ink); margin-bottom: 8px; }
.ms-head h1 { font-size: 2.25rem; font-weight: 700; line-height: 1.1; font-variation-settings: "wdth" 112; }
.ms-sub { margin: 8px 0 14px; color: var(--ink-2); }
.ms-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ms-chapter { padding: 36px 0 28px; border-bottom: 1px solid var(--line); scroll-margin-top: 80px; }
.ms-ch-num { margin: 0 0 4px; font-size: var(--t-sm); font-weight: 650; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ms-ch-head h2 { font-size: var(--t-2xl); line-height: 1.2; }
.ms-ch-meta { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 8px 0 22px; font-size: var(--t-sm); color: var(--ink-3); }
.linkish { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 0; color: var(--focus); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: .18em; }
.ms-prose { font-size: 1.0625rem; line-height: 1.72; }
.ms-prose p { margin: 0 0 1.05em; }
.ms-prose ul { margin: 0 0 1.05em; padding-left: 1.2em; }
.ms-prose li { margin-bottom: .35em; }
.ms-todo { margin: 1.4em 0 0; padding: 14px 18px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); font-size: var(--t-md); line-height: 1.55; color: var(--ink-2); }
.ms-todo h4 { margin: 0 0 6px; font-size: var(--t-sm); font-weight: 650; color: var(--ink); }
.ms-todo ul { margin: 0; padding-left: 1.1em; }
.ms-empty { color: var(--ink-3); font-style: italic; }
.ms-sources { margin-top: 22px; }
.ms-sources summary { cursor: pointer; font-size: var(--t-sm); font-weight: 650; color: var(--ink-2); }
.ms-sources ol { margin: 12px 0 0; padding-left: 1.6em; font-size: var(--t-sm); line-height: 1.5; color: var(--ink-2); }
.ms-sources li { margin-bottom: 8px; }
.ms-cite { border: 0; background: none; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; overflow-wrap: anywhere; }
.ms-cite:hover { color: var(--ink); text-decoration: underline; text-underline-offset: .18em; }
@media (max-width: 860px) {
  .ms-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .ms-toc { position: static; max-height: none; margin-bottom: 18px; padding: 12px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
  .ms-head h1 { font-size: 1.75rem; }
}
.ms-editor { display: block; width: 100%; min-height: 240px; padding: 16px 18px; border: 1px solid var(--focus); border-radius: var(--r-lg); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.0625rem; line-height: 1.72; resize: vertical; overflow: hidden; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.ms-editor:focus { outline: none; }
.ms-hint { margin: 8px 0 0; font-size: var(--t-sm); color: var(--ink-3); }
.ms-prose[data-ms-text] { cursor: text; }

/* ---------- discover: other archives ---------- */
.discover-more:not(:empty) { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.discover-more h2 { font-size: var(--t-lg); }
.discover-more .status { margin: 6px 0 16px; min-height: 0; }
.more-group { margin-bottom: 16px; }
.more-group h3 { margin-bottom: 8px; font-size: var(--t-sm); font-weight: 650; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--ink); text-decoration: none; font-size: var(--t-sm); font-weight: 550; }
.chip:hover { border-color: var(--ink-3); }
.chip .ic { color: var(--ink-3); }
.plate-rel { position: absolute; left: 8px; bottom: 8px; padding: 2px 8px; border-radius: 999px; background: rgb(0 0 0 / .62); color: #fff; font-size: var(--t-xs); font-weight: 550; pointer-events: none; }
.chip small { color: var(--ink-3); font-weight: 450; }
.dlink { margin: 14px 0 0; display: grid; gap: 6px; max-width: 760px; }
.dlink label { font-size: var(--t-sm); color: var(--ink-2); }
.dlink-row { display: flex; gap: 8px; }
.dlink-row input { flex: 1; min-width: 0; height: 36px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); }

/* ---------- background updates ---------- */
.jobs-btn { gap: 8px; }
.jobs-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--board-ink-2); }
.jobs-btn[data-state="ok"] .jobs-dot, .job[data-state="ok"] .jobs-dot { background: #6f9a7a; }
.jobs-btn[data-state="running"] .jobs-dot, .job[data-state="running"] .jobs-dot { background: var(--cloth-ochre); animation: jobs-pulse 1.6s ease-in-out infinite; }
.jobs-btn[data-state="failed"] .jobs-dot, .job[data-state="failed"] .jobs-dot { background: #d0745f; }
.jobs-btn[data-state="new"] .jobs-dot { background: #8fb7e0; }
@keyframes jobs-pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .jobs-dot { animation: none !important; } }
.jobs-pop { width: min(380px, calc(100vw - 32px)); padding: 0; }
.jobs-head { display: grid; gap: 2px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.jobs-head span, .jobs-foot { font-size: var(--t-sm); color: var(--ink-2); }
.jobs-new { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; background: var(--surface-2); font-size: var(--t-sm); }
.jobs-err { margin: 0; padding: 10px 16px; font-size: var(--t-sm); color: var(--danger); }
.jobs-list { list-style: none; margin: 0; padding: 4px 0; max-height: min(60vh, 460px); overflow: auto; }
.job { display: grid; grid-template-columns: 8px 1fr auto; gap: 12px; align-items: start; padding: 10px 16px; }
.job .jobs-dot { margin-top: 6px; }
.job + .job { border-top: 1px solid var(--line); }
.job-body { display: grid; gap: 3px; min-width: 0; }
.job-line { font-size: var(--t-sm); color: var(--ink); font-variant-numeric: tabular-nums; }
.job-about { font-size: var(--t-xs); color: var(--ink-3); }
.job-link { color: var(--ink-3); padding: 2px; border-radius: var(--r); }
.job-link:hover { color: var(--ink); }
.jobs-bar { display: block; height: 4px; margin: 3px 0 2px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.jobs-bar span { display: block; height: 100%; background: var(--cloth-ochre); border-radius: 2px; transition: width .4s var(--ease); }
.jobs-bar.indet span { width: 30%; animation: jobs-slide 1.8s ease-in-out infinite; }
@keyframes jobs-slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .jobs-bar.indet span { animation: none; width: 100%; opacity: .4; } }
.jobs-foot { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); white-space: nowrap; }
.jobs-foot span { margin-right: auto; }
.tab { white-space: nowrap; }
@media (max-width: 1360px) { .jobs-btn .btn-label { display: none; } .jobs-btn { padding: 0 12px; } }
@media (max-width: 720px) { .jobs-pop { position: fixed; left: 16px; right: 16px; top: 64px; width: auto; } }

/* ---------- drop in what you found ---------- */
.quick { display: grid; gap: 8px; margin: 0 0 18px; padding: 14px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); background: var(--surface-2); transition: border-color .15s, background .15s; }
.quick[hidden] { display: none; }
.quick.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 6%, var(--surface-2)); }
.quick label { display: grid; gap: 2px; }
.quick label span { font-size: var(--t-sm); color: var(--ink-2); font-weight: 400; }
.quick textarea { width: 100%; min-height: 84px; resize: vertical; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--t-sm); }
.quick-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.quick-status { font-size: var(--t-sm); color: var(--ink-2); }
.quick-kind { display: inline-flex !important; grid-auto-flow: column; align-items: center; gap: 6px !important; font-size: var(--t-sm); color: var(--ink-2); }
.quick-kind select { height: 30px; padding: 0 8px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--t-sm); }

/* ---------- find an image ---------- */
.img-dialog { width: min(1040px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; }
.img-body { padding: 0 24px 24px; overflow: auto; }
.img-for { margin: 0 0 12px; color: var(--ink-2); font-size: var(--t-sm); }
.img-for strong { color: var(--ink); font-weight: 600; }
.img-search { display: flex; gap: 8px; }
.img-search input { flex: 1; min-width: 0; height: 38px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; }
.img-role { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 14px 0 4px; padding: 0; border: 0; }
.img-role legend { font-size: var(--t-sm); font-weight: 600; margin-bottom: 6px; }
.img-role label { display: flex; gap: 8px; align-items: flex-start; max-width: 420px; font-size: var(--t-sm); color: var(--ink-2); cursor: pointer; }
.img-role label strong { display: block; color: var(--ink); font-weight: 600; }
.img-role input { margin-top: 3px; accent-color: var(--primary); }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 8px; }
.img-cand { margin: 0; display: grid; grid-template-rows: auto 1fr; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.img-cand.skel { height: 240px; background: var(--surface-2); animation: jobs-pulse 1.6s ease-in-out infinite; }
.img-pick { display: block; padding: 0; border: 0; background: var(--surface-2); cursor: pointer; aspect-ratio: 4 / 3; }
.img-pick img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .15s; }
.img-pick:hover img, .img-pick:focus-visible img { opacity: .85; }
.img-cand figcaption { display: grid; gap: 3px; padding: 10px 12px 12px; font-size: var(--t-sm); }
.img-cand figcaption strong { font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.img-cand figcaption > span { color: var(--ink-3); font-size: var(--t-xs); }
.img-cand-act { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.img-sug { margin-left: auto; font-size: var(--t-xs); color: var(--cloth-ochre); font-weight: 600; }
.img-manual { margin-top: 18px; font-size: var(--t-sm); }
.img-manual summary { cursor: pointer; color: var(--ink-2); font-weight: 550; }
.img-paste { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; align-items: end; }
.img-paste label { display: grid; gap: 4px; color: var(--ink-2); }
.img-paste input { height: 36px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; }
.img-paste .span2 { grid-column: 1 / -1; }
.credit.illus a { color: inherit; }
@media (max-width: 640px) { .img-body { padding: 0 16px 16px; } .img-paste { grid-template-columns: 1fr; } .img-grid { grid-template-columns: repeat(2, 1fr); } }
.img-dialog[open] { display: flex; flex-direction: column; }
.img-dialog .img-body { flex: 1; padding-top: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Transcripts */
.tr-badge { color: var(--cloth-moss); font-weight: 600; }
.card .said { display: block; margin-top: 6px; font-size: var(--t-sm); color: var(--ink-2); line-height: 1.45; }
.ts { display: inline-block; margin-right: 6px; font-size: var(--t-xs); font-variant-numeric: tabular-nums; color: var(--ink-3); }
.tr-meta { font-weight: 450; font-size: var(--t-sm); color: var(--ink-3); }
.tr-find { position: relative; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tr-find .ic { position: absolute; left: 10px; color: var(--ink-3); pointer-events: none; }
.tr-find input { flex: 1; min-width: 0; height: 34px; padding: 0 10px 0 32px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--t-md); }
.tr-count { flex: none; font-size: var(--t-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.tr-lines { max-height: 420px; overflow-y: auto; padding: 4px 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--ground); font-size: var(--t-md); line-height: 1.55; }
.tl { position: relative; margin: 0; padding: 7px 64px 7px 0; border-bottom: 1px solid var(--line); }
.tl:last-child { border-bottom: 0; }
.tl .ts { display: block; margin: 0 0 1px; }
.tq { position: absolute; right: 0; top: 6px; height: 26px; padding: 0 9px; border: 1px solid var(--line-strong); border-radius: 13px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: var(--t-xs); font-weight: 600; cursor: pointer; opacity: 0; transition: opacity .15s; }
.tl:hover .tq, .tq:focus-visible { opacity: 1; }
@media (hover: none) { .tq { opacity: 1; } }
.tr-empty { color: var(--ink-2); font-size: var(--t-md); max-width: 65ch; }
.tr .btn-row { margin-top: 10px; }
.tr-edit { margin-top: 10px; }
.tr-edit textarea { min-height: 240px; }
.tr-other { margin-top: 18px; }
