:root{
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --border: #E2E8F0;
  --border-hover: #CBD5E1;
  --text: #0F172A;
  --text-muted: #475569;
  --text-faint: #94A3B8;
  --accent: #4F46E5;
  --accent-soft: #EEF2FF;
  --btn-text: #FFFFFF;
  --danger: #EF4444;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 4px 12px -2px rgba(0,0,0,0.05);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.08), 0 12px 24px -4px rgba(0,0,0,0.08);
  color-scheme: light;
}
[data-theme="dark"]{
  --bg: #0C0C0E;
  --surface: #141418;
  --surface-2: #1A1A20;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.16);
  --text: #F3F4F6;
  --text-muted: #9CA3AF;
  --text-faint: #6B7280;
  --accent: #6366F1;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --btn-text: #FFFFFF;
  --danger: #F87171;
  --shadow: 0 2px 4px rgba(0,0,0,0.4), 0 12px 28px -8px rgba(0,0,0,0.6);
  --shadow-hover: 0 4px 16px rgba(0,0,0,0.5), 0 20px 40px -10px rgba(0,0,0,0.7);
  color-scheme: dark;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
[hidden]{ display: none !important; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background .2s ease, color .2s ease;
}
.brand-font{ font-family:'Plus Jakarta Sans', 'Inter', sans-serif; }
button{ font-family: inherit; cursor:pointer; }
input, textarea, select{ font-family: inherit; }
::selection{ background: var(--accent-soft); }
:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Topbar ---------- */
.topbar{
  display:flex; align-items:center; gap:20px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky; top:0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.brand{
  display:flex; align-items:center; gap:9px;
  font-size: 19px; font-weight: 700; letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand .mark{
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(155deg, var(--accent), #7C79F0 120%);
  position: relative; flex-shrink:0;
}
.brand .mark::after{
  content:""; position:absolute; left:6px; top:6px; right:6px;
  height: 2px; border-radius: 2px; background: rgba(255,255,255,0.85);
  box-shadow: 0 5px 0 rgba(255,255,255,0.65), 0 10px 0 rgba(255,255,255,0.45);
}
.search-wrap{
  flex:1; max-width: 460px; position: relative;
}
.search-wrap svg{
  position:absolute; left:13px; top:50%; transform:translateY(-50%);
  width:16px; height:16px; color: var(--text-faint); pointer-events:none;
}
.search-wrap input{
  width:100%; padding: 9px 14px 9px 37px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
}
.search-wrap input::placeholder{ color: var(--text-faint); }
.search-wrap input:focus{ border-color: var(--accent); outline:none; }

.topbar-actions{ display:flex; align-items:center; gap:10px; margin-left:auto; }

.topbar-actions .btn-ghost {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 7px 14px; border-radius: 20px;
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s ease;
}
.topbar-actions .btn-ghost:hover {
  background: var(--surface-2); border-color: var(--text-faint);
}
.topbar-actions .btn-ghost svg { width: 14px; height: 14px; }

.icon-btn{
  width:36px; height:36px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  display:flex; align-items:center; justify-content:center;
  color: var(--text-muted); transition: all .15s ease;
}
.icon-btn:hover{ color: var(--text); border-color: var(--text-faint); }
.icon-btn svg{ width:17px; height:17px; }

.btn-primary{
  display:flex; align-items:center; gap:7px;
  background: var(--accent); color: var(--btn-text, #fff); border:none;
  padding: 9px 16px; border-radius: 20px;
  font-size: 13.5px; font-weight:600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06), 0 6px 16px -6px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: transform .12s ease, box-shadow .2s ease;
  white-space: nowrap;
}
.btn-primary:hover{ transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.08), 0 10px 22px -6px color-mix(in srgb, var(--accent) 65%, transparent); }
.btn-primary svg{ width:15px; height:15px; }

/* ---------- Layout ---------- */
.layout{
  display:grid;
  grid-template-columns: 1fr 260px;
  gap: 28px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px;
}

.panel-head{
  display:flex; align-items:baseline; gap:10px; margin-bottom:18px;
}
.panel-head h1{
  font-size: 21px; margin:0; font-weight:600; letter-spacing:-0.01em;
}
.panel-head .count-pill{
  font-size: 12px; color: var(--text-muted); background: var(--surface-2);
  border: 1px solid var(--border); padding: 2px 9px; border-radius: 20px;
}

.notes-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.note-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 14px;
  display:flex; flex-direction:column; gap:10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
  position:relative;
  min-height: 168px;
}
.note-card.is-pinned {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}
.note-card:hover{
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: color-mix(in srgb, var(--border) 40%, var(--text-faint));
}
.note-card .tag-row{
  display:flex; align-items:center; gap: 8px; flex-wrap: wrap;
  padding-right: 60px;
}
.card-actions {
  position: absolute; right: 12px; top: 12px;
  display: flex; gap: 4px; opacity: 0; transition: opacity .15s ease;
}
.note-card:hover .card-actions, .note-card.is-pinned .card-actions { opacity: 1; }
.tag-chip{
  display:inline-flex; align-items:center; gap:6px;
  font-size: 11px; font-weight:600; letter-spacing:.03em; text-transform:uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.tag-chip .dot{ width:7px; height:7px; border-radius:50%; flex-shrink:0; }

.sortable-ghost {
  opacity: 0.35 !important;
  border: 2px dashed var(--accent) !important;
  background: color-mix(in srgb, var(--accent) 10%, transparent) !important;
}
.sortable-chosen {
  transform: scale(1.02) !important;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4) !important;
  cursor: grabbing !important;
}

.action-btn {
  width: 26px; height:26px; border-radius:8px; border:none; background:transparent;
  color: var(--text-faint); display:flex; align-items:center; justify-content:center;
  transition: color .15s ease, background .15s ease; cursor: pointer;
}
.action-btn:hover{ background: var(--surface-2); color: var(--text); }
.action-btn.del-btn:hover{ color: var(--danger); }
.action-btn.pin-btn.pinned { color: var(--accent); opacity: 1; }
.action-btn svg{ width:15px; height:15px; }

.note-card h3{
  margin:0; font-size:15.5px; font-weight:600; letter-spacing:-0.01em;
  line-height:1.35; padding-right: 60px;
}
.note-card .markdown-preview {
  margin:0; font-size:13px; color: var(--text-muted); line-height:1.55;
  display:-webkit-box; -webkit-line-clamp:4; -webkit-box-orient:vertical; overflow:hidden;
  flex:1;
}
.markdown-preview, #viewModeContent {
  color: #94A3B8 !important;
  font-size: 13.5px; line-height: 1.6;
}
#viewModeContent *, .markdown-preview * {
  color: #94A3B8 !important;
}
#viewModeContent h1, #viewModeContent h2, #viewModeContent h3, #viewModeContent h4, #viewModeContent strong {
  color: #CBD5E1 !important;
}
#viewModeContent a {
  color: #818CF8 !important;
}
.note-card .markdown-preview * { margin: 0; padding: 0; font-size: 13px !important; }
.note-card .markdown-preview img, .note-card .markdown-preview audio {
  max-width: 100%; max-height: 60px; object-fit: contain; border-radius: 4px; margin-top: 4px;
}
.note-card .meta{
  font-size:11px; color: var(--text-faint); font-weight:500;
  letter-spacing:.01em; margin-top:2px;
}

