@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;700&display=swap');
@import url('/fonts/lxgwwenkai/style.css');

@font-face {
  font-family: 'Smiley Sans';
  font-style: normal;
  font-display: swap;
  src: url('/fonts/smiley-sans/SmileySans-Oblique.ttf.woff2') format('woff2');
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f0eb;
  --text: #3a3a3a;
  --primary: #8b5a2b;
  --primary-light: #a07040;
  --sidebar-bg: #fff;
  --welcome-sidebar-bg: rgba(255,255,255,0.7);
  --content-bg: #fff;
  --sidebar-width: 320px;
  --header-height: 56px;
  --toolbar-height: 48px;
  --border: #e0d8d0;
  --font-size: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --delete-color: #c0392b;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --text: #333333;
  --sidebar-bg: #fafafa;
  --welcome-sidebar-bg: #f5f5f5;
  --content-bg: #ffffff;
  --border: #e0e0e0;
  --primary: #8b5a2b;
  --primary-light: #a07040;
}

:root[data-theme="sepia"] {
  --bg: #f4ecd6;
  --text: #5b4636;
  --sidebar-bg: #f0e8d0;
  --welcome-sidebar-bg: #ede3c8;
  --content-bg: #f8f0dc;
  --border: #d8cdb0;
  --primary: #8b6914;
  --primary-light: #a07b20;
}

:root[data-theme="dark"] {
  --bg: #1a1a2e;
  --text: #c8c8d4;
  --sidebar-bg: #16213e;
  --welcome-sidebar-bg: #16213e;
  --content-bg: #0f3460;
  --border: #2a2a4a;
  --primary: #e8b86d;
  --primary-light: #f0c880;
  --delete-color: #e74c3c;
}

:root[data-theme="black"] {
  --bg: #000000;
  --text: #cccccc;
  --sidebar-bg: #111111;
  --welcome-sidebar-bg: #111111;
  --content-bg: #000000;
  --border: #222222;
  --primary: #e8b86d;
  --primary-light: #f0c880;
  --delete-color: #e74c3c;
}



body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
}

#app {
  position: relative;
  min-height: 100vh;
}

/* ── Welcome Screen ─────────────────────────────────────────── */
#welcomeScreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bg) 0%, #ede4d8 100%);
  z-index: 10;
  transition: opacity 0.4s ease;
}

#welcomeScreen.hidden {
  opacity: 0;
  pointer-events: none;
}

.welcome-layout {
  display: flex;
  height: 100vh;
}

#welcomeSidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--welcome-sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  overflow-y: auto;
}

.welcome-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-center {
  text-align: center;
  max-width: 520px;
  width: 90%;
  padding: 40px 20px;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.welcome-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 15px;
  color: #888;
  margin-bottom: 28px;
}

.welcome-input-row {
  display: flex;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

#urlInput {
  flex: 1;
  padding: 12px 18px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  background: var(--content-bg);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#urlInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(139, 90, 43, 0.1);
}

#loadBtn {
  padding: 12px 28px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#loadBtn:hover { background: var(--primary-light); }
#loadBtn:active { transform: scale(0.97); }

.welcome-loading {
  margin-top: 16px;
  color: #999;
  font-size: 14px;
}

/* ── History Section ─────────────────────────────────────────── */
.history-header {
  font-size: 13px;
  font-weight: 600;
  color: #999;
  letter-spacing: 1px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

#historyList {
  text-align: left;
}

.history-item {
  display: flex;
  align-items: flex-start;
  padding: 8px 10px;
  margin-bottom: 4px;
  background: rgba(255,255,255,0.5);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.history-item:hover { background: rgba(255,255,255,0.85); }

.history-item-info {
  flex: 1;
  min-width: 0;
  pointer-events: none;
}

.history-item-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.history-item-meta {
  display: flex;
  gap: 8px;
  font-size: 11px;
  color: #aaa;
  margin-top: 2px;
}

.history-item-site {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.history-item-chapter {
  white-space: nowrap;
}

.history-del-btn {
  background: none;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  color: var(--delete-color, #c0392b);
  opacity: 0;
  padding: 2px 4px;
  flex-shrink: 0;
  margin-left: 4px;
  transition: opacity 0.15s;
}

.history-item:hover .history-del-btn { opacity: 1; }

.history-empty {
  text-align: center;
  color: #ccc;
  font-size: 13px;
  padding: 20px 10px;
}

/* ── Reader Header ───────────────────────────────────────────── */
#readerHeader {
  background: var(--content-bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
}

#readerHeader.hidden { display: none; }

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-book-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  flex-shrink: 0;
}

.header-input-row {
  flex: 1;
  display: flex;
  gap: 6px;
}

#headerUrlInput {
  flex: 1;
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

#headerUrlInput:focus { border-color: var(--primary); }

#headerLoadBtn {
  padding: 8px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#headerLoadBtn:hover { background: var(--primary-light); }

.header-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #999;
  padding: 4px 8px;
  line-height: 1;
}

.header-close:hover { color: var(--text); }

/* ── Floating Button & Popup ─────────────────────────────────── */
#floatContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.float-popup {
  background: var(--content-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  padding: 16px;
  margin-bottom: 12px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.popup-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.popup-label {
  font-size: 11px;
  font-weight: 600;
  color: #999;
  letter-spacing: 0.5px;
}

.popup-font-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.float-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(139, 90, 43, 0.35);
  transition: transform 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.float-btn:hover {
  transform: scale(1.08);
  background: var(--primary-light);
}

.float-btn:active { transform: scale(0.95); }

/* ── Layout ──────────────────────────────────────────────────── */
#layout {
  display: flex;
}

#layout.reading {
  overflow: hidden;
}

