:root {
  --bg: #0d131f;
  --bg-elev: #121a29;
  --panel: #16202f;
  --panel-2: #1b2738;
  --border: #24334c;
  --border-soft: #1c2940;
  --text: #e8eef8;
  --text-dim: #9db0c9;
  --muted: #6d7f99;
  --accent: #5b9dff;
  --accent-soft: #2a4a7a;
  --accent-glow: rgba(91, 157, 255, 0.22);
  --pink: #ff8fb1;
  --green: #4fd39a;
  --amber: #ffc46b;
  --red: #ff6b81;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Code", "JetBrains Mono",
    Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --panel-2: #f0f3f9;
  --border: #dbe2ee;
  --border-soft: #e6ebf4;
  --text: #1a2438;
  --text-dim: #4d5e78;
  --muted: #8494ad;
  --accent: #2f6fdd;
  --accent-soft: #d6e4ff;
  --accent-glow: rgba(47, 111, 221, 0.14);
  --shadow: 0 8px 32px rgba(21, 40, 80, 0.1);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a { color: var(--accent); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }

/* ---------------------------------------------------------------- 启动屏 */

#boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 100;
  transition: opacity 0.35s ease;
}
#boot.gone { opacity: 0; pointer-events: none; }

.boot-mark {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.12em;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.07); opacity: 1; }
}
.boot-mark svg { animation: breathe 2.4s ease-in-out infinite; }

/* ---------------------------------------------------------------- 登录 */

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, var(--accent-glow), transparent 70%),
    var(--bg);
}

.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.login-card .sub {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
}

input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover { background: var(--border-soft); }
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.danger { color: var(--red); border-color: rgba(255, 107, 129, 0.35); }

.error-text {
  color: var(--red);
  font-size: 13px;
  min-height: 20px;
  margin-top: 4px;
}

/* ---------------------------------------------------------------- 主框架 */

.shell {
  display: grid;
  grid-template-columns: 232px 320px 1fr;
  height: 100vh;
  height: 100dvh;
}

/* 侧边导航 */
.nav {
  background: var(--bg-elev);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  padding-top: calc(14px + var(--safe-top));
  gap: 2px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px 16px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
  user-select: none;
}
.brand svg { flex: none; }
.brand small {
  display: block;
  font-size: 9.5px;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.5;
  white-space: normal;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  text-align: left;
  width: 100%;
  transition: background 0.14s, color 0.14s;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--text); }
[data-theme="light"] .nav-item.active { background: var(--accent-soft); }
.nav-item .ico { flex: none; opacity: 0.9; }
.nav-item .badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.nav-spacer { flex: 1; }

.nav-foot {
  border-top: 1px solid var(--border-soft);
  padding-top: 10px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  flex: none;
}
.user-chip .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { display: block; color: var(--muted); font-size: 11px; }

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  transition: background 0.3s;
}
.sync-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.sync-dot.offline { background: var(--amber); }
.sync-dot.error { background: var(--red); }

/* 列表栏 */
.list-pane {
  background: var(--panel);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.pane-head {
  padding: 14px 16px 10px;
  padding-top: calc(14px + var(--safe-top));
  border-bottom: 1px solid var(--border-soft);
  flex: none;
}
.pane-head h2 {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.pane-head .hint { font-size: 12px; color: var(--muted); }

.pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

/* 编辑区 */
.edit-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

.edit-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  padding-top: calc(10px + var(--safe-top));
  border-bottom: 1px solid var(--border-soft);
  flex: none;
  background: var(--bg);
  z-index: 2;
}
.edit-head .title {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
.edit-head .meta { font-size: 12px; color: var(--muted); white-space: nowrap; }

.edit-body {
  flex: 1;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- 文档条目 */

.doc-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  transition: background 0.13s;
  border: 1px solid transparent;
}
.doc-item:hover { background: var(--panel-2); }
.doc-item.active {
  background: var(--panel-2);
  border-color: var(--accent);
}
.doc-item .row1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.doc-item .t {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-item .d {
  font-size: 11.5px;
  color: var(--muted);
  flex: none;
  font-variant-numeric: tabular-nums;
}
.doc-item .row2 {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.doc-item .tags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }

.lock-badge, .shared-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--muted);
  flex: none;
  line-height: 1.6;
}
.shared-badge { color: var(--accent); border-color: var(--accent-soft); }

.tag-pill {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--panel-2);
  color: var(--text-dim);
  border: 1px solid var(--border-soft);
  transition: background 0.13s;
}
.tag-pill:hover { background: var(--accent-soft); color: var(--text); }

