/* Slate Library — css/library.css
   Namespace: .lib-* for new rules; relies on css/base.css tokens.
   Do NOT edit the token block here — import base.css first. */

/* ===== LIBRARY EXTRAS ===== */
:root {
  --lib-serif: Georgia, "Times New Roman", serif;
  --lib-sidebar-w: 220px;
  --lib-topbar-h: 52px;
  --lib-reader-col: 68ch;
  --lib-cover-ratio: 52.5%;
  /* Collection color dots/tints — keyed by slug */
  --cc-market-memos:      #E05D77;
  --cc-semis-memos:       #4C8FDE;
  --cc-thematic-primers:  #7B6DE9;
  --cc-notes-misc:        #6FA85E;
  --cc-hubs:              #41A69F;
  --cc-in-conversation:   #DFA43F;
  --cc-citrindex:         #B562B0;
  --cc-flash-notes:       #E5764C;
  --cc-trade-updates:     #E05D77;
  --cc-state-of-the-themes: #4C8FDE;
  --cc-small-themes:      #7B6DE9;
  --cc-stock-theses:      #41A69F;
  --cc-thematic-updates:  #6FA85E;
  --cc-annual-trades:     #DFA43F;
  --cc-education:         #B562B0;
}

/* Per-collection tint via class on card/row container */
.lib-coll-market-memos      { --cc: var(--cc-market-memos); }
.lib-coll-semis-memos       { --cc: var(--cc-semis-memos); }
.lib-coll-thematic-primers  { --cc: var(--cc-thematic-primers); }
.lib-coll-notes-misc        { --cc: var(--cc-notes-misc); }
.lib-coll-hubs              { --cc: var(--cc-hubs); }
.lib-coll-in-conversation   { --cc: var(--cc-in-conversation); }
.lib-coll-citrindex         { --cc: var(--cc-citrindex); }
.lib-coll-flash-notes       { --cc: var(--cc-flash-notes); }
.lib-coll-trade-updates     { --cc: var(--cc-trade-updates); }
.lib-coll-state-of-the-themes { --cc: var(--cc-state-of-the-themes); }
.lib-coll-small-themes      { --cc: var(--cc-small-themes); }
.lib-coll-stock-theses      { --cc: var(--cc-stock-theses); }
.lib-coll-thematic-updates  { --cc: var(--cc-thematic-updates); }
.lib-coll-annual-trades     { --cc: var(--cc-annual-trades); }
.lib-coll-education         { --cc: var(--cc-education); }

