:root {
  --bg: #0c0c10; --surface: #16161d; --surface-2: #1d1d26;
  --ink: #ececf4; --muted: #8a8a9a; --accent: #7b68c8; --border: #262633;
  --danger: #c85b5b; --warn: #d99a3a; --ok: #5bae7b;
}
[data-theme="paper"] {
  --bg: #f5f2ea; --surface: #fffdf7; --surface-2: #efe9dd;
  --ink: #1b1a18; --muted: #6f6a5e; --accent: #5b4a9e; --border: #ddd5c6;
  --danger: #a33c3c; --warn: #a9762a; --ok: #3f7d55;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; line-height: 1.5;
  transition: background 0.3s ease, color 0.3s ease;
}
a { color: var(--accent); }
.hidden { display: none !important; }

/* Intro */
#intro { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 50; overflow: hidden; }
#intro .mock {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 24px clamp(16px, 4vw, 40px) 40px;
  overflow: hidden;
  filter: blur(14px) saturate(1.05);
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
  transform: scale(1.06);
}
#intro .mock-topbar {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; max-width: 1280px; padding: 12px 18px;
  border-bottom: 1px solid var(--border); margin-bottom: 20px;
}
#intro .mock-brand { font-weight: 700; font-size: 1.05rem; }
#intro .mock-brand span { color: var(--accent); }
#intro .mock-ava {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--border);
}
#intro .mock-composer {
  display: flex; gap: 10px; align-items: center;
  width: 100%; max-width: 1280px; margin-bottom: 16px;
}
#intro .mock-input {
  flex: 1; padding: 11px 14px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 0.9rem;
}
#intro .mock-add {
  padding: 11px 18px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 0.9rem; font-weight: 500;
}
#intro .mock-chips {
  display: flex; gap: 8px; flex-wrap: wrap;
  width: 100%; max-width: 1280px; margin-bottom: 18px;
}
#intro .mock-chip {
  padding: 5px 12px; border-radius: 20px; font-size: 0.8rem;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
#intro .mock-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
#intro .mock-feed {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; max-width: 1280px;
}
#intro .mock-note {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
#intro .mock-t { font-size: 0.9rem; color: var(--ink); line-height: 1.45; }
#intro .mock-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 0; }
#intro .mock-tags span { font-size: 0.76rem; color: var(--accent); }
#intro .mock-todo { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
#intro .mock-todo.done { color: var(--muted); text-decoration: line-through; }
#intro .mock-meta { font-size: 0.74rem; color: var(--muted); margin-top: 8px; }
#intro .panel {
  position: relative; z-index: 1; text-align: center;
  max-width: 420px; padding: 40px 32px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  border: 1px solid var(--border); border-radius: 18px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
#intro h1 { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 10px; }
#intro h1 span { color: var(--accent); }
#intro .tagline { color: var(--muted); font-size: 0.98rem; margin-bottom: 6px; }
#intro .desc { color: var(--muted); font-size: 0.86rem; line-height: 1.5; margin-bottom: 26px; }

/* Buttons */
.btn {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px; cursor: pointer; font-size: 0.9rem;
  font-weight: 500; transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border: none; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Gate panels */
#gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 40; }
.gate-card {
  width: 100%; max-width: 400px; margin: 20px; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 30px 28px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.3);
}
.gate-card h1 { font-size: 1.25rem; margin-bottom: 8px; text-align: center; }
.gate-card h1 span { color: var(--accent); }
.gate-card .sub { color: var(--muted); font-size: 0.88rem; margin-bottom: 20px; text-align: center; }
.field { display: block; margin-bottom: 14px; }
.field span.lbl { display: block; color: var(--muted); font-size: 0.8rem; margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  font-size: 0.95rem; outline: none; font-family: inherit;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.codeinput {
  width: 100%; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 12px;
  font-size: 1.05rem; text-align: center; letter-spacing: 3px; text-transform: uppercase;
  outline: none;
}
.codeinput:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 0.8rem; min-height: 1.2em; margin-top: 8px; text-align: center; }
.hint { color: var(--muted); font-size: 0.78rem; line-height: 1.45; margin: 10px 0 0; }
.muted-center { text-align: center; color: var(--muted); font-size: 0.82rem; margin-top: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.78rem; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.row-inline { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); cursor: pointer; }

