:root {
  color-scheme: light;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI',
    sans-serif;
  line-height: 1.4;
  font-size: 16px;
  background: #f5f6f9;
  color: #1f2430;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  border-bottom: 1px solid rgba(32, 35, 42, 0.08);
  box-shadow: 0 4px 12px rgba(15, 18, 32, 0.04);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 2rem;
}

.header-inner h1 {
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0;
}

.header-actions {
  display: flex;
  flex: 1 1 320px;
  gap: 0.75rem;
  justify-content: flex-end;
  align-items: center;
}

.header-actions input,
.header-actions select {
  height: 2.5rem;
  padding: 0 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid rgba(30, 34, 45, 0.12);
  background: #fff;
  font: inherit;
  color: inherit;
  min-width: 0;
  box-shadow: 0 2px 6px rgba(20, 25, 39, 0.08);
}

.header-actions input:focus,
.header-actions select:focus {
  outline: 3px solid rgba(90, 122, 255, 0.24);
  outline-offset: 2px;
}

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.75rem 3rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.75rem 1.5rem;
}

.item-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 100%;
}

.item-card h2,
.item-card p {
  margin: 0;
}

.cover-wrapper {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 0.75rem;
  cursor: pointer;
  perspective: 1200px;
  outline: none;
}

.cover-wrapper:focus-visible {
  box-shadow: 0 0 0 3px rgba(90, 122, 255, 0.4);
}

.cover-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform 0.65s ease;
}

.cover-wrapper .cover-face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  backface-visibility: hidden;
  background: linear-gradient(160deg, rgba(36, 40, 51, 0.08), transparent);
  box-shadow: 0 16px 30px rgba(14, 18, 33, 0.18);
  display: grid;
  place-items: center;
}

.cover-front {
  z-index: 2;
}

.cover-back {
  transform: rotateY(180deg);
  background: linear-gradient(160deg, rgba(229, 224, 208, 0.9), rgba(210, 200, 180, 0.7));
}

.cover-wrapper.is-flipped .cover-inner {
  transform: rotateY(180deg);
}

.cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  backface-visibility: hidden;
}

.cover-wrapper.no-cover .cover {
  display: none;
}

.cover-fallback {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.82);
  background: linear-gradient(150deg, rgba(78, 93, 168, 0.4), rgba(23, 28, 40, 0.2));
  text-transform: uppercase;
}

.cover-wrapper.no-cover .cover-fallback {
  display: flex;
}

.book-frame {
  width: 88%;
  height: 88%;
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.9), rgba(245, 239, 219, 0.92));
  border: 2px solid rgba(96, 80, 45, 0.25);
  border-radius: 0.6rem;
  box-shadow: inset 0 10px 25px rgba(120, 90, 45, 0.2),
    inset 0 -6px 12px rgba(140, 110, 70, 0.15);
  padding: 1.1rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow: hidden;
}

.cover-abstract {
  margin: 0;
  color: rgba(45, 38, 28, 0.9);
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: left;
  overflow: auto;
  max-height: 100%;
}

.cover-abstract::-webkit-scrollbar {
  width: 6px;
}

.cover-abstract::-webkit-scrollbar-thumb {
  background: rgba(98, 80, 42, 0.35);
  border-radius: 999px;
}

.title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.title-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.title-link:hover,
.title-link:focus-visible {
  color: #3b49df;
  text-decoration: underline;
}

.creator {
  color: rgba(31, 36, 48, 0.68);
  font-size: 0.9rem;
}

#toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  font-size: 0.95rem;
  background: rgba(32, 37, 48, 0.92);
  color: #fff;
  transition: transform 0.3s ease, opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.loading-state,
.empty-state {
  color: rgba(31, 36, 48, 0.6);
  font-size: 1rem;
  text-align: center;
  grid-column: 1 / -1;
}

.library-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 960px;
  margin: 1.5rem auto 0;
  padding: 0 1rem;
  color: rgba(24, 31, 49, 0.7);
  font-size: 0.95rem;
}

.library-stats .stats-label {
  font-weight: 600;
  color: #182142;
}

.library-stats .stats-counts {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.library-stats .stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(55, 82, 241, 0.1);
  color: #182142;
  font-size: 0.9rem;
}

.library-stats .stats-chip strong {
  font-weight: 600;
  font-feature-settings: 'tnum';
}

.babel-loading {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 3rem 2.5rem;
  border-radius: 24px;
  margin: 3rem auto;
  max-width: 640px;
  text-align: center;
  color: #e5e7ff;
  background: radial-gradient(circle at top, rgba(63, 87, 245, 0.55), rgba(14, 19, 44, 0.9));
  box-shadow: 0 20px 45px rgba(20, 26, 71, 0.55);
  overflow: hidden;
}

.babel-loading::before,
.babel-loading::after {
  content: '';
  position: absolute;
  inset: -15%;
  background: repeating-linear-gradient(
    90deg,
    rgba(229, 231, 255, 0.08) 0,
    rgba(229, 231, 255, 0.08) 1px,
    transparent 1px,
    transparent 18px
  );
  opacity: 0.35;
  animation: babel-scroll 18s linear infinite;
}

.babel-loading::after {
  animation-direction: reverse;
  opacity: 0.2;
}

