
:root {
  --bg: #f6f5f2; --panel: #efede8; --paper: #ffffff; --text: #1f2328; --muted: #6b6f76;
  --line: #e2dfd8; --hover: #e7e4de; --accent: #3a6ee0; --accent-soft: #e3ebfc; --danger: #cc3b3b;
  --ink-auto: #1f2328; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161719; --panel: #1c1d20; --paper: #222326; --text: #e8e7e3; --muted: #9a9ca1;
    --line: #313337; --hover: #2a2c30; --accent: #7aa2ff; --accent-soft: #28324d; --danger: #ff6b6b;
    --ink-auto: #ececea; --shadow: 0 0 0 1px #2c2e32;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
.icon { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: 8px; }
.icon:not(:disabled):hover { background: var(--hover); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.on { background: var(--accent-soft); color: var(--accent); }
.link { color: var(--accent); padding: 2px 4px; border-radius: 4px; }
.link:hover { text-decoration: underline; }
.primary { background: var(--accent); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 600; }
.primary:hover { filter: brightness(1.08); }

/* ---------- welcome ---------- */
.welcome { height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--paper); box-shadow: var(--shadow); border-radius: 16px; padding: 36px; max-width: 420px; text-align: center; display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 24px; }
.card p { margin: 0 0 8px; color: var(--muted); line-height: 1.5; }
.card code { font-size: 12.5px; }
.logo { font-size: 36px; }

/* ---------- layout ---------- */
.app { height: 100%; display: grid; grid-template-columns: 270px 1fr; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px 16px; font-size: 15px; }
.side-head .icon { font-size: 20px; }
.where { display: flex; align-items: center; gap: 4px; padding: 0 12px 8px 16px; color: var(--muted); font-size: 12px; min-width: 0; }
.where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#search { margin: 0 12px 8px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--text); font: inherit; outline: none; }
#search:focus { border-color: var(--accent); }
.list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.item { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.item:hover { background: var(--hover); }
.item.active { background: var(--paper); box-shadow: var(--shadow); }
.item b { display: flex; gap: 6px; align-items: center; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.item b .t { overflow: hidden; text-overflow: ellipsis; }
.item b .ink-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.item .snip { color: var(--muted); font-size: 12.5px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-top: 2px; }
.item .when { color: var(--muted); font-size: 11px; margin-top: 3px; opacity: .8; }
.empty-list { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 13px; }
.side-foot { border-top: 1px solid var(--line); padding: 8px 12px; display: flex; gap: 8px; font-size: 12.5px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { padding: 5px 12px; border-radius: 7px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--paper); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 6px; }
.spacer { flex: 1; }
.swatches { display: inline-flex; gap: 4px; margin: 0 4px; }
.sw { width: 20px; height: 20px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); }
.sw.on { border-color: var(--paper); box-shadow: 0 0 0 2px var(--accent); }
.sw.auto { background: conic-gradient(var(--ink-auto) 0 50%, var(--paper) 0 100%); }
#width { width: 90px; accent-color: var(--accent); }
.status { color: var(--muted); font-size: 12px; margin-right: 6px; }
.status.err { color: var(--danger); }
.danger:hover { color: var(--danger); }

/* ---------- the page ---------- */
.scroller { flex: 1; overflow: auto; padding: 28px 24px 0; }
.page {
  position: relative; width: 760px; margin: 0 auto; background: var(--paper);
  border-radius: 12px 12px 0 0; box-shadow: var(--shadow); padding: 44px 56px 0;
  transition: box-shadow .15s;
}
body.draw .page { box-shadow: var(--shadow), 0 0 0 2px var(--accent); }
.title { width: 100%; border: 0; outline: none; background: transparent; color: var(--text); font-family: inherit; font-size: 28px; font-weight: 700; line-height: 1.3; padding: 0; margin: 0 0 14px; }
.text {
  display: block; width: 100%; border: 0; outline: none; resize: none; overflow: hidden;
  background: transparent; color: var(--text); padding: 0; margin: 0;
  font: 17px/1.75 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.title::placeholder, .text::placeholder { color: var(--muted); opacity: .6; }
canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.live { touch-action: none; }
body.draw .live { pointer-events: auto; cursor: crosshair; }
body.draw.eraser .live { cursor: none; }
body.draw .text, body.draw .title { user-select: none; -webkit-user-select: none; }
.empty-main { flex: 1; display: grid; place-items: center; color: var(--muted); }

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 38% 62%; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .scroller { padding: 12px 0 0; }
}