/* Topbar */
header.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.brand { font-weight: 700; letter-spacing: 0.04em; font-size: 1.05rem; }
.brand span { color: var(--accent); }
.tb-actions { display: flex; gap: 8px; align-items: center; position: relative; }
.btn.icon-btn-top { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; }
.btn.icon-btn-top:hover { border-color: var(--danger); color: var(--danger); }
.btn.icon-btn-top .ic { width: 18px; height: 18px; }
.user-chip { color: var(--muted); font-size: 0.8rem; margin-right: 4px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 0.85rem;
  background-size: cover; background-position: center; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.avatar.preview { width: 56px; height: 56px; font-size: 1.3rem; cursor: default; flex-shrink: 0; }
.menu {
  position: absolute; right: 0; top: 44px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; min-width: 160px; padding: 6px; display: none; z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.menu.open { display: block; }
.menu button {
  display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--ink); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 0.88rem;
}
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }

/* App main */
main.app { max-width: 720px; margin: 0 auto; padding: 18px 20px 40px; }
.status { font-size: 0.78rem; color: var(--muted); text-align: center; margin-bottom: 12px; min-height: 1.2em; white-space: pre-line; }
.composer { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.composer input {
  flex: 1; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px; padding: 13px 14px; font-size: 0.95rem; outline: none;
}
.composer input:focus { border-color: var(--accent); }
.composer button.primary { padding: 13px 20px; border-radius: 10px; font-weight: 600; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; min-width: 140px; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 0.88rem; outline: none; }
.search:focus { border-color: var(--accent); }

/* Chips + feed */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 999px; padding: 4px 12px;
  font-size: 0.8rem; cursor: pointer; transition: 0.15s;
}
.chip.active { color: var(--ink); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
.feed { display: flex; flex-direction: column; gap: 12px; }
.note {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 18px; position: relative;
}
.note .t { font-weight: 500; margin-bottom: 4px; white-space: pre-wrap; word-break: break-word; }
.note .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.note .tag { color: var(--accent); font-size: 0.75rem; }
.note .links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.note .link { color: var(--accent); font-size: 0.78rem; text-decoration: none; }
.note .todo { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.note .todo.done { text-decoration: line-through; opacity: 0.6; }
.note .meta { color: var(--muted); font-size: 0.75rem; margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.note .src { display: inline-block; font-size: 0.65rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.note .actions { display: flex; flex-direction: column; gap: 6px; position: absolute; top: 12px; right: 12px; }
.note .icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.9rem; opacity: 0.5; line-height: 1; padding: 2px; }
.note .icon-btn:hover { opacity: 1; color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 44px 0; }

/* Settings */
.page-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.page-panel h2 { font-size: 0.95rem; margin-bottom: 14px; }
.setting-row { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 0; font-size: 0.88rem; }
.setting-row.right { flex-direction: row; justify-content: flex-end; }
.setting-row.center { justify-content: center; }
.setting-row .l { color: var(--muted); font-size: 0.8rem; font-weight: 500; letter-spacing: 0.01em; }
.setting-row input[type=text], .setting-row input[type=email], .setting-row input[type=password] {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 0.92rem; width: 100%; box-sizing: border-box; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.setting-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.setting-row input[disabled] { opacity: 0.7; cursor: not-allowed; }
.setting-row .row-inline { display: flex; align-items: center; gap: 8px; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--ink); }
.btn.ghost:hover { background: var(--surface-2); }
.readonly { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 0.82rem; color: var(--muted); word-break: break-all; }
.usage-note { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; padding: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 0.82rem; line-height: 1.45; }
.usage-row { display: flex; gap: 10px; align-items: flex-start; }
.usage-row .usage-k { flex: 0 0 72px; color: var(--accent); font-weight: 600; }
.usage-row .usage-v { color: var(--muted); }
.usage-row code { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; font-size: 0.78rem; }
.tglink { color: var(--accent); text-decoration: none; font-weight: 600; }
.tglink:hover { text-decoration: underline; }
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; cursor: pointer; transition: 0.2s; }
.switch .slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: var(--muted); border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }
.txn { border-bottom: 1px solid var(--border); padding: 8px 0; font-size: 0.82rem; }
.txn:last-child { border-bottom: none; }
.txn .who { color: var(--accent); }
.txn .when { color: var(--muted); font-size: 0.7rem; }

/* ---- Grid view (drag-and-drop arrange) ---- */
.feed.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; align-items: start; }
.feed.grid .note { cursor: grab; }
.feed.grid .note:active { cursor: grabbing; }
.feed.grid .note.dragging { opacity: 0.45; outline: 2px dashed var(--accent); outline-offset: 3px; }
.feed.grid .note .actions { flex-direction: row; top: auto; right: auto; position: static; margin-top: 10px; justify-content: flex-end; }