/* ---------------------------------------------------------------- 编辑器 */

.editor-wrap {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}
.editor-wrap.single { grid-template-columns: 1fr; }

.editor-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border-soft);
}

#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 22px 26px 120px;
  font-family: var(--mono);
  font-size: calc(var(--read-font-size, 15px) - 0.5px);
  line-height: var(--read-line-height, 1.85);
  tab-size: 2;
  overflow-y: auto;
  min-height: 0;
}
#editor::placeholder { color: var(--muted); opacity: 0.7; }

.preview {
  overflow-y: auto;
  padding: 22px 26px 120px;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-soft);
  flex: none;
  flex-wrap: wrap;
  background: var(--bg);
}
.tool-btn {
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  min-width: 30px;
  text-align: center;
}
.tool-btn:hover { background: var(--panel-2); color: var(--text); }
.tool-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

.status-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 26px calc(6px + var(--safe-bottom));
  font-size: 11.5px;
  color: var(--muted);
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.status-bar .spacer { flex: 1; }
.status-bar .saved { color: var(--green); }
.status-bar .dirty { color: var(--amber); }

/* ---------------------------------------------------------------- Markdown */

.md {
  font-size: var(--read-font-size, 15px);
  line-height: var(--read-line-height, 1.8);
  font-family: var(--read-font, var(--font));
  word-wrap: break-word;
}
.md > *:first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 1.4em 0 0.5em;
  line-height: 1.35;
  font-weight: 600;
}
.md h1 { font-size: 1.6em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border-soft); }
.md h2 { font-size: 1.32em; padding-bottom: 0.2em; border-bottom: 1px solid var(--border-soft); }
.md h3 { font-size: 1.14em; }
.md h4 { font-size: 1em; color: var(--text-dim); }
.md p { margin: 0.7em 0; }
.md ul, .md ol { margin: 0.7em 0; padding-left: 1.5em; }
.md li { margin: 0.28em 0; }
.md li::marker { color: var(--muted); }
.md blockquote {
  margin: 0.9em 0;
  padding: 0.4em 1em;
  border-left: 3px solid var(--accent-soft);
  background: var(--panel);
  border-radius: 0 6px 6px 0;
  color: var(--text-dim);
}
.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--panel-2);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--pink);
}
.md pre {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 1em 0;
}
.md pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md img { max-width: 100%; border-radius: var(--radius-sm); }
.md table { border-collapse: collapse; margin: 1em 0; font-size: 0.94em; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 11px; }
.md th { background: var(--panel-2); font-weight: 600; }
.md a { text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.md a:hover { border-bottom-color: var(--accent); }

.wikilink {
  color: var(--accent);
  border-bottom: 1px dashed var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.wikilink:hover { border-bottom-style: solid; }
.wikilink.missing { color: var(--muted); border-bottom-color: var(--muted); }
.wikilink.denied { color: var(--muted); border-bottom: 1px dotted var(--muted); cursor: not-allowed; }

.hash-tag {
  color: var(--accent);
  background: var(--accent-glow);
  padding: 0.05em 0.45em;
  border-radius: 20px;
  font-size: 0.9em;
  cursor: pointer;
  text-decoration: none;
}

.md .task-done { color: var(--muted); text-decoration: line-through; }

/* ---------------------------------------------------------------- 日历 */

.calendar { padding: 4px 8px 20px; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0 8px;
}
.cal-day {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12.5px;
  color: var(--text-dim);
  transition: background 0.13s, border-color 0.13s;
  position: relative;
  padding: 2px;
}
.cal-day:hover { background: var(--border-soft); }
.cal-day.empty { background: transparent; pointer-events: none; }
.cal-day.today { border-color: var(--accent); color: var(--text); font-weight: 600; }
.cal-day.has-doc { background: var(--accent-soft); color: var(--text); }
.cal-day.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day .dots { display: flex; gap: 2px; height: 4px; }
.cal-day .dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  display: block;
}
.cal-month-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 12px;
  font-size: 14px;
  font-weight: 600;
}
.cal-legend {
  display: flex;
  gap: 14px;
  font-size: 11.5px;
  color: var(--muted);
  padding: 12px 4px 0;
  flex-wrap: wrap;
}
.cal-legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