/* Tint bg/text for spine fallback + chips */
.lib-coll-market-memos      { --t-bar: #E05D77; --t-bg: rgba(224,93,119,0.10); --t-text: #AD3B55; }
.lib-coll-semis-memos       { --t-bar: #4C8FDE; --t-bg: rgba(76,143,222,0.10); --t-text: #2F6BB2; }
.lib-coll-thematic-primers  { --t-bar: #7B6DE9; --t-bg: rgba(123,109,233,0.10); --t-text: #5A4BC5; }
.lib-coll-notes-misc        { --t-bar: #6FA85E; --t-bg: rgba(111,168,94,0.10); --t-text: #497C3A; }
.lib-coll-hubs              { --t-bar: #41A69F; --t-bg: rgba(65,166,159,0.10); --t-text: #2A7B75; }
.lib-coll-in-conversation   { --t-bar: #DFA43F; --t-bg: rgba(223,164,63,0.10); --t-text: #8F6A1E; }
.lib-coll-citrindex         { --t-bar: #B562B0; --t-bg: rgba(181,98,176,0.10); --t-text: #8E4589; }
.lib-coll-flash-notes       { --t-bar: #E5764C; --t-bg: rgba(229,118,76,0.10); --t-text: #B14E28; }
.lib-coll-trade-updates     { --t-bar: #E05D77; --t-bg: rgba(224,93,119,0.10); --t-text: #AD3B55; }
.lib-coll-state-of-the-themes { --t-bar: #4C8FDE; --t-bg: rgba(76,143,222,0.10); --t-text: #2F6BB2; }
.lib-coll-small-themes      { --t-bar: #7B6DE9; --t-bg: rgba(123,109,233,0.10); --t-text: #5A4BC5; }
.lib-coll-stock-theses      { --t-bar: #41A69F; --t-bg: rgba(65,166,159,0.10); --t-text: #2A7B75; }
.lib-coll-thematic-updates  { --t-bar: #6FA85E; --t-bg: rgba(111,168,94,0.10); --t-text: #497C3A; }
.lib-coll-annual-trades     { --t-bar: #DFA43F; --t-bg: rgba(223,164,63,0.10); --t-text: #8F6A1E; }
.lib-coll-education         { --t-bar: #B562B0; --t-bg: rgba(181,98,176,0.10); --t-text: #8E4589; }

[data-theme="dark"] .lib-coll-market-memos     { --t-bg: rgba(224,93,119,0.15); --t-text: #F095A8; }
[data-theme="dark"] .lib-coll-semis-memos      { --t-bg: rgba(76,143,222,0.15); --t-text: #97BFEE; }
[data-theme="dark"] .lib-coll-thematic-primers { --t-bg: rgba(123,109,233,0.16); --t-text: #B1A7F2; }
[data-theme="dark"] .lib-coll-notes-misc       { --t-bg: rgba(111,168,94,0.15); --t-text: #A4CE96; }
[data-theme="dark"] .lib-coll-hubs             { --t-bg: rgba(65,166,159,0.15); --t-text: #8BD0CB; }
[data-theme="dark"] .lib-coll-in-conversation  { --t-bg: rgba(223,164,63,0.14); --t-text: #E9C079; }
[data-theme="dark"] .lib-coll-citrindex        { --t-bg: rgba(181,98,176,0.16); --t-text: #D9A0D6; }
[data-theme="dark"] .lib-coll-flash-notes      { --t-bg: rgba(229,118,76,0.15); --t-text: #F0A183; }
[data-theme="dark"] .lib-coll-trade-updates    { --t-bg: rgba(224,93,119,0.15); --t-text: #F095A8; }
[data-theme="dark"] .lib-coll-state-of-the-themes { --t-bg: rgba(76,143,222,0.15); --t-text: #97BFEE; }
[data-theme="dark"] .lib-coll-small-themes     { --t-bg: rgba(123,109,233,0.16); --t-text: #B1A7F2; }
[data-theme="dark"] .lib-coll-stock-theses     { --t-bg: rgba(65,166,159,0.15); --t-text: #8BD0CB; }
[data-theme="dark"] .lib-coll-thematic-updates { --t-bg: rgba(111,168,94,0.15); --t-text: #A4CE96; }
[data-theme="dark"] .lib-coll-annual-trades    { --t-bg: rgba(223,164,63,0.14); --t-text: #E9C079; }
[data-theme="dark"] .lib-coll-education        { --t-bg: rgba(181,98,176,0.16); --t-text: #D9A0D6; }

/* ===== RESET (scoped to lib body) ===== */
.lib-page *,
.lib-page *::before,
.lib-page *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== TOPBAR ===== */
#lib-topbar {
  height: var(--lib-topbar-h);
  flex: 0 0 var(--lib-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  z-index: 50;
  position: relative;
}
#lib-topbar::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.35;
  pointer-events: none;
}
.lib-tb-left, .lib-tb-right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 1;
}
.lib-tb-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
}
.lib-logo-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  text-decoration: none;
}
.lib-app-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.lib-tb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  transition: background 120ms, color 120ms;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.lib-tb-btn:hover { background: var(--hover); color: var(--ink); }
.lib-tb-btn.icon-only { padding: 7px; }
.lib-tb-divider { width: 1px; height: 20px; background: var(--line-strong); margin: 0 2px; }

/* Search bar */
.lib-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0 12px;
  height: 32px;
  width: 300px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 150ms, border-color 150ms;
}
.lib-search-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-card);
}
.lib-search-wrap svg { color: var(--ink-3); flex-shrink: 0; }
.lib-search-wrap input {
  flex: 1;
  font-size: 13.5px;
  color: var(--ink);
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
}
.lib-search-wrap input::placeholder { color: var(--ink-3); }
.lib-search-kbd {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--ink-3);
  background: var(--hover);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
}
#lib-ft-toggle {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: var(--hover);
  color: var(--ink-3);
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 120ms;
}
#lib-ft-toggle.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
#lib-ft-toggle:hover { color: var(--ink-2); }

/* ===== APP LAYOUT ===== */
.lib-app { display: flex; flex: 1; overflow: hidden; }

/* ===== SIDEBAR ===== */
#lib-sidebar {
  width: var(--lib-sidebar-w);
  flex: 0 0 var(--lib-sidebar-w);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
#lib-sidebar::-webkit-scrollbar { width: 5px; }
#lib-sidebar::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
.lib-sb-section { padding: 16px 12px 8px; }
.lib-sb-section + .lib-sb-section { border-top: 1px solid var(--line); padding-top: 12px; }
.lib-sb-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 4px;
  margin-bottom: 6px;
}
.lib-sb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 100ms, color 100ms;
  font-size: 13px;
  color: var(--ink-2);
  background: none;
  border: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
}
.lib-sb-item:hover { background: var(--hover); color: var(--ink); }
.lib-sb-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lib-sb-item-left { display: flex; align-items: center; gap: 8px; }
.lib-sb-count {
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--ink-3);
  background: var(--hover);
  padding: 1px 6px;
  border-radius: 99px;
}
.lib-sb-item.active .lib-sb-count { color: var(--accent); background: var(--accent-soft); }

/* Collection list in sidebar */
.lib-coll-list { display: flex; flex-direction: column; gap: 1px; margin-top: 2px; }
.lib-coll-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--ink-3);
  transition: background 100ms, color 100ms;
  background: none;
  border: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
}
.lib-coll-row:hover { background: var(--hover); color: var(--ink-2); }
.lib-coll-row.active { color: var(--accent); background: var(--accent-soft); }
.lib-coll-row-left { display: flex; align-items: center; gap: 7px; }
.lib-coll-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cc, var(--ink-3));
  flex-shrink: 0;
}
.lib-coll-row.active .lib-coll-dot { background: var(--accent); }
.lib-coll-count {
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--ink-3);
}
.lib-coll-row.active .lib-coll-count { color: var(--accent); }

/* FILES section items (dimmed/quiet) */
.lib-sb-item.lib-quiet { opacity: 0.6; }
.lib-sb-hint {
  font-size: 11px;
  color: var(--ink-3);
  padding: 2px 12px 8px;
  font-style: italic;
}

/* ===== MAIN ===== */
#lib-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* Toolbar strip */
#lib-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 44px;
  flex: 0 0 44px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.lib-toolbar-left, .lib-toolbar-right { display: flex; align-items: center; gap: 8px; }
.lib-toolbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.lib-toolbar-count { font-size: 12.5px; color: var(--ink-3); margin-left: 4px; }
.lib-seg {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--hover);
  border-radius: 8px;
  padding: 2px;
}
.lib-seg-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  transition: color 120ms, background 120ms;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.lib-seg-btn:hover { color: var(--ink); }
.lib-seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }
.lib-sort-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  transition: all 120ms;
  font-family: inherit;
  cursor: pointer;
}
.lib-sort-btn:hover { color: var(--ink); border-color: var(--accent); }

/* ===== CONTENT AREA ===== */
#lib-content { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
#lib-content::-webkit-scrollbar { width: 8px; }
#lib-content::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }

/* Dot grid canvas */
#lib-grid-canvas {
  min-height: 100%;
  background-image: radial-gradient(var(--dot) 1.1px, transparent 1.1px);
  background-size: 22px 22px;
  padding: 24px 24px 40px;
}

/* ===== HERO SLOT ===== */
#lib-hero {
  display: flex;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-board);
  margin-bottom: 28px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 200ms cubic-bezier(0.2,0.8,0.3,1), box-shadow 200ms;
  position: relative;
  border: none;
  width: 100%;
  font-family: inherit;
  text-align: left;
}
#lib-hero:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 48px -16px rgba(27,34,48,0.2), 0 4px 12px -2px rgba(27,34,48,0.1);
}
[data-theme="dark"] #lib-hero:hover {
  box-shadow: 0 20px 48px -12px rgba(0,0,0,0.65), 0 4px 12px -2px rgba(0,0,0,0.4);
}
.lib-hero-cover {
  flex: 0 0 42%;
  position: relative;
  overflow: hidden;
  min-height: 280px;
  background: var(--hover);
}
.lib-hero-cover img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform 400ms ease;
}
#lib-hero:hover .lib-hero-cover img { transform: scale(1.04); }
.lib-hero-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  /* typographic spine: 4px tint bar + title text */
  position: relative;
  background: var(--t-bg, var(--hover));
  overflow: hidden;
}
.lib-hero-fallback .lib-spine-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--t-bar, var(--accent));
}
.lib-hero-fallback .lib-spine-text {
  font-size: 14px;
  font-weight: 650;
  color: var(--t-text, var(--ink-2));
  padding: 16px 20px;
  line-height: 1.4;
}
.lib-hero-badge {
  position: absolute; top: 14px; left: 14px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 99px;
}
.lib-hero-body {
  flex: 1;
  padding: 36px 40px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.lib-hero-coll {
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--cc, var(--accent));
  margin-bottom: 10px;
}
.lib-hero-title {
  font-family: var(--lib-serif);
  font-size: 26px; font-weight: 700;
  line-height: 1.25; letter-spacing: -0.02em; color: var(--ink);
  margin-bottom: 10px;
}
.lib-hero-subtitle {
  font-size: 14px; color: var(--ink-2); line-height: 1.5; margin-bottom: 20px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-hero-meta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.lib-hero-author { font-size: 13px; font-weight: 600; color: var(--ink); }
.lib-hero-date { font-size: 12px; color: var(--ink-3); }
.lib-meta-sep { color: var(--line-strong); }
.lib-hero-reading { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-3); }

/* ===== YEAR SHELF DIVIDERS (from archive-gallery graft) ===== */
.lib-year-shelf {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 16px;
}
.lib-year-shelf:not(:first-child) { margin-top: 28px; }
.lib-year-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--ink-3); white-space: nowrap;
}
.lib-year-line { flex: 1; height: 1px; background: var(--line); }
.lib-year-count { font-family: var(--mono); font-size: 10px; color: var(--ink-3); white-space: nowrap; }

