/* ============ Jot — clean & minimal ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #f7f6f3;
  --panel: #fdfdfc;
  --panel-2: #ffffff;
  --ink: #1f1e1b;
  --ink-2: #6f6a61;
  --ink-3: #a39d92;
  --line: #e9e6df;
  --line-2: #dedad1;
  --accent: #c07f10;
  --accent-ink: #94620b;
  --accent-soft: #f6edda;
  --accent-fold: #9a6a12;
  --pin: #e0a419;
  --danger: #c2482f;
  --sel: #efece4;
  --kbd-bg: #f1efe9;
  --shadow: 0 8px 30px rgba(30, 25, 10, .12);
  --mark: #fbe9b4;
  --code-bg: #f1efe9;
}
:root[data-theme="dark"] {
  --bg: #151412;
  --panel: #1c1b18;
  --panel-2: #211f1c;
  --ink: #eae7e1;
  --ink-2: #a09a8e;
  --ink-3: #6e695f;
  --line: #2b2925;
  --line-2: #38352f;
  --accent: #d9a032;
  --accent-ink: #e2b04e;
  --accent-soft: #2e2718;
  --accent-fold: #a87a1d;
  --pin: #d9a032;
  --danger: #e06a50;
  --sel: #2a2823;
  --kbd-bg: #262420;
  --shadow: 0 10px 34px rgba(0, 0, 0, .5);
  --mark: #5c4a14;
  --code-bg: #262420;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --panel: #1c1b18;
    --panel-2: #211f1c;
    --ink: #eae7e1;
    --ink-2: #a09a8e;
    --ink-3: #6e695f;
    --line: #2b2925;
    --line-2: #38352f;
    --accent: #d9a032;
    --accent-ink: #e2b04e;
    --accent-soft: #2e2718;
    --accent-fold: #a87a1d;
    --pin: #d9a032;
    --danger: #e06a50;
    --sel: #2a2823;
    --kbd-bg: #262420;
    --shadow: 0 10px 34px rgba(0, 0, 0, .5);
    --mark: #5c4a14;
    --code-bg: #262420;
  }
}

html, body { height: 100%; }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
kbd {
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--kbd-bg); border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 5px; padding: 3px 5px; color: var(--ink-2);
}
::selection { background: var(--accent-soft); }
::placeholder { color: var(--ink-3); }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 228px 300px 1fr;
  height: 100dvh;
  background: var(--bg);
}

/* ---------- sidebar ---------- */
.side {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  padding: 10px 10px 8px;
  min-width: 0;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; font-size: 16px; }
#collapseBtn { display: none; }

.nb-nav { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 8px;
  color: var(--ink-2); text-align: left; width: 100%;
  position: relative;
}
.nav-item:hover { background: var(--sel); color: var(--ink); }
.nav-item.active { background: var(--sel); color: var(--ink); font-weight: 600; }
.nav-item .nb-icon { width: 20px; flex: none; display: inline-flex; align-items: center; justify-content: center; opacity: .85; }
.nav-item.active .nb-icon { color: var(--accent-ink); opacity: 1; }
.nav-item .nb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nb-count { font-size: 12px; color: var(--ink-3); flex: none; }
.nav-item .nb-menu-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 6px; display: none;
  align-items: center; justify-content: center; color: var(--ink-2);
  background: var(--panel-2); border: 1px solid var(--line);
  font-weight: 700; line-height: 1;
}
.nav-item:hover .nb-menu-btn { display: flex; }
.nav-item:hover .nb-menu-btn:hover { color: var(--ink); border-color: var(--line-2); }
.nav-item.sep-above { margin-top: 10px; }
.nav-item.trash-item { color: var(--ink-3); }

.nb-menu {
  position: fixed; z-index: 60; min-width: 150px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column;
}
.new-nb {
  margin: 8px 2px 4px; padding: 7px 9px; border-radius: 8px;
  color: var(--ink-3); text-align: left; font-size: 14px;
  display: flex; align-items: center; gap: 9px;
}
.new-nb svg { margin-left: 3px; }
.new-nb:hover { background: var(--sel); color: var(--ink); }

.side-foot { display: flex; gap: 4px; padding: 6px 2px 2px; border-top: 1px solid var(--line); }

/* ---------- generic small buttons ---------- */
.ibtn {
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); flex: none;
}
.ibtn:hover { background: var(--sel); color: var(--ink); }
.ibtn.on { color: var(--accent-ink); }
.pbtn {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: var(--accent); color: #fff; font-size: 19px; font-weight: 600; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.pbtn:hover { filter: brightness(1.06); }
.tbtn {
  background: var(--accent); color: #fff; border-radius: 8px;
  padding: 7px 14px; font-weight: 600; font-size: 14px;
}
.tbtn:hover { filter: brightness(1.06); }
.tbtn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line-2); }
.tbtn.ghost:hover { color: var(--ink); background: var(--sel); filter: none; }
.tbtn.danger { background: var(--danger); }

/* ---------- note list pane ---------- */
.list {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}
.list-head { display: flex; gap: 8px; padding: 12px 12px 8px; align-items: center; }
.menu-btn { display: none; }
.search {
  flex: 1; display: flex; align-items: center; gap: 7px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 0 8px 0 10px; height: 32px; color: var(--ink-3); min-width: 0;
}
.search:focus-within { border-color: var(--line-2); color: var(--ink-2); }
.search input { flex: 1; border: 0; outline: 0; background: none; height: 100%; min-width: 0; }
.search kbd { opacity: .7; }
.search:focus-within kbd { display: none; }

.list-sub {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 16px 8px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-2); text-transform: uppercase; letter-spacing: .5px;
}
.count-pill { font-weight: 500; color: var(--ink-3); letter-spacing: 0; text-transform: none; }

