/* 续墨 · 一套样式，手机优先，桌面只是把纸居中 */
:root {
  --bg: #f2ece0;
  --paper: #fffdf7;
  --ink: #221e19;
  --ink-2: #453f36;
  --muted: #8c8375;
  --line: #e4dbc9;
  --accent: #a63a2a;
  --accent-soft: rgba(166, 58, 42, .09);
  --gold: #8a6a2f;
  --radius: 14px;
  --col: 680px;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --sans: system-ui, -apple-system, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --shadow-1: 0 1px 2px rgba(60, 45, 25, .05), 0 6px 18px -10px rgba(60, 45, 25, .18);
  --shadow-2: 0 -2px 30px -6px rgba(40, 30, 15, .18);
  --dur: .22s;
  --ease: cubic-bezier(.32, .72, 0, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131210;
    --paper: #1c1a16;
    --ink: #e9e2d4;
    --ink-2: #c9c1b2;
    --muted: #8b8376;
    --line: #2e2a23;
    --accent: #cc5b44;
    --accent-soft: rgba(204, 91, 68, .12);
    --gold: #c0a164;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 22px -12px rgba(0, 0, 0, .6);
    --shadow-2: 0 -2px 30px -6px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 14px;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* ---------- 顶栏 ---------- */
.bar {
  flex: none; display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 3;
}
.bar .grow { flex: 1; min-width: 0; }
.bar h1 {
  margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .04em;
  font-family: var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bar h1.brand { font-size: 17px; letter-spacing: .2em; }
.text-btn { font-size: 12.5px; color: var(--muted); padding: 8px 11px; border-radius: 9px; }
.text-btn:active { background: var(--accent-soft); }
.bar .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.icon-btn {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  display: grid; place-items: center; font-size: 17px; color: var(--ink-2);
  transition: background var(--dur) var(--ease);
}
.icon-btn:active { background: var(--accent-soft); }
.icon-btn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 登录 ---------- */
.gate { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { width: 100%; max-width: 340px; text-align: center; }
.seal {
  width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 12px;
  background: var(--accent); color: #fff8ef; display: grid; place-items: center;
  font-family: var(--serif); font-size: 26px; line-height: 1;
  box-shadow: 0 6px 18px -8px rgba(166, 58, 42, .7);
}
.gate h1 { font-family: var(--serif); font-size: 23px; margin: 0 0 6px; letter-spacing: .18em; text-indent: .18em; }
.gate p.lead { margin: 0 0 26px; font-size: 12.5px; color: var(--muted); letter-spacing: .02em; }
.field { margin-bottom: 10px; text-align: left; }
.field label { display: block; font-size: 11px; color: var(--muted); margin: 0 0 5px 3px; letter-spacing: .06em; }
.input {
  width: 100%; height: 44px; padding: 0 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font-size: 15px; outline: none; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  height: 44px; padding: 0 18px; border-radius: 11px; font-size: 14.5px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .12s var(--ease), opacity var(--dur);
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--accent); color: #fff8ef; width: 100%; margin-top: 8px; }
.btn.primary:disabled { opacity: .5; }
.btn.ghost { border: 1px solid var(--line); color: var(--ink-2); background: var(--paper); }
.btn.flat { color: var(--accent); font-size: 13px; }
.gate .switch { margin-top: 18px; font-size: 12.5px; color: var(--muted); }
.gate .switch button { color: var(--accent); }
.err { color: var(--accent); font-size: 12px; min-height: 16px; margin: 8px 2px 0; text-align: left; }

/* ---------- 书架 ---------- */
.shelf { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); max-width: var(--col); margin: 0 auto; width: 100%; }
.book {
  display: block; width: 100%; text-align: left;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; margin-bottom: 11px; box-shadow: var(--shadow-1);
  transition: transform .14s var(--ease), box-shadow .2s;
}
.book:active { transform: scale(.99); }
.book .t { font-family: var(--serif); font-size: 17px; letter-spacing: .02em; margin-bottom: 5px; }
.book .p {
  font-size: 12.5px; line-height: 1.7; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book .m { margin-top: 10px; display: flex; align-items: center; gap: 12px; font-size: 11px; color: var(--muted); }
.book .m .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line); }
.book.new {
  display: flex; align-items: center; gap: 9px; justify-content: center;
  border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); font-size: 13px;
}
.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  height: 46px; padding: 0 22px; border-radius: 23px;
  background: var(--accent); color: #fff8ef; font-size: 14px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 7px;
  box-shadow: 0 8px 24px -8px rgba(166, 58, 42, .8);
  z-index: 4;
}
.fab:active { transform: translateX(-50%) scale(.97); }

