/* =========================================================
   LIBRARY — library.html (loaded after base.css)
   1. Page + navigation controls
   2. Header: filters + search
   3. Grid view
   4. List view
   5. Responsive
   ========================================================= */


/* 1. Page + navigation controls
   ========================================================= */
.library-page {
  overflow: hidden;
}

/* Top-left LIBRARY link (≤1120px): a block-like box, skewed by its h1 on hover. */
#library-menu a {
  display: inline-block;
}

.library-page .theme-item.is-active a {
  transform: skewX(-10deg);
}

/* "Grid / List" switch in the navigation bar */
.library-view-nav {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.library-view-nav button {
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  line-height: inherit;
}

.library-view-nav button:hover,
.library-view-nav button.is-active {
  transform: skewX(-10deg);
}


/* 2. Header: filters as check boxes, then the search field
   ========================================================= */
.library-header > h1 {
  width: 100%;
}

.library-filter-search-row {
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--fg);
}

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  align-items: center;
}

.library-filters button,
.library-search-wrap input {
  padding: 3px 0 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: calc(var(--size-meta) * var(--text-scale));
  line-height: var(--leading);
}

.library-filters button {
  cursor: pointer;
  white-space: nowrap;
}

.library-filters button:focus-visible {
  outline: 1px dotted var(--fg);
  outline-offset: 2px;
}

/* Each filter starts with a square box: crossed when the filter is on,
   faintly crossed on hover. */
.library-filters button::before {
  --cross-color: transparent;
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.4em;
  border: 1px solid var(--fg);
  background:
    linear-gradient(45deg, transparent calc(50% - 0.5px), var(--cross-color) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(-45deg, transparent calc(50% - 0.5px), var(--cross-color) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.library-filters button:hover::before {
  --cross-color: color-mix(in srgb, var(--fg) 35%, transparent);
}

.library-filters button.is-active::before {
  --cross-color: var(--fg);
}

/* Search: last word of the row, no frame. Grey "Type keyword" until
   something is typed; the caret appears only once the field is clicked. */
.library-search-wrap input {
  width: 7em;
  outline: none;
  appearance: none;
}

/* Where supported, the field grows with what is typed. */
@supports (field-sizing: content) {
  .library-search-wrap input {
    width: auto;
    min-width: 7em;
    field-sizing: content;
  }
}

.library-search-wrap input::-webkit-search-cancel-button {
  appearance: none;
}

.library-search-wrap input::placeholder {
  color: color-mix(in srgb, var(--fg) 55%, transparent);
  opacity: 1;
}

/* 3. Grid view
   library.js adds the dividers and completes the last row with empty
   cells so the grid always looks complete.
   ========================================================= */
/* --library-columns is set by library.js (3, 2 or 1). */
.library-archive.grid-view {
  display: grid;
  grid-template-columns: repeat(var(--library-columns, 3), minmax(0, 1fr));
}

.library-item {
  min-width: 0;
  background: var(--bg);
}

.library-archive.grid-view .library-item { padding: 15px; }
.library-archive.grid-view .has-col-divider { border-right: 1px solid var(--fg); }
.library-archive.grid-view .library-item.has-row-divider { border-bottom: 1px solid var(--fg); }

.library-grid-filler {
  min-width: 0;
  min-height: 1px;
  background: var(--bg);
  pointer-events: none;
}

.library-item .library-card-link {
  display: block;
  height: 100%;
  text-decoration: none;
}

.library-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  padding: 7% 9%; /* room between the image and the lines of the grid */
  display: flex;
  align-items: center;
  justify-content: center;
}

.library-image img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  /* Grey (multiplied) with the shadow; colour, same shadow, on hover (only the
     colour is animated: the shadow is drawn once). */
  filter: grayscale(100%);
  box-shadow: var(--shadow);
  mix-blend-mode: multiply;
  transition: filter var(--colour-fade);
}

.library-card-link:hover .library-image img,
.library-card-link:focus-visible .library-image img {
  filter: grayscale(0%);
  mix-blend-mode: normal;
}

/* Card without image: the source is set where the image would be. */
.library-image--text {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12%;
  border: 1px solid var(--fg);
  font-size: calc(var(--size-text) * var(--text-scale));
  line-height: var(--leading);
  text-align: center;
}

.library-title {
  font-size: calc(var(--size-text) * var(--text-scale));
  line-height: var(--leading);
}

.library-meta {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  margin-top: 8px;
  font-size: calc(var(--size-meta) * var(--text-scale));
  line-height: var(--leading);
}

.library-meta span:last-child {
  flex: 0 0 auto;
  text-align: right;
}


/* 4. List view
   Source and date become real grid columns so dates sit flush right.
   ========================================================= */
.library-archive.list-view .library-item.has-row-divider { border-bottom: 1px solid var(--fg); }

.library-archive.list-view .library-card-link {
  padding: 10px 0;
}

/* List view: titles read as links — underlined, blurred on hover. */
.library-archive.list-view .library-title {
  text-decoration: underline;
}

.library-archive.list-view .library-card-link:hover .library-title,
.library-archive.list-view .library-card-link:focus-visible .library-title {
  text-decoration: none;
  filter: blur(1px);
}

.library-archive.list-view .library-image {
  display: none;
}

.library-archive.list-view .library-item-text {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(160px, .7fr);
  gap: 30px;
  align-items: start;
}

.library-archive.list-view .library-meta {
  display: contents;
}

.library-archive.list-view .library-meta span:first-child {
  grid-column: 2;
}

.library-archive.list-view .library-meta span:last-child {
  grid-column: 3;
  justify-self: end;
}


/* 5. Responsive
   ========================================================= */
@media screen and (max-width: 1120px) {
  .library-page {
    overflow: auto;
  }
}

@media screen and (max-width: 760px) {
  .library-archive.list-view .library-item-text {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 15px;
  }

  .library-archive.list-view .library-meta span:first-child {
    grid-column: 1;
  }

  .library-archive.list-view .library-meta span:last-child {
    grid-column: 2;
  }
}

@media screen and (max-width: 480px) {
  .library-filters {
    gap: 5px 16px;
  }
}