/* ---------------------------------------------------------------- 通用小组件 */

.section-title {
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 14px 12px 6px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 13.5px;
  line-height: 1.9;
}
.empty svg { opacity: 0.35; margin-bottom: 12px; }

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.22s ease;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.toast.warn { border-left-color: var(--amber); }
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
.toast .close { color: var(--muted); margin-left: auto; flex: none; }

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* 冲突提示条 */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: rgba(255, 196, 107, 0.12);
  border-bottom: 1px solid rgba(255, 196, 107, 0.3);
  font-size: 13px;
  color: var(--amber);
  flex: none;
  flex-wrap: wrap;
}
.banner .grow { flex: 1; min-width: 140px; }

/* 搜索 */
.search-box { position: relative; }
.search-box input { padding-left: 32px; }
.search-box .ico {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.hit-snippet {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hit-snippet mark {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
}

/* 图谱 */
.graph-wrap { flex: 1; position: relative; min-height: 0; }
#graph { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#graph:active { cursor: grabbing; }

/* 设置 */
.settings { padding: 10px 16px 60px; max-width: 620px; }
.settings h3 {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 26px 0 10px;
  text-transform: uppercase;
}
.settings .row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
}
.settings .row .grow { flex: 1; min-width: 0; }
.settings .row .desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

.switch {
  width: 42px;
  height: 24px;
  border-radius: 20px;
  background: var(--border);
  position: relative;
  transition: background 0.18s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

.device-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border-soft);
}
.device-row .name { flex: 1; }
.device-row .when { font-size: 11.5px; color: var(--muted); }

/* 阅读设置控件 */
.range {
  width: 108px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}
.range-val {
  font-size: 12px;
  color: var(--muted);
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  flex: none;
}
.select-sm {
  width: auto;
  min-width: 100px;
  padding: 5px 8px;
  font-size: 13px;
  flex: none;
}
.accent-picker {
  display: flex;
  gap: 6px;
  flex: none;
}
.accent-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 0;
  transition: transform 0.12s, border-color 0.12s;
}
.accent-dot:hover { transform: scale(1.14); }
.accent-dot.on { border-color: var(--text); }

/* 白名单 HTML 的内联排版 */
.md span[style],
.md div[align] {
  /* 让用户在 Markdown 里写的内联样式生效，但不影响布局 */
  display: inline;
}
.md div[align] { display: block; }

/* ---------------------------------------------------------------- 手机端 */

.mobile-tabs { display: none; }

@media (max-width: 1080px) {
  .shell { grid-template-columns: 200px 1fr; }
  .list-pane.overlay { display: none; }
}

@media (max-width: 760px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .nav { display: none; }
  .list-pane {
    border-right: none;
    padding-bottom: calc(64px + var(--safe-bottom));
  }
  .edit-pane {
    position: fixed;
    inset: 0;
    z-index: 30;
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .edit-pane.open { transform: translateX(0); }

  .mobile-tabs {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--bg-elev);
    border-top: 1px solid var(--border-soft);
    padding-bottom: var(--safe-bottom);
  }
  .mobile-tabs button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 0 7px;
    font-size: 10.5px;
    color: var(--muted);
  }
  .mobile-tabs button.active { color: var(--accent); }
  .mobile-tabs .ico { display: block; }

  .editor-wrap { grid-template-columns: 1fr; }
  .editor-area { border-right: none; }
  .preview { display: none; }
  .editor-wrap.show-preview .editor-area { display: none; }
  .editor-wrap.show-preview .preview { display: block; }

  #editor { padding: 16px 18px 120px; font-size: 15px; }
  .preview { padding: 16px 18px 120px; }
  .edit-head { padding: 8px 12px; padding-top: calc(8px + var(--safe-top)); }
  .toast-stack { bottom: calc(78px + var(--safe-bottom)); }
  .range { width: 84px; }
  .accent-dot { width: 20px; height: 20px; }
}