/* ===== CARD GRID ===== */
.lib-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

/* Article card */
.lib-card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: transform 180ms cubic-bezier(0.2,0.8,0.3,1), box-shadow 180ms;
  display: flex; flex-direction: column;
  border: 1px solid transparent;
  position: relative;
  font-family: inherit;
}
.lib-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--line);
}
.lib-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Card cover: either img or typographic spine */
.lib-card-cover {
  position: relative;
  padding-bottom: var(--lib-cover-ratio);
  overflow: hidden;
  background: var(--t-bg, var(--hover));
  flex-shrink: 0;
}
.lib-card-cover img {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;
  transition: transform 350ms ease;
}
.lib-card:hover .lib-card-cover img { transform: scale(1.05); }

/* Typographic spine fallback (archive-gallery graft) */
.lib-card-spine {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; align-items: center;
  background: var(--t-bg, var(--hover));
  overflow: hidden;
}
.lib-card-spine .lib-spine-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--t-bar, var(--ink-3));
}
.lib-card-spine .lib-spine-text {
  padding: 10px 14px 10px 20px;
  font-size: 11.5px; font-weight: 650; line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--t-text, var(--ink-2));
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}

.lib-card-locked-overlay {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(15,18,22,0.5);
  display: flex; align-items: center; justify-content: center;
}
.lib-lock-icon {
  background: rgba(255,255,255,0.92);
  border-radius: 50%; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.lib-card-chip {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(255,255,255,0.92);
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-2); padding: 2px 8px; border-radius: 99px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
[data-theme="dark"] .lib-card-chip { background: rgba(22,26,33,0.88); color: var(--ink-2); }

.lib-card-body { padding: 14px 14px 12px; display: flex; flex-direction: column; flex: 1; }
.lib-card-coll {
  font-size: 10px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--cc, var(--accent)); margin-bottom: 6px;
}
.lib-card-title {
  font-family: var(--lib-serif);
  font-size: 15.5px; font-weight: 700;
  line-height: 1.3; letter-spacing: -0.01em; color: var(--ink);
  margin-bottom: 5px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-card-subtitle {
  font-size: 12px; color: var(--ink-3); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  margin-bottom: 10px; flex: 1;
}
.lib-card-meta {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 10px; border-top: 1px solid var(--line);
}
.lib-card-date { font-size: 11.5px; color: var(--ink-3); }
.lib-card-reading { display: flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-3); }

/* Placeholder cards for future types */
.lib-placeholder-card {
  background: var(--surface); border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow-card); border: 1px dashed var(--line-strong);
  opacity: 0.65; display: flex; flex-direction: column; position: relative;
}
.lib-placeholder-cover {
  padding-bottom: var(--lib-cover-ratio); background: var(--hover);
  display: flex; align-items: center; justify-content: center; position: relative;
}
.lib-placeholder-icon {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px; color: var(--ink-3);
}
.lib-placeholder-body { padding: 14px; flex: 1; }
.lib-placeholder-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-3); background: var(--hover); padding: 2px 8px; border-radius: 99px;
  margin-bottom: 8px;
}
.lib-placeholder-title { font-size: 13px; font-weight: 600; color: var(--ink-2); line-height: 1.4; margin-bottom: 4px; }
.lib-placeholder-subtitle { font-size: 11.5px; color: var(--ink-3); line-height: 1.4; }

