/* ══════════════════════════════════════════════════════════════════════════
   Library — shared styles for every page in the Library menu.

   Loads after app-shell.css and uses only its tokens; no new palette values,
   font stacks or spacing constants are introduced here. Breakpoints match
   the shell's own (1024px, 520px).

   Layout follows the established shell pattern: filters live in .sidebar,
   which the shell already folds into the hamburger drawer below 1024px, so
   the mobile filter drawer is the app's existing one rather than a second
   implementation. Search sits in the main column so it stays reachable when
   the filters are put away.
   ══════════════════════════════════════════════════════════════════════════ */

/* The shell has no visually-hidden utility and every control here needs a
   real <label>, so one is added rather than labelling by placeholder. */
.lib-sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.lib-main {
  flex: 1 1 auto;
  min-width: 0; min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Header: title, search, count, sort ─────────────────────────────── */

.lib-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lib-intro {
  flex: 1 0 100%;
  margin: -0.25rem 0 0;
  color: var(--silver-dim);
  font-size: 0.82rem;
  line-height: 1.4;
}

.lib-head h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  color: var(--gold);
  margin-right: 0.25rem;
}

.lib-search-wrap { position: relative; flex: 1 1 16rem; min-width: 0; }

.lib-search {
  width: 100%;
  background: var(--maroon-deep);
  color: var(--silver);
  border: 1px solid var(--maroon-edge);
  border-radius: var(--radius-sm);
  padding: 0.5rem 2.2rem 0.5rem 0.7rem;
  min-height: 2.75rem;                    /* 44px touch target */
}
.lib-search:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 192, 74, 0.18);
}

.lib-search-clear {
  position: absolute;
  right: 0.3rem; top: 50%;
  transform: translateY(-50%);
  width: 2rem; height: 2rem;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  color: var(--silver-dim);
  font-size: 1.1rem; line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}
.lib-search-clear:hover { color: var(--gold); }
.lib-search-clear[hidden] { display: none; }

.lib-count {
  font-size: 0.85rem;
  color: var(--silver-dim);
  white-space: nowrap;
}

.lib-sort-wrap { display: flex; align-items: center; gap: 0.4rem; }
.lib-sort-wrap label { font-size: 0.78rem; text-transform: uppercase;
                       letter-spacing: 0.08em; color: var(--silver-dim); }

.lib-select, .lib-num {
  background: var(--maroon-deep);
  color: var(--silver);
  border: 1px solid var(--maroon-edge);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  min-height: 2.75rem;
  width: 100%;
}
.lib-select:focus, .lib-num:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 192, 74, 0.18);
}
.lib-select option { background: var(--maroon); }

/* ── Results: list beside detail ────────────────────────────────────── */

.lib-split {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap);
}

.lib-results-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.lib-controls {
  flex: 0 0 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(8rem, auto);
  align-items: center;
  gap: .75rem;
}
.lib-controls .lib-search-wrap { width: 100%; }
.lib-controls .lib-sort-wrap { min-width: 0; }
.lib-controls .lib-select { min-width: 0; }
.lib-controls .lib-count {
  grid-column: 1 / -1;
  margin-top: -.35rem;
}
.lib-results-column > .lib-list { flex: 1 1 auto; }

.lib-list, .lib-detail {
  border: 1px solid var(--maroon-edge);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(78, 24, 38, 0.75) 0%, rgba(56, 16, 26, 0.75) 100%);
  min-height: 0;
}
.lib-list { background: var(--maroon-deep); }
.lib-detail { padding: var(--panel-pad); }

html body.app-body button.lib-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  min-height: 2.75rem;
  background: transparent !important;
  border: 0 !important;
  border-bottom: 1px solid var(--maroon-edge) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  color: var(--silver) !important;
  font-weight: inherit !important;
  letter-spacing: normal;
  text-align: left;
  cursor: pointer;
  transform: none !important;
  filter: none !important;
}
html body.app-body button.lib-row:hover:not(:disabled) {
  background: rgba(var(--theme-accent-rgb), 0.06) !important;
  box-shadow: none !important;
  transform: none !important;
  filter: none;
}
html body.app-body button.lib-row.selected {
  background: rgba(var(--theme-accent-rgb), 0.12) !important;
}
html body.app-body button.lib-row:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: -2px;
}

.lib-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.lib-row-title { color: var(--silver); overflow-wrap: anywhere; }
.lib-row.selected .lib-row-title { color: var(--gold); }
.lib-row-meta { font-size: 0.78rem; color: var(--silver-dim); }

.lib-badges { display: flex; gap: 0.25rem; flex-wrap: wrap; justify-content: flex-end; }
.lib-badge {
  font-size: 0.68rem;
  padding: 0.08rem 0.4rem;
  border: 1px solid var(--maroon-edge);
  border-radius: 999px;
  color: var(--gold-deep);
  white-space: nowrap;
}

.lib-more { width: 100%; margin: 0.6rem 0; }

/* ── Detail pane ────────────────────────────────────────────────────── */