.babel-loading .glyph-stream {
  font-family: 'Courier New', monospace;
  font-size: 1.45rem;
  letter-spacing: 0.15rem;
  color: rgba(229, 231, 255, 0.8);
  min-height: 2.4rem;
  text-transform: lowercase;
}

.babel-loading .loading-caption {
  font-size: 0.95rem;
  color: rgba(229, 231, 255, 0.7);
  max-width: 420px;
  line-height: 1.5;
}

.babel-loading .loading-caption em {
  color: #ffffff;
  font-style: normal;
}

.scroll-sentinel {
  width: 100%;
  height: 1px;
  grid-column: 1 / -1;
  pointer-events: none;
}

@keyframes loading-spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loading-banner-glow {
  0% {
    box-shadow: 0 14px 28px rgba(55, 82, 241, 0.08);
  }
  100% {
    box-shadow: 0 22px 45px rgba(55, 82, 241, 0.18);
  }
}

@keyframes babel-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-120px);
  }
}

.detail-overlay.hidden {
  display: none;
}

.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 19, 33, 0.55);
  backdrop-filter: blur(2px);
}

.detail-panel {
  position: relative;
  z-index: 1;
  width: min(900px, 92vw);
  max-height: 92vh;
  background: #fdfdfd;
  border-radius: 1rem;
  box-shadow: 0 30px 60px rgba(10, 14, 30, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 2rem 2.25rem 1.25rem;
  background: radial-gradient(circle at top left, rgba(226, 230, 250, 0.6), transparent),
    #ffffff;
}

.detail-item-type {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  color: rgba(73, 82, 110, 0.7);
}

.detail-header h2 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.2;
  color: #1f2430;
}

.detail-creators {
  margin: 0.75rem 0 0;
  color: rgba(36, 42, 56, 0.75);
  font-size: 1rem;
}

.detail-close {
  border: none;
  background: rgba(31, 37, 52, 0.1);
  color: rgba(31, 37, 52, 0.7);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  font-size: 1.9rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.detail-close:hover,
.detail-close:focus-visible {
  background: rgba(59, 73, 223, 0.12);
  color: #3b49df;
}

.detail-meta {
  margin: 0;
  padding: 0 2.25rem 1.25rem;
  color: rgba(36, 42, 56, 0.6);
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(37, 44, 63, 0.08);
}

.detail-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 2.25rem;
  border-bottom: 1px solid rgba(37, 44, 63, 0.08);
}

.detail-tabs button {
  background: none;
  border: none;
  padding: 0.9rem 1.2rem;
  font: inherit;
  font-size: 0.95rem;
  color: rgba(36, 42, 56, 0.62);
  border-radius: 0.75rem 0.75rem 0 0;
  cursor: pointer;
  position: relative;
}

.detail-tabs button[aria-selected='true'] {
  color: #3b49df;
  font-weight: 600;
}

.detail-tabs button[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, #3b49df, #5e89ff);
  border-radius: 999px;
}

.detail-body {
  position: relative;
  padding: 1.75rem 2.25rem 2.25rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.detail-loading {
  font-size: 1rem;
  color: rgba(36, 42, 56, 0.6);
}

.detail-section h3 {
  margin-top: 0;
  font-size: 1.1rem;
  color: #20283c;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem 1.5rem;
}

.info-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.info-label {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(73, 82, 110, 0.65);
}

.info-value {
  font-size: 0.95rem;
  color: rgba(36, 42, 56, 0.9);
}

.info-abstract {
  margin-top: 1.75rem;
  padding: 1.25rem 1.5rem;
  border-radius: 0.85rem;
  background: rgba(243, 246, 255, 0.8);
  box-shadow: inset 0 0 0 1px rgba(59, 73, 223, 0.08);
}

.info-abstract h3 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: #2a3350;
}

.info-abstract p {
  margin: 0;
  white-space: pre-line;
  color: rgba(36, 42, 56, 0.85);
  font-size: 0.95rem;
  line-height: 1.6;
}

.notes-list,
.attachments-list,
.related-list,
.tags-list {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.note-card {
  background: rgba(245, 244, 252, 0.7);
  border-radius: 0.8rem;
  padding: 1rem 1.25rem;
  box-shadow: inset 0 0 0 1px rgba(59, 73, 223, 0.12);
}

.note-card h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: #2a3350;
}

.note-content {
  color: rgba(36, 42, 56, 0.82);
  font-size: 0.92rem;
  line-height: 1.5;
}

.tags-list li {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(59, 73, 223, 0.12);
  color: #3b49df;
  width: fit-content;
}

.attachments-list li,
.related-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  background: rgba(242, 244, 252, 0.85);
}

.attachments-list li > div:first-child,
.related-list li > div:first-child {
  flex: 1 1 auto;
}

.attachment-title,
.related-title {
  margin: 0;
  font-size: 0.95rem;
  color: rgba(36, 42, 56, 0.9);
}

.attachment-meta {
  font-size: 0.8rem;
  color: rgba(36, 42, 56, 0.6);
}

.detail-link {
  background: none;
  border: none;
  color: #3b49df;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.detail-link:hover,
.detail-link:focus-visible {
  text-decoration: underline;
}

.empty-panel {
  color: rgba(36, 42, 56, 0.6);
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .header-inner {
    padding: 1.25rem;
  }

  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .grid {
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .detail-panel {
    width: 96vw;
    max-height: 96vh;
  }

  .detail-header,
  .detail-meta,
  .detail-tabs,
  .detail-body {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}