.add-note-tile{
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:8px; min-height:168px; color: var(--text-faint);
  background: transparent; transition: all .15s ease; cursor: pointer;
}
.add-note-tile:hover{ border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-note-tile svg{ width:22px; height:22px; }
.add-note-tile span{ font-size:13px; font-weight:600; }

.empty-state{
  text-align:center; padding: 70px 20px; color: var(--text-muted);
}
.empty-state .glyph{ font-size:30px; margin-bottom:10px; }
.empty-state h3{ margin:0 0 6px; color:var(--text); font-size:16px; }
.empty-state p{ margin:0; font-size:13.5px; }

/* ---------- Categories panel ---------- */
.categories-panel{ align-self:start; position: sticky; top: 90px; }
.categories-panel h2{
  font-size: 12.5px; text-transform:uppercase; letter-spacing:.06em;
  color: var(--text-faint); font-weight:700; margin: 4px 0 12px;
}
.category-list{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:2px; }
.category-item{
  display:flex; align-items:center; gap:10px;
  padding: 9px 10px; border-radius: 10px;
  font-size: 13.5px; font-weight:500; color: var(--text-muted);
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease;
  position:relative; cursor: pointer;
}
.category-item:hover{ background: var(--surface-2); color: var(--text); }
.category-item.active{
  background: var(--accent-soft); color: var(--accent); font-weight:600;
}
.category-item .dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.category-item .name{ flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.category-item .num{
  font-size:11.5px; color: var(--text-faint); background: var(--surface);
  border: 1px solid var(--border); padding: 1px 7px; border-radius: 20px;
  font-weight:600;
}
.category-item.active .num{ color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); background: var(--surface); }
.category-item .del-cat{
  width:20px; height:20px; border:none; background:transparent; color:var(--text-faint);
  border-radius:6px; display:none; align-items:center; justify-content:center; flex-shrink:0; cursor: pointer;
}
.category-item:hover .del-cat{ display:flex; }
.category-item .del-cat:hover{ color: var(--danger); background: var(--surface); }
.category-item .del-cat svg{ width:12px; height:12px; }

.add-cat-btn{
  display:flex; align-items:center; gap:8px; width:100%;
  background:none; border: none; color: var(--text-faint);
  font-size: 13px; font-weight:600; padding: 10px; margin-top:6px; border-radius:10px; cursor: pointer;
}
.add-cat-btn:hover{ color: var(--accent); background: var(--surface-2); }
.add-cat-btn svg{ width:14px; height:14px; }

.storage-note{
  margin-top: 22px; padding: 13px 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; line-height:1.6; color: var(--text-faint);
}
.storage-note strong{ color: var(--text-muted); }

/* ---------- Modal & Editor ---------- */
.modal-overlay{
  position: fixed; inset:0; background: rgba(10,10,12,0.6);
  backdrop-filter: blur(4px);
  display:flex; align-items:center; justify-content:center;
  padding: 20px; z-index: 100;
  animation: fadeIn .15s ease;
}
.modal-overlay[hidden]{ display:none !important; }
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }
.modal{
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 600px; border: 1px solid var(--border);
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.5);
  animation: pop .16s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop{ from{ transform: translateY(8px) scale(.98); opacity:0 } to{ transform:none; opacity:1 } }