.lib-detail h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  color: var(--gold);
}
.lib-detail-meta { color: var(--silver-dim); font-size: 0.82rem; margin-bottom: 0.75rem; }
.lib-detail-block { margin-top: 0.85rem; }
.lib-detail-block h4 {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--gold-deep); margin-bottom: 0.3rem;
}
.lib-detail-text { font-size: 0.88rem; line-height: 1.55; white-space: pre-wrap; }
.lib-source-note {
  display: block; margin-top: 0.65rem; padding-top: 0.55rem;
  border-top: 1px solid var(--line); color: var(--gold);
  font-size: 0.82rem; line-height: 1.4;
}

.lib-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}
.lib-facts dt { color: var(--silver-dim); white-space: nowrap; }
.lib-facts dd { color: var(--silver); overflow-wrap: anywhere; }

.lib-feature { display: flex; gap: 0.5rem; font-size: 0.85rem; padding: 0.15rem 0; }
.lib-feature-lv { color: var(--gold-deep); min-width: 2.2rem; }

.lib-open { display: inline-block; text-decoration: none; text-align: center; }

/* Non-SRD sources: the original text is withheld and the record's own
   summary stands in for it. The note explains why, so a short entry never
   reads as missing data. */
.lib-redacted-note {
  border-left: 3px solid var(--gold-deep);
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.5rem;
  color: var(--gold-deep);
  font-size: 0.82rem;
  font-style: italic;
}

/* Where the repo's data genuinely has nothing to show. Said out loud rather
   than left blank, so a gap never reads as "this entry has no text". */
.lib-gap {
  margin-top: 0.85rem;
  border: 1px dashed var(--gold-deep);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
  color: var(--gold-deep);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ── Facets, in the sidebar ─────────────────────────────────────────── */

.lib-facet + .lib-facet { margin-top: 0.9rem; }
.lib-facet-name {
  font-family: var(--font-display);
  font-size: 0.8rem; font-variant: small-caps; letter-spacing: 0.12em;
  color: var(--gold); margin-bottom: 0.35rem;
}

.lib-dropdown-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  width: 100%;
  background: var(--maroon-deep);
  color: var(--silver);
  border: 1px solid var(--maroon-edge);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.55rem;
  min-height: 2.75rem;
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
}
.lib-dropdown-toggle:hover { border-color: var(--gold-deep); }
.lib-dropdown-toggle:focus-visible,
.lib-dropdown-toggle[aria-expanded="true"] {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(230, 192, 74, 0.18);
}
.lib-dropdown-toggle-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-dropdown-caret {
  flex: 0 0 auto; width: 0.5rem; height: 0.5rem; margin-top: -0.2rem;
  border-right: 1.5px solid var(--silver-dim);
  border-bottom: 1.5px solid var(--silver-dim);
  transform: rotate(45deg);
}
.lib-dropdown-toggle[aria-expanded="true"] .lib-dropdown-caret { transform: rotate(-135deg); margin-top: 0.15rem; }

.lib-dropdown-panel {
  margin-top: 0.35rem;
  background: var(--maroon-deep);
  border: 1px solid var(--maroon-edge);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
}

.lib-checks { display: flex; flex-direction: column; gap: 0.1rem; max-height: 13rem; overflow: auto; }
.lib-check { display: flex; align-items: center; gap: 0.45rem; min-height: 1.9rem; }
.lib-check input { width: 1rem; height: 1rem; flex: 0 0 auto; }
.lib-check-label {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  font-size: 0.84rem; color: var(--silver); cursor: pointer;
}
.lib-check-n { color: var(--silver-dim); font-size: 0.72rem; }

.lib-range { display: flex; align-items: center; gap: 0.4rem; }
.lib-range-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--silver-dim);
}

/* ── Empty and error states ─────────────────────────────────────────── */

.lib-empty, .lib-error {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.75rem;
  padding: var(--panel-pad);
  color: var(--silver-dim);
  font-size: 0.9rem;
}
.lib-error h3 { color: var(--danger); font-family: var(--font-display);
                font-variant: small-caps; letter-spacing: 0.08em; }
.lib-empty .act, .lib-error .act { flex: 0 0 auto; }

/* ── Compact ────────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  /* One column: the detail pane follows the list rather than sitting beside
     it, and both scroll inside the workspace rather than the page. */
  .lib-split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 0.8fr); }
  .lib-head h1 { width: 100%; }
  .lib-checks { max-height: none; }
}

@media (max-width: 520px) {
  .lib-head { gap: 0.5rem; }
  .lib-count { width: 100%; }
  .lib-badges { display: none; }        /* the row title needs the width */
  .lib-facts { grid-template-columns: 1fr; gap: 0 ; }
  .lib-facts dt { margin-top: 0.4rem; }
  .lib-controls { grid-template-columns: minmax(0, 1fr) minmax(7rem, 42%); gap: .5rem; }
}

/* Named paragraphs for traits, actions and reactions — a creature's action
   list comma-joined onto one line is unreadable. */
.lib-entry { font-size: 0.87rem; line-height: 1.5; margin-bottom: 0.5rem; }
.lib-entry strong { color: var(--gold-bright); }
/* The preview at the head of a results row: a placed card picture, or the
   equipment catalogue's own artwork where no picture has been placed. The
   detail panel shows the same equipment illustration at 48px below. */
