/* ==========================================================================
   《痞子宅男》沉浸式小說閱讀器 核心樣式表
   ========================================================================== */

:root {
  /* 預設主題：Midnight Obsidian (暗黑黑曜石) */
  --bg-primary: #121214;
  --bg-secondary: #1a1a1e;
  --bg-tertiary: #24242a;
  --text-primary: #e4e4e7;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-light: rgba(16, 185, 129, 0.15);
  --border-color: rgba(255, 255, 255, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.5);
  --card-bg: rgba(255, 255, 255, 0.03);
  --quote-border: #f59e0b;
  
  --font-family-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-family-serif: "Songti TC", "Noto Serif TC", "Source Han Serif TC", PMingLiU, Georgia, serif;
  
  --reader-font: var(--font-family-sans);
  --reader-font-size: 18px;
  --reader-line-height: 1.95;
  --reader-max-width: 800px;
}

/* 主題 2：Parchment (羊皮紙紙質暖光) */
[data-theme="parchment"] {
  --bg-primary: #fbf0d9;
  --bg-secondary: #f4e3c3;
  --bg-tertiary: #ebd4ab;
  --text-primary: #332822;
  --text-secondary: #6b574a;
  --text-muted: #968070;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-light: rgba(180, 83, 9, 0.12);
  --border-color: rgba(70, 50, 40, 0.12);
  --shadow-color: rgba(70, 50, 40, 0.15);
  --card-bg: rgba(70, 50, 40, 0.04);
  --quote-border: #d97706;
}

/* 主題 3：Clean Light (清新明亮白) */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f4f4f5;
  --bg-tertiary: #e4e4e7;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #a1a1aa;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-light: rgba(5, 150, 105, 0.1);
  --border-color: rgba(0, 0, 0, 0.08);
  --shadow-color: rgba(0, 0, 0, 0.08);
  --card-bg: rgba(0, 0, 0, 0.02);
  --quote-border: #f59e0b;
}

/* 主題 4：Slate Gray (青石沉思冷灰) */
[data-theme="slate"] {
  --bg-primary: #1e293b;
  --bg-secondary: #0f172a;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --accent-light: rgba(56, 189, 248, 0.15);
  --border-color: rgba(255, 255, 255, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.4);
  --card-bg: rgba(255, 255, 255, 0.03);
  --quote-border: #38bdf8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--reader-font);
  transition: background-color 0.25s ease, color 0.25s ease;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* 捲動條樣式 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* 頂部閱讀進度條 */
#reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  width: 0%;
  z-index: 100;
  transition: width 0.1s linear;
}

/* 導航列 */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-title-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: center;
  max-width: 45vw;
}

.nav-book-title {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-chapter-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
}

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

.icon-btn.active {
  color: var(--accent);
  background: var(--accent-light);
  border-color: var(--accent);
}

/* 主要閱讀容器 */
.reader-container {
  max-width: var(--reader-max-width);
  margin: 80px auto 140px;
  padding: 0 24px;
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  transition: max-width 0.25s ease, font-size 0.2s ease, line-height 0.2s ease;
}

/* 章節標題區塊 */
.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.chapter-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.chapter-main-title {
  font-size: 1.85em;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  line-height: 1.3;
}

.chapter-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

/* 正文排版 */
.content-body p {
  text-indent: 2em;
  margin: 1.15em 0;
  color: var(--text-primary);
  word-break: break-word;
}

.content-body h1, .content-body h2, .content-body h3 {
  margin: 1.6em 0 0.8em;
  line-height: 1.4;
  color: var(--text-primary);
}

.content-body h1 { font-size: 1.5em; border-left: 4px solid var(--accent); padding-left: 12px; }
.content-body h2 { font-size: 1.3em; }
.content-body h3 { font-size: 1.15em; color: var(--accent); }

.content-body hr {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: 2.5em 0;
}

.content-body blockquote {
  border-left: 3px solid var(--quote-border);
  padding: 8px 16px;
  margin: 1.5em 0;
  background: var(--card-bg);
  border-radius: 0 6px 6px 0;
  color: var(--text-secondary);
  font-style: normal;
}

.content-body ul, .content-body ol {
  padding-left: 1.5em;
  margin: 1em 0;
}

.content-body li {
  margin: 0.5em 0;
  color: var(--text-secondary);
}

.content-body strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* 底部換章列 */
.chapter-nav-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 60px;
  padding-top: 30px;
  border-top: 1px solid var(--border-color);
}

.nav-step-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  flex: 1;
  justify-content: center;
}

.nav-step-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.nav-step-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* 側邊欄抽屜 (目錄) */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 380px;
  max-width: 85vw;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  z-index: 90;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

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

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

.drawer-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.drawer-search {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-color);
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}

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

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.section-group {
  margin-bottom: 16px;
}

.section-title {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--card-bg);
  border-left: 3px solid var(--accent);
}

.chapter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
  color: var(--text-secondary);
  font-size: 14px;
}

.chapter-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chapter-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-left: 3px solid var(--accent);
}

.chapter-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* 設定面板 (Pop-up Settings Modal) */
.settings-modal {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 320px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 12px 36px var(--shadow-color);
  padding: 20px;
  z-index: 70;
  display: none;
  animation: fadeInDown 0.2s ease;
}

.settings-modal.open {
  display: block;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.setting-row {
  margin-bottom: 18px;
}

.setting-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
  font-weight: 500;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.theme-btn {
  height: 36px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.theme-btn.active {
  border-color: var(--accent);
  transform: scale(1.04);
}

.theme-btn-obsidian { background: #121214; color: #e4e4e7; border-color: #333; }
.theme-btn-parchment { background: #fbf0d9; color: #332822; border-color: #d8c29d; }
.theme-btn-light { background: #ffffff; color: #18181b; border-color: #e4e4e7; }
.theme-btn-slate { background: #1e293b; color: #f8fafc; border-color: #334155; }

.btn-group {
  display: flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.btn-group-item {
  flex: 1;
  padding: 6px 0;
  text-align: center;
  font-size: 13px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-group-item.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* 浮動有聲書控制條 (Audio Player Bar) */
.audio-player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 60;
  box-shadow: 0 -4px 20px var(--shadow-color);
  transform: translateY(120%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.audio-player-bar.show {
  transform: translateY(0);
}

.audio-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}

.audio-icon-pulse {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.audio-title-wrap {
  display: flex;
  flex-direction: column;
}

.audio-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.audio-narrator {
  font-size: 11px;
  color: var(--text-muted);
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 600px;
}

.audio-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: color 0.15s;
}

.audio-btn:hover {
  color: var(--text-primary);
}

.audio-btn-play {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.audio-btn-play:hover {
  background: var(--accent-hover);
  color: #fff;
}

.audio-progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.audio-time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

.audio-slider {
  flex: 1;
  height: 4px;
  appearance: none;
  background: var(--border-color);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.audio-slider::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.audio-extra {
  display: flex;
  align-items: center;
  gap: 8px;
}

.audio-rate-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
}

/* 響應式優化 */
@media (max-width: 640px) {
  .nav-title-group { max-width: 35vw; }
  .reader-container { padding: 0 16px; margin: 68px auto 160px; }
  .chapter-main-title { font-size: 1.5em; }
  .audio-player-bar { flex-wrap: wrap; padding: 8px 12px; }
  .audio-info { width: 100%; min-width: unset; margin-bottom: 4px; }
  .audio-controls { width: 100%; max-width: 100%; }
}
