/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f5f5f0; --surface: #fff; --text: #333; --text-secondary: #888;
  --primary: #c0392b; --primary-hover: #a93226; --border: #e0ddd5;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --header-bg: #2c3e50; --header-text: #ecf0f1;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "Source Han Serif SC", "Noto Serif CJK SC", "STSong", serif;
  --reader-bg: #fffef5; --reader-text: #3a3a3a;
  --reader-max-w: 800px; --reader-font: 18px; --reader-line-h: 1.8;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; }

/* === Header === */
#header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--header-bg); color: var(--header-text);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.header-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px;
}
.logo { font-size: 20px; font-weight: 700; color: var(--header-text); text-decoration: none; }
.logo:hover { text-decoration: none; opacity: 0.9; }
.search-box input {
  padding: 8px 14px; border: none; border-radius: 20px;
  background: rgba(255,255,255,0.15); color: #fff;
  font-size: 14px; width: 220px; outline: none;
  transition: background 0.2s, width 0.2s;
}
.search-box input::placeholder { color: rgba(255,255,255,0.5); }
.search-box input:focus { background: rgba(255,255,255,0.25); width: 280px; }

/* === Main === */
#main { padding-top: 70px; max-width: 1100px; margin: 0 auto; min-height: calc(100vh - 70px); }

/* === Loading === */
.loading { display: flex; justify-content: center; padding: 60px 0; }
.loading.hidden { display: none; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Bookshelf (Home) === */
.bookshelf { padding: 20px; }
.bookshelf h2 { font-size: 18px; margin-bottom: 16px; color: var(--text-secondary); }
.bookshelf.empty {
  text-align: center; padding: 80px 20px; color: var(--text-secondary);
}
.bookshelf.empty .empty-icon { font-size: 64px; margin-bottom: 16px; display: block; }
.bookshelf.empty p { font-size: 16px; line-height: 1.6; }

.novel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}

.novel-card {
  background: var(--surface); border-radius: 10px; overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.novel-card:hover { transform: translateY(-3px); box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.novel-card-cover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  height: 140px; display: flex; align-items: center; justify-content: center;
  font-size: 48px;
}
.novel-card:nth-child(6n+2) .novel-card-cover { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.novel-card:nth-child(6n+3) .novel-card-cover { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
.novel-card:nth-child(6n+4) .novel-card-cover { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }
.novel-card:nth-child(6n+5) .novel-card-cover { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }
.novel-card:nth-child(6n+6) .novel-card-cover { background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%); }
.novel-card-cover .format-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.3); color: #fff;
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
}

