/* ===================== 基础 & 主题变量 ===================== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

:root[data-theme="paper"] {
  --bg: #f6f1e7;
  --bg-elevated: #fbf8f1;
  --text: #2b2620;
  --text-dim: #8a8072;
  --accent: #4f6f5f;
  --accent-soft: rgba(79, 111, 95, 0.14);
  --border: rgba(43, 38, 32, 0.1);
  --shadow: rgba(60, 50, 30, 0.12);
  --danger: #a34a3f;
}

:root[data-theme="eyecare"] {
  --bg: #cfe6c9;
  --bg-elevated: #e6f2e0;
  --text: #33422c;
  --text-dim: #71816a;
  --accent: #4c7a4f;
  --accent-soft: rgba(76, 122, 79, 0.16);
  --border: rgba(51, 66, 46, 0.14);
  --shadow: rgba(40, 60, 35, 0.16);
  --danger: #a34a3f;
}

:root[data-theme="night"] {
  --bg: #14161c;
  --bg-elevated: #1b1e26;
  --text: #e8e3d8;
  --text-dim: #77808f;
  --accent: #d9a35f;
  --accent-soft: rgba(217, 163, 95, 0.14);
  --border: rgba(232, 227, 216, 0.1);
  --shadow: rgba(0, 0, 0, 0.4);
  --danger: #e2897a;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.4s ease, color 0.4s ease;
  min-height: 100%;
}

/* subtle paper grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: radial-gradient(rgba(0,0,0,0.02) 1px, transparent 1px);
  background-size: 3px 3px;
  z-index: 0;
}

.view { position: relative; z-index: 1; min-height: 100vh; }

svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

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

.toast {
  position: fixed; bottom: 36px; left: 50%; z-index: 50;
  transform: translateX(-50%) translateY(10px);
  background: rgba(20, 20, 24, 0.88); color: #f0ece2;
  padding: 11px 20px; border-radius: 999px; font-size: 13px;
  max-width: 86vw; text-align: center; line-height: 1.5;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== 首页：作品库 ===================== */
#view-library { max-width: 980px; margin: 0 auto; padding: 40px 24px 120px; }

.lib-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 32px; }
.lib-header-actions { display: flex; align-items: center; gap: 4px; }
.lib-title h1 { font-family: "Songti SC", "Noto Serif SC", serif; font-size: 34px; letter-spacing: 4px; font-weight: 600; }
.lib-sub { color: var(--text-dim); margin-top: 6px; font-size: 14px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  transition: background 0.2s, color 0.2s;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.lib-stats {
  display: flex; align-items: center; gap: 32px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px 24px; margin-bottom: 28px;
  box-shadow: 0 6px 20px var(--shadow);
  flex-wrap: wrap; cursor: pointer; transition: box-shadow 0.15s;
}
.lib-stats:hover { box-shadow: 0 10px 26px var(--shadow); }
.stat-block { display: flex; flex-direction: column; gap: 2px; min-width: 64px; }
.stat-num { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-dim); }
.mini-cal {
  margin-left: auto; display: grid; grid-template-columns: repeat(7, 9px); grid-auto-rows: 9px; gap: 2px;
  align-content: start;
}
.mini-cal-cell { width: 9px; height: 9px; border-radius: 2px; background: var(--border); }
.mini-cal-cell.empty { visibility: hidden; }
.mini-cal-cell.today { box-shadow: inset 0 0 0 1.5px var(--accent); }

.lib-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.tab {
  padding: 8px 18px; border-radius: 999px; font-size: 14px;
  color: var(--text-dim); border: 1px solid transparent;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-soft); font-weight: 600; }

