  :root {
    --bg: #f5f3ee;
    --text: #2b2b2b;
    --text-dim: #9a948a;
    --focus: #d9480f;
    --bar-bg: rgba(245, 243, 238, 0.8);
    --btn-bg: rgba(0, 0, 0, 0.06);
    --btn-text: #2b2b2b;
    --shadow: rgba(0, 0, 0, 0.12);
  }
  [data-theme="dark"] {
    --bg: #15171a;
    --text: #e8e6e1;
    --text-dim: #6b6f76;
    --focus: #ffa94d;
    --bar-bg: rgba(21, 23, 26, 0.8);
    --btn-bg: rgba(255, 255, 255, 0.08);
    --btn-text: #e8e6e1;
    --shadow: rgba(0, 0, 0, 0.5);
  }

  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin: 0; height: 100%; }
  body {
    background: var(--bg);
    color: var(--text);
    font-family: "Noto Serif Tibetan", -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, "Hiragino Sans", "Yu Gothic", "Meiryo", "Noto Sans JP", "Kailasa", "Microsoft Himalaya", "Noto Sans Tibetan", sans-serif;
    transition: background 0.4s ease, color 0.4s ease;
    overflow: hidden;
    touch-action: manipulation;
  }

  /* 顶部栏 */
  .topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--bar-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    z-index: 20;
    border-bottom: 1px solid var(--shadow);
  }
  .title { position: absolute; left: 50%; transform: translateX(-50%); font-size: 15px; font-weight: 600; letter-spacing: 0.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--focus); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; text-decoration: none; flex-shrink: 0; cursor: pointer; transition: opacity .2s; overflow: hidden; }
  .avatar:hover { opacity: .9; }
  .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .actions { display: flex; gap: 8px; }
  .btn {
    border: none;
    background: var(--btn-bg);
    color: var(--btn-text);
    width: 38px; height: 38px;
    border-radius: 10px;
    font-size: 17px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s ease, background 0.3s ease;
  }
  #fontMinus, #fontPlus {
    width: 48px;
    font-size: 16px;
    font-weight: 600;
  }
  .btn:active { transform: scale(0.9); }
  .btn svg { width: 20px; height: 20px; }
  .play-btn svg { width: 22px; height: 22px; }

  /* 阅读区 */
  .reader {
    position: absolute;
    top: 54px; bottom: 0;
    left: 0; right: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 720px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 40vh 10px;
    line-height: 1.9;
    font-size: 18px;
    text-align: center;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .reader::-webkit-scrollbar { display: none; }

  .reader p { margin: 0 0 0.6em; text-align: center; }

  /* 逐行阅读：行号 + 当前行聚焦放大 */
  .reader .line {
    display: flex;
    align-items: baseline;
    padding: 0.1em 0;
    color: var(--text);
    opacity: 0.5;
    transition: opacity 0.25s ease, color 0.25s ease, font-size 0.2s ease;
  }
  .reader .line-no {
    flex: none;
    width: 28px;
    margin-right: 8px;
    text-align: right;
    font-size: 12px;
    color: var(--text-dim);
    opacity: 0.7;
    user-select: none;
  }
  .reader .line-text { flex: 1; text-align: center; }
  .reader .line.active {
    color: var(--focus);
    opacity: 1;
    font-size: 1.3em;
    font-weight: 600;
  }
  .reader .line.active .line-no { color: var(--focus); opacity: 1; }
  /* 标记行：正文高亮为蓝色（含聚焦态） */
  .reader .line.marked .line-text { color: #2563eb; }
  .reader .word {
    display: inline-block;
    color: var(--text-dim);
    opacity: 0.45;
    transform: scale(0.82);
    transform-origin: center center;
    transition: opacity 0.2s ease, color 0.2s ease;
    will-change: transform, opacity;
  }
  /* 为放大预留水平空间，避免焦点字压到上下文 */
  .reader.zh .word { padding: 0 0.25em; margin: 0 0.06em; }
  .reader.en .word { padding: 0 0.45em; margin: 0 0.1em; }
  .reader .space { display: inline-block; width: 0.28em; }

  /* 自动滚动控制条 */
  .controls {
    position: fixed;
    bottom: 18px; left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--bar-bg);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-radius: 30px;
    box-shadow: 0 6px 24px var(--shadow);
    z-index: 20;
  }
  /* 字体放大/缩小按钮：底部固定，与滚动按钮齐平，屏幕左侧距边距 10px，上下排列 */
  .font-stack {
    position: fixed;
    bottom: 18px;
    left: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 30;
  }
  .play-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--focus);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.15s ease;
  }
  .play-btn:active { transform: scale(0.9); }
  .speed {
    display: flex; align-items: center; gap: 6px;
    color: var(--text); font-size: 13px;
  }
  .speed input { width: 90px; accent-color: var(--focus); }
  .speed-val { flex: none; min-width: 34px; text-align: center; font-variant-numeric: tabular-nums; color: var(--focus); font-weight: 600; }

  /* 书架 */
  .shelf {
    position: absolute;
    top: 54px; bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 960px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 18px 16px 40px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 20px 14px;
    align-content: start;
  }
  .shelf::-webkit-scrollbar { display: none; }
  .book { cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
  .cover {
    width: 100%;
    aspect-ratio: 3 / 4;
    border-radius: 10px;
    box-shadow: 0 6px 18px var(--shadow);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    padding: 12px;
    color: #fff;
    transition: transform 0.15s ease;
  }
  .book:active .cover { transform: scale(0.97); }
  .cover img.cover-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  .cover-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg-card-hover, #18181d); color: var(--text-dim, #71717a); font-size: 12px; }
  .cover-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    text-align: center;
    text-shadow: 0 1px 4px rgba(0,0,0,0.35);
  }
  .book .meta { padding: 0 2px; text-align: center; }
  .book-title {
    font-size: 13px; font-weight: 600; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .book-author { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

  /* 开课按钮（盾牌图标） */
  .class-btn { color: var(--focus); }

  /* 弹窗 */
  .modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 50; padding: 20px;
  }
  .modal {
    width: 100%; max-width: 320px;
    background: var(--bar-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border: 1px solid var(--shadow);
    border-radius: 16px;
    padding: 22px 20px;
    text-align: center;
    box-shadow: 0 12px 40px var(--shadow);
  }
  .modal h3 { margin: 0 0 14px; font-size: 17px; }
  .modal-sub { font-size: 13px; color: var(--text-dim); margin: -8px 0 14px; }
  .class-code-box { margin: 10px 0 18px; }
  .class-code {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
    font-size: 34px; font-weight: 700; letter-spacing: 6px; color: var(--focus);
  }
  .class-hint { font-size: 12px; color: var(--text-dim); margin-top: 8px; }
  .modal-input {
    width: 100%; height: 46px; box-sizing: border-box;
    border-radius: 10px; border: 1px solid var(--shadow);
    background: var(--bg); color: var(--text);
    font-size: 20px; text-align: center; letter-spacing: 4px;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
    outline: none;
  }
  .modal-input:focus { border-color: var(--focus); }
  .modal-error { color: #f87171; font-size: 13px; min-height: 18px; margin-top: 8px; }
  .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
  .btn-primary, .btn-secondary {
    flex: 1; height: 44px; border: none; border-radius: 10px;
    font-size: 15px; font-weight: 600; cursor: pointer;
  }
  .btn-primary { background: var(--focus); color: #fff; }
  .btn-secondary { background: var(--btn-bg); color: var(--btn-text); }
  .btn-primary:disabled, .btn-secondary:disabled { opacity: .5; cursor: not-allowed; }
  .modal-close {
    margin-top: 22px; background: none; border: none; color: var(--text-dim);
    font-size: 13px; cursor: pointer;
  }

  /* 加载失败 / 空状态提示（不回退静态内容） */
  .empty-tip {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1.6;
  }