.novel-card-info { padding: 12px; }
.novel-card-info h3 {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.novel-card-info .meta {
  font-size: 12px; color: var(--text-secondary); margin-top: 4px;
}
.novel-card-cover { position: relative; }

/* === Detail Page === */
.detail { padding: 20px; }
.detail-header {
  display: flex; gap: 24px; align-items: flex-start;
  background: var(--surface); border-radius: 12px; padding: 24px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.detail-cover {
  width: 120px; height: 160px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 56px;
}
.detail-info { flex: 1; }
.detail-info h1 { font-size: 22px; margin-bottom: 8px; }
.detail-info .author { color: var(--text-secondary); margin-bottom: 12px; font-size: 14px; }
.detail-info .stats { display: flex; gap: 16px; font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }
.detail-actions { display: flex; gap: 10px; }
.btn {
  padding: 8px 20px; border: none; border-radius: 6px;
  font-size: 14px; font-weight: 500;
  background: var(--primary); color: #fff; transition: background 0.15s;
}
.btn:hover { background: var(--primary-hover); }
.btn-outline {
  background: transparent; border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* Chapter list */
.chapter-list { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.chapter-list-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 15px;
}
.chapter-item {
  display: flex; align-items: center; padding: 12px 20px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background 0.1s; font-size: 14px; gap: 10px;
}
.chapter-item:last-child { border-bottom: none; }
.chapter-item:hover { background: #f9f8f5; }
.chapter-item .chapter-index {
  width: 28px; height: 28px; border-radius: 50%;
  background: #eef; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-secondary); flex-shrink: 0;
}
.chapter-item.read { color: var(--text-secondary); }
.chapter-item.current {
  background: #fef0ef; font-weight: 600; color: var(--primary);
}
.chapter-item.current .chapter-index { background: var(--primary); color: #fff; }

/* === Reader Page === */
.reader-page {
  max-width: var(--reader-max-w); margin: 0 auto; padding: 20px 24px 40px;
  background: var(--reader-bg); color: var(--reader-text);
  min-height: calc(100vh - 70px);
  transition: background 0.3s, color 0.3s;
}
.reader-header {
  text-align: center; margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.reader-header h2 { font-size: 16px; font-weight: 600; }
.reader-header .subtitle { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.reader-content {
  font-family: var(--font-mono);
  font-size: var(--reader-font);
  line-height: var(--reader-line-h);
  word-wrap: break-word;
  letter-spacing: 0.02em;
}
.reader-content p {
  text-indent: 2em;
  margin-bottom: 0.5em;
  white-space: pre-wrap;
}
.reader-nav {
  display: flex; justify-content: space-between; gap: 10px;
  margin-top: 30px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.reader-nav button {
  padding: 10px 24px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); font-size: 14px;
  transition: all 0.15s;
}
.reader-nav button:hover { border-color: var(--primary); color: var(--primary); }
.reader-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.back-link {
  display: inline-block; margin-bottom: 16px; font-size: 13px;
}

/* === Settings Panel === */
.settings-panel {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--surface); box-shadow: 0 -2px 20px rgba(0,0,0,0.15);
  border-radius: 16px 16px 0 0;
  transition: transform 0.3s;
}
.settings-panel.hidden { transform: translateY(100%); }
.settings-content {
  max-width: 500px; margin: 0 auto; padding: 20px;
}
.settings-content h3 { margin-bottom: 16px; font-size: 16px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.setting-row label { font-size: 14px; color: var(--text-secondary); }
.setting-controls { display: flex; align-items: center; gap: 10px; }
.setting-controls span { min-width: 28px; text-align: center; font-size: 14px; }
.btn-icon {
  padding: 4px 10px; border: 1px solid var(--border);
  border-radius: 4px; background: var(--bg); font-size: 13px;
}
.btn-icon:hover { border-color: var(--primary); }
.btn-close {
  display: block; width: 100%; margin-top: 16px;
  padding: 10px; border: none; border-radius: 6px;
  background: var(--primary); color: #fff; font-size: 14px;
}

/* === Reader themes === */
body.theme-dark {
  --bg: #1a1a2e; --surface: #16213e; --text: #e0e0e0;
  --text-secondary: #8899aa; --border: #2a3a5a;
  --reader-bg: #1a1a2e; --reader-text: #e0dcd0;
}
body.theme-sepia {
  --bg: #f4ecd8; --surface: #fcf4e6; --text: #5b4636; --text-secondary: #8b7d6b;
  --border: #e8dccc; --reader-bg: #fcf4e6; --reader-text: #5b4636;
}

/* === Back to top === */
.go-top {
  position: fixed; bottom: 80px; right: 20px;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  font-size: 18px; display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow); z-index: 50;
}
.go-top.show { display: flex; }

/* === Auth Links (Header) === */
.auth-links { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.auth-link { color: var(--header-text); opacity: 0.8; }
.auth-link:hover { opacity: 1; text-decoration: none; }
.auth-user { opacity: 0.6; margin-right: 4px; }

/* === Auth Page === */
.auth-page {
  display: flex; justify-content: center; padding: 60px 20px;
}
.auth-card {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  padding: 32px; width: 100%; max-width: 380px;
}
.auth-card h2 { text-align: center; margin-bottom: 20px; font-size: 20px; }
.auth-hint { text-align: center; font-size: 13px; color: var(--primary); margin-bottom: 8px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-input {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; background: var(--bg); color: var(--text); outline: none;
}
.auth-input:focus { border-color: var(--primary); }
.auth-btn { width: 100%; margin-top: 4px; }
.auth-error {
  background: #fef2f2; color: #dc2626; padding: 8px 12px;
  border-radius: 6px; font-size: 13px;
}
.auth-error.hidden { display: none; }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-secondary); }

/* === Admin Page === */
.admin-page { padding: 20px; }
.admin-page h2 { font-size: 20px; margin-bottom: 20px; }
.admin-section {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px; overflow-x: auto;
}
.admin-section h3 { font-size: 16px; margin-bottom: 12px; }
.admin-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.admin-table th, .admin-table td {
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th { font-weight: 600; color: var(--text-secondary); font-size: 12px; }
.admin-table tbody tr:hover { background: #f9f8f5; }
body.theme-dark .admin-table tbody tr:hover { background: #1e2a3a; }
body.theme-sepia .admin-table tbody tr:hover { background: #f5ede0; }
.btn-sm {
  padding: 3px 10px; border: none; border-radius: 4px;
  font-size: 12px; cursor: pointer;
}
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* === Mobile === */
@media (max-width: 600px) {
  .header-inner { padding: 0 12px; }
  .search-box input { width: 140px; font-size: 13px; }
  .search-box input:focus { width: 180px; }
  .novel-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .novel-card-cover { height: 110px; font-size: 36px; }
  .detail-header { flex-direction: column; align-items: center; text-align: center; }
  .detail-actions { justify-content: center; }
  .detail-cover { width: 100px; height: 140px; }
  .reader-page { padding: 16px; }
  .reader-nav button { padding: 8px 14px; font-size: 13px; }
  .settings-content { padding: 16px; }
}

@media (max-width: 400px) {
  .novel-grid { grid-template-columns: 1fr 1fr; }
}
