:root {
  --bg: #f4f1e8; --panel: #fffdf8; --ink: #1d221f; --muted: #6b716d; --line: #e2ddd0;
  --accent: #1f5c4e; --accent-ink: #f4f1e8; --code: #b83b3b; --code-bg: #f1ece1;
  --callout: #ede8dc; --shadow: 0 1px 2px rgba(0,0,0,.08);
  --c-gray:#6b716d; --c-brown:#8a5a3b; --c-orange:#c96a1b; --c-yellow:#9a7b0a; --c-green:#2f7d4a;
  --c-blue:#2a63b3; --c-purple:#6d47b8; --c-pink:#b53d7c; --c-red:#c23b3b;
  --bg-gray:#ebe9e4; --bg-brown:#efe3da; --bg-orange:#fbe8d3; --bg-yellow:#fbf1c9; --bg-green:#ddefe1;
  --bg-blue:#dde8f8; --bg-purple:#e8e0f7; --bg-pink:#f7dfea; --bg-red:#f8dcdc;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101614; --panel: #18201d; --ink: #e7e4dc; --muted: #9aa39e; --line: #2a332f;
    --accent: #6fbfa5; --accent-ink: #0f1a16; --code: #ff8a80; --code-bg: #22302b;
    --callout: #1f2a26; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --c-gray:#a2a8a4; --c-brown:#d2a07f; --c-orange:#f0a35b; --c-yellow:#e2c25a; --c-green:#7fd19c;
    --c-blue:#86b3f0; --c-purple:#b79cf0; --c-pink:#f08cc1; --c-red:#f08080;
    --bg-gray:#27302c; --bg-brown:#3a2d25; --bg-orange:#3f2d1c; --bg-yellow:#3d3517; --bg-green:#1e3a2a;
    --bg-blue:#1f2d45; --bg-purple:#2d2543; --bg-pink:#40233a; --bg-red:#432121;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-wrap: anywhere; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
#app { display: flex; flex-direction: column; height: 100%; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--accent); color: var(--accent-ink);
  padding: calc(var(--sat) + 8px) 8px 8px; display: flex; align-items: center; gap: 6px; min-height: 48px; }
