@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,700;1,9..144,300;1,9..144,400&family=Lora:ital,wght@0,400;0,500;1,400;1,500&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
  /* Dark Mode: Soft Midnight Paper (Kindle/Readwise inspired) */
  --bg:          #161719; 
  --surface:     #1e1f22; 
  --surface2:    #27292d; 
  --border:      #2e3035; 
  --border2:     #3e4147; 
  --text:        #e3e1db; 
  --text-soft:   #a3a097; 
  --text-faint:  #706d66; 
  --accent:      #88b293; /* Sage Green */
  --accent-soft: #6fa07c; 
  --amber:       #e59a73; /* Terracotta */
  --amber-soft:  #cc815a; 
  --red:         #d98888; 
  --blue:        #8ebdcf; 
  --tag-bg:      #212326; 
  --tag-border:  #2e3135; 
  --code-bg:     #1d1f22; 
  --shadow:      rgba(0, 0, 0, 0.4);

  --font-ui:      'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-reading: 'Lora', Georgia, 'Times New Roman', serif;
  --font-title:   'Fraunces', 'Playfair Display', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  --radius:    8px;
  --radius-lg: 14px;
  --sidebar-w: 288px;
  --content-w: 720px;
  
  /* Micro-animations and transitions */
  --transition-fast: 120ms cubic-bezier(0.25, 0.8, 0.25, 1);
  --transition: 280ms cubic-bezier(0.25, 1, 0.5, 1);
  --transition-slow: 500ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] {
  /* Light Mode: Warm Sepia Book Paper */
  --bg:          #faf8f5; 
  --surface:     #f4f0ea; 
  --surface2:    #ebe5db; 
  --border:      #e0d7c7; 
  --border2:     #cec4b4; 
  --text:        #2b2b2a; 
  --text-soft:   #5c5852; 
  --text-faint:  #8e877d; 
  --accent:      #2f573d; /* Forest Green */
  --accent-soft: #417552; 
  --amber:       #a85f39; /* Clay Terracotta */
  --amber-soft:  #8c4d29; 
  --red:         #b24343; 
  --blue:        #2d5b78; 
  --tag-bg:      #f2ece2; 
  --tag-border:  #e0d7c7; 
  --code-bg:     #f3ede2; 
  --shadow:      rgba(80, 70, 60, 0.08);
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); color-scheme: dark; scroll-behavior: smooth; }
[data-theme="light"] html { color-scheme: light; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition), transform var(--transition); }
a:hover { color: var(--amber); }
::selection { background: var(--accent); color: var(--bg); }

/* ── Shell Layout ── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.site-title {
  font-family: var(--font-title);
  font-size: 15px;
  font-weight: 700;
  color: var(--amber);
  letter-spacing: -0.01em;
  line-height: 1.2;
  flex: 1;
  min-width: 0;
  transition: color var(--transition);
}
.site-title:hover { color: var(--amber-soft); }

.theme-toggle {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-soft);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.theme-toggle:hover { background: var(--surface2); border-color: var(--accent); color: var(--accent); }
.theme-toggle .t-icon { display: inline-block; transition: transform var(--transition); }
.theme-toggle:hover .t-icon { transform: scale(1.2) rotate(15deg); }
.theme-toggle:active .t-icon { transform: scale(0.9) rotate(-10deg); }

/* ── Search ── */
.search-wrap {
  position: relative;
  padding: 12px 12px 8px;
  border-bottom: 1px solid var(--border);
}

.search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12.5px;
  padding: 8px 10px 8px 32px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  appearance: none;
  -webkit-appearance: none;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus { border-color: var(--accent); background: var(--bg); box-shadow: 0 0 0 3px rgba(136,178,147,0.15); }
[data-theme="light"] .search-input:focus { box-shadow: 0 0 0 3px rgba(47,87,61,0.1); }

.search-wrap::before {
  content: '';
  position: absolute;
  left: 21px;
  top: 50%;
  transform: translateY(-50%) translateY(-3px);
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--text-faint);
  border-radius: 50%;
  pointer-events: none;
}
.search-wrap::after {
  content: '';
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%) translateY(3px) rotate(45deg);
  width: 5px;
  height: 1.5px;
  background: var(--text-faint);
  border-radius: 1px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% - 8px);
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 8px 24px var(--shadow);
  max-height: 320px;
  overflow-y: auto;
}
.search-results[hidden] { display: none; }

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), padding-left var(--transition);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface2); color: var(--accent); padding-left: 16px; }
.sr-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-type { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }
.search-no-results { padding: 10px 12px; color: var(--text-faint); font-size: 12px; text-align: center; }