.note-list { flex: 1; overflow-y: auto; padding: 0 8px 14px; }
.note-card {
  width: 100%; text-align: left;
  padding: 10px 10px 9px; border-radius: 10px; margin-bottom: 2px;
  display: block; border: 1px solid transparent;
}
.note-card:hover { background: var(--sel); }
.note-card.active { background: var(--panel-2); border-color: var(--line-2); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.nc-top { display: flex; align-items: baseline; gap: 6px; }
.nc-title {
  font-weight: 600; font-size: 14px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nc-title.untitled { color: var(--ink-3); font-weight: 500; }
.nc-pin { color: var(--pin); flex: none; display: inline-flex; }
.nc-snip {
  font-size: 13px; color: var(--ink-2); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nc-meta { display: flex; align-items: center; gap: 7px; margin-top: 4px; font-size: 11.5px; color: var(--ink-3); }
.nc-nb {
  background: var(--sel); border-radius: 5px; padding: 1px 6px; max-width: 40%;
  overflow: hidden; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px;
}
.nc-nb svg { flex: none; opacity: .7; }
.note-card.active .nc-nb { background: var(--sel); }
.nc-tasks { display: inline-flex; align-items: center; gap: 4px; }
.nc-tasks.done { color: var(--accent-ink); font-weight: 600; }

.list-empty { padding: 40px 20px; text-align: center; color: var(--ink-3); font-size: 13.5px; }
.list-empty .big { margin-bottom: 10px; display: flex; justify-content: center; opacity: .6; }
.list-empty .big svg { stroke-width: 1.6; }

/* ---------- editor ---------- */
.editor { display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.ed-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.ed-empty-inner { text-align: center; color: var(--ink-3); font-size: 14px; }
.ed-empty-icon { margin-bottom: 14px; opacity: .55; display: flex; justify-content: center; }
.ed-empty .hint { margin-top: 10px; font-size: 12.5px; }

.ed-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ed-bar { display: flex; align-items: center; gap: 8px; padding: 10px 24px 6px; max-width: 760px; margin: 0 auto; width: 100%; }
.back-btn { display: none; }
.title-input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font-size: 21px; font-weight: 700; color: var(--ink); padding: 4px 2px;
}
.ed-actions { display: flex; align-items: center; gap: 3px; }
.nb-select {
  max-width: 130px; height: 30px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--ink-2); padding: 0 4px; outline: 0; cursor: pointer;
  text-overflow: ellipsis;
}
.nb-select:hover { background: var(--sel); color: var(--ink); }

.more-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 34px; z-index: 50; min-width: 170px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: var(--shadow); padding: 5px; display: flex; flex-direction: column;
}
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu-item { text-align: left; padding: 7px 10px; border-radius: 7px; font-size: 13.5px; color: var(--ink); }
.menu-item:hover { background: var(--sel); }
.menu-item.danger { color: var(--danger); }

.ed-body { flex: 1; min-height: 0; display: flex; }
.ta, .preview {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 10px 26px 60px; overflow-y: auto;
}
.ta {
  border: 0; outline: 0; background: none; resize: none;
  font: 15px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color: var(--ink); caret-color: var(--accent);
}
.preview { cursor: default; }

.ed-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px; font-size: 12px; color: var(--ink-3);
  border-top: 1px solid var(--line);
}
.foot-right { display: flex; align-items: center; gap: 10px; }
.saved-dot { display: inline-flex; align-items: center; gap: 5px; }
.saved-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #7cb56b; transition: background .2s; }
.saved-dot.saving::before { background: var(--ink-3); }

.trash-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 12px; font-size: 13px; color: var(--ink-2);
  background: var(--panel); border-top: 1px solid var(--line);
}
.trash-bar .tbtn { background: var(--danger); padding: 6px 12px; font-size: 13px; }

/* ---------- markdown ---------- */
.md { font-size: 15.5px; line-height: 1.7; }
.md > * + * { margin-top: .65em; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin-top: 1.1em; }
.md > h1:first-child, .md > h2:first-child, .md > h3:first-child { margin-top: 0; }
.md h1 { font-size: 24px; } .md h2 { font-size: 19px; } .md h3 { font-size: 16px; }
.md a { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.md a:hover { border-bottom-color: var(--accent-ink); }
.md ul, .md ol { padding-left: 1.5em; }
.md li + li { margin-top: .18em; }
.md ul.tasks { list-style: none; padding-left: .2em; }
.md li.task { display: flex; align-items: flex-start; gap: 9px; }
.md li.task > input {
  appearance: none; -webkit-appearance: none; cursor: pointer; flex: none;
  width: 17px; height: 17px; margin-top: 4.5px; border-radius: 5px;
  border: 1.5px solid var(--line-2); background: var(--panel-2); position: relative;
}
.md li.task > input:hover { border-color: var(--accent); }
.md li.task > input:checked { background: var(--accent); border-color: var(--accent); }
.md li.task > input:checked::after {
  content: ""; position: absolute; left: 4.5px; top: 1.5px;
  width: 4.5px; height: 8.5px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.md li.task.done > span { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.md li.task > span { flex: 1; min-width: 0; }
.md blockquote { border-left: 3px solid var(--line-2); padding: .1em 0 .1em 1em; color: var(--ink-2); }
.md code {
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--code-bg); border-radius: 5px; padding: 2px 5px;
}
.md pre { background: var(--code-bg); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line-2); margin: 1.2em 0; }
.md mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 3px; }
.md .task-progress {
  font-size: 12px; color: var(--ink-3); margin-top: 2px;
}
.md .progress-track {
  height: 4px; border-radius: 2px; background: var(--sel); overflow: hidden; margin-top: 6px;
}
.md .progress-fill { height: 100%; border-radius: 2px; background: var(--accent); transition: width .35s ease; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 16, 8, .35);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px;
  backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }

.palette {
  width: 560px; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden;
  animation: pop .14s ease;
}
.palette input {
  width: 100%; border: 0; outline: 0; background: none;
  padding: 15px 18px; font-size: 16px; border-bottom: 1px solid var(--line);
}
.palette-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
.pal-item {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 9px; font-size: 14px; color: var(--ink);
}
.pal-item .pi-icon { width: 22px; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.pal-item .pi-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pal-item .pi-hint { font-size: 12px; color: var(--ink-3); flex: none; }
.pal-item.sel { background: var(--sel); }
.pal-empty { padding: 20px; text-align: center; color: var(--ink-3); font-size: 13.5px; }

.sheet {
  width: 440px; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow); padding: 22px;
  animation: pop .14s ease;
  max-height: 76vh; overflow-y: auto;
}
.sheet h2 { font-size: 15px; margin-bottom: 12px; }
.sheet h2 + .keys { margin-bottom: 18px; }
.keys { display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; color: var(--ink-2); }
.keys > div { display: flex; align-items: center; gap: 6px; }
.keys span { margin-left: 6px; }
.keys code { background: var(--code-bg); padding: 2px 7px; border-radius: 5px; font-size: 12.5px; }
.fineprint { font-size: 12.5px; color: var(--ink-3); margin: 4px 0 16px; }
#helpClose { width: 100%; }

