:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #eef2ff;
  --border: #d1d5db;
  --text: #111827;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  width: min(1200px, calc(100% - 2rem));
  margin: 0 auto;
}

.topbar {
  padding: 1.2rem 0.75rem;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-bottom: none;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.12);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.2vw, 2.2rem);
  color: #f8fafc;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  font-size: 1.4em;
}

.highlight {
  background: linear-gradient(135deg, #25D366, #1AA34A);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.controls {
  display: grid;
  gap: 1rem;
  margin: 2rem 0 1rem;
}

.search-box,
.filters {
  display: grid;
  gap: 0.5rem;
}

label {
  font-size: 0.95rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  padding: 0.95rem 1rem;
  border-radius: 0.85rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.book-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  justify-content: center;
  align-items: stretch;
  grid-auto-rows: auto;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
  height: 100%;
  width: 100%;
  max-width: 260px;
  margin-inline: auto;
}

.card-content {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1 1 auto;
}

.image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--surface-alt);
  overflow: hidden;
}

.book-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transition: opacity 0.35s ease;
  display: block;
}

.book-image.loaded {
  opacity: 1;
}

.image-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.72);
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid rgba(79, 70, 229, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.card-content {
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.3;
}

.card-meta {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
  align-items: center;
}

.badge {
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  color: var(--muted);
  font-size: 0.78rem;
}

.details-button {
  border: 1px solid rgba(100, 116, 139, 0.18);
  background: rgba(239, 246, 255, 0.9);
  color: #1f2937;
  padding: 0.65rem 0.85rem;
  border-radius: 0.85rem;
  font-size: 0.9rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.details-button:hover {
  background: rgba(226, 232, 240, 0.95);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.55);
  padding: 1.5rem;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-dialog {
  width: min(520px, 100%);
  background: var(--surface);
  border-radius: 1.25rem;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.18);
  padding: 1.6rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
}

.modal-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.modal-title {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
}

.modal-category {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.12);
  color: var(--muted);
  font-size: 0.85rem;
}

.modal-description {
  margin: 0;
  color: #334155;
  line-height: 1.7;
  font-size: 0.95rem;
}

.modal-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.keyword {
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  background: rgba(124,58,237,0.12);
  color: var(--accent);
  font-size: 0.78rem;
}

.card-actions {
  margin-top: auto;
  display: grid;
  gap: 0.45rem;
  padding-top: 0.4rem;
}

.button,
.link-button {
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 100%;
  padding: 0.45rem 0.65rem;
  border-radius: 0.85rem;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.button {
  background: linear-gradient(135deg, #25D366, #1AA34A);
  color: white;
  box-shadow: 0 8px 14px rgba(37, 211, 102, 0.16);
}

.link-button {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.status {
  color: var(--muted);
  margin-bottom: 1rem;
}

.footer {
  padding: 1.5rem 0 2rem;
  color: var(--muted);
}

@media (min-width: 720px) {
  .controls {
    grid-template-columns: 2fr 1fr;
  }
}

@media (max-width: 719px) {
  .book-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
  }

  .card {
    max-width: none;
    border-radius: 0.75rem;
  }

  .card-content {
    padding: 0.5rem;
    gap: 0.25rem;
  }

  .card-title {
    font-size: 0.75rem;
    line-height: 1.2;
  }

  .card-meta {
    font-size: 0.65rem;
    gap: 0.2rem;
  }

  .badge {
    padding: 0.15rem 0.35rem;
    font-size: 0.6rem;
  }

  .details-button {
    padding: 0.4rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 0.6rem;
  }

  .button,
  .link-button {
    padding: 0.35rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 0.6rem;
  }

  .image-wrapper {
    aspect-ratio: 2 / 3;
  }
}
