/* ============================================
   《草根创业翻身笔记》阅读网站样式
   设计风格：深夜书房 · 沉稳书卷
   ============================================ */

/* --- CSS Variables (Light Theme Default) --- */
:root {
  --bg-primary: #f5f0e8;
  --bg-secondary: #ebe5d9;
  --bg-card: #f0ead8;
  --text-primary: #2d2d2d;
  --text-secondary: #5a5247;
  --text-muted: #8a8078;
  --accent: #8b6914;
  --accent-light: #a8832a;
  --accent-bg: rgba(139, 105, 20, 0.08);
  --border: rgba(45, 45, 45, 0.1);
  --shadow: rgba(45, 45, 45, 0.06);
  --overlay: rgba(45, 45, 45, 0.5);
  --header-bg: rgba(245, 240, 232, 0.92);
  --modal-bg: #f5f0e8;
  --mask-gradient: linear-gradient(to bottom, transparent 0%, var(--bg-primary) 100%);
  --font-body: 'Noto Serif SC', 'Songti SC', 'SimSun', serif;
  --font-heading: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-size-base: 17px;
  --line-height: 1.9;
  --paragraph-spacing: 1.5em;
  --content-max-width: 680px;
  --sidebar-width: 300px;
  --header-height: 52px;
  --transition-speed: 0.3s;
}

/* --- Dark Theme --- */
[data-theme="dark"] {
  --bg-primary: #1a1a1e;
  --bg-secondary: #222226;
  --bg-card: #252528;
  --text-primary: #c8c0b4;
  --text-secondary: #a09888;
  --text-muted: #706860;
  --accent: #c9a96e;
  --accent-light: #d4b87a;
  --accent-bg: rgba(201, 169, 110, 0.1);
  --border: rgba(200, 192, 180, 0.1);
  --shadow: rgba(0, 0, 0, 0.2);
  --overlay: rgba(0, 0, 0, 0.6);
  --header-bg: rgba(26, 26, 30, 0.92);
  --modal-bg: #222226;
  --mask-gradient: linear-gradient(to bottom, transparent 0%, var(--bg-primary) 100%);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: var(--line-height);
  min-height: 100vh;
  transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Progress Bar --- */
.progress-bar {
  position: fixed;
  top: 64px;
  left: 0;
  width: 100%;
  height: 3px;
  background: var(--border);
  z-index: 1000;
}

.progress-bar__fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease-out;
  border-radius: 0 2px 2px 0;
}

/* --- Header --- */
.header {
  position: fixed;
  top: 64px;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  transition: background var(--transition-speed) ease;
}

.header__menu-btn {
  height: 40px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 8px;
  transition: background var(--transition-speed) ease;
  flex-shrink: 0;
}

.header__menu-text {
  font-size: 14px;
  font-family: var(--font-heading);
  white-space: nowrap;
}

.header__menu-btn:active {
  background: var(--accent-bg);
}

.header__title {
  flex: 1;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
  padding: 0 8px;
}

.header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.header__action-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-speed) ease;
}

.header__action-btn:active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* --- Sidebar Overlay --- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed) ease, visibility var(--transition-speed) ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: calc(64px + var(--header-height));
  left: 0;
  width: var(--sidebar-width);
  max-width: 85vw;
  height: 100vh;
  background: var(--bg-secondary);
  z-index: 300;
  transform: translateX(-100%);
  transition: transform var(--transition-speed) ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar.active {
  transform: translateX(0);
}

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

.sidebar__title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar__close-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all var(--transition-speed) ease;
}

.sidebar__close-btn:active {
  background: var(--accent-bg);
  color: var(--accent);
}

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.sidebar__nav-item {
  display: block;
  padding: 14px 20px;
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  line-height: 1.5;
}

.sidebar__nav-item:active {
  background: var(--accent-bg);
}

.sidebar__nav-item.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-bg);
  font-weight: 500;
}

.sidebar__nav-item .nav-item-title {
  display: block;
  margin-bottom: 2px;
}