.modal-sheet .modal-body { color: var(--ink-2); font-size: 13.5px; margin: -4px 0 14px; }
.modal-sheet .modal-body:empty { display: none; }
#modalInput {
  width: 100%; border: 1px solid var(--line-2); background: var(--bg);
  border-radius: 9px; padding: 9px 12px; outline: 0; margin-bottom: 14px;
}
#modalInput:focus { border-color: var(--accent); }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-bottom: 16px; }
.emoji-grid button {
  padding: 8px 0; border-radius: 8px; border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.emoji-grid button:hover { background: var(--sel); color: var(--ink); }
.emoji-grid button.sel { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

@keyframes pop { from { transform: scale(.97) translateY(-4px); opacity: 0; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 200;
  animation: toast-in .18s ease;
  display: flex; align-items: center; gap: 10px; max-width: 90vw;
}
.toast button { color: var(--accent); font-weight: 700; }
@keyframes toast-in { from { transform: translate(-50%, 8px); opacity: 0; } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 300; }

.scrim { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }

  .side {
    position: fixed; z-index: 80; left: 0; top: 0; bottom: 0; width: 264px;
    background: var(--panel-2); transform: translateX(-105%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .app.side-open .side { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.3); }
  #collapseBtn { display: inline-flex; }
  .menu-btn { display: inline-flex; }

  .list, .editor { grid-area: 1 / 1; }
  .app[data-view="list"] .editor { display: none; }
  .app[data-view="editor"] .list { display: none; }
  .back-btn { display: inline-flex; }
  .ta, .preview { padding: 8px 18px 60px; }
  .title-input { font-size: 19px; }
  .nb-select { max-width: 92px; }
  .overlay { padding-top: 8vh; }
}

@media (display-mode: standalone) {
  .list-head { padding-top: 12px; }
}

/* ================= variables: chips, panel, math ================= */
.vchip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-soft); border: 1px solid rgba(192,127,16,.32);
  color: var(--accent-ink); border-radius: 6px; padding: 0 7px 0 5px;
  font-size: 12.5px; font-weight: 600; vertical-align: -2px; line-height: 1.55;
  white-space: nowrap; cursor: pointer; max-width: 100%;
}
.vchip .vic { display: inline-flex; opacity: .7; flex: none; }
.vchip .vn { opacity: .75; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.vchip .vv { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }
.vchip.vchip-unset { border-style: dashed; opacity: .8; }
.vchip.due-soon .vv { color: var(--accent-ink); }
.vchip.due-past { border-color: rgba(194,72,47,.4); }
.vchip.due-past .vv { color: var(--danger); }

.math-line {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 6px 10px; border-radius: 8px; background: var(--sel); margin: 4px 0;
}
.math-line .mexpr { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13.5px; color: var(--ink-2); }
.math-line .mres { margin-left: auto; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; font-size: 15px; color: var(--accent-ink); }
.math-line .mres.err { color: var(--ink-3); font-weight: 500; }

.vars-panel {
  position: fixed; right: 0; top: 0; bottom: 0; width: 302px; z-index: 90;
  background: var(--panel-2); border-left: 1px solid var(--line-2);
  box-shadow: var(--shadow); display: flex; flex-direction: column; padding: 12px 12px 12px;
}
.vp-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14.5px; padding: 4px 4px 10px; }
.vp-head .vp-hic { display: inline-flex; color: var(--accent-ink); }
.vp-x { margin-left: auto; }
.vp-body { flex: 1; overflow-y: auto; }
.vp-sec { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-3); padding: 12px 4px 6px; }
.vp-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px;
  font-size: 13px; cursor: pointer;
}
.vp-row:hover, .vp-row.open { background: var(--sel); }
.vp-row .vp-ic { color: var(--ink-3); display: inline-flex; flex: none; }
.vp-name { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.vp-val { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--accent-ink); font-weight: 700; background: var(--accent-soft); border-radius: 6px; padding: 1px 7px; font-size: 11.5px; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vp-val .due-past { color: var(--danger); }
.vp-uses { font-size: 10.5px; color: var(--ink-3); flex: none; width: 42px; text-align: right; }
.vp-empty { font-size: 12.5px; color: var(--ink-3); padding: 4px 8px 8px; }
.vp-note { font-size: 11.5px; color: var(--ink-3); padding: 14px 8px 6px; line-height: 1.5; }
.vp-new {
  margin-top: 8px; border: 1px dashed var(--line-2); border-radius: 9px; padding: 9px;
  color: var(--ink-2); font-size: 13px; display: flex; align-items: center; justify-content: center; gap: 7px;
}
.vp-new:hover { background: var(--sel); color: var(--ink); }
.vp-form { padding: 8px; background: var(--sel); border-radius: 10px; margin: 2px 0 8px; }
.vp-in {
  width: 100%; border: 1px solid var(--line-2); background: var(--panel-2);
  border-radius: 8px; padding: 7px 9px; outline: 0; font-size: 13px; margin-bottom: 7px;
  color: var(--ink);
}
.vp-in:focus { border-color: var(--accent); }
.vp-form-row { display: flex; gap: 7px; }
.vp-sel { cursor: pointer; }
.vp-form-btns { display: flex; gap: 7px; align-items: center; }
.vp-form-btns .tbtn { padding: 6px 11px; font-size: 12.5px; }

/* ================= editor autocomplete popup ================= */
.ta-pop {
  position: fixed; z-index: 130; width: 300px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 11px;
  box-shadow: var(--shadow); padding: 5px; max-height: 300px; overflow-y: auto;
}
.ta-pop .s-item {
  width: 100%; display: flex; align-items: center; gap: 9px; text-align: left;
  padding: 7px 9px; border-radius: 8px; font-size: 13px; color: var(--ink);
}
.ta-pop .s-item.sel { background: var(--sel); }
.ta-pop .s-ic { display: inline-flex; color: var(--ink-2); flex: none; width: 18px; justify-content: center; }
.ta-pop .s-lab { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ta-pop .s-hint { font-size: 11px; color: var(--ink-3); flex: none; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ta-pop .s-sec-tag { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .5px; flex: none; }

/* ================= modules ================= */
.mod {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 12px;
  padding: 12px 15px 13px; margin: 14px 0; box-shadow: 0 1px 4px rgba(30,25,10,.05);
}
.mod-head {
  display: flex; align-items: center; gap: 7px; font-size: 10.5px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .8px; font-weight: 700; margin-bottom: 10px;
}
.mod-head .mtag { background: var(--sel); border-radius: 5px; padding: 2px 8px; text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 11.5px; color: var(--ink-2); }
.mod-head .medit { margin-left: auto; display: inline-flex; gap: 2px; }
.mhbtn { width: 24px; height: 24px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); }
.mhbtn:hover { background: var(--sel); color: var(--ink); }
.mod-grid { display: flex; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.mfield { display: flex; flex-direction: column; gap: 4px; font-size: 10.5px; color: var(--ink-3); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.mfield input {
  border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 8px;
  padding: 6px 10px; font-size: 14px; color: var(--ink); font-weight: 600; width: 110px;
  font-family: ui-monospace, Menlo, Consolas, monospace; outline: 0;
}
.mfield input:focus { border-color: var(--accent); }
.mrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-2); padding: 3.5px 0; }
.mrow b { color: var(--ink); font-family: ui-monospace, Menlo, Consolas, monospace; }
.mrow.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 9px; color: var(--ink); font-weight: 600; }
.mrow.total .mbig { font-size: 21px; color: var(--accent-ink); }
.msave { margin-top: 9px; font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mc-row { display: flex; align-items: center; gap: 14px; padding: 2px 0; }
.mc-btn {
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--panel-2); font-size: 17px; font-weight: 700; color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.mc-btn:hover { border-color: var(--line-2); background: var(--sel); color: var(--ink); }
.mc-btn.plus { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 13.5px; width: auto; padding: 0 12px; }
.mc-btn.plus:hover { filter: brightness(1.06); }
.mc-num { font-size: 26px; font-weight: 700; color: var(--ink); display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.mc-num span { font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.mslide input[type="range"] { flex: 1; accent-color: var(--accent); }
.mslide b { font-family: ui-monospace, Menlo, Consolas, monospace; min-width: 30px; text-align: right; }
.msw { position: relative; display: inline-flex; cursor: pointer; }
.msw input { position: absolute; opacity: 0; }
.msw-t { width: 36px; height: 21px; border-radius: 11px; background: var(--line-2); position: relative; transition: background .15s; }
.msw-t::after { content: ""; position: absolute; left: 2.5px; top: 2.5px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.msw input:checked + .msw-t { background: var(--accent); }
.msw input:checked + .msw-t::after { transform: translateX(15px); }
.mbtn-add { padding: 6px 14px; font-size: 13px; }
.mprog { padding: 2px 0 6px; }
.mtimer .mt-disp { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 27px; font-weight: 700; min-width: 92px; }
.mt-disp.running { color: var(--accent-ink); }
.mtimer .tbtn { padding: 6px 14px; font-size: 13px; }
.mrand b { transition: opacity .1s; }
.mrand b.spinning { opacity: .55; }
.mroll-head { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; padding: 2px 0 7px; }
.mroll-row { display: flex; align-items: center; gap: 9px; padding: 4.5px 0; font-size: 13.5px; border-top: 1px solid var(--line); }
.mroll-row input { appearance: none; -webkit-appearance: none; cursor: pointer; width: 16px; height: 16px; border-radius: 5px; border: 1.5px solid var(--line-2); background: var(--panel-2); flex: none; }
.mroll-row input:hover { border-color: var(--accent); }
.mroll-t { flex: 1; min-width: 0; }
.mroll-src { font-size: 11px; color: var(--ink-3); background: var(--sel); border-radius: 5px; padding: 2px 7px; flex: none; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mroll-src:hover { color: var(--ink); }
.mroll-row.done-out { opacity: .35; transition: opacity .3s; }
.mchart-svg { position: relative; margin-top: 6px; }
.mchart-svg svg { width: 100%; height: 56px; display: block; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark-area { fill: var(--accent); opacity: .12; stroke: none; }
.spark-dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
.mchart-empty { font-size: 12px; color: var(--ink-3); padding: 10px 0 4px; }
.mchart-tip {
  position: absolute; top: -6px; background: var(--ink); color: var(--bg);
  font-size: 11px; font-weight: 600; border-radius: 6px; padding: 3px 8px; pointer-events: none;
  white-space: nowrap;
}
.mod-err .mtag { color: var(--danger); }

/* ================= module builder ================= */
.builder {
  width: 760px; max-width: 96vw; background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
  animation: pop .14s ease; max-height: 86vh;
}
.b-head { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 14.5px; }
.b-head svg { color: var(--accent-ink); }
.b-name-in {
  flex: 1; min-width: 0; border: 1px solid transparent; background: var(--sel); border-radius: 8px;
  padding: 6px 11px; font-size: 13.5px; font-weight: 600; color: var(--ink); outline: 0;
}
.b-name-in:focus { border-color: var(--accent); background: var(--panel-2); }
.b-cols { display: flex; min-height: 300px; flex: 1; overflow: hidden; }
.b-pal { width: 172px; border-right: 1px solid var(--line); padding: 10px; overflow-y: auto; background: var(--panel); flex: none; }
.b-pal-sec { font-size: 10px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-3); padding: 9px 4px 5px; }
.b-pal-item {
  width: 100%; display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); border: 1px solid var(--line);
  background: var(--panel-2); margin-bottom: 5px; text-align: left;
}
.b-pal-item:hover { color: var(--ink); border-color: var(--line-2); background: var(--sel); }
.b-pal-item::before { content: ""; width: 8px; height: 8px; border-radius: 3px; flex: none; }
.b-pal-item.in::before { background: #3f77c9; }
.b-pal-item.co::before { background: var(--accent); }
.b-pal-item.di::before { background: #4f9d5d; }
.b-pal-item.va::before { background: #8a63b8; }
.b-pal-item.x::before { background: #7d8a99; }
.b-stack { flex: 1; padding: 14px 16px; display: flex; flex-direction: column; gap: 7px; background: var(--bg); overflow-y: auto; }
.blk {
  border: 1px solid var(--line-2); border-left-width: 4px; background: var(--panel-2);
  border-radius: 9px; padding: 8px 10px; font-size: 13px; display: flex; align-items: center; gap: 9px;
  box-shadow: 0 1px 2px rgba(30,25,10,.04);
}
.blk .b-tag { font-size: 9px; font-weight: 800; letter-spacing: .7px; border-radius: 4px; padding: 2px 6px; flex: none; }
.blk.in { border-left-color: #3f77c9; } .blk.in .b-tag { background: rgba(63,119,201,.12); color: #3f77c9; }
.blk.co { border-left-color: var(--accent); } .blk.co .b-tag { background: var(--accent-soft); color: var(--accent-ink); }
.blk.di { border-left-color: #4f9d5d; } .blk.di .b-tag { background: rgba(79,157,93,.12); color: #4f9d5d; }
.blk.va { border-left-color: #8a63b8; } .blk.va .b-tag { background: rgba(138,99,184,.12); color: #8a63b8; }
.blk.x { border-left-color: #7d8a99; } .blk.x .b-tag { background: rgba(125,138,153,.14); color: #66707d; }
.blk-params { flex: 1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; min-width: 0; }
.mb-in {
  border: 1px solid var(--line); background: var(--bg); border-radius: 7px;
  padding: 4.5px 8px; font-size: 12.5px; color: var(--ink); outline: 0; width: 110px;
}
.mb-in:focus { border-color: var(--accent); }
.mb-in.mb-sm { width: 88px; }
.mb-in.mb-xs { width: 52px; }
.mb-in.mb-wide { flex: 1; min-width: 140px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.mb-sel { cursor: pointer; width: auto; }
.mb-chk { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; color: var(--ink-2); }
.mb-chk input { accent-color: var(--accent); }
.blk-ctl { display: inline-flex; gap: 1px; flex: none; }
.b-drop { border: 1.5px dashed var(--line-2); border-radius: 9px; padding: 10px; text-align: center; color: var(--ink-3); font-size: 12.5px; }
.b-foot { display: flex; align-items: center; gap: 9px; padding: 12px 16px; border-top: 1px solid var(--line); }
.b-hint { font-size: 12px; color: var(--ink-3); margin-right: auto; }
.mod-chooser { min-width: 210px; max-height: 60vh; overflow-y: auto; }
.mc-mine { font-size: 10px; color: var(--ink-3); background: var(--sel); border-radius: 4px; padding: 1px 5px; margin-left: 5px; }

@media (max-width: 900px) {
  .vars-panel { width: 100%; }
  .b-cols { flex-direction: column; }
  .b-pal { width: 100%; display: flex; flex-wrap: wrap; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); }
  .b-pal-item { width: auto; }
  .b-pal-sec { width: 100%; }
}

/* ================= tags, links, due chips ================= */
.tag-chip {
  display: inline; color: var(--accent-ink); font-weight: 600;
  background: var(--accent-soft); border-radius: 5px; padding: 0 5px; font-size: .92em;
}
.tag-chip:hover { text-decoration: underline; }
.side-tags { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.side-tags-h {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 5px 9px; border-radius: 8px; color: var(--ink-3);
  font-size: 11px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase;
}
.side-tags-h:hover { color: var(--ink); background: var(--sel); }
.tag-item { padding: 5px 9px; font-size: 13.5px; }
.tag-hash { font-weight: 700; color: var(--ink-3); font-size: 13px; }

.nlink {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: -1px;
  color: var(--accent-ink); font-weight: 600; font-size: .96em;
  border-bottom: 1px solid var(--accent-soft); padding: 0 1px;
}
.nlink svg { opacity: .65; }
.nlink:hover { border-bottom-color: var(--accent-ink); }
.nlink-missing { opacity: .65; border-bottom-style: dashed; }
.backlinks { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 10px; }
.bl-h { display: flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px; }
.bl-row {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border-radius: 8px; font-size: 13.5px;
}
.bl-row:hover { background: var(--sel); }
.bl-t { font-weight: 600; }
.bl-nb { font-size: 11px; color: var(--ink-3); }

.due-chip {
  display: inline-flex; align-items: center; gap: 4px; vertical-align: -1px;
  background: var(--sel); color: var(--ink-2); border-radius: 6px; padding: 0 7px;
  font-size: 11.5px; font-weight: 600; line-height: 1.7; white-space: nowrap;
}
.due-chip svg { opacity: .7; }
.due-chip.due-soon { background: var(--accent-soft); color: var(--accent-ink); }
.due-chip.due-past { background: rgba(194,72,47,.12); color: var(--danger); }
.due-badge { background: var(--accent); color: #fff !important; border-radius: 9px; padding: 1px 7px; font-weight: 700; }

/* ---- Today view ---- */
.td-sec { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--ink-3); padding: 14px 10px 6px; }
.td-sec.od { color: var(--danger); }
.td-row {
  display: grid; grid-template-columns: 16px 1fr; column-gap: 9px; row-gap: 4px;
  align-items: start; padding: 8px 10px; border-radius: 9px; font-size: 13.5px;
}
.td-row:hover { background: var(--sel); }
.td-row input {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  width: 16px; height: 16px; border-radius: 5px; border: 1.5px solid var(--line-2); background: var(--panel-2);
  margin-top: 2px;
}
.td-row input:hover { border-color: var(--accent); }
.td-t {
  grid-column: 2; min-width: 0; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.td-meta { grid-column: 2; display: flex; align-items: center; gap: 7px; min-width: 0; }
.mem-dot { width: 16px; }
.td-src { font-size: 11px; color: var(--ink-3); background: var(--sel); border-radius: 5px; padding: 2px 7px; flex: none; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-src:hover { color: var(--ink); }
.td-row.done-out { opacity: .3; transition: opacity .3s; }
.mem-row .due-chip { background: var(--sel); }

/* ---- streaks ---- */
.streak-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-3); background: var(--sel); border-radius: 6px; padding: 3px 9px; margin-bottom: 10px;
}
.streak-run { display: inline-flex; align-items: center; gap: 3px; color: var(--accent-ink); }

/* ================= images, lightbox, sketch ================= */
.nimg { max-width: 100%; border-radius: 10px; border: 1px solid var(--line); cursor: zoom-in; display: block; margin: 6px 0; }
.nimg-missing { min-height: 60px; background: var(--sel); }
.overlay.lightbox { align-items: center; padding: 30px; cursor: zoom-out; }
.overlay.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow); }
.sketch { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; animation: pop .14s ease; }
.sk-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.sk-tools { display: flex; align-items: center; gap: 6px; margin: 0 auto; }
.sk-color { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); }
.sk-color.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--panel-2) inset; }
.sk-eraser { background: #fff; border: 1px solid var(--line-2); color: #999; }
.sk-bar .tbtn { padding: 5px 11px; font-size: 12.5px; }
#skCanvas { display: block; touch-action: none; cursor: crosshair; }

/* ================= history ================= */
.hv-sheet {
  width: 700px; max-width: 96vw; max-height: 84vh; display: flex; flex-direction: column;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow); overflow: hidden; animation: pop .14s ease;
}
.hv-cols { display: flex; flex: 1; min-height: 260px; overflow: hidden; }
.hv-list { width: 190px; border-right: 1px solid var(--line); overflow-y: auto; padding: 8px; flex: none; }
.hv-row { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.hv-row:hover, .hv-row.sel { background: var(--sel); }
.hv-words { font-size: 11px; color: var(--ink-3); font-weight: 500; }
.hv-view { flex: 1; overflow-y: auto; padding: 14px 18px; }
.hv-title { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.hv-view pre { white-space: pre-wrap; font: 13px/1.6 ui-monospace, Menlo, Consolas, monospace; color: var(--ink-2); }

/* ================= scratchpad ================= */
.scratch {
  position: fixed; right: 18px; bottom: 18px; width: 300px; z-index: 85;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 13px;
  box-shadow: var(--shadow); overflow: hidden; animation: pop .14s ease;
}
.sc-bar { display: flex; align-items: center; gap: 7px; padding: 8px 8px 8px 12px; font-size: 12px; font-weight: 700; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.sc-bar .mhbtn:first-of-type { margin-left: auto; }
.scratch textarea {
  width: 100%; height: 190px; border: 0; outline: 0; background: none; resize: none;
  padding: 10px 12px; font: 13.5px/1.6 ui-monospace, Menlo, Consolas, monospace; color: var(--ink);
}

/* ================= tints ================= */
.tint-row { display: flex; gap: 7px; margin: -6px 0 16px; }
.tint-sw { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.tint-sw.sel { border-color: var(--ink); box-shadow: 0 0 0 2px var(--panel-2) inset; }
.tint-none { background: var(--accent); }

/* ================= year stats ================= */
.yr-sheet h2 { display: flex; align-items: center; gap: 8px; }
.yr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.yr-stat { background: var(--sel); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.yr-stat b { font-size: 22px; }
.yr-stat span { font-size: 11.5px; color: var(--ink-2); }
.yr-months { display: flex; flex-direction: column; gap: 3px; }
.yr-mrow { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink-3); }
.yr-ml { width: 26px; flex: none; }
.yr-bar { flex: 1; height: 10px; border-radius: 5px; background: var(--sel); overflow: hidden; }
.yr-bar span { display: block; height: 100%; border-radius: 5px; background: var(--accent); opacity: .75; }
.yr-mc { width: 24px; text-align: right; font-weight: 600; color: var(--ink-2); }

/* ---- repeat options ---- */
.rep-opts { display: flex; gap: 7px; margin-bottom: 14px; }
.rep-opt { flex: 1; border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.rep-opt:hover { background: var(--sel); color: var(--ink); }
.rep-opt.sel { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.tpl-list { display: flex; flex-direction: column; gap: 3px; }
.tpl-row { display: flex; align-items: center; gap: 4px; }
.tpl-use { flex: 1; display: flex; align-items: center; gap: 9px; text-align: left; padding: 8px 10px; border-radius: 8px; font-size: 13.5px; }
.tpl-use:hover { background: var(--sel); }
.tpl-use svg { color: var(--ink-3); }

/* ================= focus mode ================= */
body.focus .side, body.focus .list, body.focus .scratch { display: none !important; }
body.focus .app { grid-template-columns: 1fr; }
body.focus .ed-bar, body.focus .ed-foot { opacity: .2; transition: opacity .2s; }
body.focus .ed-bar:hover, body.focus .ed-bar:focus-within, body.focus .ed-foot:hover { opacity: 1; }
body.focus .ta, body.focus .preview { max-width: 620px; }
body.focus .backlinks { display: none; }

/* ================= shared notebooks ================= */
.collab-dot { display: inline-flex; margin-left: 6px; color: var(--accent-ink); opacity: .8; vertical-align: -1px; }
.collab-members { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.collab-m {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-radius: 8px; background: var(--panel-2);
  font-size: 13px;
}
.collab-m > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collab-role { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.ro-tag {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 100px; padding: 1px 8px; margin-right: 8px;
}
body.read-only-note .ta { opacity: .82; }
body.read-only-note #pinBtn, body.read-only-note #deleteNoteBtn { opacity: .4; pointer-events: none; }

/* ================= file attachments ================= */
.nfile {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; margin: 3px 0;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--panel-2); color: var(--ink-2);
  font-size: 13.5px; max-width: 100%; text-align: left;
}
.nfile:hover { border-color: var(--accent); color: var(--ink); }
.nfile-i { display: inline-flex; flex: none; color: var(--accent-ink); }
.nfile-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nfile-s { flex: none; font-size: 11.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nfile-s:empty { display: none; }
.nfile.nfile-missing { opacity: .55; border-style: dashed; }
.ed-body.drop-file { outline: 2px dashed var(--accent); outline-offset: -6px; border-radius: 10px; }

/* ================= admin ================= */
.admin-sheet { width: 560px; max-height: 82vh; }
.admin-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.admin-head h2 { display: flex; align-items: center; gap: 7px; margin: 0; flex: 1; min-width: 0; }
.admin-head h2 svg { color: var(--accent-ink); flex: none; }
.admin-wait { color: var(--ink-3); font-size: 13px; padding: 18px 0; text-align: center; }

.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 14px; }
.admin-stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 1px;
}
.admin-stat-l { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.admin-stat b { font-size: 20px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.admin-stat-s { font-size: 11.5px; color: var(--ink-3); }

.admin-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 46vh; overflow-y: auto; }
.admin-acct { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel); }
.admin-acct.banned { opacity: .62; }
.admin-acct-top { display: flex; align-items: center; gap: 8px; }
.admin-email { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-pill {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  background: var(--danger); color: #fff; border-radius: 100px; padding: 1px 7px;
}
.admin-acct-sub { font-size: 12px; color: var(--ink-3); margin: 2px 0 7px; font-variant-numeric: tabular-nums; }
.admin-acct-acts { display: flex; flex-wrap: wrap; gap: 5px; }
.admin-mini {
  font-size: 11.5px; padding: 3px 8px; border-radius: 7px;
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--bg);
}
.admin-mini:hover { background: var(--sel); color: var(--ink); }
.admin-mini.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line-2)); }
.admin-mini.danger:hover { background: var(--danger); color: #fff; }

.admin-note { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 9px; }
.admin-note:hover { background: var(--sel); }
.admin-note > span:first-child { font-size: 13.5px; color: var(--ink); }
.admin-note-m { font-size: 11.5px; color: var(--ink-3); }
.admin-note-t { font-size: 15px; margin: 10px 0 8px; }
.admin-note-b {
  white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.55;
  background: var(--code-bg); border-radius: 9px; padding: 12px 14px;
  max-height: 50vh; overflow-y: auto; font-family: inherit;
}
.admin-sealed {
  display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--ink-2);
  background: var(--accent-soft); border-radius: 9px; padding: 11px 13px; line-height: 1.5;
}
.admin-sealed svg { flex: none; margin-top: 1px; }
.admin-flags { margin-bottom: 12px; }

/* ================= sign-in gate ================= */
body.gated { overflow: hidden; }
body.gated .app, body.gated .toast, body.gated .scratch { visibility: hidden; }
.gate {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
}
.gate-card {
  width: 400px; max-width: 100%;
  background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 16px; box-shadow: var(--shadow); padding: 30px 28px 24px;
  animation: pop .16s ease;
}
.gate-mark { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.gate-mark span { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.gate-h { font-size: 17px; font-weight: 600; margin-bottom: 16px; letter-spacing: -.01em; }
.gate .acct-tabs { margin-bottom: 16px; }
.gate .modal-btns { margin-top: 2px; }
.gate-fine { margin: 16px 0 0; line-height: 1.5; }
@media (max-width: 480px) {
  .gate { align-items: flex-start; padding-top: 8vh; }
  .gate-card { padding: 24px 20px 20px; border: 0; background: none; box-shadow: none; }
}

/* ================= recovery code ================= */
.rec-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px; letter-spacing: .06em; text-align: center;
  background: var(--code-bg); border: 1px dashed var(--line-2);
  border-radius: 10px; padding: 14px 10px; margin-bottom: 14px;
  cursor: pointer; user-select: all; word-break: break-all;
}
.rec-code:hover { border-color: var(--accent); }

/* ================= nested notebooks ================= */
.nav-item.nb-child { padding-left: 22px; }
.nav-item.nb-d2 { padding-left: 36px; }
.nav-item.nb-child::before {
  content: ''; position: absolute; left: 13px; top: 6px; bottom: 6px;
  width: 1px; background: var(--line-2);
}
.nav-item.nb-d2::before { left: 27px; }
.nav-item { position: relative; }
.nav-item.has-kids { padding-left: 25px; }
.nav-item.nb-child.has-kids { padding-left: 38px; }
.nb-twist {
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%); z-index: 1;
  width: 16px; height: 16px; display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); border-radius: 4px; cursor: pointer;
}
.nav-item.nb-child .nb-twist { left: 19px; }
.nb-twist svg { transition: transform .14s ease; transform: rotate(-90deg); }
.nb-twist.open svg { transform: rotate(0deg); }
.nb-twist:hover { background: var(--sel); color: var(--ink); }

/* ================= line items, converter, roll-up ================= */
.mitems { margin: 4px 0 2px; }
.mitems table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mitems th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-3); font-weight: 600; padding: 0 6px 5px;
}
.mitems th.num, .mitems td.num, .mitems .mit-line { text-align: right; }
.mitems td { padding: 2px 4px; }
.mitems input {
  width: 100%; border: 1px solid transparent; background: var(--panel-2);
  border-radius: 7px; padding: 5px 8px; font-size: 13px; color: var(--ink); outline: 0;
}
.mitems input:focus { border-color: var(--accent); background: var(--panel); }
.mitems input.num { text-align: right; font-variant-numeric: tabular-nums; width: 68px; }
.mit-line { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; padding-right: 6px !important; }
.mit-x {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; color: var(--ink-3);
}
.mit-x:hover { background: var(--sel); color: var(--danger); }
.mit-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.mit-add { padding: 4px 9px; font-size: 12px; }
.mit-tot { margin-left: auto; display: flex; align-items: baseline; gap: 7px; font-size: 12.5px; color: var(--ink-3); }
.mit-tot b { color: var(--ink); font-variant-numeric: tabular-nums; }
.mit-tot .mbig { font-size: 17px; }

.mconv { display: flex; align-items: center; gap: 8px; padding: 3px 0; flex-wrap: wrap; }
.mconv > span:first-child { color: var(--ink-2); font-size: 13px; }
.mconv-in {
  width: 88px; border: 1px solid var(--line-2); background: var(--bg);
  border-radius: 8px; padding: 5px 8px; outline: 0; text-align: right;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.mconv-in:focus { border-color: var(--accent); }
.mconv-u { color: var(--ink-3); font-weight: 500; font-size: 12.5px; }
.mconv-ar { color: var(--ink-3); }
.mconv b[data-out] { margin-left: auto; font-variant-numeric: tabular-nums; }

.mnroll-list { display: flex; flex-direction: column; gap: 1px; margin-top: 6px; }
.mnroll-row {
  display: flex; align-items: baseline; gap: 10px; width: 100%;
  padding: 4px 7px; border-radius: 7px; font-size: 12.5px; color: var(--ink-2); text-align: left;
}
.mnroll-row:hover { background: var(--sel); color: var(--ink); }
.mnroll-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mnroll-row b { font-variant-numeric: tabular-nums; }
.mnroll-more { font-size: 11.5px; color: var(--ink-3); padding: 3px 7px; }

/* ================= formula variables + units ================= */
.vp-value { flex: 1; min-width: 0; }
.vp-unit { width: 74px; flex: none; text-align: center; }
.vp-calc {
  font-size: 12px; color: var(--ink-2); background: var(--code-bg);
  border-radius: 7px; padding: 6px 9px; margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}
.vp-calc-val { font-variant-numeric: tabular-nums; }
.vp-calc-val::before { content: '= '; color: var(--ink-3); }
.vchip.vchip-calc .vic { color: var(--accent-ink); }
.vchip.vchip-calc .vv { font-variant-numeric: tabular-nums; }

/* ================= tables ================= */
.table-wrap { overflow-x: auto; margin: 14px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th, .md td { border: 1px solid var(--line-2); padding: 7px 11px; text-align: left; }
.md th { background: var(--sel); font-weight: 600; }
.md td { font-variant-numeric: tabular-nums; }
.md tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--sel) 45%, transparent); }

/* ================= sorting, selection, bulk actions ================= */
.sort-select { margin-left: auto; max-width: 150px; font-size: 12px; padding: 2px 4px; }
.note-card.dragging { opacity: .45; }
.note-card.drop-to { box-shadow: inset 0 2px 0 var(--accent); }
.note-card.picked { background: var(--accent-soft); }
.note-card.picked .nc-title { color: var(--accent-ink); }

.bulk-bar {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 11px;
  background: var(--panel-2); border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  animation: pop .14s ease;
}
.bulk-bar .bulk-n { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-right: auto; white-space: nowrap; }
.bulk-bar .tbtn { padding: 5px 9px; font-size: 12.5px; }
.bulk-bar .tbtn.danger { background: var(--danger); color: #fff; }
.bulk-bar .nb-select { max-width: 120px; font-size: 12px; }
.list { position: relative; }

/* ================= account + sync ================= */
.acct-item .nb-icon { opacity: .8; }
.acct-item.syncing .nb-icon { animation: acct-spin 1.4s linear infinite; }
@keyframes acct-spin { to { transform: rotate(360deg); } }
.acct-status {
  font-size: 11.5px; color: var(--ink-3);
  padding: 0 10px 4px 32px; margin-top: -2px;
}
.acct-status.bad { color: var(--danger); }

.acct-sheet h2 { margin-bottom: 10px; }
.acct-lede { font-size: 13px; color: var(--ink-2); line-height: 1.5; margin-bottom: 14px; }
.acct-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.acct-tab {
  padding: 7px 10px; font-size: 12.5px; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.acct-tab:hover { color: var(--ink); }
.acct-tab.on { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }

.acct-form { display: flex; flex-direction: column; }
.acct-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.acct-field span { font-size: 12px; color: var(--ink-2); }
.acct-field input {
  width: 100%; border: 1px solid var(--line-2); background: var(--bg);
  border-radius: 9px; padding: 9px 12px; outline: 0; font-size: 14px; color: var(--ink);
}
.acct-field input:focus { border-color: var(--accent); }
.acct-msg {
  font-size: 12.5px; color: var(--ink-2); background: var(--sel);
  border-radius: 8px; padding: 8px 10px; margin-bottom: 12px;
}
.acct-msg.bad { color: var(--danger); background: transparent; border: 1px solid var(--danger); }

.acct-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px; color: var(--ink-3); font-size: 12px; }
.acct-or::before, .acct-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.acct-oauth { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }

.acct-who { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.acct-who > div { display: flex; flex-direction: column; min-width: 0; }
.acct-who strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-ink);
}
.acct-sub { font-size: 12px; color: var(--ink-3); }
.acct-rows { display: flex; flex-direction: column; margin-bottom: 16px; }
.acct-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  font-size: 13.5px; color: var(--ink-2); text-align: left;
}
.acct-row:hover { background: var(--sel); color: var(--ink); }
.acct-row svg { flex: none; opacity: .8; }

/* ================= print ================= */
@media print {
  .side, .list, .ed-bar, .ed-foot, .trash-bar, .vars-panel, .toast, .scratch, .ta-pop, .backlinks, .streak-pill, .overlay { display: none !important; }
  .app { display: block; height: auto; }
  .editor { display: block; background: #fff; }
  .ed-wrap { display: block; }
  .ed-body { display: block; }
  .preview { max-width: 100%; padding: 0; overflow: visible; color: #111; }
  body { overflow: visible; background: #fff; }
  .mod { break-inside: avoid; box-shadow: none; }
  .mod-head .medit, .mc-btn, [data-rpick], .mt-start, [data-treset] { display: none !important; }
  html { color-scheme: light; }
}