/* ---------- 目录 ---------- */
.toc { padding: 8px 0 calc(30px + env(safe-area-inset-bottom)); max-width: var(--col); margin: 0 auto; width: 100%; }
.toc-head { padding: 14px 20px 12px; }
.toc-head .premise {
  font-size: 12.5px; line-height: 1.75; color: var(--muted);
  border-left: 2px solid var(--line); padding-left: 11px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.ch {
  display: flex; align-items: baseline; gap: 12px; width: 100%; text-align: left;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  transition: background var(--dur) var(--ease);
}
.ch:active { background: var(--accent-soft); }
.ch .no { font-family: var(--serif); font-size: 11.5px; color: var(--accent); flex: none; min-width: 3.6em; white-space: nowrap; letter-spacing: .02em; }
.ch .body { flex: 1; min-width: 0; }
.ch .name { font-family: var(--serif); font-size: 15.5px; margin-bottom: 4px; }
.ch .name.blank { color: var(--muted); font-style: italic; }
.ch .prev {
  font-size: 11.5px; color: var(--muted); line-height: 1.6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ch .w { font-size: 10.5px; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }

/* ---------- 写作 ---------- */
.pane { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.paper-col { max-width: var(--col); margin: 0 auto; padding: 18px 20px calc(120px + env(safe-area-inset-bottom)); }
#ch-title {
  width: 100%; border: 0; outline: none; background: transparent;
  font-family: var(--serif); font-size: 21px; letter-spacing: .02em; color: var(--ink);
  padding: 4px 0 14px; border-bottom: 1px solid var(--line); margin-bottom: 22px;
}
#ch-title::placeholder { color: var(--muted); opacity: .55; }
.hint-line { font-size: 12.5px; color: var(--muted); line-height: 1.85; margin: 0 0 20px; }
#body {
  outline: none; font-family: var(--serif); font-size: 17px; line-height: 1.95;
  letter-spacing: .012em; color: var(--ink); text-align: justify;
  min-height: 55dvh; word-break: break-word;
}
#body p { margin: 0 0 .55em; text-indent: 2em; }
#body p:last-child { margin-bottom: 0; }
#body p.empty::after { content: ""; }

/* AI 草稿 */
.draft {
  margin: 22px 0 0; padding: 14px 0 6px 14px;
  border-left: 2px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 10px 10px 0; animation: rise .3s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.draft .txt {
  font-family: var(--serif); font-size: 17px; line-height: 1.95; letter-spacing: .012em;
  white-space: pre-wrap; word-break: break-word; text-align: justify;
}
.draft .txt p { margin: 0 0 .55em; text-indent: 2em; }
.draft .txt p:last-child { margin-bottom: 0; }
.draft .caret {
  display: inline-block; width: 2px; height: 1.05em; vertical-align: -.18em;
  background: var(--accent); margin-left: 1px; animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.draft .note { font-size: 11px; color: var(--muted); margin: 12px 0 10px; letter-spacing: .04em; }
.draft .acts { display: flex; gap: 8px; padding-bottom: 10px; align-items: center; }
.draft .acts .btn { height: 36px; padding: 0 14px; font-size: 12.5px; border-radius: 9px; white-space: nowrap; }
.draft .acts .btn.primary { width: auto; flex: 1; margin: 0; }
.draft .acts .btn.flat { flex: none; padding: 0 6px; }

.screen.write::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 108px;
  pointer-events: none; z-index: 3;
  background: linear-gradient(to top, var(--bg) 46%, transparent);
}
.composer-fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  height: 44px; padding: 0 20px; border-radius: 22px;
  background: var(--paper); color: var(--ink); border: 1px solid var(--line);
  font-size: 13.5px; display: inline-flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-2); z-index: 4;
  transition: opacity var(--dur);
}
.composer-fab .ai-dot { color: var(--accent); font-size: 15px; }
.composer-fab:active { transform: translateX(-50%) scale(.97); }

