:root {
  --primary: #e85d04;
  --primary-hover: #d45003;
  --primary-light: #fff3eb;
  --text-dark: #333;
  --text-mid: #666;
  --text-light: #999;
  --border: #e8e8e8;
  --bg-page: #fff;
  --bg-section: #f7f7f7;
  --bg-card: #fff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 2px 8px rgba(0,0,0,.1);
  --radius: 4px;
  --radius-lg: 8px;
  --nav-height: 56px;
  --max-width: 1200px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font); color: var(--text-dark); background: var(--bg-page);
  line-height: 1.6; min-height: 100vh; padding-top: var(--nav-height);
}
a { color: var(--text-dark); text-decoration: none; transition: color .2s; }
a:hover { color: var(--primary); }
img { max-width: 100%; height: auto; display: block; }
ul, ol { list-style: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ========== Navigation ========== */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--nav-height); background: var(--bg-page);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.nav-container {
  max-width: var(--max-width); margin: 0 auto; padding: 0 24px;
  display: flex; align-items: center; height: 100%; gap: 8px;
}
.nav-logo {
  font-size: 22px; font-weight: 700; color: var(--primary);
  white-space: nowrap; margin-right: 24px; flex-shrink: 0;
}
.nav-logo:hover { color: var(--primary-hover); }
.nav-links { display: flex; align-items: center; gap: 24px; flex-shrink: 0; }
.nav-links a {
  font-size: 15px; color: var(--text-mid); position: relative;
  padding: 4px 0; transition: color .2s; white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active { color: var(--text-dark); font-weight: 500; }
.nav-links a.active::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -2px;
  height: 2px; background: var(--primary); border-radius: 1px;
}
.nav-search {
  display: flex; align-items: center; margin-left: auto;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-section); overflow: hidden; transition: border-color .2s;
}
.nav-search:focus-within { border-color: var(--primary); background: #fff; }
.nav-search input[type="text"] {
  border: none; outline: none; background: transparent;
  padding: 7px 14px; width: 200px; font-size: 14px; color: var(--text-dark);
}
.nav-search input[type="text"]::placeholder { color: var(--text-light); }
.nav-search button {
  border: none; background: transparent; cursor: pointer;
  padding: 6px 12px; color: var(--text-light); font-size: 16px; transition: color .2s;
}
.nav-search button:hover { color: var(--primary); }
.nav-admin {
  flex-shrink: 0; margin-left: 16px;
}
.nav-admin a {
  display: inline-block; padding: 5px 14px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 14px;
  color: var(--text-mid); transition: all .2s;
}
.nav-admin a:hover { border-color: var(--primary); color: var(--primary); }

/* ========== Main Content ========== */
.main-content {
  max-width: var(--max-width); margin: 0 auto; padding: 0 24px;
}

/* ========== Library / Home ========== */
.library-container { padding: 16px 0; }
.search-result-header { padding: 16px 0 8px; }
.search-result-header h2 { font-size: 18px; font-weight: 600; }

.filter-section { padding: 16px 0 8px; }
.filter-row {
  display: flex; align-items: baseline; padding: 8px 0; font-size: 14px; flex-wrap: wrap;
}
.filter-label { color: var(--text-light); width: 70px; flex-shrink: 0; }
.filter-options { display: flex; flex-wrap: wrap; gap: 4px; }
.filter-option {
  padding: 4px 14px; border-radius: 3px; color: var(--text-mid); transition: all .15s;
}
.filter-option:hover { color: var(--primary); }
.filter-option.active { color: var(--primary); font-weight: 500; background: var(--primary-light); }

.sort-tabs {
  display: flex; gap: 24px; border-bottom: 1px solid var(--border);
  padding: 12px 0 0; margin-bottom: 20px;
}
.sort-tab {
  padding-bottom: 10px; font-size: 15px; color: var(--text-mid);
  position: relative; transition: color .2s;
}
.sort-tab:hover { color: var(--text-dark); }
.sort-tab.active { color: var(--primary); font-weight: 500; }
.sort-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--primary); border-radius: 1px;
}

/* ========== Book Grid ========== */
.book-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px;
}
.book-card {
  display: flex; gap: 16px; padding: 16px; border-radius: var(--radius);
  transition: box-shadow .2s, transform .15s; cursor: pointer;
}
.book-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.book-cover {
  width: 120px; height: 160px; flex-shrink: 0; border-radius: var(--radius);
  overflow: hidden; background: var(--bg-section);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,.3);
  padding: 10px; text-align: center; word-break: break-all; line-height: 1.3;
}
.cover-placeholder.large { font-size: 30px; padding: 16px; }

