:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-dark: #0284c7;
  --accent-gradient: linear-gradient(135deg, #38bdf8, #818cf8);
  --border: #334155;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* Status Bar */
.status-bar {
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  padding: 0.375rem 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Textbook Badges */
.textbook-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: #f59e0b;
  color: #0f172a;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  z-index: 2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.textbook-badge--offline {
  background: #ef4444;
  color: white;
}

.textbook-badge--github {
  background: #6e40c9;
  color: white;
}

.textbook-card--offline {
  opacity: 0.7;
}

.textbook-card--offline:hover {
  opacity: 0.9;
}

.textbook-note {
  font-size: 0.7rem;
  color: #f59e0b;
  margin-top: 0.25rem;
  font-style: italic;
}

.btn-disabled {
  background: var(--bg-card-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: default;
  pointer-events: none;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(30, 41, 59, 0.9);
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.header-badge {
  background: var(--accent-dark);
  color: white;
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-weight: 500;
  letter-spacing: 0.025em;
}

/* Main Container */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem;
}

/* Filters */
.filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: end;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex: 1;
  min-width: 160px;
}

.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.filter-group select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.filter-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Search */
.search-wrapper {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrapper input {
  width: 100%;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-wrapper input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.search-wrapper input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Stats */
.stats {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.stats strong {
  color: var(--text-primary);
}

/* Textbook Grid */
.textbook-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.textbook-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  cursor: pointer;
  position: relative;
}

.textbook-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-dark);
}

.textbook-card:active {
  transform: translateY(-2px);
}

.textbook-thumb {
  width: 100%;
  aspect-ratio: 3/4;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.textbook-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 400ms ease;
}

.textbook-card:hover .textbook-thumb img {
  transform: scale(1.05);
}

.textbook-thumb-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.textbook-thumb-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.textbook-info {
  padding: 1rem;
}

.textbook-subject {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

.textbook-chapter {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.textbook-actions {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
}

.btn-primary:hover {
  background: #7dd3fc;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  gap: 1rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Error */
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  gap: 1rem;
  color: #f87171;
}

.error-icon {
  font-size: 3rem;
}

.error-text {
  font-size: 1rem;
  text-align: center;
}

/* Empty */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  gap: 1rem;
  color: var(--text-muted);
  text-align: center;
}

.empty-state svg {
  width: 64px;
  height: 64px;
  opacity: 0.4;
}

.empty-state h3 {
  font-size: 1.125rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.empty-state p {
  font-size: 0.875rem;
  max-width: 400px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transform: translateY(calc(100% + 3rem));
  opacity: 0;
  transition: all 400ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 200;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  font-size: 1.25rem;
}

.toast-message {
  font-size: 0.875rem;
  color: var(--text-primary);
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 2rem;
  margin-top: 3rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.textbook-card {
  animation: fadeInUp 400ms ease both;
}

.textbook-card:nth-child(1) { animation-delay: 0ms; }
.textbook-card:nth-child(2) { animation-delay: 50ms; }
.textbook-card:nth-child(3) { animation-delay: 100ms; }
.textbook-card:nth-child(4) { animation-delay: 150ms; }
.textbook-card:nth-child(5) { animation-delay: 200ms; }
.textbook-card:nth-child(6) { animation-delay: 250ms; }
.textbook-card:nth-child(7) { animation-delay: 300ms; }
.textbook-card:nth-child(8) { animation-delay: 350ms; }
.textbook-card:nth-child(9) { animation-delay: 400ms; }
.textbook-card:nth-child(10) { animation-delay: 450ms; }
.textbook-card:nth-child(11) { animation-delay: 500ms; }
.textbook-card:nth-child(12) { animation-delay: 550ms; }
.textbook-card:nth-child(13) { animation-delay: 600ms; }
.textbook-card:nth-child(14) { animation-delay: 650ms; }
.textbook-card:nth-child(15) { animation-delay: 700ms; }

/* Responsive */
@media (max-width: 768px) {
  .header {
    padding: 0.75rem 1rem;
  }

  .header h1 {
    font-size: 1.125rem;
  }

  .header-subtitle {
    display: none;
  }

  .container {
    padding: 1rem;
  }

  .filters {
    flex-direction: column;
    gap: 0.75rem;
  }

  .filter-group {
    min-width: 100%;
  }

  .search-wrapper {
    min-width: 100%;
  }

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

  .textbook-info {
    padding: 0.75rem;
  }

  .textbook-chapter {
    font-size: 0.8125rem;
  }
}

@media (max-width: 480px) {
  .textbook-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
}
