/* Library-specific source/annotation separation. Loaded after all theme files. */
:root { --source-highlight: rgba(218,166,35,.24); }
[data-theme="cyberpunk"] { --source-highlight: rgba(255,47,135,.2); }
[data-theme="corporate"] { --source-highlight: rgba(255,196,61,.28); }
.library-page .wrap { max-width: 1260px; }
.library-layout {
  display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(19rem, 1fr);
  align-items: start; gap: 1.25rem;
}
.source-column { min-width: 0; }
.source-column-head {
  margin: 0 0 1rem; padding: .55rem .7rem;
  border-left: 3px solid var(--accent); background: var(--card-bg);
}
.source-column-head h2 {
  margin: 0; color: var(--title-fg); font: 700 .78rem/1.3 var(--font-head);
  letter-spacing: .1em; text-transform: uppercase;
}
.source-column-head p { margin: .15rem 0 0; color: var(--muted); font-size: .76rem; }

.annotation-rail {
  position: sticky; top: .75rem; max-height: calc(100vh - 1.5rem);
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden; border: 1px solid var(--note-border); border-radius: 8px;
  background: var(--note-bg); box-shadow: 0 5px 20px rgba(0,0,0,.1);
}
.annotation-rail-head {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .65rem .75rem; border-bottom: 1px solid var(--note-border);
}
.annotation-rail-head h2 {
  margin: 0; color: var(--title-fg); font: 700 .76rem/1.3 var(--font-head);
  letter-spacing: .1em; text-transform: uppercase;
}
.annotation-rail-head p { margin: .05rem 0 0; color: var(--muted); font-size: .72rem; font-style: italic; }
.annotation-rail-actions { display: flex; align-items: center; gap: .25rem; }
.annotation-rail-actions button {
  border: 1px solid var(--border); border-radius: 4px; padding: .24rem .45rem;
  background: var(--card-bg); color: var(--fg); cursor: pointer; font: inherit;
  font-size: .7rem;
}
.annotation-rail-actions button:disabled { opacity: .4; cursor: default; }
#annotation-copy.copied::after { content: " copied"; }
#annotation-close { font-size: 1.05rem; line-height: .8; }
.annotation-rail-content { min-height: 12rem; overflow-y: auto; padding: .85rem; }
.annotation-prompt { margin: 0; color: var(--muted); font-size: .88rem; font-style: italic; }
.annotation-selection-title {
  margin: 0 0 .75rem; color: var(--title-fg); font: 700 1rem/1.3 var(--font-head);
}
.rail-section { margin-bottom: .8rem; }
.rail-section > h4 {
  margin: 0 0 .35rem; color: var(--muted); font: 700 .7rem/1.3 var(--font-head);
  letter-spacing: .09em; text-transform: uppercase;
}
.rail-note-body p, .annotation-rail .author-body p { margin: .5rem 0; }
.rail-note-body ul, .annotation-rail .author-body ul {
  margin: .4rem 0 .4rem 1.1rem; padding: 0;
}
.rail-note-body blockquote, .annotation-rail .author-body blockquote {
  margin: .5rem 0; padding: .1rem 0 .1rem .7rem;
  border-left: 3px solid var(--border); color: var(--muted); font-style: italic;
}
.rail-note-body a.entry-xref, .annotation-rail .author-body a.entry-xref {
  border-bottom: 1px dashed currentColor; cursor: pointer;
}
.rail-note-body a.entry-xref::before,
.annotation-rail .author-body a.entry-xref::before {
  content: "\21B3 "; opacity: .6; font-size: .9em;
}
.annotation-rail .author-section:first-of-type { margin-top: .7rem; padding-top: .7rem; border-top: 1px solid var(--border); }

.annotation-trigger {
  appearance: none; width: 100%; border: 0; border-radius: 3px;
  padding: .14rem .22rem; background: var(--source-highlight);
  color: var(--fg); cursor: pointer; font: inherit; line-height: inherit;
  text-align: left; opacity: 1;
  box-shadow: inset 0 -1px 0 var(--note-border);
  transition: background .15s, box-shadow .15s;
}
.annotation-trigger:hover, .annotation-trigger:focus-visible {
  outline: none; background: var(--flash); box-shadow: 0 0 0 2px var(--note-border);
}
.annotation-trigger.is-selected { background: var(--flash); box-shadow: 0 0 0 2px var(--accent); }
.editorial-marker {
  border: 1px solid var(--note-border); border-radius: 999px;
  padding: .08rem .4rem; background: transparent; color: var(--muted);
  cursor: pointer; font: 600 .62rem/1.3 var(--font-body);
  letter-spacing: .07em; text-transform: uppercase;
}
.editorial-marker:hover, .editorial-marker:focus-visible,
.editorial-marker.is-selected {
  outline: none; color: var(--fg); background: var(--note-bg);
  box-shadow: 0 0 0 2px var(--note-border);
}
.annotation-backdrop { display: none; }

[data-theme="academic"] .library-page .source-column-head { text-align: left; }
[data-theme="academic"] .library-page .entry-desc.annotation-trigger::first-letter {
  font-size: inherit; line-height: inherit; float: none; padding: 0; color: inherit;
}
[data-theme="corporate"] .annotation-rail { border-radius: 12px; }
[data-theme="cyberpunk"] .annotation-rail { box-shadow: 0 0 18px rgba(176,38,255,.16); }

@media (max-width: 900px) {
  .library-page .wrap { max-width: 820px; }
  .library-layout { display: block; }
  .annotation-rail {
    position: fixed; z-index: 30; inset: auto .5rem .5rem;
    max-height: min(72vh, 42rem); transform: translateY(calc(100% + 1rem));
    transition: transform .2s ease; visibility: hidden;
  }
  .annotation-rail.is-open { transform: translateY(0); visibility: visible; }
  .annotation-backdrop {
    position: fixed; z-index: 29; inset: 0; width: 100%; height: 100%;
    border: 0; background: rgba(0,0,0,.42); cursor: default;
  }
  .annotation-backdrop.is-open { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .annotation-rail { transition: none; }
  .annotation-trigger { transition: none; }
}