.book-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.book-title {
  font-size: 16px; font-weight: 600; color: var(--text-dark);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px;
}
.book-author { font-size: 13px; color: var(--text-light); margin-bottom: 4px; }
.book-meta { font-size: 13px; color: var(--text-light); margin-bottom: 6px; }
.book-desc {
  font-size: 13px; color: var(--text-mid); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; flex: 1;
}
.book-time { font-size: 12px; color: var(--text-light); margin-top: 6px; }

/* ========== Pagination ========== */
.pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 6px; padding: 32px 0;
}
.page-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; color: var(--text-mid); transition: all .2s;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 500;
}

/* ========== Book Detail ========== */
.book-detail-container { padding: 16px 0 40px; }
.breadcrumb { padding: 8px 0 16px; font-size: 13px; color: var(--text-light); }
.breadcrumb a { color: var(--text-light); }
.breadcrumb a:hover { color: var(--primary); }

.book-detail-header { display: flex; gap: 32px; padding: 20px 0 32px; }
.book-detail-cover {
  width: 200px; height: 270px; flex-shrink: 0; border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-md); background: var(--bg-section);
}
.book-detail-cover img { width: 100%; height: 100%; object-fit: cover; }

.book-detail-info { flex: 1; }
.book-detail-info h1 { font-size: 24px; font-weight: 700; margin-bottom: 12px; }

.book-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tag-status, .tag-category, .tag-format, .tag-item {
  display: inline-block; padding: 2px 10px;
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 12px; color: var(--text-mid);
}
.tag-status { border-color: var(--primary); color: var(--primary); }
.tag-status.ongoing { border-color: #2ecc71; color: #2ecc71; }
.tag-status.completed { border-color: var(--primary); color: var(--primary); }
.tag-format { background: #3498db; color: #fff; border-color: #3498db; }

.book-detail-author { font-size: 14px; color: var(--text-mid); margin-bottom: 8px; }
.book-detail-wordcount { font-size: 14px; color: var(--text-mid); margin-bottom: 8px; }
.book-detail-latest { font-size: 14px; color: var(--text-mid); margin-bottom: 20px; }
.book-detail-latest a { color: var(--primary); }
.update-time { color: var(--text-light); margin-left: 12px; }

.book-detail-actions { display: flex; gap: 12px; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 32px; border-radius: 24px; font-size: 15px;
  cursor: pointer; border: none; transition: all .2s; font-weight: 500;
  text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-outline { background: transparent; color: var(--text-mid); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: 12px 48px; font-size: 16px; }
.btn-sm { padding: 6px 16px; font-size: 13px; border-radius: 16px; }
.btn-danger { background: #e74c3c; color: #fff; border: none; }
.btn-danger:hover { background: #c0392b; color: #fff; }
.btn-disabled { opacity: .4; pointer-events: none; }

/* Description */
.book-description-section {
  background: var(--bg-section); padding: 28px; border-radius: var(--radius-lg);
  margin-bottom: 24px;
}
.book-description-section h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.book-description-content {
  font-size: 15px; line-height: 1.8; color: var(--text-mid);
}

/* Chapter List */
.chapter-list-section { padding: 8px 0; }
.chapter-list-section h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.volume-title { font-size: 16px; font-weight: 600; margin: 20px 0 12px; color: var(--text-dark); }
.chapter-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 16px;
}
.chapter-link, .chapter-grid a {
  padding: 8px 4px; font-size: 14px; color: var(--text-mid);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: color .15s;
  display: block;
}
.chapter-link:hover, .chapter-grid a:hover { color: var(--primary); }

/* ========== Reading Page ========== */
body.reading-page { padding-top: 0; }
.reader-container { min-height: 100vh; position: relative; }

.reader-topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-height); background: var(--bg-page);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px;
}
.reader-back {
  font-size: 15px; color: var(--text-dark); display: flex; align-items: center; gap: 4px;
}
.reader-back:hover { color: var(--primary); }

.reader-content { max-width: 800px; margin: 0 auto; padding: 40px 20px 60px; }
.chapter-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.chapter-meta { font-size: 13px; color: var(--text-light); margin-bottom: 32px; }
.chapter-text {
  font-size: 18px; line-height: 2; color: var(--text-dark);
}
.chapter-text p { text-indent: 2em; margin-bottom: 0.8em; }

.reader-nav {
  display: flex; justify-content: center; gap: 16px;
  padding: 40px 0 60px; max-width: 600px; margin: 0 auto;
}
.reader-nav .btn { min-width: 140px; }

/* Floating Toolbar */
.reader-toolbar {
  position: fixed; right: 24px; top: 50%; transform: translateY(-50%);
  z-index: 900; display: flex; flex-direction: column; gap: 4px;
}
.toolbar-btn {
  width: 52px; height: 52px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: rgba(60,60,60,.85); color: #fff; border: none;
  border-radius: var(--radius-lg); cursor: pointer; font-size: 11px;
  transition: background .2s; backdrop-filter: blur(4px);
}
.toolbar-icon { font-size: 18px; line-height: 1; }
.toolbar-text { font-size: 10px; }
.toolbar-btn:hover { background: rgba(40,40,40,.95); }

/* Font Panel */
.font-panel {
  position: fixed; inset: 0; z-index: 1100;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.3);
}
.font-panel[style*="flex"] { display: flex; }
.font-panel-content {
  background: var(--bg-page); border-radius: var(--radius-lg);
  padding: 24px; box-shadow: var(--shadow-md); min-width: 280px;
}
.font-panel-content label {
  display: block; font-size: 14px; color: var(--text-mid);
  margin-bottom: 8px; margin-top: 16px;
}
.font-panel-content label:first-child { margin-top: 0; }
.font-size-btns { display: flex; gap: 8px; }
.font-size-btns button {
  padding: 6px 16px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-page); color: var(--text-mid); cursor: pointer;
  font-size: 13px; transition: all .2s;
}
.font-size-btns button:hover { border-color: var(--primary); color: var(--primary); }