@media (min-width: 769px) {
  #layout.reading #sidebar {
    height: 100%;
    position: static;
  }
}

/* ── Sidebar ─────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease, border-color 0.25s ease;
  z-index: 50;
  overflow: hidden;
  white-space: nowrap;
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: flex-start;
}

#sidebar.closed {
  width: 0;
  border-right-color: transparent;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

#novelTitle {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#tocContainer { flex: 1; overflow-y: auto; }

#tocList { list-style: none; }

#tocList li { border-bottom: 1px solid #f5f0f0; }

#tocList a {
  display: block;
  padding: 9px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

#tocList a:hover { background: #f5f0eb; color: var(--primary); }

#tocList a.active {
  background: #ede4d8;
  color: var(--primary);
  font-weight: 600;
}

.loading {
  padding: 40px;
  text-align: center;
  color: #999;
}

/* ── Reader ──────────────────────────────────────────────────── */
#reader {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--content-bg);
  min-height: 0;
}

.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #bbb;
  font-size: 15px;
  min-height: 300px;
}

.placeholder-icon { font-size: 56px; margin-bottom: 12px; opacity: 0.5; }

#readerContent {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#readerContent.visible {
  display: flex;
}

.reader-toolbar {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: var(--toolbar-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
  background: var(--content-bg);
}

.chapter-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.size-display {
  font-size: 12px;
  color: #888;
  min-width: 22px;
  text-align: center;
}

#fontFamilySelect {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  background: var(--content-bg);
  color: var(--text);
  cursor: pointer;
  width: 100%;
}

#homeBtn {
  font-size: 15px;
  padding: 5px 7px;
}

.theme-switcher {
  display: flex;
  gap: 4px;
  align-items: center;
}

.theme-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0;
  outline: none;
  padding: 0;
}

.theme-btn:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.theme-btn.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}

.theme-btn::after {
  content: 'A';
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.icon-btn:hover { background: var(--border); }

#contentArea {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  width: 100%;
}

#contentInner {
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 24px 20px;
  font-size: var(--font-size);
  line-height: 2;
  letter-spacing: 0.5px;
  text-align: justify;
  white-space: pre-wrap;
  word-wrap: break-word;
}

@media (max-width: 768px) {
  #contentInner {
    padding: 16px 14px;
  }
}

.font-default { font-family: inherit; }
.font-noto-serif-sc { font-family: 'Noto Serif SC', serif; }
.font-lxgw-wenkai { font-family: 'LXGW WenKai', cursive; }
.font-smiley-sans { font-family: 'Smiley Sans', sans-serif; }
.font-honor-sans { font-family: 'HONOR Sans', sans-serif; }
.font-tsanger { font-family: '仓耳字库', 'TsangerJinKai', 'Tsanger', serif; }

.reader-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.nav-btn {
  padding: 7px 24px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.nav-btn:hover { background: var(--border); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#sidebar-overlay { display: none; }

/* ── Status Message ──────────────────────────────────────────── */
.status-msg {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  display: none;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ── Scrollbar ───────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.15) transparent; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .welcome-layout { flex-direction: column; }
  #welcomeSidebar {
    width: 100%;
    max-height: 35vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
  }
  .welcome-title { font-size: 24px; }
  .welcome-input-row { flex-direction: column; }
  #loadBtn { width: 100%; }

  #floatContainer { bottom: 16px; right: 16px; }
  #floatContainer .float-btn { width: 44px; height: 44px; font-size: 18px; }
  #floatPopup { min-width: 180px; padding: 14px; }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    overflow-y: auto;
  }

  #sidebar.open { transform: translateX(0); }

  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
  }

  #sidebar-overlay.open { display: block; }

  .header-inner { flex-wrap: wrap; gap: 6px; }
  .header-book-title { max-width: 100%; }
}

@media (max-width: 480px) {
  .header-input-row { flex-direction: column; }
  #headerLoadBtn { width: 100%; }
}
