:root {
  --primary: #1a56db;
  --primary-dark: #1e3a8a;
  --accent: #f59e0b;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.header-inner { display: flex; align-items: center; gap: 20px; padding: 12px 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand-mark {
  background: var(--accent);
  color: #1f2937;
  font-weight: 800;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 1.1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1.05rem; }
.brand-text small { opacity: .8; font-size: .75rem; }
.search-form { flex: 1; display: flex; min-width: 220px; max-width: 520px; }
.search-form input {
  flex: 1; border: none; border-radius: 8px 0 0 8px; padding: 10px 14px; font-size: .95rem; outline: none;
}
.search-form button { border: none; background: var(--accent); border-radius: 0 8px 8px 0; padding: 0 16px; cursor: pointer; font-size: 1.05rem; }
.header-nav { display: flex; gap: 16px; }
.header-nav a { color: #e0e7ff; text-decoration: none; font-weight: 500; font-size: .92rem; }
.header-nav a:hover { color: #fff; }

/* Hero */
.hero { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%); color: #fff; border-radius: var(--radius); padding: 34px 28px; margin: 20px 0; }
.hero h1 { margin: 0 0 8px; font-size: 1.7rem; }
.hero p { margin: 0; opacity: .92; max-width: 760px; }
.hero .stats { display: flex; gap: 24px; margin-top: 16px; flex-wrap: wrap; }
.hero .stat { background: rgba(255,255,255,.12); border-radius: 10px; padding: 8px 16px; }
.hero .stat b { display: block; font-size: 1.3rem; }
.hero .stat span { font-size: .8rem; opacity: .85; }

/* Filters */
.filters {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 600; }
.filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; font-size: .9rem; min-width: 160px; }
.grade-pills { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.grade-pills a {
  text-decoration: none; color: var(--primary); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 14px; font-size: .88rem; font-weight: 600; background: #fff;
}
.grade-pills a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.filters .reset { margin-left: auto; }

/* Grid */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 18px; margin: 16px 0 30px; }
.book-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: var(--text);
  transition: transform .15s, box-shadow .15s, border-color .15s; display: flex; flex-direction: column;
}
.book-card:hover { transform: translateY(-4px); box-shadow: 0 10px 28px rgba(26,86,219,.16); border-color: #c7d7f5; }
.book-cover { aspect-ratio: 3/4; background: #e8ecf4; overflow: hidden; position: relative; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s; }
.book-card:hover .book-cover img { transform: scale(1.05); }
.cover-pages {
  position: absolute; bottom: 8px; right: 8px; background: rgba(17,24,39,.78); color: #fff;
  font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.book-info { padding: 11px 13px 13px; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.book-info h3 { margin: 0; font-size: .88rem; line-height: 1.35; font-weight: 700; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.4em; }
.book-subject { font-size: .75rem; color: var(--primary); font-weight: 600; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: .68rem; padding: 2px 8px; border-radius: 999px; background: #eef2ff; color: var(--primary); font-weight: 600; }
.badge.pub { background: #fef3c7; color: #92400e; }
.badge.pages { background: #f1f5f9; color: var(--muted); }
.book-meta { display: flex; flex-direction: column; gap: 2px; margin-top: auto; padding-top: 6px; border-top: 1px dashed var(--border); font-size: .72rem; color: var(--muted); }
.book-meta .authors { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Pagination */
.pagination { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding-bottom: 30px; }
.pagination a, .pagination span {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff;
  text-decoration: none; color: var(--text); font-weight: 600; font-size: .9rem;
}
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled { color: #bbb; }

/* Detail */
.book-detail { display: grid; grid-template-columns: 300px 1fr; gap: 28px; margin: 24px 0; }
@media (max-width: 760px) { .book-detail { grid-template-columns: 1fr; } }
.detail-cover { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: #fff; }
.detail-cover img { width: 100%; display: block; }
.detail-info h1 { margin: 0 0 6px; font-size: 1.5rem; }
.meta-table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.meta-table th, .meta-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: top; }
.meta-table th { color: var(--muted); white-space: nowrap; width: 160px; font-weight: 600; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 12px 22px; border-radius: 10px;
  font-weight: 700; font-size: .95rem; text-decoration: none; border: none; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-green { background: #059669; color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Viewer */
.viewer-wrap { margin: 18px 0 30px; }
.viewer-frame {
  width: 100%; height: 80vh; min-height: 500px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #525659; overflow: hidden;
}

/* Download page */
.dl-box {
  max-width: 560px; margin: 30px auto; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
}
.dl-box h1 { font-size: 1.25rem; margin-top: 0; }
.captcha-row { display: flex; gap: 12px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.captcha-row img { border-radius: 8px; border: 1px solid var(--border); }
.captcha-row input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 1.1rem; letter-spacing: 2px; width: 150px; text-transform: uppercase; }
.refresh-captcha { background: none; border: none; cursor: pointer; font-size: 1.2rem; }
.countdown-note { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; border-radius: 8px; padding: 10px 14px; font-size: .88rem; margin: 14px 0; }
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: .9rem; }
.alert-box { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; border-radius: 8px; padding: 10px 14px; margin: 12px 0; font-size: .9rem; }

/* Legal pages */
.legal-page { max-width: 800px; margin: 24px auto 40px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 32px 36px; }
.legal-page h1 { font-size: 1.5rem; margin-top: 0; color: var(--primary-dark); }
.legal-page h2 { font-size: 1.1rem; margin-top: 26px; }
.legal-page p, .legal-page li { color: #374151; font-size: .95rem; }
.legal-page .updated { color: var(--muted); font-size: .82rem; }

/* Footer */
.site-footer { background: #111827; color: #d1d5db; margin-top: 40px; padding: 36px 0 20px; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 28px; }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr; } }
.footer-grid h4 { color: #fff; margin: 0 0 10px; font-size: .95rem; }
.footer-grid a { display: block; color: #9ca3af; text-decoration: none; font-size: .88rem; padding: 3px 0; }
.footer-grid a:hover { color: #fff; }
.footer-legal { border-top: 1px solid #374151; margin-top: 26px; padding-top: 16px; font-size: .8rem; color: #9ca3af; }

/* Browse homepage */
.level-section { margin: 28px 0; }
.level-title { font-size: 1.15rem; color: var(--primary-dark); border-left: 4px solid var(--accent); padding-left: 10px; margin: 0 0 14px; }
.grade-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; align-items: stretch; }
.grade-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column;
}
.grade-card .subject-pills { margin-top: auto; }
.grade-covers { display: flex; gap: 6px; margin-bottom: 10px; }
.grade-covers a { flex: 1; aspect-ratio: 3/4; border-radius: 6px; overflow: hidden; background: #e8ecf4; box-shadow: 0 2px 6px rgba(0,0,0,.1); }
.grade-covers img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.grade-covers a:hover img { transform: scale(1.08); }
.grade-head { display: flex; justify-content: space-between; align-items: baseline; text-decoration: none; margin-bottom: 10px; }
.grade-num { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.grade-count { font-size: .78rem; color: var(--muted); }
.grade-head:hover .grade-num { text-decoration: underline; }
.subject-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  text-decoration: none; background: #eef2ff; color: var(--primary); font-size: .78rem;
  font-weight: 600; padding: 3px 10px; border-radius: 999px;
}
.pill:hover { background: var(--primary); color: #fff; }
.pill.more { background: #fef3c7; color: #92400e; }
.pub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; align-items: stretch; }
.pub-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-decoration: none; display: flex; flex-direction: column; gap: 8px;
  min-height: 92px;
}
.pub-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(26,86,219,.12); }
.pub-name { font-weight: 700; color: var(--text); font-size: .92rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pub-count {
  font-size: .78rem; color: var(--primary); margin-top: auto; align-self: flex-start;
  background: #eef2ff; font-weight: 600; padding: 3px 10px; border-radius: 999px;
}

/* Grouped list */
.group-header { margin: 26px 0 4px; display: flex; align-items: baseline; gap: 10px; }
.group-header h2 { font-size: 1.05rem; margin: 0; color: var(--primary-dark); border-bottom: 2px solid var(--accent); padding-bottom: 6px; width: 100%; }
.group-count { font-size: .78rem; color: var(--muted); font-weight: 500; }

/* Locked viewer */
.viewer-locked {
  border: 2px dashed #c7d7f5; border-radius: var(--radius); background: #f8faff;
  min-height: 320px; display: flex; align-items: center; justify-content: center; margin: 18px 0 30px; text-align: center;
}
.lock-inner { padding: 40px 20px; max-width: 460px; }
.lock-icon { font-size: 3rem; margin-bottom: 8px; }
.lock-inner h2 { margin: 0 0 8px; color: var(--primary-dark); font-size: 1.2rem; }
.lock-inner p { color: var(--muted); margin: 0 0 18px; font-size: .92rem; }

/* Reader pages (gate + reading) */
.reader-body { background: #f4f6fb; }
.reader-header {
  position: sticky; top: 0; z-index: 50; background: #111827; color: #fff;
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
}
.reader-back {
  color: #fff; text-decoration: none; font-size: 1.3rem; padding: 2px 10px; border-radius: 8px; background: rgba(255,255,255,.1);
}
.reader-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.reader-title strong { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title span { font-size: .78rem; color: #9ca3af; }
.reader-main { padding: 12px 16px 20px; }
.reader-frame { height: calc(100vh - 76px); }

/* Gate card */
.gate-card {
  max-width: 640px; margin: 40px auto; background: #fff; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px; box-shadow: 0 8px 30px rgba(17,24,39,.08);
}
.gate-book { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.gate-book img { width: 92px; border-radius: 8px; border: 1px solid var(--border); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.gate-book h1 { font-size: 1.15rem; margin: 0 0 4px; }
.gate-sub { color: var(--muted); font-size: .85rem; margin: 0 0 6px; }
.gate-book a { font-size: .82rem; color: var(--primary); }
.btn-block { width: 100%; justify-content: center; margin-top: 6px; }
.gate-legal { color: var(--muted); font-size: .78rem; margin: 14px 0 0; text-align: center; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-group input, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem;
  font-family: inherit;
}
.honeypot { position: absolute; left: -9999px; opacity: 0; }