.modal-head{
  display:flex; align-items:center; justify-content:space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2{ margin:0; font-size:15.5px; font-weight:600; }
.modal-body{ padding: 18px 20px; display:flex; flex-direction:column; gap:14px; }
.field label{
  display:block; font-size:11.5px; font-weight:700; text-transform:uppercase;
  letter-spacing:.05em; color: var(--text-faint); margin-bottom:7px;
}
.field input[type=text], .field textarea, .field select{
  width:100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px; resize: vertical;
}

/* Toolbar */
.editor-toolbar {
  display: flex; gap: 4px; padding: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 10px 10px 0 0;
}
.toolbar-btn {
  background: transparent; border: none; border-radius: 6px;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); cursor: pointer;
}
.toolbar-btn:hover { background: var(--surface); color: var(--text); }
.toolbar-btn svg { width: 14px; height: 14px; }
.toolbar-btn.recording { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

.field textarea{ 
  min-height: 200px; line-height: 1.55; font-family: monospace;
  border-radius: 0 0 10px 10px; margin-top: 0;
}
.field input:focus, .field textarea:focus, .field select:focus{ border-color: var(--accent); outline:none; background: var(--surface); }

.cat-select-row{ display:flex; flex-wrap:wrap; gap:8px; }
.cat-pick{
  display:flex; align-items:center; gap:6px;
  padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);
  font-size:12.5px; font-weight:600; color: var(--text-muted); background: var(--surface-2);
  cursor: pointer;
}
.cat-pick .dot{ width:7px; height:7px; border-radius:50%; }
.cat-pick.selected{ border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); color: var(--text); background: var(--accent-soft); }

.modal-foot{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding: 16px 20px; border-top: 1px solid var(--border);
}
.btn-ghost-modal {
  background:none; border:1px solid var(--border); color: var(--text-muted);
  padding: 9px 15px; border-radius:10px; font-size:13.5px; font-weight:600; cursor: pointer;
}
.btn-ghost-modal:hover{ color: var(--text); border-color: var(--text-faint); }
.btn-danger-text{
  background:none; border:none; color: var(--danger); font-size:13px; font-weight:600;
  padding: 8px 4px; display:flex; align-items:center; gap:6px; cursor: pointer;
}
.btn-danger-text:hover { opacity: 0.8; }
.btn-danger-text svg{ width:14px; height:14px; }
.btn-row{ display:flex; gap:10px; margin-left:auto; }