/* ── Sidebar Nav ── */
.sidebar-section {
  padding: 10px 12px 4px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

.nav-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 6px 4px 4px;
}

.sidebar-nav a {
  display: block;
  padding: 6px 8px;
  margin: 2px 4px;
  color: var(--text-soft);
  font-size: 12.5px;
  border-radius: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}
.sidebar-nav a:hover { color: var(--text); background: var(--surface2); transform: translateX(4px); }
.sidebar-nav a.active { color: var(--accent); background: var(--surface2); font-weight: 500; }

/* ── Category Pills ── */
.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
}
.cat-pill {
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 20px;
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  color: var(--text-soft);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.cat-pill:hover { background: var(--surface2); color: var(--accent); border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px var(--shadow); }
.cat-pill:active { transform: translateY(0); }
.cat-pill.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* ── Sidebar Footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.5;
}

/* ── Main / Progress Bar ── */
.progress-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: 2px;
  background: var(--border);
  z-index: 50;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--amber));
  width: 0;
  transition: width 80ms linear;
}

/* Page load fade-in & slide-up animation */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

main {
  padding: 48px 52px 100px;
  min-height: 100vh;
  animation: fadeInUp var(--transition-slow) forwards;
}

/* ── Index Page ── */
.index-header {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.index-title {
  font-family: var(--font-title);
  font-size: 32px;
  font-weight: 300;
  color: var(--amber);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}
.index-desc {
  color: var(--text-soft);
  font-size: 13px;
  margin-bottom: 20px;
}
.cat-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cat-filter-btn {
  font-family: var(--font-ui);
  font-size: 11.5px;
  padding: 5px 12px;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-soft);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.cat-filter-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--tag-bg); transform: translateY(-1.5px); box-shadow: 0 4px 10px var(--shadow); }
.cat-filter-btn:active { transform: translateY(0); }
.cat-filter-btn.active { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 500; }
.cat-filter-btn .count { opacity: 0.7; margin-left: 3px; font-size: 10px; }

.index-groups { display: flex; flex-direction: column; gap: 0; }

.index-group {
  border-bottom: 1px solid var(--border);
  padding: 20px 0;
  transition: opacity var(--transition);
}
.index-group.hidden { display: none; }

.group-heading {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.group-count {
  font-size: 10px;
  color: var(--text-faint);
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 10px;
}

.note-list { list-style: none; }
.note-list-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 8px 12px;
  margin: 2px 0;
  border-radius: var(--radius);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  color: var(--text);
  font-size: 13px;
  transition: color var(--transition), background var(--transition), transform var(--transition);
}
.note-list-item:last-child { border-bottom: none; }
.note-list-item:hover { color: var(--accent); background: var(--surface); transform: translateX(6px); }
.note-list-item:hover .note-list-title { color: var(--accent); }
.note-list-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-list-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.link-count { color: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }

/* ── Status Dots ── */
.status-dot { font-size: 10px; }
.status-dot.complete { color: var(--accent); }
.status-dot.draft    { color: var(--amber); }
.status-dot.stub     { color: var(--text-faint); }
.status-dot.inbox    { color: var(--blue); }
.status-dot.permanent { color: var(--accent); }
.status-dot.other    { color: var(--text-faint); }

/* ── Note Page ── */
.note { max-width: var(--content-w); }

.note-top-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.type-badge {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  padding: 2px 7px;
  border-radius: 4px;
}
.domain-badge {
  font-size: 11px;
  color: var(--text-faint);
}
.domain-badge + .domain-badge::before { content: ', '; }

.note-title {
  font-family: var(--font-title);
  font-size: 38px;
  font-weight: 300;
  color: var(--amber);
  letter-spacing: -0.025em;
  line-height: 1.15;
  margin-bottom: 16px;
}

.note-status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-soft);
  font-size: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.note-status-sep { color: var(--border2); }

.note-summary {
  font-family: var(--font-reading);
  font-style: italic;
  font-size: 15.5px;
  line-height: 1.7;
  color: var(--text-soft);
  margin-bottom: 20px;
  max-width: 68ch;
}

