*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #111; color: #ccc; }
body { min-height: 100vh; }

a { color: #6af; text-decoration: none; }

/* ============ Header ============ */
.header {
  background: #1a1a1a;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #333;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 20px; color: #eee; }
.header a { color: #999; font-size: 14px; }
.header a:hover { color: #fff; }

/* ============ Book Grid ============ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}
.book-card {
  background: #1a1a1a;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: 1px solid #2a2a2a;
}
.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  border-color: #444;
}
.book-card .cover {
  aspect-ratio: 3/4;
  background: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.book-card .cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.book-card .cover .placeholder {
  color: #555;
  font-size: 48px;
}
.book-card .info {
  padding: 10px 12px;
}
.book-card .info .title {
  font-size: 14px;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.book-card .info .meta {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}

/* ============ Reader ============ */
.reader-body {
  background: #000;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.reader-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(0,0,0,.8);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  transform: translateY(-100%);
  transition: transform .25s;
}
.reader-toolbar.show { transform: translateY(0); }
.reader-toolbar .back { color: #999; cursor: pointer; padding: 4px 8px; }
.reader-toolbar .back:hover { color: #fff; }
.reader-toolbar .page-info { color: #aaa; flex: 1; text-align: center; }
.reader-toolbar button {
  background: none;
  border: 1px solid #444;
  color: #ccc;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.reader-toolbar button:hover { background: #333; color: #fff; }
.reader-toolbar button.active { background: #6af; color: #000; border-color: #6af; }

.reader-viewport {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow: hidden;
}

.reader-image-container {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reader-image-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.reader-image-container img.w-fit { max-height: none; width: 100%; }
.reader-image-container img.h-fit { max-width: none; height: 100%; }

.reader-nav {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 35%;
  z-index: 50;
  cursor: pointer;
}
.reader-nav.prev { left: 0; }
.reader-nav.next { right: 0; }
.reader-nav .arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 36px;
  color: rgba(255,255,255,.15);
  transition: color .2s;
}
.reader-nav.prev .arrow { left: 16px; }
.reader-nav.next .arrow { right: 16px; }
.reader-nav:hover .arrow { color: rgba(255,255,255,.6); }
.reader-nav-center {
  position: fixed;
  top: 0; bottom: 0; left: 35%; right: 35%;
  z-index: 10;
}

/* scroll mode */
.reader-scroll {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.reader-scroll .page {
  display: block;
  width: 100%;
  height: auto;
}
.reader-scroll .page-container {
  text-align: center;
}

/* loading / error */
.reader-loading {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  color: #666;
  font-size: 16px;
  z-index: 5;
}

/* ============ Admin ============ */
.admin-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}
.admin-container h2 { color: #eee; margin-bottom: 16px; }
.admin-container form {
  background: #1a1a1a;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 24px;
  border: 1px solid #2a2a2a;
}
.admin-container .field {
  margin-bottom: 12px;
}
.admin-container label {
  display: block;
  font-size: 13px;
  color: #999;
  margin-bottom: 4px;
}
.admin-container input, .admin-container textarea {
  width: 100%;
  padding: 8px 12px;
  background: #222;
  border: 1px solid #333;
  border-radius: 4px;
  color: #ddd;
  font-size: 14px;
}
.admin-container input:focus, .admin-container textarea:focus {
  outline: none;
  border-color: #6af;
}
.admin-container textarea { resize: vertical; min-height: 60px; }
.admin-container .btn {
  padding: 8px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}
.admin-container .btn-primary { background: #6af; color: #000; }
.admin-container .btn-primary:hover { background: #8bf; }
.admin-container .btn-danger { background: #e44; color: #fff; }
.admin-container .btn-danger:hover { background: #f66; }
.admin-container .btn-sm { padding: 4px 12px; font-size: 12px; }

.admin-login {
  max-width: 360px;
  margin: 80px auto;
  text-align: center;
}
.admin-login input {
  width: 100%;
  padding: 10px 14px;
  background: #222;
  border: 1px solid #333;
  border-radius: 4px;
  color: #ddd;
  font-size: 16px;
  margin-bottom: 12px;
}
.admin-login input:focus { outline: none; border-color: #6af; }

.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.book-table th, .book-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid #2a2a2a;
}
.book-table th { color: #888; font-weight: normal; }
.book-table td { color: #ccc; }
.book-table td .actions { display: flex; gap: 6px; }

/* ============ Empty State ============ */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: #555;
}
.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 16px; }

/* ============ Responsive ============ */
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px; }
  .reader-nav { width: 30%; }
  .reader-nav .arrow { font-size: 24px; }
  .admin-container { padding: 12px; }
  .book-table th:nth-child(3), .book-table td:nth-child(3) { display: none; }
}
