/* Notes library: the collections page, and the reader with a rail of every note beside it */

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- library view */
.lib-crumb { margin: 0 0 18px; font-size: var(--fs-small); }
.lib-crumb a { color: var(--text-2); }
.lib-crumb a::before { content: "\2190\00a0"; }
.lib-h1 { margin: 0 0 12px; color: var(--name, var(--text)); font: 400 var(--fs-name)/1.2 var(--font-text); }


.lib-collections .summary { margin: 0 0 10px; color: var(--name); font-size: var(--fs-small); line-height: 1.55; }
.lib-start::after { content: "\00a0\2192"; }

/* under each card, full width: its notes (one list open on the page at a time) and its more info */
.lib-panel { grid-column: 1 / -1; margin: 4px 0 0; }
.lib-panel[hidden] { display: none; }
.lib-parts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 4px 18px;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg-elev);
  font-size: var(--fs-small);
  animation: lib-open 0.15s ease;
}
@keyframes lib-open { from { opacity: 0; transform: translateY(-4px); } }
.lp-block { min-width: 0; padding: 4px 0; }
.lp-head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 4px; padding: 0 8px; color: var(--text); font-weight: 700; }
.lp-part { color: var(--muted); font-size: var(--fs-xs); font-weight: 400; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.lp-block ol { margin: 0; padding: 0; list-style: none; }
.lp-block a {
  display: grid;
  grid-template-columns: 2.4em 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 4px 8px;
  border-radius: 5px;
  color: var(--text-2);
  line-height: 1.45;
}
.lp-block a:hover { background: var(--tag-bg); color: var(--accent); text-decoration: none; }
.lp-block a:hover .lp-num { color: var(--accent); }
.lp-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.lp-pp { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }

@media (max-width: 640px) {
  .lib-parts { grid-template-columns: 1fr; }
}

/* ---- reader view: the library hides, the rail and the frame fill the window */
.lib-reader { display: none; }
.lib-reading .lib-home { display: none; }
.lib-reading .lib-reader { display: block; }
.lib-reading .theme-toggle { display: none; }
.lib-reading body { overflow: hidden; }

.lib-body { --rail-w: 300px; }

.lib-rail {
  position: fixed;
  z-index: 6;
  top: 0;
  bottom: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: var(--rail-w);
  border-right: 1px solid var(--rule);
  background: var(--bg);
  font-size: 0.8rem;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 10px; }
.rail-back { color: var(--text-2); font-size: var(--fs-small); }
.rail-back:hover { color: var(--accent); text-decoration: none; }
.rail-close { display: none; border: 0; background: none; color: var(--text-2); font-size: 1.4rem; line-height: 1; cursor: pointer; }

.rail-search { position: relative; display: block; margin: 0 14px 10px; }
.rail-search input {
  width: 100%;
  height: 32px;
  padding: 0 30px 0 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
}
.rail-search input:focus { outline: none; border-color: var(--accent); }
.rail-search input::-webkit-search-cancel-button { display: none; }
.rail-search kbd {
  position: absolute;
  top: 7px;
  right: 8px;
  padding: 0 5px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--muted);
  font: 400 var(--fs-xs)/16px var(--font-mono);
  pointer-events: none;
}
.rail-search input:focus + kbd, .rail-search input:not(:placeholder-shown) + kbd { display: none; }

.rail-tree, .rail-results { flex: 1; overflow-y: auto; margin: 0; padding: 0 10px 28px 12px; list-style: none; }
.rail-tree ol, .rail-toc { margin: 0; padding: 0; list-style: none; }

.rail-col + .rail-col { margin-top: 14px; }
.rail-col-h {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 0 0 4px;
  padding: 6px 6px 6px 8px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--text);
  font: 700 0.8rem/1.35 var(--font-text);
  text-align: left;
  cursor: pointer;
}
.rail-col-h small { color: var(--muted); font-weight: 400; }
.rail-col-h::before { content: "\25BE"; color: var(--muted); font-weight: 400; transition: transform 0.15s ease; }
.rail-col-h[aria-expanded="false"]::before { transform: rotate(-90deg); }
.rail-col-h span { flex: 1; }
.rail-col-h:hover { background: var(--tag-bg); }

.rail-group { display: flex; align-items: baseline; gap: 6px; margin: 10px 0 2px 8px; color: var(--text); font-weight: 700; font-size: 0.75rem; }
.rg-part { color: var(--muted); font-size: 0.66rem; font-weight: 400; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.rail-note {
  display: grid;
  grid-template-columns: 2.3em 1fr auto;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text-2);
  line-height: 1.4;
}
.rail-item.sub .rail-note { padding-left: 16px; }
.rail-note:hover { background: var(--tag-bg); color: var(--accent); text-decoration: none; }
.rail-note.current { background: var(--tag-bg); color: var(--accent); font-weight: 700; }
.rn-num { color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rn-pp { color: var(--muted); font-weight: 400; font-size: 0.7rem; }

/* the open note's sections, under it; the one being read is marked */
.rail-toc { margin: 2px 0 6px 2.3em !important; padding-left: 8px !important; border-left: 1px solid var(--rule); }
.rail-item.sub .rail-toc { margin-left: calc(2.3em + 8px) !important; }
.rail-toc a { display: block; padding: 2px 8px; border-radius: 4px; color: var(--text-2); line-height: 1.4; }
.rail-toc .rt-2 { padding-left: 18px; color: var(--muted); }
.rail-toc a:hover { color: var(--accent); text-decoration: none; }
.rail-toc a.here { color: var(--accent); background: var(--tag-bg); }

.rail-results a { display: block; padding: 6px 8px; border-radius: 4px; color: var(--text); line-height: 1.4; }
.rail-results a:hover, .rail-results a.active { background: var(--tag-bg); text-decoration: none; }
.rr-h { display: block; color: var(--accent); }
.rr-s { display: block; color: var(--muted); font-size: 0.72rem; }
.rr-none { padding: 6px 8px; color: var(--muted); }

.lib-stage { position: fixed; top: 0; right: 0; bottom: 0; left: var(--rail-w); }
.lib-frame { display: block; width: 100%; height: 100%; border: 0; background: var(--bg); }
.stage-top { display: none; }

/* last page of a note: the next one, offered in a corner */
.up-next {
  position: absolute;
  z-index: 5;
  right: 18px;
  bottom: 74px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100% - 36px));
  padding: 9px 10px 9px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--bg-elev);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
  font-size: 0.8rem;
  animation: up-next 0.2s ease;
}
@keyframes up-next { from { opacity: 0; transform: translateY(6px); } }
.un-label { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
.un-link { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.un-link::after { content: "\00a0\2192"; }
.un-close { border: 0; background: none; color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer; }

/* small screens: a thin bar on top, and the rail slides in over the pages */
@media (max-width: 900px) {
  .lib-stage { left: 0; display: flex; flex-direction: column; }
  .stage-top {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 44px;
    padding: 0 12px;
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
    font-size: 0.8rem;
  }
  .rail-open {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: var(--bg-elev);
    color: var(--text);
    font: inherit;
    cursor: pointer;
  }
  .rail-open svg { fill: none; stroke: currentColor; stroke-width: 1.6; }
  .stage-title { min-width: 0; overflow: hidden; color: var(--text-2); text-overflow: ellipsis; white-space: nowrap; }
  .lib-frame { flex: 1; height: auto; }
  .lib-rail {
    width: min(340px, 88vw);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
  }
  .lib-rail.open { transform: none; }
  .rail-close { display: block; }
  .up-next { bottom: 70px; }
}

.up-next[hidden], .rail-results[hidden], .rail-tree[hidden] { display: none; }
