

#libraryBody { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
#view-library .card { margin: 0; }
.lib-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.lib-card p { margin: 0; }
.lib-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.lib-title { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(24px, 2.4vw, 30px); line-height: 1.15; }
.lib-count { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--text-secondary); }
.lib-count b, .lib-fig b { color: var(--text-primary); font-weight: 600; }
.lib-fig { color: var(--text-secondary); }
.lib-fig > b:first-child { font-size: 20px; }
.lib-rule { max-width: 74ch; }


.lib-ladder { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.lib-rung { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; min-width: 0;
  padding: 8px 10px; background: var(--surface-1); border: 1px solid var(--border);
  border-top: 3px solid var(--ilm-c, var(--border-strong)); border-radius: var(--radius-sm); }
.lib-rung-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; min-width: 0; }
.lib-rung-step { font-size: 13px; font-weight: 600; line-height: 1.3; min-width: 0; }
.lib-rung-fig > b { font-size: 18px; font-weight: 600; }
.lib-rung-n { justify-self: end; }
.lib-rung.is-none .lib-rung-fig > b { color: var(--text-secondary); }


.lib-shelf { list-style: none; margin: 4px 0 0; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 16px 0; overflow: hidden; }
.lib-shelf > li { display: flex; min-width: 0; }
.lib-tome { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; align-content: start; justify-items: center;
  min-width: 0; padding: 0 0 4px; text-align: center; text-decoration: none; color: var(--text-primary); border-radius: var(--radius-sm); }
.lib-stand { position: relative; display: grid; place-items: end center; width: 100%; padding: 6px 0 3px; margin-bottom: 5px; }

.lib-stand::after { content: ""; position: absolute; left: 0; bottom: 0; width: 200vw; height: 3px;
  background: color-mix(in oklab, var(--text-primary) 16%, var(--border)); }
.lib-book { position: relative; display: grid; grid-template-rows: auto 1fr auto; justify-items: center; box-sizing: border-box;
  width: 80px; height: 106px; padding: 7px 7px 9px 9px; border-radius: 3px 7px 7px 3px;
  border-left: 8px solid color-mix(in oklab, var(--ilm-c, var(--border-strong)) 80%, var(--surface-1));
  background: linear-gradient(90deg, color-mix(in oklab, var(--ilm-c, var(--border)) 34%, var(--surface-1)) 0 3px,
    color-mix(in oklab, var(--ilm-c, var(--border)) 15%, var(--surface-1)) 3px);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ilm-c, var(--border)) 55%, transparent),
    inset -4px 0 0 -1px color-mix(in oklab, var(--text-primary) 12%, transparent); }
.lib-book-rank { justify-self: end; font-size: 11px; font-weight: 700; line-height: 1.5; min-width: 1.6em; text-align: center;
  border-radius: 5px; background: color-mix(in oklab, var(--ilm-c, var(--border)) 26%, var(--surface-1));
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ilm-c, var(--border)) 75%, transparent); }
.lib-book-tick { align-self: center; max-width: 100%; font-size: 13px; font-weight: 600; letter-spacing: .02em; overflow-wrap: anywhere; line-height: 1.2; }
.lib-book-tick.is-long { font-size: 11px; letter-spacing: 0; }
.lib-book-bands { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; width: 100%; }
.lib-book-bands i { height: 4px; border-radius: 2px; background: color-mix(in oklab, var(--text-primary) 14%, transparent); }
.lib-book-bands i.on { background: var(--ilm-c, var(--brand)); }
.lib-tome-name { max-width: 100%; padding: 0 8px; font-size: 13px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-tome-next { padding: 0 8px; color: var(--text-secondary); line-height: 1.35; }
.lib-tome:hover .lib-book { box-shadow: inset 0 0 0 1.5px var(--ilm-c, var(--brand)), inset -4px 0 0 -1px color-mix(in oklab, var(--text-primary) 12%, transparent); }
.lib-tome:hover .lib-tome-name { text-decoration: underline; text-decoration-color: color-mix(in oklab, var(--brand) 60%, transparent); text-underline-offset: 3px; }
.lib-tome:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--brand); }
.lib-tome.is-dusty .lib-book { filter: saturate(.3); opacity: .8; }
.lib-dust { margin-right: 2px; }


.lib-relics { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 10px; }
.lib-relic { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 8px; min-width: 0; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
.lib-relic.is-earned { border-color: color-mix(in oklab, var(--ilm-c, var(--brand)) 70%, var(--border));
  background: color-mix(in oklab, var(--ilm-c, var(--brand)) 7%, var(--surface-1)); }
.lib-case { position: relative; display: grid; place-items: center; padding: 2px 0 10px;
  border-bottom: 2px solid color-mix(in oklab, var(--ilm-c, var(--border-strong)) 40%, var(--border)); }
.lib-case-lock { position: absolute; top: -4px; right: -2px; display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50%; color: var(--text-secondary); background: var(--surface-1); box-shadow: inset 0 0 0 1px var(--border-strong); }
.lib-relic-body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lib-relic-body .eyebrow { margin: 0; }
.lib-relic-name { margin: 0; font-family: var(--font); font-size: 15px; font-weight: 650; line-height: 1.3; }
.lib-relic-name .ilm-rank { margin-left: 2px; vertical-align: 1px; }

.lib-relic-body > .lib-relic-state { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: auto; padding-top: 8px;
  border-top: 1px solid var(--border); }
.lib-relic-state .hq-bar { flex: 1 1 60px; width: auto; }
.lib-relic-gift { padding-bottom: 3px; }
.lib-relic-gift .eyebrow { margin-right: 4px; }

@media (max-width: 760px) {
  
  .lib-ladder { grid-template-columns: minmax(0, 1fr); gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-1); }
  .lib-rung { grid-template-columns: minmax(0, 1fr) auto; padding: 7px 10px; border: 0; border-left: 3px solid var(--ilm-c, var(--border-strong)); border-radius: 0; background: transparent; }
  .lib-rung + .lib-rung { border-top: 1px solid var(--border); }
  .lib-rung-top { grid-column: 1; }
  .lib-rung-fig { grid-column: 2; grid-row: 1; }
  .lib-rung-fig > b { font-size: 15px; }
  .lib-rung-n { display: none; }
  
  .lib-card > .lib-rule { order: 2; }
  .lib-card > .lib-ladder { order: 3; }
}
@media (max-width: 640px) {
  .lib-shelf { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
  .lib-tome { min-height: 44px; }
  
  .lib-relics { grid-template-columns: minmax(0, 1fr); }
  .lib-relic { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto; gap: 12px; }
  .lib-case { align-self: start; padding: 0 0 8px; }
  .lib-case .ilm-icon { --ilm-size: 56px !important; }
}
