:root {
  --primary: #7c3aed;
  --primary-2: #a855f7;
  --pink: #ec4899;
  --amber: #f59e0b;
  --grad: linear-gradient(135deg, #7c3aed 0%, #a855f7 45%, #ec4899 100%);
  --grad-soft: linear-gradient(135deg, #ede9fe 0%, #fce7f3 100%);
  --bg: #fbfafd;
  --surface: #ffffff;
  --text: #1f2333;
  --muted: #6b7280;
  --dark: #141a33;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(124, 58, 237, 0.10);
  --shadow-hover: 0 18px 40px rgba(124, 58, 237, 0.22);
  --border: #ece9f6;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, #f3e8ff 0%, transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, #ffe4e6 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; width: 100%; }
main.container { flex: 1; }

/* ---------- Navbar ---------- */
.navbar {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 66px;
  gap: 12px;
}
.brand {
  font-size: 1.35rem;
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand-icon {
  font-size: 1.6rem;
  -webkit-text-fill-color: initial;
  filter: drop-shadow(0 4px 10px rgba(124, 58, 237, 0.35));
}
.nav-links { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav-links > a { color: var(--text); font-weight: 500; padding: 6px 10px; border-radius: 10px; transition: color 0.15s, background 0.15s; }
.nav-links > a:hover { color: var(--primary); background: #f3edff; }
.nav-links > a.active { color: var(--primary); background: #f3edff; font-weight: 600; }
.nav-user { color: var(--muted); font-size: 0.9rem; }
.nav-toggle { display: none; background: none; border: none; font-size: 1.7rem; cursor: pointer; color: var(--text); }

@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    padding: 12px 0 4px;
  }
  .nav-links.open { display: flex; }
  .nav-links .btn { text-align: center; }
}

/* ---------- Botones ---------- */
.btn {
  display: inline-block;
  padding: 11px 22px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  text-align: center;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s, color 0.15s;
  color: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.35);
}
.btn-primary:hover { box-shadow: 0 12px 26px rgba(124, 58, 237, 0.45); transform: translateY(-1px); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04); }
.btn-ghost:hover { background: #f7f4ff; border-color: #d8ccf5; transform: translateY(-1px); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #f97316); color: #fff; box-shadow: 0 8px 20px rgba(239, 68, 68, 0.35); }
.btn-danger:hover { transform: translateY(-1px); color: #fff; }
.btn-fav-active { background: #ffe4e6; border-color: #fecdd3; color: #e11d48; }
.btn-fav-active:hover { background: #ffd0d6; }
.btn-lg { padding: 15px 32px; font-size: 1.05rem; }
.btn-sm { padding: 6px 13px; font-size: 0.82rem; border-radius: 999px; }
.btn-block { display: block; width: 100%; }
.inline { display: inline; }

/* ---------- Alertas ---------- */
.alert {
  padding: 14px 18px;
  border-radius: 14px;
  margin-bottom: 16px;
  font-weight: 500;
  border: 1px solid transparent;
}
.alert-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  text-align: center;
  padding: 70px 20px 46px;
  color: #fff;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(236, 72, 153, 0.35), transparent 55%),
    radial-gradient(900px 500px at 85% 0%, rgba(168, 85, 247, 0.45), transparent 55%),
    linear-gradient(135deg, #312e81 0%, #6d28d9 55%, #a21caf 100%);
  border-radius: 0 0 34px 34px;
  box-shadow: 0 20px 50px rgba(109, 40, 217, 0.35);
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.14) 1.5px, transparent 1.5px);
  background-size: 26px 26px;
  pointer-events: none;
}
.hero h1 {
  position: relative;
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}
.hero h1 .hl {
  background: linear-gradient(90deg, #fcd34d, #f9a8d4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p { position: relative; color: #e9d5ff; max-width: 600px; margin: 0 auto; font-size: 1.08rem; }
.hero-actions { position: relative; margin-top: 26px; display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero .btn-primary { background: #fff; color: var(--primary-dark, #6d28d9); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25); }
.hero .btn-primary:hover { background: #f3e8ff; color: #6d28d9; }
.hero .btn-ghost { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.4); color: #fff; box-shadow: none; }
.hero .btn-ghost:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }

/* ---------- Busqueda ---------- */
.search-bar {
  display: flex;
  gap: 10px;
  margin: -20px auto 28px;
  max-width: 760px;
  background: var(--surface);
  padding: 12px;
  border-radius: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  flex-wrap: wrap;
}
.search-bar input {
  flex: 1 1 240px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 1rem;
  font-family: inherit;
  background: #f7f5ff;
}
.search-bar input:focus { outline: 2px solid var(--primary-2); border-color: transparent; }
.search-bar select {
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 1rem;
  font-family: inherit;
  background: #f7f5ff;
}

/* ---------- Pagina ---------- */
.page { padding-top: 30px; padding-bottom: 56px; }
.page h1 { margin-top: 0; font-weight: 800; letter-spacing: -0.01em; }
.page h2 { font-weight: 700; }

/* ---------- Grid de libros ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 24px;
  margin-top: 10px;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: fadeUp 0.5s ease both;
}
.book-card:nth-child(2n) { animation-delay: 0.05s; }
.book-card:nth-child(3n) { animation-delay: 0.1s; }
.book-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-hover); }
.book-cover { position: relative; display: block; aspect-ratio: 3 / 4; background: var(--grad-soft); }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.3s; }
.book-card:hover .book-cover img { transform: scale(1.05); }
.book-type {
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--grad);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 4px 10px rgba(124, 58, 237, 0.4);
}
.book-info { padding: 14px; }
.book-title { margin: 0 0 3px; font-size: 1rem; font-weight: 700; line-height: 1.3; }
.book-title a { color: var(--text); }
.book-title a:hover { color: var(--primary); }
.book-author { color: var(--muted); margin: 0 0 10px; font-size: 0.86rem; }

.badge {
  display: inline-block;
  background: linear-gradient(135deg, #ede9fe, #fce7f3);
  color: #6d28d9;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
}
.badge-type { background: linear-gradient(135deg, #fef3c7, #fde68a); color: #92400e; }
.badge-ok { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: #065f46; }
.badge-off { background: linear-gradient(135deg, #fef3c7, #fcd34d); color: #92400e; }

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

/* ---------- Detalle de libro ---------- */
.book-detail {
  display: flex;
  gap: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.book-detail-cover { flex: 0 0 260px; }
.book-detail-cover img {
  width: 100%;
  border-radius: 16px;
  aspect-ratio: 3/4;
  object-fit: cover;
  box-shadow: var(--shadow-hover);
}
.book-detail-info h1 { margin: 0 0 4px; font-weight: 800; font-size: 2rem; }
.book-detail-info .book-author { font-size: 1.08rem; margin-bottom: 10px; }
.book-description { margin: 18px 0; color: #4b5563; white-space: pre-line; }
.book-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 22px; }

@media (max-width: 640px) {
  .book-detail { flex-direction: column; padding: 20px; }
  .book-detail-cover { flex: none; width: 62%; margin: 0 auto; }
}

.progress-block { margin-top: 20px; max-width: 440px; }
.progress-label { font-size: 0.9rem; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.progress-track { height: 10px; background: #ece9f6; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--grad); border-radius: 999px; }

/* ---------- Continuar leyendo ---------- */
.continue-list { display: flex; flex-direction: column; gap: 14px; }
.continue-item {
  display: flex;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  align-items: center;
  transition: transform 0.15s, box-shadow 0.15s;
}
.continue-item img { width: 60px; height: 82px; object-fit: cover; border-radius: 8px; box-shadow: 0 6px 14px rgba(0, 0, 0, 0.15); }
.continue-info { flex: 1; display: flex; flex-direction: column; gap: 5px; color: var(--text); }
.continue-info strong { font-size: 1.02rem; }
.continue-info span { color: var(--muted); font-size: 0.88rem; }
.continue-info small { color: var(--muted); font-weight: 500; }
.continue-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }

/* ---------- Auth ---------- */
.auth-card {
  max-width: 440px;
  margin: 30px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin-top: 0; font-weight: 800; }
.auth-card label, .admin-form label { display: block; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.auth-card input, .admin-form input[type=text],
.admin-form input[type=file], .admin-form textarea, .admin-form select {
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  font-family: inherit;
  background: #f7f5ff;
  transition: border 0.15s, box-shadow 0.15s;
}
.auth-card input:focus, .admin-form input:focus, .admin-form textarea:focus, .admin-form select:focus {
  outline: none;
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.2);
}
.auth-alt { text-align: center; color: var(--muted); margin-top: 18px; }

/* ---------- Reader ---------- */
.reader-bar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.reader-bar-left, .reader-bar-right { display: flex; align-items: center; gap: 10px; }
.reader-title { font-weight: 700; }
.reader-theme { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font-family: inherit; }
.reader-wrap {
  position: relative;
  height: calc(100vh - 136px);
  margin: 16px auto;
  max-width: 880px;
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.reader-viewer { width: 100%; height: 100%; overflow-y: auto; }
.reader-viewer iframe { border: none; }
.reader-status { text-align: center; padding: 8px; color: var(--muted); font-size: 0.9rem; font-weight: 500; }

.theme-sepia { background: #f4ecd8; border-color: #e0d4b8; }
.theme-dark { background: #1e1e2e; border-color: #333; color: #d4d4d4; }

.pdf-page { display: block; margin: 0 auto 14px; box-shadow: var(--shadow); max-width: 100%; }
.reader-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  border: none;
  background: rgba(124, 58, 237, 0.14);
  color: #6d28d9;
  font-size: 2.2rem;
  cursor: pointer;
  border-radius: 14px;
  z-index: 5;
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.15s;
}
.reader-nav-btn:hover { background: rgba(124, 58, 237, 0.3); transform: translateY(-50%) scale(1.06); }
.reader-nav-prev { left: 10px; }
.reader-nav-next { right: 10px; }

/* ---------- Admin ---------- */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin: 22px 0; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}
.stat-card:hover { transform: translateY(-4px); }
.stat-num {
  display: block;
  font-size: 2.1rem;
  font-weight: 800;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-label { color: var(--muted); font-size: 0.88rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: #f6f3ff; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6d28d9; }
.table tbody tr:hover { background: #fbf8ff; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty-cell { text-align: center; color: var(--muted); padding: 28px; }
.admin-form { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px; max-width: 760px; box-shadow: var(--shadow); }
.form-row { display: flex; gap: 18px; flex-wrap: wrap; }
.form-row label { flex: 1 1 250px; }
.checkbox { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.checkbox input { width: auto; }

/* ---------- Varios ---------- */
.empty-state { text-align: center; color: var(--muted); padding: 60px 0; }
.empty-state .empty-emoji { font-size: 3.5rem; display: block; margin-bottom: 12px; }
.empty-state p { margin-bottom: 18px; font-size: 1.05rem; }
.footer {
  background: linear-gradient(135deg, #141a33, #2e1065);
  color: #c4b5fd;
  padding: 30px 0;
  text-align: center;
  font-size: 0.9rem;
  margin-top: auto;
}
.footer .container p { margin: 0; }