.lib-row-icon{width:42px;height:42px;flex:none;object-fit:contain;border-radius:.25rem;margin-right:.55rem}
.lib-detail-art{float:right;width:48px;height:48px;margin:0 0 .5rem .6rem;object-fit:contain;border:1px solid rgba(0,0,0,.18);border-radius:.35rem}
/* A condition has no card picture, so its device leads the open entry — the
   same one the tracker puts on the figure, at a size worth looking at. */
.lib-condition-mark{float:right;width:64px;height:64px;margin:0 0 .5rem .7rem;object-fit:contain;border:1px solid var(--gold-deep);border-radius:.4rem;background:rgba(0,0,0,.18)}

/* ── Card pictures ────────────────────────────────────────────────────────
   A picture placed on a Library record. Two sizes of the same thing: 128px in
   the corner of the open card, and the existing 1.6rem row mark in the results
   list, which this reuses rather than duplicates. */
.lib-card-art {
  float: right;
  display: grid;
  gap: .3rem;
  justify-items: center;
  width: 128px;
  margin: 0 0 .6rem .75rem;
}
.lib-card-art img {
  width: 128px;
  height: 128px;
  object-fit: contain;
  border: 1px solid var(--gold-deep);
  border-radius: .4rem;
  background: rgba(var(--theme-abyss-rgb), .35);
}
/* Only the curator sees this, and only ever one per card. */
html body.app-body button.lib-card-art-set {
  width: 100%;
  min-height: 0;
  padding: .25rem .4rem;
  border: 1px dashed var(--gold-deep);
  border-radius: .3rem;
  background: transparent;
  color: var(--gold);
  font-size: .68rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}
html body.app-body button.lib-card-art-set:hover:not(:disabled) {
  border-style: solid;
  background: rgba(var(--theme-accent-rgb), .12);
}
/* With no picture there is nothing to frame, so the control stands alone. */
.lib-card-art:not(.is-set) { width: 7.5rem; }
/* Equipment draws its own catalogue illustration. A placed card picture is the
   more specific answer to "what does this record look like", so it stands in
   for that one rather than sitting beside it. */
.lib-detail.has-card-art .lib-detail-art { display: none; }

/* ── The picker ─────────────────────────────────────────────────────────── */
.card-art-content { width: min(46rem, calc(100vw - 2rem)); }
.card-art-for { margin: 0 0 .6rem; color: var(--silver-dim); font-size: .85rem; }
.card-art-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  margin-bottom: .7rem;
}
.card-art-bar label { color: var(--silver-dim); font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; }
.card-art-bar select { flex: 0 1 12rem; }
.card-art-bar input[type="search"] { flex: 1 1 10rem; min-width: 0; }
.card-art-count { color: var(--silver-dim); font-size: .74rem; white-space: nowrap; }

.card-art-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  gap: .5rem;
  overflow-y: auto;
  max-height: min(52vh, 26rem);
  padding: .5rem;
  border: 1px solid var(--gold-deep);
  border-radius: .4rem;
  background: rgba(var(--theme-abyss-rgb), .28);
}
html body.app-body button.card-art-tile {
  display: grid;
  gap: .25rem;
  justify-items: center;
  min-height: 0;
  padding: .35rem .25rem;
  border: 1px solid transparent;
  border-radius: .35rem;
  background: transparent;
  color: var(--silver-dim);
  font-size: .62rem;
  line-height: 1.2;
  text-transform: none;
}
html body.app-body button.card-art-tile:hover:not(:disabled),
html body.app-body button.card-art-tile:focus-visible {
  border-color: var(--gold);
  background: rgba(var(--theme-accent-rgb), .14);
  color: var(--gold-bright);
}
.card-art-tile img { width: 100%; height: auto; aspect-ratio: 1; object-fit: contain; }
.card-art-tile span { overflow: hidden; width: 100%; text-overflow: ellipsis; white-space: nowrap; }
.card-art-tile[hidden] { display: none; }
.card-art-note { margin: .5rem; color: var(--silver-dim); font-size: .85rem; }

.card-art-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  margin-top: .75rem;
}
/* The file input is the label: a bare one is unstyleable and reads as a
   different kind of control from the buttons beside it. */
.card-art-upload { position: relative; overflow: hidden; cursor: pointer; }
.card-art-upload input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.card-art-status { flex: 1 1 8rem; color: var(--silver-dim); font-size: .78rem; }
.card-art-status.is-problem { color: var(--gold-bright); }

@media (max-width: 560px) {
  .lib-card-art, .lib-card-art img { width: 96px; }
  .lib-card-art img { height: 96px; }
  .card-art-grid { max-height: 44vh; }
}

/* Feature names lead; Description is a supporting label. */
.lib-detail .lib-origin-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--gold);
  margin: 1rem 0 0.3rem;
}
.lib-detail-block h4.lib-origin-description {
  font-family: inherit !important;
  font-size: 0.9rem !important;
  font-variant: normal;
  text-transform: none;
  border-bottom: 0;
  letter-spacing: normal;
}
