/* =========================================================
   Library / shelf
   ========================================================= */

:root {
  --bg: #eceae4;
  --ink: #17172a;
  --muted: #726f68;
  --line: rgba(23, 23, 42, 0.10);
  --accent: #e2761b;
  --navy: #24245c;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over `.lib-btn { display: inline-flex }`. */
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 70% at 50% -10%, #f8f7f3 0%, #eceae4 45%, #dfdcd4 100%);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------------- header ---------------- */

.lib-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(18px, 5vw, 56px) 18px;
  border-bottom: 1px solid var(--line);
}
.lib-brand { display: flex; align-items: center; gap: 14px; }
.lib-brand svg {
  width: 30px; height: 30px;
  fill: none; stroke: var(--navy); stroke-width: 1.4; stroke-linejoin: round;
}
.lib-brand div { display: flex; flex-direction: column; }
.lib-brand strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.1;
}
.lib-brand span {
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.lib-admin {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.lib-admin[hidden] { display: none; }
.lib-admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(31, 138, 91, 0.10);
  color: #1f8a5b;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.lib-admin-chip[hidden] { display: none; }
.lib-admin-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #1f8a5b;
  box-shadow: 0 0 0 2px rgba(31, 138, 91, 0.18);
}

.lib-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  font: inherit;
  font-size: 13px;
  padding: 9px 14px;
  cursor: pointer;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.lib-btn:hover { background: #f6f4ef; border-color: rgba(23, 23, 42, 0.2); }
.lib-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.lib-btn.primary:hover { background: #ef8326; }
.lib-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- filters ---------------- */

.lib-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.lib-search {
  flex: 1 1 220px;
  min-width: 160px;
  font: inherit;
  font-size: 13.5px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.lib-search:focus,
.lib-sort:focus { outline: 2px solid rgba(226, 118, 27, 0.45); outline-offset: 1px; }
.lib-sort {
  font: inherit;
  font-size: 13px;
  padding: 10px 30px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #726f68 50%),
    linear-gradient(135deg, #726f68 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.lib-tagbar { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 100%; }
.lib-tagbar[hidden] { display: none; }
.lib-tag {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.lib-tag:hover { color: var(--ink); border-color: rgba(23, 23, 42, 0.2); }
.lib-tag.is-on { background: var(--navy); border-color: var(--navy); color: #fff; }

.lib-progress { display: flex; flex-direction: column; gap: 5px; margin-top: 5px; }
.lib-progress-label { font-size: 11.5px; font-weight: 600; color: var(--accent); }
.lib-progress-track {
  height: 3px;
  border-radius: 3px;
  background: rgba(23, 23, 42, 0.1);
  overflow: hidden;
}
.lib-progress-track i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--navy), var(--accent));
}
.lib-card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.lib-card-tag {
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--navy);
  background: rgba(36, 36, 92, 0.08);
  padding: 2px 7px;
  border-radius: 999px;
}

/* ---------------- grid ---------------- */

.lib-main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 48px) clamp(18px, 5vw, 56px) 48px;
}

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: clamp(20px, 3vw, 34px);
}

.lib-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  border-radius: 4px;
}
.lib-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / var(--aspect, 1.4145);
  border-radius: 3px;
  background: #e4e1d9;
  box-shadow: 0 10px 24px rgba(20, 20, 45, 0.16), 0 2px 6px rgba(20, 20, 45, 0.1);
  overflow: hidden;
  transition: transform 0.22s cubic-bezier(0.22, 0.61, 0.36, 1), box-shadow 0.22s ease;
}
.lib-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.lib-cover.is-empty {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35), transparent 60%),
    #e4e1d9;
}
.lib-cover.is-empty::after {
  content: "No cover";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.lib-card:hover .lib-cover {
  transform: translateY(-5px) rotate(-0.4deg);
  box-shadow: 0 20px 40px rgba(20, 20, 45, 0.24), 0 4px 10px rgba(20, 20, 45, 0.12);
}
.lib-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.lib-draft {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(23, 23, 42, 0.82);
  color: #fff;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.lib-card.is-draft .lib-cover { opacity: 0.85; }
.lib-card.is-draft .lib-cover img { filter: grayscale(0.25); }
.lib-draft.lib-access { top: auto; bottom: 10px; background: rgba(36, 36, 92, 0.9); }

.lib-meta { display: flex; flex-direction: column; gap: 2px; padding: 0 2px; }
.lib-meta strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.3;
  min-height: 2.6em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-meta span {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-meta em {
  font-style: normal;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 3px;
}

/* ---------------- empty / footer ---------------- */

.lib-empty {
  max-width: 420px;
  margin: 12vh auto 0;
  text-align: center;
}
.lib-empty[hidden] { display: none; }
.lib-empty h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  margin: 0 0 10px;
}
.lib-empty p { color: var(--muted); margin: 0 0 20px; }

.lib-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(18px, 5vw, 56px) 22px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.lib-foot a { color: var(--muted); text-decoration: none; }
.lib-foot a:hover { color: var(--ink); }
.lib-foot-links { display: flex; gap: 18px; }
#draftsLink { color: var(--accent); }
#draftsLink[hidden] { display: none; }

@media (max-width: 560px) {
  .lib-top { padding: 16px 16px 14px; }
  .lib-brand strong { font-size: 20px; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 18px; }
  .lib-main { padding: 22px 16px 36px; }
}

/* Install button: only rendered when the browser offers an install prompt. */
.lib-install {
  margin-right: 6px;
  border-color: var(--accent, #24245c);
  color: var(--accent, #24245c);
}