.lib-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.work-card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex; flex-direction: column; gap: 10px; min-height: 140px;
  position: relative; overflow: hidden;
}
/* 卡片每次生成时错落浮现（首次打开、切换标签、从写作页回来） */
@media (prefers-reduced-motion: no-preference) {
  .work-card { animation: cardIn 0.46s cubic-bezier(0.22, 0.9, 0.32, 1) both; animation-delay: var(--card-delay, 0ms); }
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.work-card:hover { transform: translateY(-3px); box-shadow: 0 10px 28px var(--shadow); }
.work-card .tag {
  align-self: flex-start; font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.work-card h3 { font-family: "Songti SC", "Noto Serif SC", serif; font-size: 18px; line-height: 1.4; }
.work-card .meta { font-size: 12px; color: var(--text-dim); margin-top: auto; display: flex; justify-content: space-between; }
.work-card .card-progress { height: 4px; background: var(--border); border-radius: 999px; overflow: hidden; }
.work-card .card-progress-fill { height: 100%; background: var(--accent); }
.work-card .card-del {
  position: absolute; top: 10px; right: 10px; width: 26px; height: 26px;
  opacity: 0; transition: opacity 0.2s;
}
.work-card:hover .card-del { opacity: 0.6; }
.work-card .card-del:hover { opacity: 1; color: var(--danger); }

.lib-empty { text-align: center; color: var(--text-dim); padding: 80px 0; }
.lib-empty p:first-child { font-size: 16px; margin-bottom: 6px; color: var(--text); }

.fab {
  position: fixed; right: 32px; bottom: 32px; width: 56px; height: 56px;
  border-radius: 50%; background: var(--accent); color: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px var(--shadow);
  transition: transform 0.2s;
}
.fab:hover { transform: scale(1.08) rotate(90deg); }
.fab svg { width: 24px; height: 24px; stroke-width: 2.2; }

/* ===================== 视图切换动画 =====================
 * 进入写作页：整页淡入 + 顶栏从上方落下 + 纸张从下方浮起 + 章节栏从左滑入，层次感来自不同元素的错峰
 * 回到作品库：整页淡入，卡片自带错落浮现 */
@media (prefers-reduced-motion: no-preference) {
  #view-library.view-anim-in { animation: viewFade 0.3s ease both; }
  #view-editor.view-anim-in { animation: viewFade 0.28s ease both; }
  #view-editor.view-anim-in .editor-topbar { animation: topbarIn 0.42s cubic-bezier(0.22, 0.9, 0.32, 1) both; }
  #view-editor.view-anim-in .content-area { animation: sheetIn 0.5s cubic-bezier(0.22, 0.9, 0.32, 1) both; }
  #view-editor.view-anim-in .chapter-panel { animation: panelIn 0.42s cubic-bezier(0.22, 0.9, 0.32, 1) both; }
}
/* 沉浸模式下顶栏是隐藏的悬浮卡片，有自己的位移逻辑，不参与入场动画 */
body.atmosphere-mode #view-editor.view-anim-in .editor-topbar,
body.focus-mode #view-editor.view-anim-in .editor-topbar { animation: none; }
@keyframes viewFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes topbarIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes sheetIn { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
@keyframes panelIn { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

/* ===================== 编辑器 ===================== */
#view-editor { height: 100vh; }
.editor-shell { display: flex; height: 100%; overflow: hidden; }

.chapter-panel {
  width: 260px; flex-shrink: 0; background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.25s ease, margin-left 0.35s cubic-bezier(0.22, 0.9, 0.32, 1), opacity 0.28s ease;
}
.chapter-panel[hidden] { display: none; }
/* 桌面端：点顶栏的列表按钮把章节栏整个收进左边，完全聚焦正文 */
@media (min-width: 761px) {
  .chapter-panel.collapsed { margin-left: -260px; }
}
.chapter-panel-head {
  display: flex; align-items: center; gap: 6px; padding: 14px;
  border-bottom: 1px solid var(--border);
}
.chapter-panel-title { flex: 1; font-size: 14px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-list { flex: 1; overflow-y: auto; padding: 8px; }

.chapter-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.chapter-item:hover { background: var(--accent-soft); }
.chapter-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chapter-item .ch-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-item.active .ch-name { cursor: text; }
.chapter-item.active .ch-name:hover { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; }
.chapter-item .ch-name-input {
  flex: 1; min-width: 0; font: inherit; color: inherit; background: var(--bg-elevated);
  border: 1px solid var(--accent); border-radius: 6px; padding: 1px 5px; outline: none;
}
.chapter-item .ch-count { font-size: 11px; opacity: 0.7; flex-shrink: 0; }
.chapter-item .ch-del { opacity: 0; width: 20px; height: 20px; flex-shrink: 0; }
.chapter-item:hover .ch-del { opacity: 0.5; }
.chapter-item .ch-del:hover { opacity: 1; color: var(--danger); }
.chapter-item.dragging { opacity: 0.4; }

.editor-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.editor-topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chapter-title-group { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 120px; }
.chapter-title-input {
  border: none; background: none; color: var(--text);
  font-family: "Songti SC", "Noto Serif SC", serif; font-size: 18px;
  flex: 1; min-width: 0; outline: none;
}
.chapter-title-input::placeholder { color: var(--text-dim); }
#atmo-chapter-toggle[hidden] { display: none; }
.topbar-stats { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.topbar-stats .dot { opacity: 0.4; }
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.save-indicator { font-size: 12px; color: var(--text-dim); margin-right: 8px; opacity: 0; transition: opacity 0.3s; }
.save-indicator.show { opacity: 1; }

.only-mobile { display: none; }

.target-bar { display: flex; align-items: center; gap: 12px; padding: 0 24px 12px; }
.target-bar[hidden] { display: none; }
.target-track { flex: 1; height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.target-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }
.target-bar span { font-size: 12px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.editor-body { position: relative; flex: 1; overflow: hidden; display: flex; justify-content: center; }
/* 正文是一张"纸"：两侧有可见的纸张边缘，让人一眼看到书写区域在哪里 */
.content-area {
  position: relative; z-index: 1;
  width: 100%; max-width: 760px; height: 100%;
  border: none; outline: none; resize: none; color: var(--text);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  box-shadow: 0 0 34px var(--shadow);
  font-family: "Songti SC", "Noto Serif SC", "STSong", serif;
  font-size: 18px; line-height: 2; letter-spacing: 0.5px;
  padding: 40px 48px 50vh;
  transition: background 0.5s ease, color 0.5s ease, box-shadow 0.5s ease;
  border-radius: 0;
  scrollbar-width: none; -ms-overflow-style: none; /* 写作区永远不露滚动条（尤其氛围模式的玻璃卡片上很丑） */
  overflow-y: auto; white-space: pre-wrap; overflow-wrap: break-word; cursor: text;
}
.content-area::-webkit-scrollbar { display: none; width: 0; height: 0; }
/* contenteditable 的占位符：空的时候画在第一行的位置 */
.content-area.is-empty::before {
  content: attr(data-placeholder);
  position: absolute; left: 48px; right: 48px; top: 40px;
  color: var(--text-dim); pointer-events: none;
}
/* 段落排版（纯显示效果，保存的文字不含缩进空格和空行） */
.content-area.ts-indent > div { text-indent: 2em; }
.content-area.ts-gap > div + div { margin-top: 1em; } /* 行高 2，1em 正好隔半行 */

/* ===================== 氛围模式 ===================== */
.atmo-bg {
  position: absolute; inset: 0; z-index: 0; overflow: hidden;
  opacity: 0; transition: opacity 0.45s ease;
  background: linear-gradient(168deg, #414b58 0%, #232932 100%); /* 天气画面加载前先垫的暮色底 */
}
.atmo-bg[hidden] { display: none; }
.atmo-bg.show { opacity: 1; }
.atmo-bg iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: none; pointer-events: none;
  opacity: 0; transition: opacity 1s ease;
}
.atmo-bg.ready iframe { opacity: 1; }
/* 给天气画面罩一层"暮色"：四周和底部微微压暗（晕影），让亮底的雨/雪场景沉下来，
 * 玻璃卡片的光才衬得出来。压多少由 --atmo-dim 按天气控制（晴天轻、雨雪重） */
.atmo-bg::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 130% 100% at 50% 28%, rgba(9, 13, 20, 0) 42%, rgba(9, 13, 20, 0.42) 100%),
    linear-gradient(180deg, rgba(9, 13, 20, 0.12) 0%, rgba(9, 13, 20, 0) 30%, rgba(9, 13, 20, 0) 58%, rgba(9, 13, 20, 0.32) 100%),
    rgba(9, 13, 20, 0.14);
  opacity: var(--atmo-dim, 0.8);
  transition: opacity 0.8s ease;
}

/* 进入/退出氛围模式的编排：纸张化作玻璃卡片浮起，短杠随后浮现；退出时纸张淡回来 */
@media (prefers-reduced-motion: no-preference) {
  body.atmo-entering .content-area { animation: atmoCardIn 0.65s cubic-bezier(0.22, 0.9, 0.32, 1) both; }
  body.atmo-entering .immersive-dash { animation: dashIn 0.5s ease 0.35s both; }
  body.atmo-exit-anim .content-area { animation: atmoCardIn 0.45s ease both; }
}
@keyframes atmoCardIn { from { opacity: 0; transform: translateY(16px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes dashIn { from { opacity: 0; } }

/* 氛围模式的玻璃卡片：真正的磨砂玻璃——
 * "白"不靠涂白漆（白漆涂厚了就是奶油/白瓷，光透不过来，边缘又硬又闷），
 * 而是把玻璃背后的景色 模糊(blur) + 提亮(brightness) + 提饱和(saturate)，
 * 白色只淡淡罩一层且永远到不了不透明。光是从玻璃后面透出来的，
 * 所以不管透明度调到哪里，它都是柔和、发亮、有颗粒感的磨砂玻璃 */
body.atmosphere-mode .content-area {
  margin: 32px 0; padding: 36px 40px 40vh; max-width: 700px;
  background: linear-gradient(168deg,
    rgba(255, 255, 255, calc(var(--atmo-card-alpha, 0.18) + 0.04)) 0%,
    rgba(255, 255, 255, var(--atmo-card-alpha, 0.18)) 38%,
    rgba(255, 255, 255, calc(var(--atmo-card-alpha, 0.18) + 0.02)) 100%);
  backdrop-filter: blur(var(--atmo-card-blur, 24px)) saturate(1.4) brightness(var(--atmo-card-bright, 1.08));
  -webkit-backdrop-filter: blur(var(--atmo-card-blur, 24px)) saturate(1.4) brightness(var(--atmo-card-bright, 1.08));
  /* 边缘要"消失在雾里"而不是一圈亮箍（啤酒瓶感就是描边+内高光太重）：
   * 描边压到似有似无，顶部高光只留一丝，去掉整圈的内泛光 */
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 22px;
  box-shadow:
    0 24px 70px rgba(0,0,0,0.28),
    inset 0 1px 0 rgba(255,255,255,0.22);
  color: #262218; caret-color: #262218; height: calc(100% - 64px);
}
body.atmosphere-mode .content-area.is-empty::before { color: rgba(38,34,24,0.42); left: 40px; right: 40px; top: 36px; }
body.atmosphere-mode.typewriter-mode .content-area { padding-top: 40vh; }

/* 卡片尺寸：宽屏比例（更矮，贴近笔记本屏幕比例），居中悬浮 */
body.atmosphere-mode.atmo-card-wide .editor-body { align-items: center; }
body.atmosphere-mode.atmo-card-wide .content-area {
  height: min(600px, 66vh); padding-bottom: 36px;
}
body.atmosphere-mode.atmo-card-wide.typewriter-mode .content-area { padding-top: 36px; }

.atmo-panel[hidden] { display: none; }
/* 设置面板与写作卡片同一种"透白毛玻璃"质地，整个页面只有一种玻璃语言 */
.atmo-panel {
  position: fixed; /* 挂在 body 下、由 JS 贴着顶栏定位——放进顶栏里 backdrop-filter 会嵌套失效，玻璃变透明纱 */
  z-index: 27;
  background: rgba(255,255,255,0.26);
  backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  -webkit-backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  border: 1px solid rgba(255,255,255,0.24); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px; min-width: 240px;
  color: #2c2720; box-shadow: 0 14px 40px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.22);
}
.atmo-row { display: flex; align-items: center; gap: 8px; }
.atmo-label { font-size: 11px; color: rgba(44,39,32,0.6); width: 44px; flex-shrink: 0; }
.atmo-seg { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
.atmo-pill {
  padding: 7px 12px; border-radius: 8px; font-size: 12px; white-space: nowrap;
  border: 1px solid rgba(0,0,0,0.15); color: rgba(51,48,42,0.8); background: transparent;
  transition: all 0.15s; cursor: pointer;
}
.atmo-pill:hover { background: rgba(0,0,0,0.06); color: #1f1b15; }
.atmo-pill.active { background: rgba(63,93,84,0.16); border-color: rgba(63,93,84,0.55); color: #35544a; font-weight: 600; }
.atmo-pill.playing::after { content: "♪"; margin-left: 4px; }
.atmo-panel input[type="range"] { flex: 1; accent-color: #3f5d54; }
.atmo-hint { font-size: 11px; color: rgba(51,48,42,0.45); text-align: center; padding: 2px 0; }
.atmo-exit-row { margin-top: 2px; }
.atmo-exit-btn { flex: 1; text-align: center; color: rgba(140,60,45,0.85); border-color: rgba(163,74,63,0.3); }
.atmo-exit-btn:hover { background: rgba(163,74,63,0.08); color: #a34a3f; }

.chapter-switch-popover {
  flex-direction: row; flex-wrap: wrap; min-width: 0; max-width: 320px;
}

/* 小喇叭 / 字体排版弹层（纸张模式跟主题配色；氛围模式下变成与顶栏一致的玻璃，见下方覆盖） */
.ambient-popover {
  position: fixed; z-index: 27; /* 挂在 body 下、JS 贴着顶栏定位，理由同 .atmo-panel */
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px; box-shadow: 0 10px 30px var(--shadow);
  display: flex; flex-direction: column; gap: 8px; width: min(320px, 92vw);
}
/* 氛围模式：弹层与顶栏、写作卡片同一种透白毛玻璃 + 墨色文字 */
body.atmosphere-mode .ambient-popover {
  background: rgba(255,255,255,0.26);
  backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  -webkit-backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  border: 1px solid rgba(255,255,255,0.24);
  box-shadow: 0 14px 40px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.22);
  color: #2c2720;
}
body.atmosphere-mode .ambient-popover .amb-label { color: rgba(44,39,32,0.6); }
body.atmosphere-mode .ambient-popover .amb-pill { border-color: rgba(0,0,0,0.15); color: rgba(51,48,42,0.85); opacity: 1; }
body.atmosphere-mode .ambient-popover .amb-pill:hover { background: rgba(0,0,0,0.06); color: #1f1b15; }
body.atmosphere-mode .ambient-popover .amb-pill.active { background: rgba(63,93,84,0.16); border-color: rgba(63,93,84,0.55); color: #35544a; }
body.atmosphere-mode .ambient-popover .amb-hint { color: rgba(51,48,42,0.5); }
body.atmosphere-mode .ambient-popover input[type="range"] { accent-color: #3f5d54; }
.amb-row { display: flex; align-items: center; gap: 8px; }
.amb-label {
  font-size: 11px; color: color-mix(in srgb, var(--text) 55%, transparent);
  width: 44px; flex-shrink: 0;
}
.amb-tracks { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.amb-pill {
  padding: 6px 11px; border-radius: 8px; font-size: 12px; white-space: nowrap;
  border: 1px solid var(--border); color: var(--text); opacity: 0.85;
  background: transparent; cursor: pointer; transition: all 0.15s;
}
.amb-pill:hover { background: color-mix(in srgb, var(--text) 8%, transparent); opacity: 1; }
.amb-pill.active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-color: var(--accent); color: var(--accent); font-weight: 600; opacity: 1;
}
.amb-pill.active::after { content: "♪"; margin-left: 4px; }
.typeset-popover .amb-pill.active::after { content: ""; margin-left: 0; }
.amb-hint { font-size: 11px; color: color-mix(in srgb, var(--text) 45%, transparent); text-align: center; padding: 2px 0; }
.ambient-popover input[type="range"] { flex: 1; accent-color: var(--accent); }

/* ===================== 沉浸式顶栏（专注模式 / 氛围模式共用） ===================== */
/* 默认：只留一根干净的短杠（无底、无 emoji），它的使命就是隐身；hover 或点按展开出完整工具栏 */
.immersive-dash {
  display: none; position: fixed; top: 6px; left: 50%; transform: translateX(-50%);
  align-items: center; justify-content: center; padding: 12px 30px;
  background: transparent; cursor: pointer; opacity: 0.55;
  transition: opacity 0.2s ease; z-index: 28;
}
.immersive-dash:hover { opacity: 1; }
body.focus-mode .immersive-dash, body.atmosphere-mode .immersive-dash { display: flex; }
/* 顶栏展开时短杠隐身，别和展开的菜单叠在一起碍眼 */
body.dash-open .immersive-dash { opacity: 0; pointer-events: none; }
.dash-weather-emoji { display: none; }
.dash-line { width: 30px; height: 3px; border-radius: 2px; background: rgba(255,255,255,0.85); box-shadow: 0 1px 4px rgba(0,0,0,0.35); }
body.focus-mode:not(.atmosphere-mode) .dash-line { background: color-mix(in srgb, var(--text) 50%, transparent); box-shadow: none; }

body.focus-mode .target-bar,
body.atmosphere-mode .target-bar { display: none; }
/* 章节栏不再瞬间消失，而是随进入氛围/专注模式滑出画面 */
body.focus-mode .chapter-panel,
body.atmosphere-mode .chapter-panel {
  margin-left: -260px; opacity: 0; pointer-events: none;
}
body.focus-mode .content-area { max-width: 700px; }
body.focus-mode::before { opacity: 0.3; }

.atmo-chapter-select {
  max-width: 140px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); border-radius: 8px; padding: 5px 8px; font-size: 12px; outline: none;
}
/* 折叠：整个顶栏变成悬浮卡片，宽度与下面的写作卡片一致（700px），默认隐藏，hover/点按短杠时展开 */
body.focus-mode .editor-topbar, body.atmosphere-mode .editor-topbar {
  position: fixed; top: 14px; left: 50%;
  transform: translateX(-50%) translateY(-10px);
  width: min(94vw, 700px); justify-content: flex-start;
  border-radius: 16px;
  opacity: 0; pointer-events: none; visibility: hidden; z-index: 26;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}
body.dash-open .editor-topbar {
  opacity: 1; pointer-events: auto; visibility: visible;
  transform: translateX(-50%) translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 氛围模式：顶栏与写作卡片、设置面板同一种透白毛玻璃 + 墨色文字 */
body.atmosphere-mode .editor-topbar {
  background: rgba(255,255,255,0.26);
  backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  -webkit-backdrop-filter: blur(30px) saturate(1.4) brightness(1.1);
  border: 1px solid rgba(255,255,255,0.24);
  box-shadow: 0 18px 50px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.22);
}
body.atmosphere-mode .editor-topbar .icon-btn, body.atmosphere-mode .save-indicator,
body.atmosphere-mode .topbar-stats { color: rgba(51,48,42,0.72); }
body.atmosphere-mode .chapter-title-input { color: #2c2720; }
body.atmosphere-mode .chapter-title-input::placeholder { color: rgba(44,39,32,0.42); }
body.atmosphere-mode .editor-topbar .icon-btn:hover { background: rgba(0,0,0,0.07); color: #1f1b15; }
body.atmosphere-mode .icon-btn.active { color: #35544a; background: rgba(63,93,84,0.16); }

/* 专注模式：顶栏跟随当前主题的纸色毛玻璃 */
body.focus-mode:not(.atmosphere-mode) .editor-topbar {
  background: color-mix(in srgb, var(--bg-elevated) 86%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  box-shadow: 0 18px 50px var(--shadow);
}

/* 沉浸态里标题按内容收窄（宽度由 JS 量好），章节箭头、字数统计全部紧贴在标题右侧 */
body.focus-mode .chapter-title-group, body.atmosphere-mode .chapter-title-group { flex: 0 1 auto; min-width: 0; gap: 4px; }
body.focus-mode .chapter-title-input, body.atmosphere-mode .chapter-title-input { flex: 0 0 auto; }
/* 沉浸态里章节栏本来就收起了，收纳按钮没有用还占位，把标题挤得离返回箭头很远 */
body.focus-mode #btn-toggle-panel, body.atmosphere-mode #btn-toggle-panel { display: none; }

/* 打字机模式：当前行居中 */
body.typewriter-mode .content-area { padding-top: 40vh; padding-bottom: 40vh; }

/* ===================== 弹窗 ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 20; backdrop-filter: blur(3px);
  animation: fadeIn 0.2s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elevated); border-radius: 18px; padding: 28px;
  width: 92%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUp 0.25s ease;
  max-height: 86vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal h2 { font-family: "Songti SC", "Noto Serif SC", serif; font-size: 20px; margin-bottom: 20px; }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; font-size: 13px; color: var(--text-dim); }
.field input[type="text"], .field input[type="number"] {
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.field input[type="range"] { accent-color: var(--accent); }

.sync-box { display: flex; flex-direction: column; gap: 10px; }
.sync-box p { font-size: 12px; color: var(--text-dim); line-height: 1.6; margin: 0; }
.sync-box p a { color: var(--accent); }
.sync-row { display: flex; gap: 8px; }
.sync-row[hidden] { display: none; }
.sync-row input[type="text"], .sync-row input[type="password"], .sync-row input[type="email"] {
  flex: 1; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 13px; outline: none;
}
.sync-status { font-size: 12px; color: var(--text-dim); }
.sync-status.error { color: var(--danger); }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 4px; }
.auth-tab { flex: 1; padding: 9px; text-align: center; border-radius: 9px; font-size: 13px; color: var(--text-dim); border: 1px solid var(--border); cursor: pointer; transition: all 0.15s; }
.auth-tab.active { background: var(--accent); color: var(--bg-elevated); border-color: var(--accent); font-weight: 600; }
.auth-forgot { font-size: 12px; color: var(--accent); cursor: pointer; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; align-self: flex-end; }
.auth-forgot:hover { opacity: 0.8; }
.auth-forgot[hidden] { display: none; }

.pwd-field { position: relative; flex: 1; display: flex; }
.pwd-field input[type="password"], .pwd-field input[type="text"] {
  flex: 1; border: 1px solid var(--border); background: var(--bg); color: var(--text);
  border-radius: 10px; padding: 9px 40px 9px 12px; font-size: 13px; outline: none; width: 100%;
}
.pwd-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border: none; background: transparent; color: var(--text-dim);
  cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 6px;
}
.pwd-eye:hover { color: var(--text); background: var(--bg-elevated); }
.pwd-eye svg { width: 17px; height: 17px; }
.account-email { font-size: 15px; font-weight: 600; }
.account-device { font-size: 12px; color: var(--text-dim); }

.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1; padding: 9px 10px; border-radius: 9px; font-size: 13px;
  border: 1px solid var(--border); color: var(--text-dim); text-align: center;
  transition: all 0.15s;
}
.seg-btn.active { background: var(--accent); color: var(--bg-elevated); border-color: var(--accent); font-weight: 600; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn { padding: 10px 20px; border-radius: 10px; font-size: 14px; font-weight: 500; transition: opacity 0.15s; }
.btn:hover { opacity: 0.85; }
.btn.primary { background: var(--accent); color: var(--bg-elevated); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }

/* ===================== 云端备份 / 回收站 ===================== */
.backup-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.backup-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--border); background: var(--bg);
  border-radius: 12px; padding: 10px 12px;
}
.backup-row-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.backup-row-time { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backup-row-meta { font-size: 12px; color: var(--text-dim); }
.backup-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn.small { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn.ghost.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.backup-hint { font-size: 12px; color: var(--text-dim); text-align: center; padding: 8px 0; line-height: 1.6; margin: 0; }
.backup-hint.error { color: var(--danger); }
.backup-work-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--border); padding: 8px 2px; }
.backup-work-row:last-child { border-bottom: none; }
.backup-work-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.backup-work-row .btn { flex-shrink: 0; white-space: nowrap; }
.backup-work-title { font-size: 14px; font-weight: 600; }
.backup-work-meta { font-size: 12px; color: var(--text-dim); }
.vip-badge {
  display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 999px;
  background: linear-gradient(135deg, #d9a35f, #b8792f); color: #fff;
  vertical-align: 2px; letter-spacing: 1px; font-weight: 600;
}

/* ===================== 码字数据弹窗 ===================== */
.stats-modal { max-width: 460px; padding: 22px; scrollbar-width: none; -ms-overflow-style: none; }
.stats-modal::-webkit-scrollbar { display: none; width: 0; height: 0; }
.stats-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.stats-modal-head h2 { margin: 0; }

.stats-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin-bottom: 14px;
}
.stats-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stats-card-head h3 { font-size: 14px; font-weight: 600; }
.stats-sub { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }

.day-nav { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.day-nav .icon-btn { width: 26px; height: 26px; }
.day-nav .icon-btn svg { width: 14px; height: 14px; }

.overview-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 8px; }
.overview-item { display: flex; flex-direction: column; gap: 4px; }
.overview-item .ov-label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-dim); }
.overview-item .ov-label svg { width: 13px; height: 13px; }
.overview-item .ov-value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.overview-item .ov-value .ov-unit { font-size: 11px; font-weight: 400; color: var(--text-dim); margin-left: 1px; }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  font-size: 11px; color: var(--text-dim); text-align: center; margin-bottom: 6px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 8px; font-size: 12px; color: var(--text); gap: 2px; position: relative;
}
.cal-day.empty { visibility: hidden; }
.cal-day.today { background: var(--accent); color: var(--bg-elevated); font-weight: 600; }
.cal-day .cal-day-num { font-variant-numeric: tabular-nums; }
.cal-day .cal-day-count { font-size: 9px; color: var(--text-dim); }
.cal-day.has-words .cal-day-count { color: inherit; opacity: 0.75; }
.cal-day.today .cal-day-count { color: var(--bg-elevated); opacity: 0.85; }

.seg.small { display: inline-flex; gap: 4px; }
.seg.small .seg-btn { flex: none; padding: 5px 12px; font-size: 12px; }

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.bar-chart::-webkit-scrollbar { display: none; width: 0; height: 0; }
.bar-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; height: 100%; gap: 6px; cursor: default; }
.bar-col .bar-daylabel { white-space: nowrap; }
.bar-col .bar-track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; position: relative; }
.bar-col .bar-fill {
  width: 60%; min-width: 6px; background: var(--accent); border-radius: 4px 4px 0 0;
  transition: opacity 0.15s; position: relative;
}
.bar-col:hover .bar-fill { opacity: 0.75; }
.bar-col .bar-daylabel { font-size: 10px; color: var(--text-dim); }
.bar-col .bar-tooltip {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%) translateY(-4px);
  background: rgba(20,20,24,0.9); color: #f0ece2; font-size: 11px; padding: 3px 7px;
  border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.bar-col:hover .bar-tooltip { opacity: 1; }

/* ===================== 响应式 / 手机 ===================== */
@media (max-width: 760px) {
  #view-library { padding: 24px 16px 100px; }
  .lib-title h1 { font-size: 28px; }
  .lib-stats { gap: 20px; padding: 16px 18px; }
  .stats-modal { padding: 18px; }
  .overview-grid { gap: 14px 6px; }

  .only-mobile { display: flex; }
  .chapter-panel {
    position: fixed; top: 0; bottom: 0; left: 0; width: 78vw; max-width: 300px;
    z-index: 10; transform: translateX(-100%);
    box-shadow: 10px 0 30px var(--shadow);
  }
  .chapter-panel.open { transform: translateX(0); }
  .editor-topbar { padding: 12px 16px; gap: 8px; }
  .chapter-title-input { font-size: 16px; }
  .topbar-stats { flex-basis: 100%; justify-content: center; order: 3; font-size: 12px; }
  .content-area { padding: 24px 20px 50vh; font-size: 17px; }
}