@media (min-width: 761px) {
  .back-btn { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------- 图片排版面板 */

:root { --cover-mask: rgba(13, 19, 31, 0.86); }
[data-theme="light"] { --cover-mask: rgba(245, 247, 251, 0.88); }

.preview img {
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.15s;
}
.preview img:hover { outline-color: var(--accent); }

.img-panel {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(430px, calc(100vw - 28px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 16px 14px;
  z-index: 90;
  font-size: 13px;
}
.ip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 6px;
}
.ip-x { color: var(--muted); padding: 2px 8px; border-radius: 6px; }
.ip-x:hover { background: var(--panel-2); color: var(--text); }
.ip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.ip-row label {
  width: 46px;
  flex: none;
  color: var(--muted);
  font-size: 12px;
}
.ip-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}
.ip-val {
  width: 42px;
  flex: none;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ip-seg { display: flex; gap: 4px; flex: 1; }
.ip-seg button {
  flex: 1;
  padding: 5px 0;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.ip-seg button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.ip-actions { display: flex; gap: 8px; margin-top: 10px; }

@media (max-width: 760px) {
  .img-panel { bottom: calc(80px + var(--safe-bottom)); }
}

/* ---------------------------------------------------------------- 图文混排编辑器 */

/* 单栏：编辑区里直接看图，不再分屏 */
.editor-wrap { grid-template-columns: 1fr !important; }
.preview { display: none !important; }
.editor-area { border-right: none !important; }

#editor.rich-editor {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
  outline: none;
}
#editor.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}
#editor.rich-editor > div,
#editor.rich-editor > p {
  margin: 0.7em 0;
}
#editor.rich-editor > div:empty,
#editor.rich-editor > p:empty {
  min-height: 1.8em;
}
#editor.rich-editor img {
  cursor: pointer;
  max-width: 100%;
  vertical-align: middle;
  transition: outline-color 0.15s;
  outline: 2px solid transparent;
  outline-offset: 2px;
}
#editor.rich-editor img:hover { outline-color: var(--accent); }

/* 浮动图片后面自动清浮动，避免布局塌掉 */
#editor.rich-editor::after {
  content: '';
  display: block;
  clear: both;
}

/* ---------------------------------------------------------------- 背景层与相框 */

.editor-host {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.editor-host > #editor {
  position: relative;
  height: 100%;
  z-index: 1;
}
.bg-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--cover-mask, rgba(13, 19, 31, 0.55));
  pointer-events: none;
}
.bg-img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center;
  max-width: none;
  max-height: none;
  will-change: transform;
  transition: opacity 0.15s;
}

/* 相框 */
.bg-img.frame-thin { border: 3px solid rgba(255, 255, 255, 0.45); }
.bg-img.frame-double { border: 7px double rgba(255, 255, 255, 0.6); }
.bg-img.frame-wood {
  border: 16px solid #6b4a2f;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.55);
}
.bg-img.frame-polaroid {
  border: 18px solid #f7f5f0;
  border-bottom-width: 56px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}
.bg-img.frame-film {
  border: 20px solid #101010;
  box-shadow: inset 0 0 0 2px #2a2a2a;
}
.bg-img.frame-ornate {
  border: 12px solid #c9a227;
  box-shadow: 0 0 0 3px #c9a227, inset 0 0 0 2px rgba(0, 0, 0, 0.45);
}

/* 相框选择按钮 */
.ip-frames {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0 2px;
}
.ip-frames button {
  padding: 4px 11px;
  border-radius: 20px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}
.ip-frames button.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="light"] { --cover-mask: rgba(245, 247, 251, 0.62); }

/* ---------------------------------------------------------------- 手机手势防误触 */

/* 正文区只接受纵向滚动，横向手势交还给浏览器前先吃掉，避免误触侧滑返回 */
#editor.rich-editor {
  touch-action: pan-y pinch-zoom;
  overscroll-behavior: contain;
}
.editor-host,
.editor-area,
.edit-pane,
.edit-body {
  overscroll-behavior: contain;
}
@media (max-width: 760px) {
  .edit-pane {
    overscroll-behavior: none;
    -webkit-user-select: text;
    user-select: text;
  }
  /* 顶栏左右留白，减少从边缘起手的返回手势 */
  .edit-head { padding-left: 16px; padding-right: 14px; }
}