.color-row{ display:flex; gap:8px; flex-wrap:wrap; }
.color-swatch{
  width:24px; height:24px; border-radius:50%; border: 2px solid transparent; cursor:pointer;
}
.color-swatch.selected{ border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

/* ========== API Vault ========== */
.vault-panel { max-width: 560px; margin: 0 auto; padding: 4px 0 40px; }
.vault-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.vault-header h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.vault-lock-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 20px;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.vault-lock-badge.unlocked { background: color-mix(in srgb, #10B981 15%, transparent); color: #10B981; border-color: #10B98144; }

.vault-form-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px; margin-bottom: 20px;
}
.vault-form-box h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.vault-form-box p { margin: 0 0 18px; font-size: 13px; color: var(--text-muted); }
.vault-input {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 14px; outline: none; box-sizing: border-box;
  transition: border-color .15s;
}
.vault-input:focus { border-color: var(--accent); }
.vault-input-row { display: flex; gap: 10px; margin-bottom: 12px; }
.vault-input-row .vault-input { margin-bottom: 0; }
.vault-err { font-size: 12px; color: var(--danger, #EF4444); margin-top: 8px; min-height: 16px; }

.vault-entry {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px;
  display: flex; align-items: center; gap: 14px; margin-bottom: 10px;
}
.vault-entry-icon {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--surface-2); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 18px;
}
.vault-entry-info { flex: 1; min-width: 0; }
.vault-entry-label { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.vault-entry-service { font-size: 12px; color: var(--text-muted); }
.vault-entry-key {
  font-family: 'JetBrains Mono', monospace; font-size: 12px;
  color: var(--text-faint); cursor: pointer; user-select: none;
  letter-spacing: .04em; margin-top: 4px;
}
.vault-entry-key.revealed { color: var(--text); }
.vault-entry-actions { display: flex; gap: 4px; flex-shrink: 0; }

.vault-add-box {
  background: var(--surface-2); border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg); padding: 20px; margin-top: 16px;
}
.vault-add-box h4 { margin: 0 0 14px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.vault-add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
@media (max-width: 500px) { .vault-add-grid { grid-template-columns: 1fr; } }
.vault-autolock-note { font-size: 12px; color: var(--text-faint); margin-top: 16px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 860px){
  .layout{ grid-template-columns: 1fr; padding: 18px; gap:22px; }
  .categories-panel{ order:-1; }
  .category-list{ flex-direction:row; overflow-x:auto; padding-bottom:4px; gap:8px; }
  .category-item{ flex-shrink:0; }
  .category-item .num{ display:none; }
  .add-cat-btn{ display:none; }
  .storage-note{ display:none; }
  .categories-panel h2{ display:none; }
  .topbar{ padding: 14px 16px; gap:12px; }
  .search-wrap{ max-width: none; }
  .editor-toolbar { overflow-x: auto; white-space: nowrap; flex-wrap: nowrap; }
  .editor-toolbar .toolbar-btn { flex-shrink: 0; }
  .modal { margin: 10px; }
}

/* ---------- Flashcards ---------- */
.flashcard-container { perspective: 1000px; width: 100%; max-width: 460px; aspect-ratio: 3/2; margin: 0 auto 24px; }
.flashcard { width: 100%; height: 100%; transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1); transform-style: preserve-3d; cursor: pointer; position: relative; }
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px; text-align: center; box-shadow: var(--shadow); font-size: 18px; font-weight: 500;
}
.flashcard-back { transform: rotateY(180deg); background: var(--surface-2); }
#fcGrading.show { opacity: 1; pointer-events: auto; }

/* ---------- Notion-Style Features ---------- */
.internal-link {
  color: var(--accent); font-weight: 600; text-decoration: underline; text-decoration-style: dotted; cursor: pointer;
}
.internal-link:hover { text-decoration-style: solid; }

.slash-menu {
  position: fixed; z-index: 350; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-hover); width: 240px; padding: 6px;
  display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto;
}
.slash-item {
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; flex-direction: column; transition: background .12s;
}
.slash-item:hover, .slash-item.selected { background: var(--surface-2); color: var(--text); }
.slash-item strong { font-size: 13px; font-weight: 600; }
.slash-item span { font-size: 11px; color: var(--text-faint); }

.kanban-board {
  display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; min-height: 400px;
}
.kanban-column {
  flex: 1; min-width: 260px; max-width: 320px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.kanban-header {
  display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 13.5px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.kanban-cards {
  display: flex; flex-direction: column; gap: 12px; min-height: 100px; flex: 1;
}
.backlink-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); font-size: 12.5px; font-weight: 500; cursor: pointer;
  transition: all .15s ease;
}
.backlink-chip:hover { border-color: var(--accent); color: var(--accent); }
.view-switcher { display: flex; gap: 6px; margin-left: auto; }

/* ---------- Reader & Editor Typography ---------- */
.markdown-preview {
  font-size: 14.5px; color: var(--text); line-height: 1.7;
}
.markdown-preview h1, .markdown-preview h2, .markdown-preview h3 {
  font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 700; color: var(--text);
  margin: 1.2em 0 0.4em; line-height: 1.3; letter-spacing: -0.02em;
}
.markdown-preview h1 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-preview h2 { font-size: 1.25em; }
.markdown-preview h3 { font-size: 1.1em; }
.markdown-preview p { margin: 0 0 1em; }
.markdown-preview blockquote {
  margin: 1em 0; padding: 10px 16px; border-left: 3px solid var(--accent);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted); font-style: italic;
}
.markdown-preview pre {
  background: #000000 !important; border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 14px 18px; overflow-x: auto;
  font-family: 'JetBrains Mono', monospace; font-size: 13px; margin: 1em 0;
}
.markdown-preview code {
  font-family: 'JetBrains Mono', monospace; font-size: 0.88em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: 6px; color: var(--accent);
}
.markdown-preview pre code { background: transparent; border: none; padding: 0; color: inherit; }
.markdown-preview ul, .markdown-preview ol { padding-left: 20px; margin: 0 0 1em; }
.markdown-preview li { margin-bottom: 0.3em; }
.markdown-preview hr { border: none; border-top: 1px solid var(--border); margin: 1.8em 0; }

