:root {
  --bg: #f5f5f2;
  --card: #ffffff;
  --text: #1c1c1a;
  --muted: #6e6e68;
  --line: #e4e3de;
  --accent: #1f6f5c;
  --accent-soft: #e3f0ec;
  --warn: #a45a12;
  --warn-soft: #fbeedd;
  --bad: #b3261e;
  --chip: #ecebe6;
  --vh: 100dvh;
  --vt: 0px;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --card: #22221f; --text: #ecebe6; --muted: #9c9b94; --line: #33332f;
    --accent: #5fbfa5; --accent-soft: #1d3530; --warn: #e3a35c; --warn-soft: #3a2a17; --bad: #f2857c; --chip: #2e2e2a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 两栏：手机上正文盖在列表上面 */
.pane { position: fixed; inset: 0; overflow-y: auto; overscroll-behavior: contain; background: var(--bg); padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
#doc { display: none; z-index: 2; }
body.has-doc #doc { display: block; }

.bar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 4px; min-height: 48px; padding: calc(env(safe-area-inset-top) + 4px) 8px 4px 16px; background: var(--bg); }
.bar .sp { flex: 1; }
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 22px; line-height: 1.3; }
.bar .link { padding: 10px 8px; color: var(--accent); font-weight: 500; white-space: nowrap; }
.bar .link.back { margin-left: -8px; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.bar .state { color: var(--muted); font-size: 13px; padding-right: 8px; white-space: nowrap; }
.bar .state.bad { color: var(--bad); }
.wrap { padding: 0 16px; }

.sync { display: flex; align-items: center; gap: 10px; margin: 2px 16px 14px; padding: 10px 14px; border-radius: 12px; background: var(--chip); font-size: 14px; }
.sync span { flex: 1; min-width: 0; }
.sync b { font-weight: 600; }
.sync small { display: block; color: var(--muted); font-size: 12px; }
.sync button { color: var(--accent); font-weight: 600; white-space: nowrap; padding: 6px 0; }
.sync.todo { background: var(--warn-soft); }
.sync.todo b { color: var(--warn); }
.sync.err b { color: var(--bad); }

.notice { margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); font-size: 14px; }
.notice ul { margin: 0; padding-left: 18px; }
.notice button { margin-top: 8px; color: var(--accent); font-weight: 600; }

.rows { margin: 0 16px 16px; background: var(--card); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 12px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row.dir .nm { font-weight: 600; }
.row.big { min-height: 64px; }
.row.big .nm { font-size: 18px; }
.row.cur { background: var(--accent-soft); }
.row .ct { color: var(--muted); font-size: 14px; }
.row .nm small { display: block; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.tag { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); font-size: 12px; }
.tag.todo { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--warn); color: #fff; }
.empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.fab { position: fixed; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 1; padding: 14px 20px; border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
@media (prefers-color-scheme: dark) { .fab, .btn.primary { color: #10201b !important; } }

/* 正文 */
.reader { max-width: 40em; margin: 0 auto; padding: 4px 20px 40px; }
.reader h2 { margin: 4px 0 2px; font: 600 22px/1.4 var(--serif); overflow-wrap: anywhere; }
.reader .meta { margin-bottom: 20px; color: var(--muted); font-size: 13px; }
.text { font: 18px/1.9 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; }
.text .t1 { font-size: 22px; font-weight: 600; }
.text .t2 { font-size: 20px; font-weight: 600; }
.text .t3 { font-weight: 600; }
.text i { font-style: normal; color: var(--line); }
.reader img { max-width: 100%; border-radius: 8px; }

body.has-doc #doc.editing { top: var(--vt); bottom: auto; height: var(--vh); display: flex; flex-direction: column; padding: 0; overflow: hidden; }
#doc.editing textarea { flex: 1; width: 100%; max-width: 44em; margin: 0 auto; padding: 8px 20px 40px; border: 0; outline: 0; resize: none; background: transparent; font: 18px/1.9 var(--serif); overscroll-behavior: contain; }

.banner { margin: 0 16px 12px; padding: 12px 14px; border-radius: 12px; background: var(--warn-soft); font-size: 15px; }
.banner button { color: var(--accent); font-weight: 600; margin-top: 6px; display: block; }

/* 冲突确认 */
.chunk { margin: 0 0 14px; padding: 12px 14px; border-radius: 14px; background: var(--card); }
.chunk.both { box-shadow: inset 3px 0 0 var(--warn); }
.chunk .who { font-weight: 600; font-size: 14px; }
.chunk .ctx { color: var(--muted); font-size: 13px; margin: 2px 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt { display: block; width: 100%; margin-top: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt small { display: block; color: var(--muted); font-size: 12px; }
.opt.on small { color: var(--accent); font-weight: 600; }
.opt div { font: 16px/1.7 var(--serif); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow-y: auto; }
details { margin: 0 0 16px; }
details summary { color: var(--accent); font-weight: 600; padding: 8px 0; cursor: pointer; }

.btn { display: block; width: 100%; padding: 13px 16px; border-radius: 12px; background: var(--chip); text-align: center; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: default; }
.btns { display: flex; gap: 10px; margin-top: 16px; }

/* 弹窗 */
dialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 20px; border: 0; border-radius: 18px; background: var(--card); color: var(--text); overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin: 0 0 10px; font-size: 18px; overflow-wrap: anywhere; }
dialog p { margin: 0 0 12px; color: var(--muted); font-size: 15px; }
label { display: block; margin: 0 0 12px; font-size: 14px; color: var(--muted); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font-size: 16px; }
label textarea { min-height: 30vh; resize: vertical; font-family: var(--serif); line-height: 1.7; }
.menu .btn { margin-top: 8px; }
.set { max-width: 560px; margin: 0 auto; padding: 0 16px; }
.set h2 { margin: 24px 0 10px; font-size: 17px; }
.set p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 9; transform: translateX(-50%); max-width: calc(100vw - 48px); padding: 10px 16px; border-radius: 10px; background: #2b2b28; color: #fff; font-size: 14px; }

/* Mac：左列表右正文 */
@media (min-width: 860px) {
  #list { right: auto; width: 340px; border-right: 1px solid var(--line); }
  #doc, body.has-doc #doc { display: block; left: 340px; }
  #list .fab { right: auto; left: 200px; }
  #doc .bar .back { display: none; }
  body.drag #list { box-shadow: inset 0 0 0 3px var(--accent); }
  .toast { left: calc(50% + 170px); }
}
