/* CSS Design System & Theme Engine */
:root {
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', STSong, 'SimSun', serif;
  --font-sans: 'Noto Sans SC', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', 'Noto Sans SC', sans-serif;
  
  --reader-max-width: 800px;
  --reader-font-size: 18px;
  --reader-line-height: 1.8;
  --header-height: 56px;
  --footer-height: 40px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 1. 配色主题预设 */
html[data-theme="light"] {
  --bg-primary: #fcfcfc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f3f5;
  --text-main: #2b2b2b;
  --text-muted: #6c757d;
  --accent: #2563eb;
  --border-color: #e9ecef;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}

html[data-theme="parchment"] {
  --bg-primary: #f5efe0;
  --bg-secondary: #ebdcb9;
  --bg-tertiary: #e4d3a8;
  --text-main: #3d3121;
  --text-muted: #786650;
  --accent: #8b5e34;
  --border-color: #dfcdad;
  --shadow: 0 8px 30px rgba(61, 49, 33, 0.1);
}

html[data-theme="eyecare"] {
  --bg-primary: #dcead8;
  --bg-secondary: #cde2c7;
  --bg-tertiary: #bed7b7;
  --text-main: #1f3621;
  --text-muted: #526f55;
  --accent: #2e6b36;
  --border-color: #b3cca9;
  --shadow: 0 8px 30px rgba(31, 54, 33, 0.09);
}

html[data-theme="slate"] {
  --bg-primary: #1e293b;
  --bg-secondary: #334155;
  --bg-tertiary: #475569;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --border-color: #475569;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

html[data-theme="dark"] {
  --bg-primary: #121214;
  --bg-secondary: #1e1e24;
  --bg-tertiary: #2a2a32;
  --text-main: #e4e4e7;
  --text-muted: #71717a;
  --accent: #a855f7;
  --border-color: #27272a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

html[data-theme="black"] {
  --bg-primary: #000000;
  --bg-secondary: #111111;
  --bg-tertiary: #222222;
  --text-main: #d4d4d8;
  --text-muted: #52525b;
  --accent: #10b981;
  --border-color: #27272a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.8);
}

html[data-font="serif"] {
  --main-font-family: var(--font-serif);
}
html[data-font="sans"] {
  --main-font-family: var(--font-sans);
}

/* 重置与通用 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: inherit;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--main-font-family);
  transition: background-color var(--transition-normal), color var(--transition-normal);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* 顶栏 */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
  transition: transform var(--transition-normal), background-color var(--transition-normal);
  backdrop-filter: blur(10px);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-main);
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  color: var(--accent);
}

.header-center {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  max-width: 40%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--bg-secondary);
}

.hidden {
  display: none !important;
}

/* 页面主布局 */
.app-main {
  padding-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* 1. 书架样式 */
.shelf-view {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.shelf-hero {
  text-align: center;
  margin-bottom: 3rem;
}

.hero-title {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
}

.search-bar-wrap {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
}

.search-bar-wrap input {
  width: 100%;
  padding: 0.8rem 1rem 0.8rem 2.8rem;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  box-shadow: var(--shadow);
  transition: border-color var(--transition-fast);
}

.search-bar-wrap input:focus {
  border-color: var(--accent);
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.shelf-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.shelf-section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
}

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

.novel-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.25rem;
  display: flex;
  flex-direction: row;
  gap: 1.25rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition-normal), border-color var(--transition-normal), box-shadow var(--transition-normal);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  align-items: center;
}

.novel-card:hover {
  transform: translateY(-5px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.novel-card-cover-wrap {
  position: relative;
  width: 90px;
  height: 120px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 3px 5px 12px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  transform-style: preserve-3d;
  perspective: 1000px;
}

.novel-card:hover .novel-card-cover-wrap {
  transform: rotateY(-10deg) translateZ(5px);
  box-shadow: 8px 10px 20px rgba(0, 0, 0, 0.3);
}

.novel-card-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.novel-card-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.35) 0%, rgba(255, 255, 255, 0.15) 30%, rgba(0, 0, 0, 0.05) 50%, rgba(255, 255, 255, 0.15) 70%, rgba(0, 0, 0, 0.25) 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.novel-card-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 120px;
  min-width: 0;
}

.novel-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.novel-card-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.novel-progress-bar {
  height: 6px;
  background-color: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.novel-progress-inner {
  height: 100%;
  background-color: var(--accent);
  width: 0%;
  border-radius: 3px;
}

.novel-card-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}

.btn-read {
  background-color: var(--accent);
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.btn-read:hover {
  opacity: 0.9;
}

.last-read-tag {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* 2. 阅读器视图 */
.reader-view {
  position: relative;
  min-height: calc(100vh - var(--header-height));
  padding-bottom: calc(var(--footer-height) + 20px);
}

.reader-container {
  max-width: var(--reader-max-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  transition: max-width var(--transition-normal);
}

.novel-article {
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  word-break: break-word;
}

.article-header {
  text-align: center;
  padding-bottom: 2.5rem;
  margin-bottom: 2.5rem;
  border-bottom: 2px stroke var(--border-color);
}

.novel-title {
  font-size: 2.2rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  letter-spacing: -0.5px;
}

.novel-meta {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.article-body p {
  margin-bottom: 1.5em;
  text-indent: 2em;
  text-align: justify;
}

.article-body h2.chapter-title {
  margin: 3.5rem 0 1.5rem 0;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--border-color);
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  text-indent: 0;
  color: var(--text-main);
  scroll-margin-top: calc(var(--header-height) + 20px);
}

/* 目录 Drawer */
.toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition-normal);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.toc-drawer.open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.drawer-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.toc-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.toc-search {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.toc-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.toc-item {
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  color: var(--text-main);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-item:hover {
  background-color: var(--bg-tertiary);
}

.toc-item.active {
  color: var(--accent);
  font-weight: 700;
  background-color: var(--bg-tertiary);
  border-left: 3px solid var(--accent);
}

/* 外观设置 Popover */
.style-popover {
  position: fixed;
  top: calc(var(--header-height) + 8px);
  right: 1.5rem;
  width: 320px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.setting-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.setting-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.val-tag {
  font-weight: 700;
  color: var(--accent);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.theme-opt {
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform var(--transition-fast);
}

.theme-opt:hover {
  transform: scale(1.03);
}

.theme-light { background: #fcfcfc; color: #2b2b2b; }
.theme-parchment { background: #f5efe0; color: #3d3121; }
.theme-eyecare { background: #dcead8; color: #1f3621; }
.theme-slate { background: #1e293b; color: #e2e8f0; }
.theme-dark { background: #121214; color: #e4e4e7; }
.theme-black { background: #000000; color: #d4d4d8; }

.button-segmented {
  display: flex;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.button-segmented button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  padding: 0.4rem;
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
}

.button-segmented button.active {
  background-color: var(--bg-secondary);
  font-weight: 700;
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stepper-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stepper-btn {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.stepper-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

/* 底部底栏 */
.reader-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--footer-height);
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  z-index: 90;
}

.footer-left {
  max-width: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer-center {
  flex: 1;
  max-width: 400px;
  margin: 0 1.5rem;
}

.progress-bar-track {
  height: 4px;
  background-color: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--accent);
  width: 0%;
  transition: width var(--transition-fast);
}

/* 响应式支持 */
@media (max-width: 640px) {
  .hero-title { font-size: 1.8rem; }
  .novel-grid { grid-template-columns: 1fr; }
  .header-center { display: none; }
  .style-popover { right: 0.5rem; left: 0.5rem; width: auto; }
}

/* 契合主题的现代滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background-color: var(--bg-primary);
  transition: background-color var(--transition-normal);
}
::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 99px;
  border: 2px solid var(--bg-primary);
  transition: background-color var(--transition-fast);
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
}

/* 智能平滑抗锯齿 */
body {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