/* ---------- Command Palette Modal ---------- */
.command-palette-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px); display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh; z-index: 500;
}
.command-palette-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 560px;
  box-shadow: var(--shadow-hover); overflow: hidden; animation: pop .12s cubic-bezier(.2,.9,.3,1.2);
}
.command-input-wrap {
  display: flex; align-items: center; gap: 12px; padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.command-input-wrap svg { width: 18px; height: 18px; color: var(--text-faint); }
.command-input-wrap input {
  flex: 1; background: transparent; border: none; outline: none;
  font-size: 16px; color: var(--text); font-weight: 500;
}
.command-list {
  max-height: 340px; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px;
}
.command-item {
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; transition: background .1s ease, color .1s ease;
}
.command-item:hover, .command-item.selected {
  background: var(--surface-2); color: var(--text);
}
/* ---------- Mobile PWA & Touch Optimizations ---------- */
@media (max-width: 640px) {
  html, body { overflow-x: hidden !important; max-width: 100vw; }
  body { padding-bottom: calc(90px + env(safe-area-inset-bottom)); overscroll-behavior-y: contain; }
  .layout { padding: 12px 12px 90px; gap: 14px; grid-template-columns: 1fr; }
  .categories-panel { display: none !important; }
  
  .topbar { padding: 10px 12px !important; gap: 8px !important; overflow: hidden; width: 100%; max-width: 100vw; }
  .topbar .brand { font-size: 16px; gap: 6px; }
  .topbar .brand .mark { width: 22px; height: 22px; border-radius: 6px; }
  .topbar-actions { gap: 4px !important; flex-shrink: 0; }
  
  #exportBtn, #importBtn { display: none !important; }

  .note-card:hover .card-actions { opacity: 0 !important; }

  .notes-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .kanban-board { flex-direction: column; gap: 14px; }
  .kanban-column { min-width: 100%; }
  
  .graph-container { height: calc(100vh - 180px); min-height: 380px; }

  .swipe-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
  }
  .swipe-wrapper .note-card {
    width: 100%;
    position: relative;
    z-index: 2;
    transition: transform 0.25s cubic-bezier(.4,0,.2,1);
    will-change: transform;
  }
  .swipe-reveal {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 64px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    z-index: 1;
  }
  .swipe-reveal-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent; cursor: pointer;
    color: var(--text-faint);
    border-radius: 8px;
    transition: color .15s ease, background .15s ease;
  }
  .swipe-reveal-btn:active { background: var(--surface-2); }
  .swipe-reveal-pin { color: var(--accent); }
  .swipe-reveal-pin.pinned { color: #10B981; }
  .swipe-reveal-del { color: #EF4444; }
  .swipe-reveal-btn svg { width: 18px; height: 18px; }

  .mobile-nav-bar {
    position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; gap: 6px; padding: 6px;
    background: color-mix(in srgb, var(--surface) 92%, #000 8%); backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid var(--border); border-radius: 24px;
    box-shadow: 0 16px 36px -8px rgba(0, 0, 0, 0.5), 0 0 24px -4px color-mix(in srgb, var(--accent) 25%, transparent);
    z-index: 400; transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .mobile-nav-item {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; border-radius: 16px; border: 1px solid transparent;
    background: var(--surface-2); color: var(--text-faint);
    cursor: pointer; transition: all .18s cubic-bezier(0.16, 1, 0.3, 1);
    touch-action: manipulation; position: relative;
  }
  .mobile-nav-item:active { transform: scale(0.90); }
  .mobile-nav-item.active {
    background: var(--accent); color: #ffffff !important; border-color: transparent;
    box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  .mobile-nav-item svg { width: 20px; height: 20px; stroke-width: 2.2; }

  #exportBtn span, #importBtn span, #newNoteBtn span, #gistSyncBtn span { display: none !important; }
  .mobile-nav-item span, .btn-ghost-modal span { display: none !important; }
  #saveNoteBtn span { display: inline-block !important; }

  @media (min-width: 641px) {
    #exportBtn span, #importBtn span, #newNoteBtn span { display: inline-block !important; }
  }

  .modal-overlay { z-index: 500; align-items: flex-end; padding: 0; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: none;
    max-height: 88vh; margin: 0; width: 100%; border-left: none; border-right: none;
    animation: slideUp .22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

  .mobile-menu-sheet {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(14px) saturate(180%); display: flex; align-items: flex-end; justify-content: center;
    z-index: 550; animation: fadeIn .18s ease;
  }
  .mobile-menu-box {
    background: color-mix(in srgb, var(--surface) 96%, #000 4%);
    border: 1px solid var(--border); border-radius: 24px 24px 0 0;
    width: 100%; max-width: 500px; padding: 22px 20px 34px;
    box-shadow: 0 -12px 40px rgba(0,0,0,0.6);
    animation: slideUp .22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .mobile-menu-list {
    display: flex; flex-direction: column; gap: 8px; margin-top: 14px; max-height: 50vh; overflow-y: auto;
  }
  .mobile-menu-btn {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border-radius: 16px; border: 1px solid var(--border);
    background: var(--surface-2); color: var(--text); font-size: 14px;
    font-weight: 600; cursor: pointer; transition: all .15s ease; touch-action: manipulation;
  }
  .mobile-menu-btn:active, .mobile-menu-btn.active {
    border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent);
  }

  .pull-search-banner {
    position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
    background: var(--accent); color: #ffffff; padding: 8px 18px; border-radius: 20px;
    font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
    z-index: 700; transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .mobile-nav-item.recording {
    background: var(--danger) !important; color: #ffffff !important;
    animation: pulseRecord 1.2s infinite ease-in-out;
  }
  @keyframes pulseRecord { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); } 50% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } }
}
@media (min-width: 641px) {
  .mobile-nav-bar { display: none !important; }
}

/* ---------- 2D Knowledge Graph View ---------- */
.graph-container {
  position: relative; width: 100%; height: calc(100vh - 160px); min-height: 420px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow);
}
#graphCanvas { width: 100%; height: 100%; display: block; cursor: grab; }
#graphCanvas:active { cursor: grabbing; }
.graph-controls {
  position: absolute; bottom: 16px; right: 16px; display: flex; gap: 8px; z-index: 10;
}