/* ── Related / Tags ── */
.related-section, .tags-section {
  margin-bottom: 16px;
}
.related-label, .tags-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 7px;
}
.related-links, .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.related-links a, .related-links .missing-link {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: var(--radius);
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  color: var(--accent);
  display: inline-block;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.related-links a:hover { background: var(--surface2); border-color: var(--accent); color: var(--amber); transform: translateY(-2px); }
.related-links a:active { transform: translateY(0); }
.related-links .missing-link { color: var(--text-faint); border-style: dashed; }
.tag-list .tag {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--tag-bg);
  border: 1px solid var(--tag-border);
  color: var(--text-soft);
}

/* ── Divider ── */
.content-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

/* ── Article Content ── */
.content {
  font-family: var(--font-reading);
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--text);
}
.content h2 {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  margin: 36px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}
.content h3 {
  font-family: var(--font-title);
  font-size: 17px;
  font-weight: 400;
  color: var(--amber);
  margin: 28px 0 10px;
  letter-spacing: -0.01em;
}
.content h4 {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 22px 0 8px;
}
.content h5, .content h6 {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  margin: 16px 0 6px;
}
.content p { margin: 16px 0; max-width: 68ch; }
.content a { color: var(--accent); border-bottom: 1px solid transparent; transition: all var(--transition); }
.content a:hover { color: var(--amber); border-bottom-color: var(--amber); }
.content strong { color: var(--text); font-weight: 500; }
.content em { color: var(--text); }
.content ul, .content ol { padding-left: 24px; margin: 16px 0; }
.content li { margin: 6px 0; }
.content ul li::marker { color: var(--accent); }
.content ol li::marker { color: var(--text-soft); }
.content .missing-link { color: var(--text-faint); border-bottom: 1px dashed var(--border2); }

.content blockquote {
  border-left: 3px solid var(--accent);
  margin: 24px 0;
  padding: 12px 20px;
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.content blockquote p {
  font-style: italic;
  color: var(--text-soft);
  margin: 0;
}

.content .section-break {
  border: none;
  border-top: 1px solid var(--border);
  margin: 28px 0;
}

.content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--code-bg);
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  margin: 20px 0;
}
.content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  color: var(--text-soft);
}
.content table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
  font-size: 14px;
}
.content th, .content td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  vertical-align: top;
  text-align: left;
}
.content th { color: var(--amber); font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; background: var(--surface); }

/* Callouts */
.callout {
  margin: 20px 0;
  padding: 12px 18px;
  border-radius: var(--radius);
  border-left: 3px solid;
  background: var(--surface);
  font-size: 14px;
}
.callout p { margin: 0; font-family: var(--font-ui); }
.callout-note   { border-color: var(--blue); }
.callout-tip    { border-color: var(--accent); }
.callout-info   { border-color: var(--blue); }
.callout-warning   { border-color: var(--amber); }
.callout-caution   { border-color: var(--red); }
.callout-important { border-color: var(--amber); }

/* ── Backlinks ── */
.backlinks {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.backlinks-heading {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.backlinks-list { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; }
.backlinks-list li a {
  font-size: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text-soft);
  transition: all var(--transition);
  display: inline-block;
}
.backlinks-list li a:hover { color: var(--accent); border-color: var(--accent); background: var(--tag-bg); transform: translateY(-2px); box-shadow: 0 4px 12px var(--shadow); }
.backlinks-list li a:active { transform: translateY(0); }

/* ── Hover Preview Tooltip ── */
.link-preview {
  position: absolute;
  z-index: 200;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: 0 12px 36px var(--shadow), 0 4px 12px var(--shadow);
  pointer-events: none;
  animation: previewIn 180ms cubic-bezier(0.25, 1, 0.5, 1);
}
@keyframes previewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.lp-title { font-family: var(--font-title); font-size: 14px; color: var(--amber); font-weight: 400; margin-bottom: 4px; }
.lp-meta  { font-size: 10.5px; color: var(--text-faint); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.lp-text  { font-family: var(--font-reading); font-size: 12.5px; line-height: 1.6; color: var(--text-soft); font-style: italic; margin: 0; }

/* ── Responsive ── */
@media (max-width: 800px) {
  :root { --sidebar-w: 100%; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { height: auto; max-height: 50vh; position: relative; border-right: none; border-bottom: 1px solid var(--border); }
  main { padding: 28px 20px 60px; }
  .note-title { font-size: 28px; }
  .index-title { font-size: 24px; }
  .progress-bar { left: 0; }
}
@media (max-width: 520px) {
  main { padding: 20px 16px 60px; }
  .note-title { font-size: 24px; }
}