/* ===== LIST VIEW (research-desk graft) ===== */
#lib-list-view { display: none; flex: 1; flex-direction: column; overflow: hidden; }
#lib-list-view.visible { display: flex; }
.lib-list-header {
  display: grid;
  grid-template-columns: 40px 1fr 180px 90px 60px;
  gap: 0;
  padding: 0 8px;
  height: 30px; align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5; flex-shrink: 0;
}
.lib-list-hcell {
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--ink-3); padding: 0 6px; white-space: nowrap; overflow: hidden;
}
#lib-list-rows {
  flex: 1; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}
#lib-list-rows::-webkit-scrollbar { width: 7px; }
#lib-list-rows::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
.lib-list-row {
  display: grid;
  grid-template-columns: 40px 1fr 180px 90px 60px;
  gap: 0;
  padding: 0 8px;
  min-height: 46px; align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: background 80ms;
}
.lib-list-row:hover { background: var(--hover); }
.lib-list-row.lib-active { background: var(--accent-soft); }
.lib-list-cell { padding: 0 6px; overflow: hidden; }
.lib-row-cover {
  width: 28px; height: 28px; border-radius: 4px; overflow: hidden;
  background: var(--t-bg, var(--hover)); position: relative; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.lib-row-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-row-spine-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--t-bar, var(--ink-3));
  border-radius: 4px 0 0 4px;
}
.lib-row-title-wrap { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.lib-row-title {
  font-size: 13px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-list-row.lib-active .lib-row-title { color: var(--accent); }
.lib-row-subtitle {
  font-size: 11.5px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-row-coll {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden;
}
.lib-row-coll-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--cc, var(--ink-3)); flex-shrink: 0;
}
.lib-row-date {
  font-size: 12px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.lib-row-read {
  font-size: 12px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* Quick-preview panel (research-desk graft) */
#lib-preview {
  width: 280px; flex: 0 0 280px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column; overflow: hidden;
  transition: opacity 150ms;
}
#lib-preview.lib-empty { opacity: 0.4; pointer-events: none; }
#lib-preview .lib-pv-cover {
  width: 100%; height: 156px; object-fit: cover; display: block; background: var(--hover);
}
#lib-preview .lib-pv-cover-ph {
  width: 100%; height: 156px;
  display: flex; align-items: center; justify-content: center;
  background: var(--t-bg, var(--hover));
  position: relative; overflow: hidden;
}
#lib-preview .lib-pv-cover-ph .lib-spine-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 4px; background: var(--t-bar, var(--accent));
}
.lib-pv-body { padding: 14px; flex: 1; overflow-y: auto; scrollbar-width: thin; }
.lib-pv-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.lib-pv-chip {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 99px;
  background: var(--t-bg, var(--hover)); color: var(--t-text, var(--ink-3));
  white-space: nowrap;
}
.lib-pv-date { font-size: 11px; color: var(--ink-3); }
.lib-pv-title {
  font-size: 14px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.35;
  margin-bottom: 5px; color: var(--ink);
}
.lib-pv-subtitle { font-size: 12.5px; color: var(--ink-2); line-height: 1.4; margin-bottom: 10px; }
.lib-pv-divider { height: 1px; background: var(--line); margin: 10px 0; }
.lib-pv-stats { display: flex; gap: 14px; margin-bottom: 10px; }
.lib-pv-stat { font-size: 11.5px; color: var(--ink-3); }
.lib-pv-stat strong { color: var(--ink-2); font-weight: 600; }
.lib-pv-snippet {
  font-size: 12.5px; line-height: 1.55; color: var(--ink-2);
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-pv-open {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 8px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; margin-top: 12px;
  cursor: pointer; font-family: inherit; border: none;
  transition: opacity 120ms;
}
.lib-pv-open:hover { opacity: 0.88; }
.lib-pv-empty { padding: 24px 14px; text-align: center; color: var(--ink-3); font-size: 13px; line-height: 1.5; }

/* ===== SNIPPET HIGHLIGHTS ===== */
.lib-snippet { font-size: 12px; color: var(--ink-2); line-height: 1.5; margin-top: 6px; }
.lib-snippet mark { background: var(--accent-soft); color: var(--accent); font-weight: 600; border-radius: 2px; padding: 0 2px; }

/* ===== EMPTY STATE ===== */
#lib-empty {
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 24px; text-align: center;
}
#lib-empty.visible { display: flex; }
.lib-empty-icon { font-size: 48px; margin-bottom: 20px; opacity: 0.4; }
.lib-empty-title { font-size: 17px; font-weight: 650; color: var(--ink); margin-bottom: 8px; letter-spacing: -0.02em; }
.lib-empty-sub { font-size: 13.5px; color: var(--ink-2); max-width: 320px; line-height: 1.55; }
.lib-empty-clear {
  margin-top: 20px; padding: 7px 16px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: none; font-family: inherit;
  transition: opacity 120ms;
}
.lib-empty-clear:hover { opacity: 0.88; }

/* ===== SKELETON ===== */
.lib-skel {
  background: linear-gradient(90deg, var(--hover) 25%, var(--line) 50%, var(--hover) 75%);
  background-size: 200% 100%;
  animation: lib-shimmer 1.4s ease infinite;
  border-radius: 4px;
}
@keyframes lib-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== TOAST ===== */
#lib-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: var(--toast-bg); color: var(--toast-ink);
  font-size: 13px; padding: 9px 18px; border-radius: 10px;
  box-shadow: var(--shadow-pop);
  opacity: 0; transition: opacity 200ms, transform 200ms; pointer-events: none; z-index: 999;
}
#lib-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== READER VIEW ===== */
#lib-reader {
  display: none;
  position: absolute; inset: 0; z-index: 100;
  background: var(--bg); overflow: hidden; flex-direction: column;
}
#lib-reader.open { display: flex; }