/* ---- Board view (columns by tag) ---- */
.feed.board { display: flex; gap: 14px; overflow-x: auto; align-items: flex-start; padding-bottom: 8px; }
.feed.board .board-col { flex: 0 0 260px; max-width: 260px; }
.feed.board .board-col h3 { font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; padding: 0 2px; }
.feed.board .board-col .note { margin-bottom: 10px; }
.feed.board .note .actions { flex-direction: row; top: auto; right: auto; position: static; margin-top: 10px; justify-content: flex-end; }

/* ---- Inline edit ---- */
.inline-edit {
  width: 100%; background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--accent); border-radius: 8px; padding: 10px 12px;
  font-size: 0.92rem; font-family: inherit; line-height: 1.45; outline: none;
  resize: vertical; min-height: 60px; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ---- Field types ---- */
.note .pinflag { margin-right: 6px; font-size: 0.8rem; }
.note-img { width: 100%; border-radius: 8px; margin: 8px 0 2px; display: block; border: 1px solid var(--border); }
.note .reminder { color: var(--warn); font-size: 0.75rem; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.note .todos { margin-top: 8px; }
.note .todo input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; flex-shrink: 0; }
.note.type-list .t::after { content: ""; display: block; height: 1px; background: var(--border); margin-top: 6px; }
.note.type-link .t::before { content: "🔗 "; }
.note.type-reminder .t::before { content: "⏰ "; }
.note.type-image .t::before { content: "🖼 "; }

/* ---- Help modal (shared with any .modal) ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 60;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  width: 100%; max-width: 620px; max-height: 82vh; overflow-y: auto;
  margin: 20px; padding: 26px 28px; box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.modal-card h2 { font-size: 1.2rem; margin-bottom: 4px; }
.modal-card h2 span { color: var(--accent); }
.modal-card .modal-sub { color: var(--muted); font-size: 0.82rem; margin-bottom: 18px; }
.modal-card h3 { font-size: 0.85rem; margin: 18px 0 6px; color: var(--accent); }
.modal-card p, .modal-card li { color: var(--muted); font-size: 0.84rem; line-height: 1.5; }
.modal-card ul { padding-left: 18px; margin: 6px 0; }
.modal-card code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: 0.78rem; }
.modal-card kbd { background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-size: 0.74rem; font-family: inherit; }
.modal-close { margin-top: 20px; }

/* ---- Settings icons + connection types ---- */
.setting-row .setting-icon { width: 18px; height: 18px; flex-shrink: 0; margin-right: 2px; vertical-align: -3px; opacity: 0.8; }
.conn-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; color: var(--muted); padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.conn-badge svg { width: 14px; height: 14px; }
.view-toggle { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 3px; }
.view-toggle button { background: none; border: none; color: var(--muted); padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 0.82rem; }
.view-toggle button.active { background: var(--accent); color: #fff; }


/* ---- Composer field-type picker ---- */
.type-pick { display: inline-flex; gap: 3px; }
.type-pick button { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 0.85rem; line-height: 1; padding: 0; }
.type-pick button:hover { border-color: var(--accent); }
.type-pick button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- Small connection icons ---- */
.conn-i { width: 13px; height: 13px; flex-shrink: 0; vertical-align: -2px; opacity: 0.85; }
.conn-badge svg { width: 13px; height: 13px; }

/* ---- Small buttons ---- */
.btn.sm { padding: 6px 12px; font-size: 0.78rem; border-radius: 7px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---- Trash modal ---- */
.trash-card { max-height: 80vh; display: flex; flex-direction: column; }
.trash-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.trash-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.trash-body { font-size: 0.9rem; color: var(--ink); line-height: 1.45; white-space: pre-wrap; word-break: break-word; margin-bottom: 6px; }
.trash-meta { font-size: 0.74rem; color: var(--muted); margin-bottom: 8px; }
.trash-actions { display: flex; gap: 8px; }
.trash-card > .trash-actions { justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--border); }