/* ---------- 底部弹层 ---------- */
.scrim {
  position: fixed; inset: 0; background: rgba(30, 22, 12, .34);
  backdrop-filter: blur(2px); z-index: 10; animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px -10px rgba(30, 20, 10, .35);
  animation: up .26s var(--ease); max-height: 86dvh; overflow-y: auto;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet .handle { width: 34px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-family: var(--serif); font-size: 16px; margin: 0 0 4px; font-weight: 500; }
.sheet .hint { font-size: 11.5px; color: var(--muted); margin: 0 0 16px; }
.sheet textarea {
  width: 100%; min-height: 76px; max-height: 34dvh; resize: none; padding: 12px 13px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-size: 14px; line-height: 1.7; outline: none;
}
.sheet textarea:focus { border-color: var(--accent); }
.sheet textarea::placeholder { color: var(--muted); opacity: .8; }
.chips { display: flex; gap: 8px; margin: 12px 0 16px; flex-wrap: wrap; }
.chip {
  height: 33px; padding: 0 14px; border-radius: 17px; font-size: 12.5px;
  border: 1px solid var(--line); color: var(--muted); background: transparent;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.sheet .btn.primary { width: 100%; margin: 0; }

/* 模态（新建作品 / 设定） */
.modal { position: fixed; inset: 0; z-index: 11; display: flex; align-items: flex-end; }
@media (min-width: 640px) { .modal { align-items: center; justify-content: center; } }
.modal .scrim { z-index: 0; }
.modal .panel {
  width: 100%; background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow-y: auto;
  animation: up .26s var(--ease); position: relative; z-index: 1;
}
@media (min-width: 640px) {
  .modal .panel { max-width: 430px; border-radius: 18px; animation: pop .22s var(--ease); padding-bottom: 20px; }
  @keyframes pop { from { opacity: 0; transform: scale(.96); } }
}
.modal h2 { font-family: var(--serif); font-size: 16px; margin: 0 0 16px; font-weight: 500; }
.modal .row { display: flex; gap: 9px; margin-top: 16px; }
.modal .row .btn { flex: 1; }
.modal .input, .modal textarea { margin-bottom: 10px; }
.modal textarea {
  width: 100%; min-height: 100px; resize: vertical; padding: 12px 13px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--bg);
  font-size: 13.5px; line-height: 1.75; outline: none;
}
.modal textarea:focus { border-color: var(--accent); }

.empty { text-align: center; padding: 62px 24px; color: var(--muted); font-size: 13px; line-height: 2; }
.empty .big { font-family: var(--serif); font-size: 17px; color: var(--ink-2); margin-bottom: 8px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom));
  background: rgba(30, 22, 12, .88); color: #fdf6ea;
  font-size: 12.5px; padding: 9px 16px; border-radius: 20px; z-index: 20;
  animation: fade .18s; pointer-events: none;
}

/* ---------- 桌面：同一份代码，把纸居中 ---------- */
@media (min-width: 900px) {
  #body, .draft .txt { font-size: 17.5px; }
  .paper-col { padding-top: 34px; }
  .shelf, .toc { padding-top: 26px; }
  .book { padding: 17px 20px; }
  .screen.write::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 108px;
  pointer-events: none; z-index: 3;
  background: linear-gradient(to top, var(--bg) 46%, transparent);
}
.composer-fab { bottom: 30px; }
  /* 桌面：顶栏与正文同宽，像一张纸而不是一个窗口 */
  .bar {
    max-width: var(--col); margin: 0 auto; width: 100%;
    border-bottom-color: transparent; background: transparent; backdrop-filter: none;
  }
  .gate-card { max-width: 330px; }
}

/* ---------- AI 味体检 ---------- */
.icon-btn.aa { font-family: var(--serif); font-size: 15px; letter-spacing: -.02em; }
.chip-label { font-size: 11px; color: var(--muted); letter-spacing: .08em; margin: 14px 0 7px; }
.chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 0 4px; }
.chips::-webkit-scrollbar { display: none; }
.chips .chip { flex: none; }

.score-row { display: flex; align-items: center; gap: 16px; margin: 6px 0 18px; }
.score {
  font-family: var(--serif); font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.score.good { color: var(--gold); }
.score.mid { color: var(--accent); }
.score.bad { color: var(--accent); }
.score-meta .lvl { font-family: var(--serif); font-size: 16px; margin-bottom: 5px; }

.metrics { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 18px; }
.metric-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.metric-top b { font-weight: 500; font-variant-numeric: tabular-nums; }
.metric-top b.ok { color: var(--gold); }
.metric-top b.bad { color: var(--accent); }
.metric-bar { height: 3px; border-radius: 2px; background: var(--line); margin-top: 6px; overflow: hidden; }
.metric-bar i { display: block; height: 100%; border-radius: 2px; }
.metric-note { font-size: 10.5px; color: var(--muted); opacity: .75; margin-top: 4px; }

.hit-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 18px; }
.hit {
  min-width: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px; background: var(--bg);
}
.hit-top { display: flex; justify-content: space-between; font-size: 12.5px; }
.hit-top b { color: var(--accent); font-weight: 500; }
.hit-samples { margin-top: 7px; font-size: 11.5px; line-height: 1.7; color: var(--muted); }
.hit-samples div {
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--serif);
}
.hit-tip { margin-top: 7px; font-size: 11px; color: var(--muted); opacity: .9; }

/* ---------- 提示词预览 ---------- */
.peek {
  display: block; margin: 12px auto 0; font-size: 11.5px; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px; padding: 4px 6px;
}
.pv-meta { font-size: 11.5px; color: var(--muted); margin: -8px 0 14px; }
.pv-label {
  font-size: 10px; letter-spacing: .16em; color: var(--muted);
  text-transform: uppercase; margin: 0 0 6px 2px;
}
.pv {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.85; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 13px 14px; margin: 0 0 16px;
  color: var(--ink);
}
