/* ---------- theme ---------- */
:root {
  --bg: #0f0f10;
  --side: #141415;
  --panel: #18181a;
  --paper: #1c1c1f;
  --raised: #232327;
  --hover: #26262b;
  --border: #2a2a2f;
  --text: #ececee;
  --muted: #9b9ba3;
  --faint: #8b8b92;            /* 4.6:1 contrast, passes WCAG AA */
  --green: #00a82d;
  --green-hi: #00c234;
  --green-ink: #4ade80;
  --green-soft: rgba(0, 168, 45, 0.14);
  --green-line: rgba(0, 168, 45, 0.55);
  --danger: #ef4444;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.spacer { flex: 1; }
::selection { background: var(--green-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2c2c31; border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #3a3a41; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }
.brand.big { font-size: 28px; justify-content: center; }
.leaf {
  width: 26px; height: 26px; border-radius: 8px 2px 8px 2px; background: linear-gradient(135deg, var(--green-hi), #0b6b25);
  box-shadow: 0 0 18px rgba(0, 194, 52, 0.35); display: inline-block; flex: none;
}
.brand.big .leaf { width: 34px; height: 34px; }
.leaf.huge { width: 64px; height: 64px; border-radius: 22px 6px 22px 6px; opacity: 0.85; }

/* ---------- buttons ---------- */
.btn-green {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--green); color: #fff; border: 0; border-radius: var(--radius);
  padding: 11px 16px; font-weight: 650; font-size: 16px; transition: background 0.15s, transform 0.05s;
}
.btn-green:hover { background: var(--green-hi); }
.btn-green:active { transform: translateY(1px); }
.btn-green:disabled { opacity: 0.6; cursor: progress; }
.btn-ghost, .btn-danger {
  background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 9px 14px; color: var(--text);
}
.btn-ghost:hover { background: var(--hover); }
.btn-danger { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }
.small { padding: 5px 10px; font-size: 13px; }
.wide { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 0; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.small { width: 24px; height: 24px; }
.icon-btn.small svg { width: 15px; height: 15px; }
.icon-btn.active { color: var(--green-ink); }
.icon-btn.active svg { fill: var(--green-ink); }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(0, 168, 45, 0.12), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-sub { text-align: center; color: var(--muted); margin: 8px 0 22px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tab { border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--raised); color: var(--text); }
form label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
form input:not(.visually-hidden) {
  display: block; width: 100%; margin-top: 6px; padding: 11px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 9px; font-size: 15px; outline: none;
}
form input:focus { border-color: var(--green-line); box-shadow: 0 0 0 3px var(--green-soft); }
.error { color: #fca5a5; min-height: 20px; font-size: 14px; margin: 4px 0 10px; }
.warning { background: rgba(250, 166, 26, 0.1); border: 1px solid rgba(250, 166, 26, 0.35); color: #fcd28a; padding: 10px 12px; border-radius: 9px; font-size: 13px; }
#unlock-logout { margin-top: 10px; }
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 44px !important; }
.eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); margin-top: 3px; width: 34px; height: 34px; display: grid; place-items: center; background: transparent; border: 0; border-radius: 7px; color: var(--faint); }
.eye:hover { color: var(--text); background: var(--hover); }
.eye.on { color: var(--green-ink); }
.strength { display: flex; align-items: center; gap: 10px; margin: -6px 0 14px; font-size: 12.5px; color: var(--muted); }
.strength-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; flex: 1; }
.strength-bar i { height: 5px; border-radius: 3px; background: var(--raised); transition: background 0.2s; }
.strength[data-score="1"] i:nth-child(-n+1) { background: #ef4444; }
.strength[data-score="2"] i:nth-child(-n+2) { background: #f59e0b; }
.strength[data-score="3"] i:nth-child(-n+3) { background: #84cc16; }
.strength[data-score="4"] i:nth-child(-n+4) { background: var(--green-hi); }
.caps { color: #fcd28a; font-size: 12.5px; margin: -8px 0 10px; }
.trust { text-align: center; color: var(--faint); font-size: 12.5px; margin-top: 18px; line-height: 1.6; }
.auth { grid-template-rows: auto; align-content: center; }
.btn-passkey { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--raised); border: 1px solid var(--green-line); color: var(--text); border-radius: var(--radius); padding: 12px 16px; font-weight: 650; font-size: 15px; margin-bottom: 4px; }
.btn-passkey:hover { background: var(--green-soft); }
.btn-passkey svg { color: var(--green-ink); }
.or { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12.5px; margin: 14px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
/* settings */
.modal.wide-modal { max-width: 460px; }
.settings-section { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.settings-section h4 { margin: 0 0 6px; font-size: 14px; }
.pk-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; margin-bottom: 8px; font-size: 14px; }
.pk-row .pk-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-row .pk-date { color: var(--faint); font-size: 12px; }
.pk-empty { color: var(--faint); font-size: 13px; margin: 6px 0 12px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 250px 340px 1fr; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- sidebar ---------- */
.sidebar { background: var(--side); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px 14px 12px; gap: 14px; min-height: 0; }
.sidebar > .brand { padding: 0 6px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--raised); border: 1px solid transparent; border-radius: var(--radius); padding: 0 12px; color: var(--faint); }
.search:focus-within { border-color: var(--green-line); }
.search input { flex: 1; background: transparent; border: 0; outline: none; padding: 10px 0; }
.new-note svg { stroke-width: 2.4; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; min-height: 0; margin: 0 -6px; padding: 0 6px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: transparent; border: 0;
  padding: 8px 10px; border-radius: 8px; color: #cfcfd4;
}
.nav-item svg { color: var(--muted); }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--green-soft); color: #fff; }
.nav-item.active svg { color: var(--green-ink); }
.nav-item .count { margin-left: auto; color: var(--faint); font-size: 12px; }
.nav-item.indent { padding-left: 40px; font-size: 14px; }
.nav-section { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--faint); }
.tag-list { display: flex; flex-direction: column; gap: 1px; }
.sidebar-footer { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--green); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; flex: none; }
.username { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- list ---------- */
.list { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.list-header { display: flex; align-items: center; gap: 8px; padding: 22px 20px 14px; }
.list-header h1 { font-size: 24px; margin: 0; font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-header .count { color: var(--faint); font-size: 15px; margin-top: 6px; }
.cards { overflow-y: auto; flex: 1; padding: 4px 12px 24px; }
.card {
  display: block; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; border-bottom-color: var(--border);
  border-radius: 0; padding: 16px 14px; color: var(--text);
}
.card:hover { background: var(--hover); border-radius: var(--radius); border-bottom-color: transparent; }
.card.active { background: var(--paper); border: 1px solid var(--green-line); border-radius: var(--radius); box-shadow: 0 0 0 3px var(--green-soft); }
.card-title { font-weight: 650; display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title svg { width: 14px; height: 14px; color: var(--green-ink); fill: var(--green-ink); }
.card-preview { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 21px; }
.card-meta { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--faint); flex-wrap: wrap; }
.chip { background: var(--raised); color: #c9c9cf; border-radius: 6px; padding: 1px 7px; font-size: 12px; }
.chip.green { background: var(--green-soft); color: var(--green-ink); }
.list-empty { color: var(--faint); text-align: center; padding: 48px 18px; }
mark { background: rgba(0, 194, 52, 0.28); color: #fff; border-radius: 3px; padding: 0 1px; }

/* ---------- editor ---------- */
.editor { background: var(--paper); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.empty-editor { margin: auto; text-align: center; color: var(--faint); display: grid; place-items: center; gap: 12px; }
.editor-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor-top { display: flex; align-items: center; gap: 6px; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; min-width: 0; }
.crumbs select { background: transparent; border: 1px solid transparent; border-radius: 7px; padding: 4px 6px; color: var(--muted); max-width: 200px; }
.crumbs select:hover { border-color: var(--border); color: var(--text); }
.crumbs select option { background: var(--raised); }
#crumb-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sep { color: var(--faint); }
.status { font-size: 12.5px; color: var(--faint); margin-right: 6px; white-space: nowrap; }
.status.saved::before {
  content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 5px; vertical-align: -1px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / contain no-repeat;
}
.trash-banner { display: flex; align-items: center; gap: 10px; padding: 10px 22px; background: rgba(239, 68, 68, 0.08); border-bottom: 1px solid rgba(239, 68, 68, 0.25); color: #fca5a5; font-size: 14px; }
.trash-banner :first-of-type { margin-left: auto; }

.toolbar { display: flex; align-items: center; gap: 2px; padding: 8px 18px; border-bottom: 1px solid var(--border); overflow-x: auto; flex: none; }
.toolbar button { display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; color: #c9c9cf; font-size: 14px; font-weight: 600; }
.toolbar button:hover { background: var(--hover); color: #fff; }
.toolbar button.on { background: var(--green-soft); color: var(--green-ink); }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex: none; }

.paper { flex: 1; overflow-y: auto; padding: 36px max(28px, calc((100% - 760px) / 2)) 80px; }
.note-title { width: 100%; background: transparent; border: 0; outline: none; font-size: 34px; font-weight: 750; letter-spacing: -0.3px; padding: 0; }
.note-title::placeholder { color: #45454c; }
.note-meta { color: var(--faint); font-size: 13px; margin: 6px 0 22px; }
.note-body { outline: none; min-height: 50vh; font-size: 16.5px; line-height: 1.7; word-wrap: break-word; }
.note-body:empty::before { content: attr(data-placeholder); color: #4a4a51; }
.note-body h1 { font-size: 26px; margin: 22px 0 8px; line-height: 1.3; }
.note-body h2 { font-size: 21px; margin: 18px 0 6px; line-height: 1.35; }
.note-body p, .note-body div { margin: 0 0 4px; }
.note-body a { color: var(--green-ink); }
.note-body blockquote { border-left: 3px solid var(--green); margin: 10px 0; padding: 4px 0 4px 16px; color: #c9c9cf; }
.note-body pre { background: #121214; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font: 14px/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; }
.note-body code { background: #121214; border-radius: 5px; padding: 1px 5px; font: 0.9em ui-monospace, Menlo, Consolas, monospace; }
.note-body hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.note-body ul, .note-body ol { padding-left: 26px; margin: 6px 0; }
.note-body ul.checklist { list-style: none; padding-left: 4px; }
.note-body ul.checklist li { position: relative; padding-left: 30px; }
.note-body ul.checklist li::before {
  content: ""; position: absolute; left: 0; top: 0.32em; width: 17px; height: 17px; border: 2px solid #55555d; border-radius: 5px; cursor: pointer;
}
.note-body ul.checklist li.done { color: var(--faint); text-decoration: line-through; }
.note-body ul.checklist li.done::before { background: var(--green); border-color: var(--green); }
.note-body ul.checklist li.done::after {
  content: ""; position: absolute; left: 6px; top: calc(0.32em + 3px); width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}

.editor-footer { display: flex; align-items: center; gap: 10px; padding: 12px 22px; border-top: 1px solid var(--border); color: var(--faint); flex-wrap: wrap; }
.tag-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--green-soft); color: var(--green-ink); border-radius: 6px; padding: 2px 4px 2px 9px; font-size: 13px; }
.tag-chip button { border: 0; background: transparent; color: inherit; padding: 0 4px; opacity: 0.7; font-size: 14px; line-height: 1; }
.tag-chip button:hover { opacity: 1; }
#tag-input { background: transparent; border: 0; outline: none; min-width: 120px; flex: 1; padding: 4px 0; }

/* ---------- toast + modal ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--raised); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: 0.2s; z-index: 50; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 12px; font-size: 17px; }
.modal p { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.modal input { display: block; width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; outline: none; margin-bottom: 16px; }
.modal input:focus { border-color: var(--green-line); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions .btn-green { font-size: 14px; padding: 8px 16px; }
.menu { position: fixed; z-index: 45; background: var(--raised); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; min-width: 170px; }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 12px; border-radius: 7px; font-size: 14px; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: #fca5a5; }
.scrim { display: none; }

/* ---------- responsive ---------- */
.mobile-only { display: none; }
@media (max-width: 1100px) {
  .app { grid-template-columns: 220px 290px 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform 0.2s; }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.sidebar-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 25; }
  .editor { display: none; }
  body.show-editor .list { display: none; }
  body.show-editor .editor { display: flex; height: 100dvh; }
  .paper { padding: 22px 18px 60px; }
  .note-title { font-size: 27px; }
  .editor-top { padding: 10px 12px; }
  .crumbs select { max-width: 130px; }
  #crumb-title, .crumbs .sep { display: none; }
}

/* ---------- v3 additions ---------- */
.link-btn { display: block; margin: 12px auto 0; background: none; border: 0; color: var(--green-ink); font-size: 13.5px; }
.link-btn:hover { text-decoration: underline; }
.reminder { background: rgba(250, 166, 26, 0.1); border: 1px solid rgba(250, 166, 26, 0.35); color: #fcd28a; border-radius: 9px; padding: 8px 10px; font-size: 13px; text-align: left; }
.reminder:hover { background: rgba(250, 166, 26, 0.18); }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.recovery-code { font: 600 19px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 1px; background: var(--bg); border: 1px dashed var(--green-line); color: var(--green-ink); border-radius: 10px; padding: 14px; text-align: center; margin: 4px 0 12px; word-break: break-all; user-select: all; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 14px 0; }
.check input { width: 17px; height: 17px; accent-color: var(--green); }
.modal-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.modal-label input { margin-top: 6px; margin-bottom: 12px !important; }
.modal .error { margin: 0 0 8px; min-height: 0; }
.share-new { display: flex; gap: 8px; margin-bottom: 14px; }
.share-new select { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; }
.share-new .btn-green { font-size: 14px; padding: 8px 14px; }
.note-body img { max-width: 100%; height: auto; border-radius: 10px; display: block; margin: 10px 0; border: 1px solid var(--border); }
.note-body img.broken { min-height: 40px; padding: 10px; color: var(--faint); font-size: 13px; }
/* share page */
.share-page { min-height: 100%; }
.share-head { display: flex; align-items: center; gap: 10px; padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--side); }
.share-head .badge { margin-left: auto; font-size: 12.5px; color: var(--green-ink); background: var(--green-soft); border-radius: 99px; padding: 4px 10px; }
.share-paper { max-width: 760px; margin: 0 auto; padding: 40px 24px 80px; }
.share-meta { color: var(--faint); font-size: 13px; margin: 6px 0 24px; }
.share-error { text-align: center; color: var(--muted); padding: 80px 24px; }

/* =====================================================================
   THEMES: "moss" (default dark), "forest" (sage/canopy dark), "light"
   Every color below comes from variables, so a theme only swaps values.
   ===================================================================== */
:root, [data-theme="moss"] {
  --forest: #11281b; --forest-2: #163322; --forest-line: #24553a; --forest-glow: rgba(22, 92, 52, 0.35);
  --sidebar-bg: #111213;
  --text-2: #cfcfd4; --strong: #ffffff; --on-accent: #ffffff; --accent-text: #6ee79a;
  --placeholder: #717177; --check-border: #6a6a72; --check-done: #0e8a30; --code-bg: #121214;
  --btn-bg: linear-gradient(180deg, #05b333, #009a2a); --btn-bg-hover: linear-gradient(180deg, #0cc43c, #00a82d);
  --btn-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 14px rgba(0, 120, 40, 0.25);
  --card-active-bg: #121915;
  --nav-active-bg: #15241a; --nav-hover: #1a1c1b;
  --editor-top-bg: transparent;
  --auth-bg: radial-gradient(900px 520px at 50% -8%, var(--forest-glow), transparent 65%),
             radial-gradient(600px 400px at 50% 110%, rgba(17, 40, 27, 0.5), transparent 70%), var(--bg);
  --quote-bg: linear-gradient(90deg, rgba(17, 40, 27, 0.45), transparent 70%);
  --mark-bg: rgba(36, 85, 58, 0.85); --mark-text: #eafff1;
  --scroll: #24302a; --scroll-hover: #2f4136;
  --danger-text: #fca5a5; --warn-text: #fcd28a; --warn-bg: rgba(250, 166, 26, 0.1); --warn-line: rgba(250, 166, 26, 0.35);
  --heading-soft: #d7efe0; --tab-active-text: #e8f5ec;
  --leaf: linear-gradient(135deg, #00c234, #0b6b25);
}

[data-theme="forest"] {
  /* deep forest backgrounds + the bright Moss green */
  --bg: #0a120d; --side: #0d1711; --panel: #0f1a13; --paper: #122017; --raised: #18291e; --hover: #1c3023;
  --border: #1f3527; --text: #e6f2e9; --muted: #9db6a6; --faint: #7a9383;
  --green: #00a82d; --green-hi: #00c234; --green-ink: #4ade80; --green-soft: rgba(0, 194, 52, 0.14); --green-line: rgba(0, 194, 52, 0.5);
  --forest: #13301f; --forest-2: #174029; --forest-line: #2a6a44; --forest-glow: rgba(0, 140, 50, 0.35);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --sidebar-bg: #0b1610; --nav-active-bg: #163a25;
  --text-2: #c8dccf; --accent-text: #6ee79a;
  --placeholder: #61796a; --check-border: #557463; --code-bg: #0b130e;
  --card-active-bg: #0c1b12; --nav-hover: #142219;
  --editor-top-bg: transparent;
  --auth-bg: radial-gradient(900px 520px at 50% -8%, rgba(0, 140, 50, 0.3), transparent 65%),
             radial-gradient(600px 400px at 50% 110%, rgba(23, 64, 41, 0.6), transparent 70%), var(--bg);
  --quote-bg: linear-gradient(90deg, rgba(23, 64, 41, 0.55), transparent 70%);
  --mark-bg: rgba(0, 194, 52, 0.3); --mark-text: #eafff1;
  --scroll: #1f3a2a; --scroll-hover: #2a4d38;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f7f4; --side: #edf3ee; --panel: #f7faf8; --paper: #ffffff; --raised: #e6eee8; --hover: #e1ebe4;
  --border: #d6e2d9; --text: #142019; --muted: #4b6254; --faint: #5a6e61;
  --green: #15803d; --green-hi: #16a34a; --green-ink: #15803d; --green-soft: rgba(21, 128, 61, 0.1); --green-line: rgba(21, 128, 61, 0.45);
  --green-ink: #14793a;
  --forest: #e2efe5; --forest-2: #d4e9da; --forest-line: #a9cfb4; --forest-glow: rgba(21, 128, 61, 0.12);
  --shadow: 0 10px 30px rgba(20, 40, 28, 0.12);
  --sidebar-bg: #edf3ee;
  --text-2: #2a3b31; --strong: #0b140f; --on-accent: #ffffff; --accent-text: #146c34;
  --placeholder: #76857b; --check-border: #8aa192; --check-done: #16a34a; --code-bg: #eef3ef;
  --btn-bg: linear-gradient(180deg, #19a04a, #15803d); --btn-bg-hover: linear-gradient(180deg, #20b056, #178a43);
  --btn-shadow: 0 4px 12px rgba(21, 128, 61, 0.22);
  --card-active-bg: #ffffff; --nav-active-bg: #d9ecdf; --nav-hover: #e1ebe4;
  --editor-top-bg: none;
  --auth-bg: radial-gradient(900px 520px at 50% -8%, rgba(21, 128, 61, 0.13), transparent 65%), var(--bg);
  --quote-bg: linear-gradient(90deg, #eaf4ec, transparent 70%);
  --mark-bg: #c6ead0; --mark-text: #0b140f; --scroll: #c6d5ca; --scroll-hover: #a9bcaf;
  --danger-text: #b91c1c; --warn-text: #8a5a00; --warn-bg: #fff6e0; --warn-line: #f0d48f;
  --heading-soft: #1e3a2a; --tab-active-text: #0b140f;
  --leaf: linear-gradient(135deg, #22c55e, #166534);
}

/* ---- rules that use the theme variables ---- */
body { transition: background-color 0.2s; }
.sidebar { background: var(--sidebar-bg); }
.nav-item { color: var(--text-2); }
.nav-item.active { background: var(--nav-active-bg); color: var(--strong); box-shadow: inset 3px 0 0 var(--green); }
.nav-item:hover:not(.active) { background: var(--nav-hover); }
.btn-green { background: var(--btn-bg); color: var(--on-accent); box-shadow: var(--btn-shadow); }
.btn-green:hover { background: var(--btn-bg-hover); }
.card.active { background: var(--card-active-bg); border-color: var(--forest-line); box-shadow: inset 3px 0 0 var(--green), 0 0 0 1px rgba(0, 0, 0, 0.06); }
.chip { color: var(--text-2); }
.chip.green, .tag-chip { background: var(--forest); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--forest-line); }
.toolbar button { color: var(--text-2); }
.toolbar button:hover { color: var(--strong); }
.toolbar button.on { background: var(--forest-2); color: var(--accent-text); }
.editor-top { background: var(--editor-top-bg); }
.avatar { background: var(--leaf); color: #fff; box-shadow: 0 0 0 2px var(--forest); }
.auth { background: var(--auth-bg); }
.auth-card { border-color: var(--border); box-shadow: var(--shadow), 0 0 0 1px rgba(36, 85, 58, 0.12); }
.tabs .tab.active { background: var(--forest-2); color: var(--tab-active-text); box-shadow: inset 0 0 0 1px var(--forest-line); }
.modal { border-color: var(--border); }
.settings-section h4 { color: var(--heading-soft); }
.recovery-code { background: var(--forest); border-color: var(--forest-line); color: var(--accent-text); }
.note-title::placeholder { color: var(--placeholder); }
.note-body:empty::before { color: var(--placeholder); }
.note-body blockquote { color: var(--text-2); border-left-color: var(--forest-line); background: var(--quote-bg); border-radius: 0 8px 8px 0; }
.note-body pre, .note-body code { background: var(--code-bg); }
.note-body ul.checklist li::before { border-color: var(--check-border); }
.note-body ul.checklist li.done::before { background: var(--check-done); border-color: var(--check-done); }
.share-head { background: var(--sidebar-bg); }
.share-head .badge { background: var(--forest); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--forest-line); }
::-webkit-scrollbar-thumb { background-color: var(--scroll); }
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-hover); }
mark { background: var(--mark-bg); color: var(--mark-text); }
.error, .btn-danger, .trash-banner, .menu button.danger { color: var(--danger-text); }
.warning, .reminder { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }
.caps { color: var(--warn-text); }
.eye.on, .link-btn { color: var(--green-ink); }
.share-paper .note-title { color: var(--text); }

/* ---- leaf logo (shape comes from leaf.svg, color from the theme) ---- */
.leaf {
  background: var(--leaf); border-radius: 0; box-shadow: none;
  -webkit-mask: url(/leaf.svg) center / contain no-repeat; mask: url(/leaf.svg) center / contain no-repeat;
}
.leaf.huge { width: 72px; height: 72px; border-radius: 0; opacity: 0.55; }

/* ---- focus mode ---- */
body.focus-mode .app { grid-template-columns: 0 0 1fr; }
body.focus-mode .sidebar, body.focus-mode .list { visibility: hidden; overflow: hidden; border: 0; padding: 0; }
.app { transition: grid-template-columns 0.25s ease; }
#focus-btn.active { color: var(--green-ink); }

/* ---- command palette ---- */
.palette-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 60; display: flex; justify-content: center; padding-top: 12vh; }
.palette { width: min(600px, 92vw); max-height: 60vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.palette input { background: transparent; border: 0; border-bottom: 1px solid var(--border); padding: 16px 18px; font-size: 17px; outline: none; color: var(--text); }
.palette-list { overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 9px; padding: 9px 12px; color: var(--text); }
.palette-item .kind { margin-left: auto; font-size: 12px; color: var(--faint); }
.palette-item .sub { color: var(--faint); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.sel { background: var(--nav-active-bg); box-shadow: inset 3px 0 0 var(--green); }
.palette-item svg { color: var(--muted); }
.palette-empty { color: var(--faint); padding: 18px; text-align: center; }
.palette-hint { border-top: 1px solid var(--border); padding: 8px 14px; font-size: 12px; color: var(--faint); display: flex; gap: 14px; }
kbd { font: 11px ui-monospace, Menlo, Consolas, monospace; background: var(--raised); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--muted); }
.search kbd { margin-left: auto; }

/* ---- theme picker ---- */
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.theme-opt { border: 1px solid var(--border); border-radius: 11px; padding: 8px; background: transparent; text-align: left; color: var(--text); font-size: 13px; font-weight: 600; }
.theme-opt:hover { border-color: var(--forest-line); }
.theme-opt.active { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.theme-swatch { height: 46px; border-radius: 7px; margin-bottom: 7px; display: grid; grid-template-columns: 1fr 1.6fr; overflow: hidden; border: 1px solid rgba(127, 127, 127, 0.18); }
.theme-swatch i { display: block; }
.theme-swatch i:last-child { position: relative; }
.theme-swatch i:last-child::after { content: ""; position: absolute; left: 10px; right: 30%; top: 14px; height: 7px; border-radius: 4px; background: var(--sw-accent); }
.modal { max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; }
.palette-backdrop { align-items: flex-start; }
.search input { min-width: 0; width: 100%; }
.search kbd { flex: none; white-space: nowrap; }
@media (max-width: 820px) { .search kbd { display: none; } }

/* selected note: solid and darker, no side bar */
.card.active { box-shadow: none; }

/* =====================================================================
   READABILITY: text size, interface size, font, line spacing, high contrast
   (values are set on <html> by theme.js from the saved preferences)
   ===================================================================== */
:root {
  --app-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --note-size: 16.5px;
  --note-line: 1.7;
  --ui-zoom: 1;
}
body, button, input, select, textarea { font-family: var(--app-font); }
.note-body { font-size: var(--note-size); line-height: var(--note-line); }
.note-title { font-size: calc(var(--note-size) * 2.05); }
.note-body h1 { font-size: calc(var(--note-size) * 1.58); }
.note-body h2 { font-size: calc(var(--note-size) * 1.27); }
.note-body pre, .note-body code { font-size: calc(var(--note-size) * 0.86); }
.card-preview, .card-title { line-height: calc(var(--note-line) - 0.15); }

/* interface size: zoom everything, and shrink the app's height to match so it still fits the screen */
body { zoom: var(--ui-zoom); }
.app { height: calc(100vh / var(--ui-zoom)); height: calc(100dvh / var(--ui-zoom)); }
.auth { min-height: calc(100vh / var(--ui-zoom)); }

/* high contrast: brighter secondary text, stronger lines */
html[data-contrast="high"]:not([data-theme="light"]):not([data-theme="paper"]) {
  --text: #ffffff; --muted: #d4d4da; --faint: #b8b8c0; --placeholder: #9a9aa2; --border: #45454d; --text-2: #f0f0f3; --check-border: #a0a0a8;
}
html[data-contrast="high"][data-theme="forest"] { --muted: #cfe3d6; --faint: #b0c8b8; --border: #3a5a46; --placeholder: #8fa898; }
html[data-contrast="high"][data-theme="light"], html[data-contrast="high"][data-theme="paper"] {
  --text: #000000; --muted: #1f2f25; --faint: #34473b; --placeholder: #57685d; --border: #98ad9f; --text-2: #0b140f; --check-border: #4f6457;
}
html[data-contrast="high"] .note-body a { text-decoration-thickness: 2px; }

/* keyboard focus is always visible */
:focus-visible { outline: 2px solid var(--green-ink); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, .note-body:focus-visible, .note-title:focus-visible { outline: none; }

/* settings controls */
.pref { margin: 12px 0 4px; }
.pref-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1; min-width: 64px; background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 7px 8px; font-size: 13.5px; }
.seg button:hover { border-color: var(--forest-line); }
.seg button.on { border-color: var(--green); background: var(--forest); color: var(--strong); box-shadow: 0 0 0 2px var(--green-soft); }
.pref-preview { margin-top: 10px; padding: 12px 14px; border: 1px dashed var(--border); border-radius: 10px; color: var(--text); font-size: var(--note-size); line-height: var(--note-line); }
.pref-preview small { display: block; color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.modal { max-height: calc((100vh - 40px) / var(--ui-zoom)); max-height: calc((100dvh - 40px) / var(--ui-zoom)); }
.palette { max-height: calc(60vh / var(--ui-zoom)); }
.palette-backdrop { padding-top: calc(12vh / var(--ui-zoom)); }
@media (max-width: 820px) {
  body.show-editor .editor { height: calc(100dvh / var(--ui-zoom)); }
  .sidebar { height: calc(100dvh / var(--ui-zoom)); }
}

/* line icons in text */
.ico { width: 1.05em; height: 1.05em; vertical-align: -0.15em; margin-right: 4px; }
.section-title { display: flex; align-items: center; gap: 8px; }
.section-title svg { width: 17px; height: 17px; color: var(--green-ink); }
.status-ok { color: var(--accent-text) !important; }
.status-warn { color: var(--warn-text) !important; }
.share-head .badge { display: inline-flex; align-items: center; gap: 2px; }

/* version history */
.history-modal { max-width: 900px; width: 100%; display: flex; flex-direction: column; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.history-head h4 { margin: 0; font-size: 16px; }
.history-grid { display: grid; grid-template-columns: 230px 1fr; gap: 14px; min-height: 0; flex: 1; }
.history-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: calc(70vh / var(--ui-zoom)); padding-right: 4px; }
.history-list button { text-align: left; background: transparent; border: 1px solid transparent; border-radius: 9px; padding: 9px 11px; color: var(--text); display: flex; flex-direction: column; gap: 2px; }
.history-list button span { font-size: 12.5px; color: var(--faint); }
.history-list button:hover { background: var(--hover); }
.history-list button.active { background: var(--card-active-bg); border-color: var(--forest-line); }
.history-pane { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; overflow-y: auto; max-height: calc(70vh / var(--ui-zoom)); background: var(--paper); }
.history-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.history-bar .btn-green { font-size: 14px; padding: 8px 14px; }
.history-title { margin: 4px 0 10px; font-size: calc(var(--note-size) * 1.5); }
.history-loading { color: var(--faint); }
@media (max-width: 820px) { .history-grid { grid-template-columns: 1fr; } .history-list { max-height: 160px; } }

/* offline */
.offline-pill { display: flex; align-items: center; gap: 8px; background: var(--raised); border: 1px solid var(--border); color: var(--muted); border-radius: 9px; padding: 8px 10px; font-size: 13px; line-height: 1.35; }
.offline-pill svg { color: var(--warn-text); flex: none; }
.offline-note { background: var(--raised); border: 1px solid var(--border); color: var(--muted); border-radius: 9px; padding: 10px 12px; font-size: 13px; margin: 0 0 10px; }

/* ---------- more themes ---------- */
[data-theme="midnight"] {
  /* pure black, minimal, green only where it matters */
  --bg: #000000; --side: #000000; --panel: #050505; --paper: #0a0a0a; --raised: #141414; --hover: #161616;
  --border: #1f1f1f; --text: #f2f2f2; --muted: #a8a8a8; --faint: #8c8c8c;
  --forest: #0b1a10; --forest-2: #0f2416; --forest-line: #1f5a35; --forest-glow: rgba(0, 140, 50, 0.2);
  --sidebar-bg: #000000; --nav-active-bg: #0d1a11; --nav-hover: #111111;
  --card-active-bg: #070d09; --editor-top-bg: transparent;
  --text-2: #d6d6d6; --placeholder: #6f6f6f; --check-border: #5a5a5a; --code-bg: #0d0d0d;
  --quote-bg: linear-gradient(90deg, rgba(15, 36, 22, 0.5), transparent 70%);
  --auth-bg: radial-gradient(800px 480px at 50% -10%, rgba(0, 140, 50, 0.16), transparent 65%), #000000;
  --scroll: #1f1f1f; --scroll-hover: #2c2c2c; --shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}
[data-theme="graphite"] {
  /* neutral dark grey, green accents */
  --bg: #161618; --side: #1c1c1f; --panel: #1f1f22; --paper: #242428; --raised: #2c2c31; --hover: #2f2f35;
  --border: #35353b; --text: #ededf0; --muted: #b0b0b8; --faint: #9a9aa3;
  --forest: #1d2a21; --forest-2: #23382a; --forest-line: #2f6b45; --forest-glow: rgba(0, 140, 50, 0.18);
  --sidebar-bg: #1c1c1f; --nav-active-bg: #263329; --nav-hover: #26262b;
  --card-active-bg: #2a2a2f; --editor-top-bg: transparent;
  --text-2: #d6d6dc; --placeholder: #77777f; --check-border: #6c6c74; --code-bg: #19191b;
  --quote-bg: linear-gradient(90deg, rgba(35, 56, 42, 0.45), transparent 70%);
  --auth-bg: radial-gradient(800px 480px at 50% -10%, rgba(0, 140, 50, 0.14), transparent 65%), #161618;
  --scroll: #3a3a40; --scroll-hover: #4a4a52;
}
[data-theme="paper"] {
  /* warm off-white, like real paper */
  color-scheme: light;
  --bg: #f6f1e7; --side: #efe8da; --panel: #f8f4ec; --paper: #fffdf8; --raised: #ebe3d3; --hover: #e7dfcd;
  --border: #ddd3bf; --text: #1f1a12; --muted: #564d3e; --faint: #675d4c;
  --green: #15803d; --green-hi: #16a34a; --green-ink: #116b33; --green-soft: rgba(21, 128, 61, 0.1); --green-line: rgba(21, 128, 61, 0.45);
  --forest: #e6efdf; --forest-2: #dbe8d2; --forest-line: #a8c49a; --forest-glow: rgba(21, 128, 61, 0.1);
  --shadow: 0 10px 30px rgba(60, 45, 20, 0.12);
  --sidebar-bg: #efe8da; --nav-active-bg: #e0e8d4; --nav-hover: #e7dfcd;
  --card-active-bg: #fffdf8; --editor-top-bg: transparent;
  --text-2: #2d2619; --strong: #120e08; --on-accent: #ffffff; --accent-text: #2f6b1f;
  --placeholder: #8a7f6c; --check-border: #9a8f7a; --check-done: #16a34a; --code-bg: #f0eadc;
  --btn-bg: linear-gradient(180deg, #19a04a, #15803d); --btn-bg-hover: linear-gradient(180deg, #20b056, #178a43);
  --btn-shadow: 0 4px 12px rgba(21, 128, 61, 0.2);
  --auth-bg: radial-gradient(900px 520px at 50% -8%, rgba(21, 128, 61, 0.1), transparent 65%), #f6f1e7;
  --quote-bg: linear-gradient(90deg, #efeadb, transparent 70%);
  --mark-bg: #d9ecc8; --mark-text: #120e08; --scroll: #d6ccb8; --scroll-hover: #c4b8a0;
  --danger-text: #a61b1b; --warn-text: #7a4f00; --warn-bg: #fdf3dc; --warn-line: #ecd08e;
  --heading-soft: #2b3a22; --tab-active-text: #1f1a12;
}

/* ---------- full-page settings ---------- */
.modal.settings-page {
  max-width: 1040px; width: 100%; height: calc((100vh - 40px) / var(--ui-zoom)); height: calc((100dvh - 40px) / var(--ui-zoom));
  max-height: none; padding: 0; overflow: hidden;
  display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr;
}
.settings-top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.settings-top h3 { margin: 0; font-size: 19px; }
.settings-top p { margin: 0; color: var(--muted); font-size: 13.5px; }
.settings-top .spacer { flex: 1; }
.settings-nav { border-right: 1px solid var(--border); padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; background: var(--sidebar-bg); }
.settings-nav button { display: flex; align-items: center; gap: 10px; text-align: left; background: transparent; border: 0; border-radius: 8px; padding: 9px 10px; color: var(--text-2); font-size: 14px; }
.settings-nav button svg { width: 16px; height: 16px; color: var(--muted); }
.settings-nav button:hover { background: var(--nav-hover); }
.settings-nav button.active { background: var(--nav-active-bg); color: var(--strong); }
.settings-nav button.active svg { color: var(--green-ink); }
.settings-body { overflow-y: auto; padding: 4px 28px 40px; scroll-behavior: smooth; }
.settings-body .settings-section { max-width: 640px; padding-top: 22px; margin-top: 22px; }
.settings-body .settings-section:first-child { border-top: 0; margin-top: 0; }
.settings-body .section-title { font-size: 16px; }
.themes { grid-template-columns: repeat(3, 1fr); }
.theme-opt { color: var(--text); }
.theme-opt .theme-name { display: block; color: var(--text); padding: 0 2px; }
@media (max-width: 820px) {
  .modal.settings-page { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; }
  .settings-nav button { white-space: nowrap; }
  .settings-body { padding: 0 16px 30px; }
  .themes { grid-template-columns: repeat(2, 1fr); }
}

/* no green side bars anywhere: active items use a flat, solid highlight */
.nav-item.active, .palette-item.sel, .card.active { box-shadow: none; }
.nav-item.active svg { color: var(--green-ink); }