.sidebar__nav-item .nav-item-summary {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* --- Main Content --- */
.main-content {
  padding: calc(var(--header-height) + 64px + 20px) 20px 120px;
  max-width: var(--content-max-width);
  margin: 0 auto;
  min-height: 100vh;
}

/* --- Chapter --- */
.chapter {
  margin-bottom: 60px;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.chapter__header {
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.chapter__number {
  font-family: var(--font-heading);
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 12px;
}

.chapter__title {
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.4;
  margin-bottom: 12px;
}

.chapter__summary {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

.chapter__body p {
  margin-bottom: var(--paragraph-spacing);
  text-align: justify;
  text-indent: 0;
}

.chapter__body p:first-child::first-letter {
  font-size: 1.2em;
  font-weight: 600;
}

.chapter__body .section-title {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 1.2em;
  font-weight: 700;
  margin: 1.5em 0 1em;
  color: var(--text-primary);
  letter-spacing: 0.1em;
}

/* --- Locked Chapter (Blur Mask) --- */
.chapter--locked {
  position: relative;
}

.chapter--locked .chapter__body {
  position: relative;
  max-height: 320px;
  overflow: hidden;
}

.chapter--locked .chapter__body::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: var(--mask-gradient);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  transition: background var(--transition-speed) ease;
}

.chapter__lock-prompt {
  text-align: center;
  padding: 24px 20px;
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.chapter__lock-prompt p {
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.6;
}

.chapter__lock-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chapter__lock-btn:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* --- Bottom Card --- */
.bottom-card {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  z-index: 50;
  transition: transform var(--transition-speed) ease, background var(--transition-speed) ease;
}

.bottom-card.hidden {
  transform: translateY(100%);
}

.bottom-card__content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.bottom-card__text {
  flex: 1;
  min-width: 0;
}

.bottom-card__title {
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.bottom-card__desc {
  font-family: var(--font-heading);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.bottom-card__qr {
  flex-shrink: 0;
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s ease;
}

.bottom-card__qr:hover {
  transform: scale(1.05);
}

.bottom-card__qr-img {
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg-card);
  display: block;
}

.bottom-card__qr-label {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-heading);
}

/* --- QR Modal --- */
.modal__content--qr {
  max-width: 320px;
  padding: 32px 24px;
  text-align: center;
}

.qr-modal__title {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.qr-modal__desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.qr-modal__img-wrap {
  display: inline-block;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 16px;
}

.qr-modal__img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  display: block;
  border-radius: 4px;
}

.qr-modal__hint {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-heading);
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed) ease, visibility var(--transition-speed) ease;
  padding: 20px;
}

.modal.active {
  opacity: 1;
  visibility: visible;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.modal__content {
  position: relative;
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 36px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  transform: scale(0.95);
  transition: transform var(--transition-speed) ease;
  box-shadow: 0 20px 60px var(--shadow);
}

.modal.active .modal__content {
  transform: scale(1);
}

.modal__icon {
  color: var(--accent);
  margin-bottom: 16px;
}

.modal__title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.modal__desc {
  font-family: var(--font-heading);
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.modal__input-wrap {
  margin-bottom: 16px;
}

.modal__input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-heading);
  font-size: 16px;
  text-align: center;
  letter-spacing: 1px;
  outline: none;
  transition: border-color 0.2s ease;
}

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

.modal__input::placeholder {
  color: var(--text-muted);
  letter-spacing: 0;
}

.modal__error {
  font-family: var(--font-heading);
  font-size: 13px;
  color: #c0392b;
  margin-bottom: 12px;
}

[data-theme="dark"] .modal__error {
  color: #e74c3c;
}

.modal__btn {
  width: 100%;
  padding: 12px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal__btn:active {
  transform: scale(0.98);
  opacity: 0.9;
}

.modal__hint {
  font-family: var(--font-heading);
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 20px;
}

.modal__link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* --- Selection --- */
::selection {
  background: var(--accent);
  color: #fff;
}

/* --- Responsive --- */
@media (min-width: 768px) {
  .main-content {
    padding-top: calc(var(--header-height) + 64px + 40px);
    padding-bottom: 140px;
  }

  .chapter__title {
    font-size: 28px;
  }

  .bottom-card {
    padding: 18px 20px;
  }

  .bottom-card__qr-img {
    width: 72px;
    height: 72px;
  }
}

/* --- Utility --- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
