:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --shadow: 0 8px 24px rgba(2, 6, 23, 0.08);
}

body[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #121a2b;
  --surface-alt: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #1e293b;
  --primary: #818cf8;
  --primary-strong: #6366f1;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.app-topbar {
  height: 64px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in oklab, var(--surface) 90%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-center {
  flex: 1;
  max-width: 540px;
  margin: 0 20px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.brand-text {
  font-weight: 700;
  letter-spacing: 0.3px;
}

.page-title {
  font-size: 14px;
  color: var(--muted);
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

.global-search {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0 12px;
  height: 40px;
}

.global-search i {
  color: var(--muted);
}

.global-search input {
  border: 0;
  background: transparent;
  color: var(--text);
  width: 100%;
  outline: 0;
}

.app-sidebar {
  position: fixed;
  top: 0;
  left: -290px;
  width: 280px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px;
  z-index: 150;
  transition: left 0.25s ease;
  overflow-y: auto;
}

.app-sidebar.open {
  left: 0;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  z-index: 120;
  display: none;
}

.sidebar-overlay.open {
  display: block;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sidebar-brand {
  font-size: 18px;
  font-weight: 700;
}

.sidebar-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 4px;
}

.sidebar-link:hover {
  background: var(--surface-alt);
  color: var(--primary-strong);
}

.flash-wrap {
  width: min(1200px, 92%);
  margin: 16px auto 0;
}

.flash-message {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.flash-content {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.flash-success {
  border-left-color: var(--success);
}

.flash-warning {
  border-left-color: var(--warning);
}

.flash-error {
  border-left-color: var(--danger);
}

.app-main {
  flex: 1;
  width: min(1320px, 92%);
  margin: 22px auto 50px;
}

.app-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4%;
}

.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

.card-surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 20px;
}

.book-card-link {
  text-decoration: none;
}

.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
}

.book-card-image-container {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(140deg, #dbeafe, #ede9fe);
}

.book-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.book-card:hover .book-card-overlay {
  opacity: 1;
}

.book-card-button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: #fff;
  color: #1e293b;
  font-weight: 700;
  cursor: pointer;
}

.book-card-info {
  padding: 14px;
}

.book-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
}

.book-card-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chip-btn,
.outline-btn,
.primary-btn {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

.chip-btn.active {
  background: color-mix(in oklab, var(--primary) 16%, var(--surface));
  border-color: var(--primary);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.primary-btn:hover {
  background: var(--primary-strong);
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

.fade-in-up {
  animation: fadeInUp 0.35s ease both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-alt);
  border-radius: 12px;
  min-height: 140px;
}

.skeleton::after {
  content: "";
  position: absolute;
  top: 0;
  left: -150px;
  width: 150px;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  animation: shimmer 1.15s infinite;
}

@keyframes shimmer {
  100% {
    transform: translateX(900px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 992px) {
  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }

  .page-title {
    display: none;
  }

  .app-main {
    width: 94%;
  }
}

@media (max-width: 640px) {
  .app-footer {
    flex-direction: column;
    gap: 4px;
    text-align: center;
  }

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

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