.library-body .store,
.library-page {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 calc(80px + env(safe-area-inset-bottom));
}

.library-hero h1 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: clamp(2rem, 4vw, 3.1rem);
  font-weight: 400;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.library-hero .hero-copy {
  max-width: 42rem;
}

.library-gate {
  margin-top: 28px;
  padding: 28px;
  border-radius: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.library-gate h2 {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 400;
}

.library-gate p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.5;
}

.library-app {
  margin-top: 8px;
}

.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 22px 0 14px;
}

.library-branches,
.library-kinds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.library-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.library-chip-org {
  padding: 6px 14px 6px 6px;
}

.library-chip img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(34, 48, 59, 0.08);
}

.library-chip.is-active {
  background: color-mix(in srgb, var(--org-accent, var(--ink)) 14%, #fff);
  border-color: color-mix(in srgb, var(--org-accent, var(--ink)) 35%, transparent);
  color: var(--ink);
}

.library-kinds .library-chip.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.library-search {
  margin-left: auto;
  min-width: min(280px, 100%);
}

.library-search input,
.library-link input,
.library-kind-pick select {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  font: inherit;
  color: var(--text);
  outline: none;
}

.library-search input:focus,
.library-link input:focus,
.library-kind-pick select:focus {
  border-color: rgba(17, 108, 181, 0.45);
  box-shadow: 0 0 0 3px rgba(17, 108, 181, 0.12);
}

.library-drop {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 14px;
  padding: 28px 24px;
  border-radius: 22px;
  border: 1.5px dashed rgba(17, 108, 181, 0.35);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(238, 246, 251, 0.7));
  cursor: pointer;
  outline: none;
  min-height: 108px;
}

.library-drop:hover,
.library-drop:focus-visible,
.library-drop.is-over {
  border-color: var(--blue);
  box-shadow: 0 16px 40px rgba(17, 108, 181, 0.12);
}

.library-drop-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.library-drop-copy strong {
  font-size: 1.05rem;
  color: var(--ink);
}

.library-drop-copy span {
  color: var(--muted);
  font-size: 0.9rem;
}

.library-kind-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.library-kind-pick select {
  width: auto;
  min-width: 140px;
}

.library-drop.is-uploading {
  cursor: wait;
  pointer-events: none;
}

.library-upload {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 24px;
  border-radius: inherit;
  background: rgba(253, 254, 252, 0.9);
  backdrop-filter: blur(8px);
}

.library-upload[hidden] {
  display: none;
}

.library-upload-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(17, 108, 181, 0.16);
  border-top-color: var(--blue);
  animation: library-spin 0.7s linear infinite;
}

.library-upload-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
}

.library-upload-copy strong {
  font-size: 1rem;
  color: var(--ink);
}

.library-upload-copy span {
  color: var(--muted);
  font-size: 0.84rem;
}

.library-upload-meter {
  width: min(280px, 80%);
  height: 6px;
  border-radius: 999px;
  background: rgba(17, 108, 181, 0.12);
  overflow: hidden;
}

.library-upload-meter span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 0.16s ease;
}

@keyframes library-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-upload-spinner {
    animation: none;
    border-top-color: rgba(17, 108, 181, 0.16);
    border-right-color: var(--blue);
  }

  .library-upload-meter span {
    transition: none;
  }
}

.library-link {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(140px, 0.8fr) minmax(0, 1.4fr) auto;
  gap: 10px;
  align-items: center;
  padding: 16px;
  margin-bottom: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.library-link-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.library-link-copy strong {
  font-size: 0.92rem;
}

.library-link-copy span {
  color: var(--muted);
  font-size: 0.78rem;
}

.library-status {
  min-height: 1.3em;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.88rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.library-card {
  display: flex;
  flex-direction: column;
  min-height: 260px;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(26, 42, 54, 0.06);
}

.library-thumb {
  position: relative;
  height: 148px;
  background:
    linear-gradient(180deg, rgba(17, 108, 181, 0.08), rgba(215, 235, 232, 0.4));
  overflow: hidden;
}

.library-thumb img,
.library-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.library-thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 16px;
  text-align: center;
  font-family: var(--display);
  font-size: 1.15rem;
  color: var(--ink);
}

.library-kind-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(253, 254, 252, 0.92);
  border: 1px solid var(--line);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.library-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  flex: 1;
}

.library-card-body h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.3;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.library-card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.library-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
}

.library-empty {
  grid-column: 1 / -1;
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
}

.library-lightbox {
  border: none;
  padding: 0;
  background: transparent;
  max-width: min(960px, calc(100vw - 24px));
  width: 100%;
}

.library-lightbox::backdrop {
  background: rgba(26, 42, 54, 0.55);
}

.library-lightbox-body {
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  min-height: 200px;
}

.library-lightbox-body img,
.library-lightbox-body video,
.library-lightbox-body iframe {
  display: block;
  width: 100%;
  max-height: 78vh;
  background: #111;
}

.library-lightbox-body iframe {
  min-height: 70vh;
  border: 0;
}

.library-lightbox-x {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 720px) {
  .library-body .store,
  .library-page {
    width: calc(100% - 28px);
  }

  .library-search {
    margin-left: 0;
    width: 100%;
  }

  .library-link {
    grid-template-columns: 1fr;
  }

  .library-drop {
    padding: 22px 16px;
  }
}