.topbar .ttl { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn { color: inherit; padding: 6px 8px; border-radius: 8px; font-size: 15px; min-width: 36px; text-align: center; }
.topbar .btn:active, .topbar .btn.on { background: rgba(255,255,255,.18); }
.topbar .dot { width: 8px; height: 8px; border-radius: 50%; background: #9ee0c3; margin-right: 4px; }
.topbar .dot.off { background: #f0a35b; }
.progress { height: 3px; background: var(--line); }
.progress .bar { height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* main */
/* tablets / desktop: keep lines readable by centring a 900px column */
.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px max(14px, calc((100% - 900px) / 2)) calc(var(--sab) + 32px); }
.topbar { padding-left: max(8px, calc((100% - 900px) / 2)); padding-right: max(8px, calc((100% - 900px) / 2)); }
@media (min-width: 700px) { html, body { font-size: 17px; } .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.boot { color: var(--muted); padding: 40px 0; text-align: center; }
.search { display: block; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); margin-bottom: 12px; font-size: 16px; }
.section { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); display: block; color: inherit; }
.card .ic { font-size: 20px; }
.card .nm { font-weight: 600; margin-top: 2px; }
.card .ct { font-size: 12px; color: var(--muted); }
.card.sub { opacity: .85; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); color: inherit; }
.row:last-child { border-bottom: 0; }
.row .ic { width: 24px; text-align: center; flex: none; }
.row .tx { flex: 1; min-width: 0; }
.row .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .m { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.row .snip { font-size: 13px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .snip mark, .t mark { background: var(--bg-yellow); color: inherit; border-radius: 3px; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--bg-gray); color: var(--ink); white-space: nowrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 4px; }
.chips .chip { border: 1px solid var(--line); background: var(--panel); }
.chips .chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.more { display: block; width: 100%; padding: 12px; text-align: center; color: var(--accent); }
.foot { margin-top: 24px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.8; }
.foot button { color: var(--accent); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0; }

/* page */
.page h1.title { font-size: 24px; line-height: 1.25; margin: 4px 0 6px; }
.page .meta { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.props { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; margin-bottom: 16px; }
.props summary { cursor: pointer; padding: 6px 0; color: var(--muted); font-size: 13px; }
.prop { display: grid; grid-template-columns: minmax(80px, 30%) 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.prop.wide { grid-template-columns: 1fr; }
.prop .k { color: var(--muted); }
.prop .v .chip { margin: 1px 3px 1px 0; }
.body { font-size: 16px; }
.body p { margin: 0 0 8px; }
.body h1, .body h2, .body h3 { line-height: 1.3; margin: 22px 0 8px; }
.body h1 { font-size: 22px; } .body h2 { font-size: 20px; } .body h3 { font-size: 17px; }
.body ul, .body ol { margin: 0 0 8px; padding-left: 22px; }
.body li { margin: 2px 0; }
.body li.todo { list-style: none; margin-left: -22px; display: flex; gap: 8px; align-items: flex-start; }
.body li.todo input { margin-top: 5px; flex: none; }
.body li.todo.done > .tx { color: var(--muted); text-decoration: line-through; }
/* nesting = indentation only (no guide lines, per user preference) */
.body .kids { margin: 2px 0 8px 0; padding-left: 22px; }
.body li > .kids { padding-left: 4px; }
.body .callout { display: flex; gap: 10px; background: var(--callout); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.body .callout .ic { flex: none; font-size: 18px; }
.body .callout .tx > p:last-child { margin-bottom: 0; }
.body details { margin: 4px 0 8px; }
.body details > summary { cursor: pointer; list-style: none; position: relative; padding-left: 18px; }
.body details > summary::before { content: "▸"; position: absolute; left: 2px; color: var(--muted); }
.body details[open] > summary::before { content: "▾"; }
.body details > summary h1, .body details > summary h2, .body details > summary h3 { display: inline; margin: 0; }
.body details > .kids { margin-left: 8px; }
.body blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--accent); color: var(--ink); }
.body pre { background: var(--code-bg); border-radius: 10px; padding: 10px 12px; margin: 8px 0; overflow-x: auto;
  font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.body pre .lang { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; }
.body code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.body p code, .body li code, .body .callout code, .body td code, .body summary code, .props code, .row code
  { color: var(--code); background: var(--code-bg); border-radius: 4px; padding: 0 4px; font-size: 0.92em; }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.body .tbl { overflow-x: auto; margin: 8px 0; }
.body table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.body th, .body td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
.body th { background: var(--bg-gray); font-weight: 600; }
.body img { max-width: 100%; height: auto; border-radius: 8px; display: block; margin: 8px 0; }
.body .cap { font-size: 13px; color: var(--muted); margin: -4px 0 10px; }
.body .file, .body .bookmark, .body .childpage, .body .childdb { display: flex; gap: 8px; align-items: center; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin: 6px 0; font-size: 14px; color: inherit; }
.body .file .nm, .body .bookmark .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.body .file small { color: var(--muted); }
.body .eq { font-family: ui-monospace, Menlo, monospace; background: var(--code-bg); border-radius: 4px; padding: 0 4px; font-size: .92em; }
.body .eqblock { font-family: ui-monospace, Menlo, monospace; background: var(--code-bg); border-radius: 8px; padding: 8px 12px; margin: 8px 0; overflow-x: auto; }
.body .colored { border-radius: 6px; padding: 2px 6px; }
.body a.ext::after { content: "↗"; font-size: .8em; margin-left: 2px; }
s { color: var(--muted); }
.c-gray{color:var(--c-gray)} .c-brown{color:var(--c-brown)} .c-orange{color:var(--c-orange)} .c-yellow{color:var(--c-yellow)}
.c-green{color:var(--c-green)} .c-blue{color:var(--c-blue)} .c-purple{color:var(--c-purple)} .c-pink{color:var(--c-pink)} .c-red{color:var(--c-red)}
.bg-gray{background:var(--bg-gray)} .bg-brown{background:var(--bg-brown)} .bg-orange{background:var(--bg-orange)} .bg-yellow{background:var(--bg-yellow)}
.bg-green{background:var(--bg-green)} .bg-blue{background:var(--bg-blue)} .bg-purple{background:var(--bg-purple)} .bg-pink{background:var(--bg-pink)} .bg-red{background:var(--bg-red)}
.bg-default{background:var(--bg-gray)}
.chip.bg-gray{color:var(--c-gray)} .chip.bg-green{color:var(--c-green)} .chip.bg-blue{color:var(--c-blue)} .chip.bg-red{color:var(--c-red)}
.chip.bg-orange{color:var(--c-orange)} .chip.bg-yellow{color:var(--c-yellow)} .chip.bg-purple{color:var(--c-purple)} .chip.bg-pink{color:var(--c-pink)} .chip.bg-brown{color:var(--c-brown)}
.pagefoot { margin: 28px 0 0; display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.pagefoot a, .pagefoot button { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }

/* edit mode */
.editing .blk { position: relative; border-radius: 6px; }
.editing .blk.editable { outline: 1px dashed var(--line); outline-offset: 2px; cursor: pointer; }
.editing .blk.editable:active { background: var(--bg-yellow); }
.editing .blk.locked { opacity: .7; }
.editing .ins { display: block; font-size: 12px; color: var(--muted); padding: 0 0 6px; }
.editing a.blk { flex-wrap: wrap; }
.editing a.blk .ins { flex-basis: 100%; padding: 4px 0 0; }
.editing .ins button { color: var(--accent); font-size: 13px; }
.blk.pending { box-shadow: inset 3px 0 0 var(--c-orange); padding-left: 6px; }
.blk.applied { box-shadow: inset 3px 0 0 var(--c-green); padding-left: 6px; }
.blk.conflict { box-shadow: inset 3px 0 0 var(--c-red); padding-left: 6px; }

/* bottom sheet editor */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; padding: 12px 14px calc(var(--sab) + 12px); box-shadow: 0 -4px 20px rgba(0,0,0,.18); max-height: 80vh; display: flex; flex-direction: column; gap: 8px; }
.sheet .hd { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sheet .hd .sp { flex: 1; }
.sheet textarea { width: 100%; min-height: 120px; max-height: 45vh; resize: vertical; padding: 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; line-height: 1.45; }
.sheet .act { display: flex; gap: 8px; justify-content: flex-end; }
.sheet .act button { padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); }
.sheet .act button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.sheet label.ck { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.sheet .help { font-size: 12px; color: var(--muted); }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 19; }

/* outbox */
.ob { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.ob .st { font-size: 12px; font-weight: 600; text-transform: uppercase; }
.ob .st.pending { color: var(--c-orange); } .ob .st.sent { color: var(--c-blue); } .ob .st.applied { color: var(--c-green); }
.ob .st.conflict, .ob .st.error { color: var(--c-red); }
.ob pre { white-space: pre-wrap; background: var(--code-bg); border-radius: 8px; padding: 6px 8px; font-size: 13px; margin: 6px 0; }
.ob .m { color: var(--muted); font-size: 12px; }
.ob button { color: var(--accent); font-size: 13px; margin-right: 10px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--sab) + 24px); transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; z-index: 30; box-shadow: var(--shadow); max-width: 90vw; }
.btnrow { display: flex; gap: 8px; margin: 8px 0 12px; flex-wrap: wrap; }
.btnrow button { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); }
.btnrow button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