/* Reading-progress bar (research-desk graft) */
#lib-read-progress {
  position: absolute; top: 0; left: 0; height: 2px;
  background: var(--accent); z-index: 200;
  width: 0%; transition: width 100ms linear; pointer-events: none;
}

#lib-reader-topbar {
  height: var(--lib-topbar-h);
  flex: 0 0 var(--lib-topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: relative;
}
.lib-back-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  transition: background 120ms, color 120ms;
  background: none; border: none; cursor: pointer; font-family: inherit;
}
.lib-back-btn:hover { background: var(--hover); color: var(--ink); }
.lib-reader-title-bar {
  font-size: 13px; font-weight: 600; color: var(--ink-3);
  max-width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-reader-pager { display: flex; align-items: center; gap: 4px; }
.lib-page-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  border: 1px solid var(--line-strong); background: none; cursor: pointer; font-family: inherit;
  transition: all 120ms;
}
.lib-page-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lib-page-btn:disabled { opacity: 0.35; pointer-events: none; }

#lib-reader-layout { display: flex; flex: 1; overflow: hidden; }

/* TOC rail */
#lib-toc {
  width: 200px; flex: 0 0 200px;
  padding: 24px 0 24px 16px;
  border-right: 1px solid var(--line);
  overflow-y: auto; scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
#lib-toc::-webkit-scrollbar { width: 4px; }
#lib-toc::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.lib-toc-label {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 10px; padding-left: 4px;
}
.lib-toc-item {
  display: block; padding: 5px 8px; border-radius: 5px;
  font-size: 12px; color: var(--ink-3); line-height: 1.4; cursor: pointer;
  transition: color 100ms, background 100ms; margin-bottom: 1px;
  border-left: 2px solid transparent; text-decoration: none;
}
.lib-toc-item:hover { color: var(--ink-2); background: var(--hover); }
.lib-toc-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }
.lib-toc-item.h3 { padding-left: 18px; font-size: 11.5px; }

/* Reader scroll */
#lib-reader-scroll {
  flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  position: relative;
}
#lib-reader-scroll::-webkit-scrollbar { width: 8px; }
#lib-reader-scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }

#lib-article {
  max-width: var(--lib-reader-col);
  margin: 0 auto;
  padding: 48px 24px 80px;
}

/* Article header */
.lib-article-header { margin-bottom: 40px; padding-bottom: 32px; border-bottom: 1px solid var(--line); }
.lib-article-coll-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--cc, var(--accent)); margin-bottom: 14px;
}
.lib-article-h1 {
  font-family: var(--lib-serif);
  font-size: 32px; font-weight: 700;
  line-height: 1.22; letter-spacing: -0.025em; color: var(--ink);
  margin-bottom: 12px;
}
.lib-article-subtitle { font-size: 16px; color: var(--ink-2); line-height: 1.55; margin-bottom: 20px; }
.lib-article-byline {
  display: flex; align-items: center; flex-wrap: wrap; gap: 16px;
  font-size: 13px; color: var(--ink-2);
}
.lib-byline-author { font-weight: 600; color: var(--ink); }
.lib-byline-sep { color: var(--line-strong); }
.lib-cover-img {
  width: 100%; border-radius: 10px; margin-top: 24px;
  box-shadow: var(--shadow-card); display: block;
}
.lib-cover-img-hidden { display: none; }

/* Locked banner */
.lib-locked-banner {
  display: none; margin: 0 0 32px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 10px; padding: 18px 20px;
  align-items: center; gap: 14px;
}
.lib-locked-banner.show { display: flex; }
.lib-locked-icon { font-size: 22px; flex-shrink: 0; }
.lib-locked-title { font-size: 14px; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.lib-locked-desc { font-size: 13px; color: var(--ink-2); }
.lib-locked-link { color: var(--accent); text-decoration: underline; }

/* Article body typography (reading-room base) */
.lib-article-body {
  font-family: var(--font);
  font-size: 16.5px; line-height: 1.72; color: var(--ink);
}
.lib-article-body h1 {
  font-family: var(--lib-serif); font-size: 26px; font-weight: 700;
  line-height: 1.25; letter-spacing: -0.02em;
  margin: 2.4em 0 0.6em; color: var(--ink);
}
.lib-article-body h2 {
  font-family: var(--lib-serif); font-size: 22px; font-weight: 700;
  line-height: 1.3; letter-spacing: -0.018em;
  margin: 2.2em 0 0.6em; color: var(--ink);
  padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.lib-article-body h3 {
  font-family: var(--lib-serif); font-size: 18px; font-weight: 700;
  line-height: 1.35; letter-spacing: -0.015em;
  margin: 1.8em 0 0.5em; color: var(--ink);
}
.lib-article-body h4 {
  font-size: 12px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  margin: 1.5em 0 0.4em; color: var(--ink-2);
}
.lib-article-body p { margin: 0 0 1.2em; }
.lib-article-body p:last-child { margin-bottom: 0; }
.lib-article-body strong { font-weight: 700; color: var(--ink); }
.lib-article-body em { font-style: italic; }
.lib-article-body a {
  color: var(--accent); text-decoration: underline;
  text-underline-offset: 2px; text-decoration-thickness: 1px;
}
.lib-article-body a:hover { text-decoration-thickness: 2px; }
.lib-article-body ul, .lib-article-body ol { padding-left: 24px; margin: 0 0 1.2em; }
.lib-article-body li { margin-bottom: 0.4em; }
.lib-article-body blockquote {
  margin: 1.6em 0; padding: 14px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft); border-radius: 0 8px 8px 0;
  font-size: 16px; color: var(--ink-2);
}
.lib-article-body blockquote p:last-child { margin: 0; }
.lib-article-body hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
.lib-article-body img {
  max-width: 100%; border-radius: 8px; display: block;
  margin: 1.6em auto; box-shadow: var(--shadow-card);
}
.lib-article-body figure { margin: 1.6em 0; text-align: center; }
.lib-article-body figcaption { font-size: 12px; color: var(--ink-3); margin-top: 8px; font-style: italic; }
.lib-article-body table { width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: 14px; }
.lib-article-body th { background: var(--hover); font-weight: 700; text-align: left; padding: 8px 12px; border-bottom: 2px solid var(--line-strong); }
.lib-article-body td { padding: 7px 12px; border-bottom: 1px solid var(--line); }
.lib-article-body code {
  font-family: var(--mono); font-size: 13.5px;
  background: var(--hover); border-radius: 4px; padding: 1px 5px; border: 1px solid var(--line);
}
.lib-article-body pre {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; overflow-x: auto; margin: 1.6em 0;
}
.lib-article-body pre code { background: none; border: none; padding: 0; font-size: 13px; }

/* ===== LIBRARY V2: SIDEBAR GROUPS ===== */

/* Section-head (collapsible CITRINI RESEARCH toggle) */
.lib-sb-section-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 0 4px; margin-bottom: 6px;
  background: none; border: none; cursor: pointer;
  font-family: inherit;
}
.lib-sb-label-inline {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-3);
}
.lib-sb-chevron {
  transition: transform 200ms; color: var(--ink-3); flex-shrink: 0;
}
.lib-sb-section-head.collapsed .lib-sb-chevron { transform: rotate(-90deg); }