/* Night Mode */
body.night-mode {
  --bg-page: #1a1a1a; --bg-section: #222; --bg-card: #252525;
  --text-dark: #ccc; --text-mid: #999; --text-light: #666;
  --border: #333; --shadow-sm: none; --shadow-md: none;
}
body.night-mode .site-header,
body.night-mode .reader-topbar { background: #1e1e1e; border-color: #333; }
body.night-mode .nav-search { background: #252525; border-color: #444; }
body.night-mode .nav-search input { color: #ccc; }
body.night-mode .book-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.4); }
body.night-mode .book-description-section { background: #222; }
body.night-mode .font-panel-content { background: #252525; }
body.night-mode .font-size-btns button { background: #333; border-color: #444; color: #aaa; }

/* ========== Shelf ========== */
.shelf-container { padding: 24px 0; }
.section-title {
  font-size: 20px; font-weight: 700; margin-bottom: 20px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.shelf-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.shelf-card {
  display: flex; gap: 12px; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius-lg); transition: box-shadow .2s;
}
.shelf-card:hover { box-shadow: var(--shadow-md); }
.shelf-cover {
  width: 80px; height: 107px; flex-shrink: 0; border-radius: var(--radius);
  overflow: hidden; background: var(--bg-section); display: block;
}
.shelf-cover img { width: 100%; height: 100%; object-fit: cover; }
.shelf-info { flex: 1; min-width: 0; }
.shelf-info h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shelf-info h3 a { color: var(--text-dark); }
.shelf-info h3 a:hover { color: var(--primary); }
.shelf-chapter { font-size: 13px; color: var(--text-light); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shelf-time { font-size: 12px; color: var(--text-light); margin-bottom: 8px; }

/* ========== Admin ========== */
.admin-login {
  max-width: 400px; margin: 80px auto; padding: 32px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.admin-login h2 { margin-bottom: 20px; font-size: 20px; text-align: center; }
.login-form { display: block; }

.alert { padding: 10px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-mid);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; outline: none;
  transition: border-color .2s; background: var(--bg-page); color: var(--text-dark);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }

.admin-container { padding: 16px 0; }
.admin-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
.admin-header h2 { font-size: 22px; }

.upload-section { margin-bottom: 32px; }
.upload-section h3 { font-size: 18px; margin-bottom: 16px; }
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 48px 24px; text-align: center; cursor: pointer;
  background: var(--bg-section); transition: border-color .2s, background .2s;
}
.upload-area:hover, .upload-area.dragover {
  border-color: var(--primary); background: var(--primary-light);
}
.upload-icon { font-size: 48px; color: var(--text-light); margin-bottom: 12px; }
.upload-area p { font-size: 15px; color: var(--text-mid); margin-bottom: 6px; }
.upload-hint { font-size: 13px; color: var(--text-light); }

.progress-bar {
  height: 6px; background: var(--border); border-radius: 3px;
  overflow: hidden; margin: 12px 0;
}
.progress-fill {
  height: 100%; background: var(--primary); border-radius: 3px;
  transition: width .3s; width: 0%;
}

.admin-books { margin-top: 32px; }
.admin-books h3 { font-size: 18px; margin-bottom: 16px; }
.books-table { width: 100%; border-collapse: collapse; }
.books-table th, .books-table td {
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px;
}
.books-table th {
  font-weight: 600; color: var(--text-mid); background: var(--bg-section); font-size: 13px;
}
.books-table tr:hover td { background: #fafafa; }
body.night-mode .books-table tr:hover td { background: #2a2a2a; }

.format-badge {
  display: inline-block; padding: 2px 8px; border-radius: 3px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  background: #3498db; color: #fff;
}
.action-cell { white-space: nowrap; display: flex; gap: 8px; }

/* Edit Modal */
.book-edit-modal {
  position: fixed; inset: 0; z-index: 1500;
  display: none; align-items: center; justify-content: center;
}
.book-edit-modal[style*="flex"] { display: flex; }
.modal-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.45);
}
.modal-content {
  position: relative; z-index: 1;
  background: var(--bg-page); border-radius: var(--radius-lg);
  width: 90%; max-width: 480px; padding: 28px; box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-content h3 { font-size: 18px; font-weight: 600; margin-bottom: 20px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ========== Empty State ========== */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text-light); font-size: 16px; }
.empty-state a { color: var(--primary); }

/* ========== Toast ========== */
.toast {
  position: fixed; top: 72px; right: 24px; z-index: 2000;
  padding: 12px 24px; border-radius: var(--radius); font-size: 14px; color: #fff;
  box-shadow: var(--shadow-md); opacity: 0; transform: translateX(40px);
  transition: opacity .3s, transform .3s;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast-success { background: #2ecc71; }
.toast-error { background: #e74c3c; }
.toast-info { background: #3498db; }

/* ========== Footer ========== */
.site-footer {
  text-align: center; padding: 24px 0; margin-top: 40px;
  border-top: 1px solid var(--border); font-size: 13px; color: var(--text-light);
}

/* ========== Utility ========== */
.text-center { text-align: center; }

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
body.night-mode ::-webkit-scrollbar-thumb { background: #444; }

/* ========== Responsive ========== */
@media (max-width: 1024px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .shelf-grid { grid-template-columns: repeat(3, 1fr); }
  .chapter-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  :root { --nav-height: 50px; }
  .nav-container { padding: 0 16px; gap: 4px; }
  .nav-links { gap: 14px; }
  .nav-links a { font-size: 14px; }
  .nav-search input[type="text"] { width: 120px; }
  .main-content { padding: 0 16px; }
  .book-grid { grid-template-columns: 1fr; gap: 12px; }
  .book-cover { width: 90px; height: 120px; }
  .book-detail-header {
    flex-direction: column; align-items: center; text-align: center; gap: 20px;
  }
  .book-detail-cover { width: 160px; height: 216px; }
  .book-tags { justify-content: center; }
  .book-detail-actions { justify-content: center; }
  .chapter-grid { grid-template-columns: 1fr; }
  .shelf-grid { grid-template-columns: repeat(2, 1fr); }
  .reader-toolbar { right: 12px; top: auto; bottom: 80px; transform: none; }
  .toolbar-btn { width: 44px; height: 44px; }
  .toolbar-icon { font-size: 16px; }
  .toolbar-text { font-size: 9px; }
  .chapter-text { font-size: 16px; }
  .reader-nav .btn { min-width: 110px; padding: 8px 20px; font-size: 14px; }
}
@media (max-width: 480px) {
  .nav-container { padding: 0 12px; }
  .nav-logo { font-size: 18px; margin-right: 10px; }
  .nav-links { gap: 10px; }
  .nav-search input[type="text"] { width: 80px; font-size: 13px; }
  .nav-admin { display: none; }
  .shelf-grid { grid-template-columns: 1fr; }
  .book-cover { width: 80px; height: 107px; }
  .reader-content { padding: 24px 16px 60px; }
  .chapter-title { font-size: 18px; }
}