/* Citrini collapsible body */
.lib-sb-citrini-body { overflow: hidden; transition: max-height 250ms ease; max-height: 2000px; }
.lib-sb-citrini-body.collapsed { max-height: 0; }

/* "All Citrini" row inside citrini section */
.lib-sb-citrini-all { margin-bottom: 4px; }

/* New post button — cobalt/accent filled */
.lib-sb-new-post {
  background: var(--accent) !important;
  color: var(--accent-ink) !important;
  font-weight: 600 !important;
  margin-bottom: 6px;
}
.lib-sb-new-post:hover { opacity: 0.88; background: var(--accent) !important; }
.lib-sb-new-post svg { color: var(--accent-ink); }

/* ===== LIBRARY V2: USER CARDS ===== */

/* User item card: cobalt-tinted spine */
--cc-user: #3B82F6;
.lib-card-user .lib-card-cover-user { background: rgba(59,130,246,0.10); }
.lib-card-cover-user .lib-spine-bar { background: #3B82F6; }
.lib-card-cover-user .lib-spine-text { color: #2563EB; }
[data-theme="dark"] .lib-card-cover-user { background: rgba(59,130,246,0.16); }
[data-theme="dark"] .lib-card-cover-user .lib-spine-text { color: #93C5FD; }

/* PDF variant: amber spine */
.lib-card-cover-user-pdf { background: rgba(245,158,11,0.10) !important; }
.lib-card-cover-user-pdf .lib-spine-bar { background: #F59E0B !important; }
.lib-card-cover-user-pdf .lib-spine-text { color: #B45309 !important; }
[data-theme="dark"] .lib-card-cover-user-pdf { background: rgba(245,158,11,0.14) !important; }
[data-theme="dark"] .lib-card-cover-user-pdf .lib-spine-text { color: #FCD34D !important; }

/* Delete button on card */
.lib-card-delete {
  background: none; border: none; cursor: pointer; padding: 3px 5px;
  border-radius: 5px; color: var(--ink-3);
  display: flex; align-items: center;
  transition: background 100ms, color 100ms;
  margin-left: auto; flex-shrink: 0;
}
.lib-card-delete:hover { background: var(--danger-bg, rgba(239,68,68,0.1)); color: var(--danger, #DC2626); }

/* User folder badge inside card */
.lib-card-folder {
  font-size: 10px; font-weight: 600; padding: 1px 6px;
  border-radius: 99px; background: var(--accent-soft); color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* User type badge */
.lib-card-user-badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--accent); margin-right: 4px;
}

/* ===== LIBRARY V2: TOAST WITH UNDO BUTTON ===== */

/* Lib-toast extended for undo button */
#lib-toast { display: flex; align-items: center; gap: 10px; pointer-events: none; }
#lib-toast.show { pointer-events: auto; }
.lib-toast-msg { flex: 1; }
.lib-toast-undo {
  background: none; border: 1px solid rgba(255,255,255,0.35);
  color: inherit; padding: 3px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
  white-space: nowrap; transition: background 100ms;
  flex-shrink: 0;
}
.lib-toast-undo:hover { background: rgba(255,255,255,0.15); }

/* ===== LIBRARY V2: COMPOSER MODAL ===== */

#lib-composer-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(10,12,18,0.55);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 180ms;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
#lib-composer-overlay.show { opacity: 1; }

.lib-composer-modal {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: 0 24px 64px -12px rgba(0,0,0,0.36), 0 8px 24px -4px rgba(0,0,0,0.14);
  width: 560px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  display: flex; flex-direction: column;
  overflow: hidden;
}
[data-theme="dark"] .lib-composer-modal {
  box-shadow: 0 24px 64px -8px rgba(0,0,0,0.7), 0 8px 24px -4px rgba(0,0,0,0.4);
}

.lib-composer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 14px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.lib-composer-title {
  font-size: 15px; font-weight: 650; color: var(--ink); letter-spacing: -0.01em;
}
.lib-composer-close {
  background: none; border: none; cursor: pointer; font-family: inherit;
  font-size: 20px; color: var(--ink-3); padding: 2px 6px; border-radius: 6px;
  line-height: 1; transition: background 100ms, color 100ms;
}
.lib-composer-close:hover { background: var(--hover); color: var(--ink); }

.lib-composer-body {
  flex: 1; overflow-y: auto; padding: 18px 20px;
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
}

.lib-field { display: flex; flex-direction: column; gap: 5px; }
.lib-field-grow { flex: 1; }
.lib-field-label {
  font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: 0.01em;
}
.lib-field-req { color: var(--danger, #DC2626); }
.lib-field-input {
  padding: 8px 11px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--bg);
  color: var(--ink); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color 140ms, box-shadow 140ms;
  width: 100%;
}
.lib-field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.lib-field-input.lib-field-error { border-color: var(--danger, #DC2626); }
.lib-field-textarea {
  padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--bg);
  color: var(--ink); font-size: 14px; font-family: inherit; line-height: 1.6;
  outline: none; resize: vertical; min-height: 140px; width: 100%;
  transition: border-color 140ms, box-shadow 140ms;
}
.lib-field-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.lib-combo-wrap { position: relative; }

/* PDF drop zone */
.lib-pdf-drop {
  position: relative; border: 1.5px dashed var(--line-strong);
  border-radius: 9px; padding: 14px 16px;
  display: flex; align-items: center; gap: 10px;
  color: var(--ink-3); font-size: 13px; cursor: pointer;
  transition: border-color 140ms, background 140ms;
  background: var(--hover);
}
.lib-pdf-drop:hover, .lib-pdf-drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.lib-pdf-warn { font-size: 12px; color: var(--warning, #D97706); margin-top: 4px; }

.lib-composer-foot {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.lib-composer-cancel {
  background: none; border: 1px solid var(--line-strong);
  padding: 7px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  color: var(--ink-2); cursor: pointer; font-family: inherit;
  transition: all 120ms;
}
.lib-composer-cancel:hover { border-color: var(--ink-3); color: var(--ink); background: var(--hover); }
.lib-composer-save {
  background: var(--accent); color: var(--accent-ink);
  border: none; padding: 7px 18px; border-radius: 8px;
  font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
  transition: opacity 120ms;
}
.lib-composer-save:hover { opacity: 0.88; }

/* ===== LIBRARY V2: READER USER CONTROLS ===== */

.lib-reader-user-controls {
  display: flex; align-items: center; gap: 6px;
}
.lib-reader-user-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  border: 1px solid var(--line-strong); background: none;
  cursor: pointer; font-family: inherit; transition: all 120ms;
}
.lib-reader-user-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lib-reader-delete-btn:hover { border-color: var(--danger, #DC2626); color: var(--danger, #DC2626); background: rgba(220,38,38,0.08); }

/* User article pill */
.lib-user-coll-pill { color: var(--accent); }

/* ===== LIBRARY V2: PDF VIEWER ===== */

.lib-pdf-viewer {
  display: flex; flex-direction: column; height: 100%;
  min-height: calc(100vh - 160px);
}
.lib-pdf-embed {
  flex: 1; width: 100%; min-height: calc(100vh - 210px);
  border: 1px solid var(--line); border-radius: 8px;
  display: block;
}
.lib-pdf-download-row {
  display: flex; justify-content: center; padding: 14px 0 4px;
}
.lib-pdf-download-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 18px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13.5px; font-weight: 600; text-decoration: none;
  transition: opacity 120ms;
}
.lib-pdf-download-btn:hover { opacity: 0.88; }

/* ===== LIBRARY V2: USER ARTICLE READER ===== */
.lib-user-article .lib-article-body {
  white-space: pre-wrap;
  font-size: 16px;
}

/* ===== C7: Citrini offline/error notice ===== */
.lib-citrini-offline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(209, 77, 77, 0.08);
  border: 1px solid rgba(209, 77, 77, 0.2);
  border-radius: 10px;
  font-size: 13px;
  color: var(--danger, #D14D4D);
  margin: 12px 0;
}

/* ===== WAVE 2b: RESPONSIVE (UX-02) ===== */

/* Hamburger button — hidden on desktop */
#lib-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 8px;
  background: none; border: none;
  cursor: pointer; color: var(--ink-2);
  transition: background 120ms, color 120ms;
  flex-shrink: 0;
}
#lib-sidebar-toggle:hover { background: var(--hover); color: var(--ink); }

/* Sidebar overlay (mobile backdrop) */
#lib-sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#lib-sidebar-backdrop.show { display: block; }

@media (max-width: 700px) {
  /* Show hamburger */
  #lib-sidebar-toggle { display: flex; }

  /* Sidebar becomes a slide-in sheet */
  #lib-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
    width: min(280px, 85vw);
    flex: none;
  }
  #lib-sidebar.open {
    transform: translateX(0);
  }

  /* Grid becomes single column */
  .lib-card-grid {
    grid-template-columns: 1fr;
  }

  /* Hero stacks vertically */
  #lib-hero {
    flex-direction: column;
  }
  .lib-hero-cover {
    flex: none;
    width: 100%;
    min-height: 180px;
  }
  .lib-hero-body {
    padding: 20px 20px 24px;
  }
  .lib-hero-title { font-size: 20px; }
  .lib-hero-subtitle { font-size: 13px; }

  /* Grid canvas padding */
  #lib-grid-canvas { padding: 16px 12px 32px; }

  /* Toolbar compact */
  #lib-toolbar { padding: 0 12px; }

  /* Search bar narrower */
  .lib-search-wrap { width: 180px; }

  /* Reader full-bleed on mobile */
  #lib-toc {
    display: none;
  }
  #lib-article {
    padding: 24px 16px 60px;
  }

  /* List view: hide collection + reading columns */
  .lib-list-header,
  .lib-list-row {
    grid-template-columns: 40px 1fr 90px;
  }
  .lib-list-cell:nth-child(3),
  .lib-list-hcell:nth-child(3) { display: none; } /* collection */
  .lib-list-cell:nth-child(5),
  .lib-list-hcell:nth-child(5) { display: none; } /* reading time */

  /* Preview panel hidden on mobile (double-click still opens reader) */
  #lib-preview { display: none !important; }

  /* Toast: full width at bottom */
  #lib-toast {
    left: 12px; right: 12px;
    transform: translateY(12px);
    width: auto;
  }
  #lib-toast.show {
    transform: translateY(0);
  }
}

/* ===== WAVE 2b: READING PROGRESS (UX-03 + FG-01 + FG-15) ===== */

/* Progress ring on card cover */
.lib-card-progress-ring {
  position: absolute;
  bottom: 8px; right: 8px;
  width: 28px; height: 28px;
  pointer-events: none;
  z-index: 5;
}
.lib-card-progress-ring circle {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  transform-origin: 50% 50%;
}
.lib-card-progress-ring .ring-bg {
  stroke: rgba(255,255,255,0.35);
  r: 11;
  cx: 14; cy: 14;
}
.lib-card-progress-ring .ring-fg {
  stroke: var(--accent);
  r: 11;
  cx: 14; cy: 14;
  transform: rotate(-90deg);
  stroke-dasharray: 69.1; /* 2π*11 */
  stroke-dashoffset: 69.1; /* will be set inline */
  transition: stroke-dashoffset 300ms;
}
.lib-card-progress-ring.done .ring-fg { stroke: #22c55e; }

/* Done badge (ring full + checkmark) */
.lib-card-done-badge {
  position: absolute; bottom: 8px; right: 8px;
  width: 22px; height: 22px;
  background: #22c55e;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
  pointer-events: none;
}
.lib-card-done-badge svg { color: #fff; }

/* Continue reading rail */
#lib-continue-rail {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  margin-bottom: 16px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
#lib-continue-rail::-webkit-scrollbar { display: none; }
#lib-continue-rail.show { display: flex; }
.lib-continue-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--accent);
  white-space: nowrap; flex-shrink: 0;
}
.lib-continue-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 7px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  cursor: pointer; flex-shrink: 0;
  transition: border-color 120ms, background 120ms;
  font-family: inherit;
  font-size: 12.5px; font-weight: 500; color: var(--ink);
}
.lib-continue-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.lib-continue-title {
  max-width: 160px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.lib-continue-pct {
  font-size: 11px; color: var(--ink-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* Mini progress bar inside continue chip */
.lib-continue-bar-wrap {
  width: 40px; height: 3px;
  background: var(--line-strong); border-radius: 99px; flex-shrink: 0;
}
.lib-continue-bar {
  height: 100%; background: var(--accent); border-radius: 99px;
  transition: width 300ms;
}

/* ===== WAVE 2b: CLIP-TO-BRAIN PILL (FG-02) ===== */
#lib-clip-pill {
  position: fixed;
  z-index: 9999;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 99px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  cursor: pointer; font-family: inherit;
  transition: transform 120ms, box-shadow 120ms;
  pointer-events: auto;
  user-select: none;
  white-space: nowrap;
}
#lib-clip-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
#lib-clip-pill.show { display: flex; }

/* ===== WAVE 2b: FONT SIZE CONTROLS (FG-20) ===== */
.lib-reader-font-controls {
  display: flex; align-items: center; gap: 2px;
}
.lib-font-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; border-radius: 6px;
  background: none; border: 1px solid var(--line-strong);
  cursor: pointer; font-family: inherit; color: var(--ink-2);
  transition: background 100ms, color 100ms, border-color 100ms;
  font-weight: 600;
  line-height: 1;
}
.lib-font-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lib-font-btn-sm { font-size: 11px; }
.lib-font-btn-md { font-size: 13px; border-left: none; border-right: none; border-radius: 0; }
.lib-font-btn-lg { font-size: 16px; }

/* ===== WAVE 2b: NEW SINCE LAST VISIT (FG-11) ===== */
.lib-new-dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--accent);
  border-radius: 50%;
  margin-left: 5px;
  flex-shrink: 0;
  vertical-align: middle;
}
.lib-card-new-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 9px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px; border-radius: 99px;
  z-index: 6;
}

/* New since banner */
#lib-new-since-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  margin-bottom: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 9px;
  font-size: 12.5px; color: var(--accent); font-weight: 600;
}
#lib-new-since-banner.show { display: flex; }
.lib-new-since-dismiss {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: var(--accent); opacity: 0.7;
  line-height: 1; padding: 0 2px;
}
.lib-new-since-dismiss:hover { opacity: 1; }

/* Sidebar "new" chip */
#lib-sb-new-chip {
  display: inline-flex; align-items: center;
  gap: 3px; padding: 1px 5px; border-radius: 99px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 9px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; flex-shrink: 0;
}

/* ===== WAVE 2b: TOAST VISUALS (UX-04) ===== */
/* Lib-toast: match main app position (bottom-right) + pill style */
#lib-toast {
  bottom: 24px;
  left: auto;
  right: 24px;
  transform: translateY(12px);
  border-radius: 10px;
  min-width: 200px;
  max-width: 380px;
}
#lib-toast.show {
  transform: translateY(0);
}

/* ===== WAVE 2b: UX-19 SKELETON + ONERROR ===== */
/* Card cover shimmer while image loads */
.lib-card-cover img.lib-img-loading {
  opacity: 0;
  transition: opacity 250ms;
}
.lib-card-cover img.lib-img-loaded {
  opacity: 1;
}
/* The lib-skel class already handles the shimmer — reuse it on cover bg */
.lib-card-cover.lib-cover-loading {
  background: linear-gradient(90deg, var(--hover) 25%, var(--line) 50%, var(--hover) 75%);
  background-size: 200% 100%;
  animation: lib-shimmer 1.4s ease infinite;
}
