/* ============================================================
   Tokens — Obsidian-inspired dark theme (Polished)
   ============================================================ */
:root {
  --bg-primary:      #1e1e2e;   /* main canvas */
  --bg-secondary:    #181825;   /* sidebar/cards */
  --bg-tertiary:     #11111b;   /* inputs/code */
  --bg-hover:        #262637;
  --bg-active:       #313244;
  --bg-elevated:     #24243a;

  --border:          #313244;
  --border-subtle:   #2a2a3d;

  --text:            #cdd6f4;
  --text-strong:     #f5f5fa;
  --text-muted:      #7f849c;
  --text-faint:      #585b70;

  --accent:          #a78bfa;   /* purple */
  --accent-hover:    #c4b5fd;
  --accent-soft:     rgba(167, 139, 250, 0.15);
  --accent-border:   rgba(167, 139, 250, 0.35);

  --blue:   #89b4fa;
  --green:  #a6e3a1;
  --yellow: #f9e2af;
  --orange: #fab387;
  --red:    #f38ba8;
  --pink:   #f5c2e7;
  --teal:   #94e2d5;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;

  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-btn: 0 2px 4px rgba(0, 0, 0, 0.2);

  --sidebar-w: 280px;
  --topbar-h: 56px;

  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-norm: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; scroll-behavior: smooth; }
body {
  background: var(--bg-primary);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  /* Animated ambient background */
  background: linear-gradient(
    135deg,
    #1a1a2e 0%,
    #1e1e2e 25%,
    #16213e 50%,
    #1e1e2e 75%,
    #1a1a2e 100%
  );
  background-size: 400% 400%;
  animation: ambientBg 20s ease infinite;
}

@keyframes ambientBg {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
::selection { background: var(--accent-soft); color: var(--text-strong); }

a { color: var(--accent); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-hover); text-decoration: underline; }
code, kbd, pre { font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace; }
kbd {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 8px; font-size: .75rem;
  color: var(--text-muted); box-shadow: 0 2px 0 var(--border);
}

.muted { color: var(--text-muted); }
.small { font-size: .8rem; }

/* Focus ring for accessibility */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   Layout
   ============================================================ */
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: rgba(24, 24, 37, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid rgba(167, 139, 250, 0.12);
  box-shadow: 4px 0 32px rgba(0, 0, 0, 0.4), inset -1px 0 0 rgba(167, 139, 250, 0.08);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-norm);
  z-index: 100;
}
.sidebar-head {
  display: flex; align-items: center; gap: .5rem;
  padding: .85rem 1.25rem; height: var(--topbar-h);
  border-bottom: 1px solid var(--border-subtle);
}
.brand { display: flex; align-items: center; gap: .65rem; color: var(--text-strong); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; color: var(--text-strong); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: grid; place-items: center; color: #0b0b15;
  font-weight: 800; font-size: 1rem;
  box-shadow: 0 2px 8px rgba(167, 139, 250, 0.4);
}
.sidebar > .btn {
  margin: .75rem 1.25rem 0;
  width: auto;
  max-width: calc(100% - 2.5rem);
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-trigger {
  margin: .75rem 1.25rem 0;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: .65rem .85rem;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  transition: all var(--transition-fast), box-shadow var(--transition-fast);
  animation: searchPulse 4s ease-in-out infinite;
  position: relative;
}
.search-trigger:hover {
  border-color: var(--accent-border);
  background: var(--bg-hover);
  color: var(--text);
  box-shadow: 0 0 0 3px var(--accent-soft);
  animation-play-state: paused;
  transform: translateY(-1px);
}
.search-trigger:active { transform: translateY(0); }

@keyframes searchPulse {
  0%, 100% {
    border-color: var(--border-subtle);
    box-shadow: none;
  }
  50% {
    border-color: var(--accent-border);
    box-shadow: 0 0 0 2px var(--accent-soft);
  }
}

.tree { flex: 1; overflow-y: auto; padding: .75rem .75rem 1.5rem; }
.tree::-webkit-scrollbar { width: 6px; }
.tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tree::-webkit-scrollbar-track { background: transparent; }

.tree-section { margin-top: 1.5rem; }
.tree-label {
  display: flex; justify-content: space-between; align-items: center;
  padding: .3rem .75rem; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted);
}
.tree-label .count {
  background: var(--bg-tertiary); color: var(--text-faint);
  padding: 2px 6px; border-radius: 99px; font-size: .65rem;
}
.tree ul { list-style: none; padding: 0; margin: 0; }
.tree-link {
  display: block; padding: .4rem .75rem; border-radius: 6px;
  color: var(--text); font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.tree-link:hover { background: var(--bg-hover); text-decoration: none; color: var(--text-strong); }
.tree-link.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 500; }

.sidebar-foot {
  padding: .75rem 1.25rem; border-top: 1px solid var(--border-subtle);
}
.user-pill {
  display: flex; align-items: center; gap: .65rem;
  padding: .45rem .6rem; background: var(--bg-tertiary);
  border-radius: var(--radius); font-size: .9rem;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  display: grid; place-items: center; color: #0b0b15;
  font-weight: 700; font-size: .85rem; flex-shrink: 0;
}

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .85rem;
  padding: 0 1.5rem;
  background: rgba(24, 24, 37, 0.8);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: none;
  box-shadow:
    0 1px 0 rgba(167, 139, 250, 0.15),
    0 4px 16px rgba(0, 0, 0, 0.3);
}
.topbar-spacer { flex: 1; }
.breadcrumb {
  color: var(--text-muted);
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}
.breadcrumb a { color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.breadcrumb .sep { color: var(--text-faint); flex-shrink: 0; }
.breadcrumb > span:nth-last-child(2) {
  color: var(--text-faint);
  flex-shrink: 0;
}
.breadcrumb > span:last-child {
  color: var(--text-strong);
  font-weight: 600;
  text-shadow: 0 0 20px rgba(167, 139, 250, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.content { flex: 1; padding: 2.5rem 2.5rem 4rem; max-width: 1200px; width: 100%; }
.narrow { max-width: 760px; margin: 0 auto; }

/* ============================================================
   Buttons
   ============================================================ */
.btn, button.btn-link {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .6rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); cursor: pointer; font: inherit; font-size: .9rem; font-weight: 500;
  transition: all var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-btn);
}
.btn:hover { background: var(--bg-hover); border-color: var(--border); color: var(--text-strong); text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); box-shadow: none; }
.btn-primary {
  background: var(--accent);
  color: #16161f;
  border-color: var(--accent);
  position: relative;
  overflow: hidden;
}
.btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 60%);
  pointer-events: none;
  opacity: 1;
  transition: opacity var(--transition-fast);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #16161f;
  box-shadow:
    0 4px 12px rgba(167, 139, 250, 0.45),
    0 0 0 1px rgba(167, 139, 250, 0.3),
    0 8px 24px rgba(167, 139, 250, 0.2);
  transform: translateY(-2px);
}
.btn-primary:hover::after { opacity: 0; }
.btn-primary:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 2px 6px rgba(167, 139, 250, 0.3);
}
.btn-ghost { background: transparent; border-color: var(--border-subtle); box-shadow: none; }
.btn-ghost:hover { background: var(--bg-hover); box-shadow: none; transform: none; }
.btn-block { display: flex; width: 100%; justify-content: center; }
button.btn-link { background: transparent; border: none; color: var(--accent); padding: 0; box-shadow: none; }
button.btn-link:hover { text-decoration: underline; transform: none; }

.icon-btn {
  width: 36px; height: 36px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer; font-size: 1.1rem;
  display: grid; place-items: center; transition: all var(--transition-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border); }

/* ============================================================
   Forms
   ============================================================ */
input, textarea, select {
  font: inherit; font-size: .95rem; width: 100%;
  padding: .65rem .85rem;
  background: var(--bg-tertiary); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { font-family: "JetBrains Mono", ui-monospace, monospace; resize: vertical; line-height: 1.6; }
label { display: block; margin-bottom: 1rem; font-size: .9rem; color: var(--text-muted); font-weight: 500; }
label input, label textarea, label select { margin-top: .45rem; }
.stacked .label { font-size: .9rem; color: var(--text-muted); margin-bottom: .45rem; }
.form-actions { display: flex; gap: .65rem; justify-content: flex-end; margin-top: 1.5rem; }
.alert { padding: .85rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .9rem; font-weight: 500; }
.alert-error { background: rgba(243, 139, 168, .15); border: 1px solid var(--red); color: var(--red); }
.banner-warn {
  background: rgba(249, 226, 175, .15); border: 1px solid var(--yellow); color: var(--yellow);
  padding: .85rem 1.1rem; border-radius: var(--radius-sm); margin-bottom: 1.5rem; font-size: .9rem;
  display: flex; align-items: center; gap: .5rem;
}

/* ============================================================
   Cards / lists / tags
   ============================================================ */
.hero { padding: 1.5rem 0 2.5rem; }
.hero h1 {
  margin: 0 0 .4rem;
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text-strong) 0%, var(--accent-hover) 60%, var(--blue) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .grid-two { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.5rem;
  transition:
    box-shadow var(--transition-norm),
    transform var(--transition-norm),
    border-color var(--transition-norm);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--transition-norm);
}
.card:hover {
  box-shadow: var(--shadow), 0 0 0 1px var(--accent-border);
  transform: translateY(-3px);
  border-color: var(--accent-border);
}
.card:hover::before { opacity: 1; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-head h2 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
.badge { background: var(--bg-tertiary); color: var(--text-muted); padding: .15rem .65rem; border-radius: 99px; font-size: .8rem; font-weight: 600; }

.article-list { list-style: none; padding: 0; margin: 0; }
.article-list li {
  position: relative;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  margin: 2px 0;
  transition:
    background var(--transition-fast),
    border-left-color var(--transition-fast),
    transform var(--transition-fast);
  cursor: pointer;
}
.article-list li:last-child { border-bottom: none; }
.article-list li:hover {
  background: var(--bg-elevated);
  border-left-color: var(--accent-border);
  transform: translateX(4px);
}
.article-list a {
  font-weight: 500; color: var(--text); font-size: 1rem;
  transition: color var(--transition-fast);
}
.article-list a::after {
  content: '';
  position: absolute;
  inset: 0;
}
.article-list a:hover { color: var(--accent); text-decoration: none; }
.meta-row { display: flex; gap: .4rem; margin-top: .35rem; flex-wrap: wrap; }

.tag {
  display: inline-flex; align-items: center;
  background: var(--accent-soft); color: var(--accent-hover);
  font-size: .75rem; padding: .15rem .6rem; border-radius: 99px;
  border: 1px solid var(--accent-border); font-weight: 500;
}

/* ============================================================
   Article rendering
   ============================================================ */
.article-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 240px;
  gap: 3rem; margin: 0 auto;
}
@media (max-width: 1100px) { .article-layout { grid-template-columns: 1fr; } }

.article { min-width: 0; }
.article-header { border-bottom: 1px solid var(--border-subtle); padding-bottom: 1.5rem; margin-bottom: 2rem; }
.article-header h1 { margin: 0 0 .6rem; font-size: 2.5rem; font-weight: 800; color: var(--text-strong); letter-spacing: -0.03em; line-height: 1.1; }
.tags { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }

.markdown-body { color: var(--text); line-height: 1.7; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--text-strong); margin: 2em 0 .8em; font-weight: 700; line-height: 1.25;
  scroll-margin-top: calc(var(--topbar-h) + 20px);
}
.markdown-body h1 { font-size: 1.8rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: .4em; }
.markdown-body h2 { font-size: 1.4rem; }
.markdown-body h3 { font-size: 1.2rem; }
.markdown-body h4 { font-size: 1.05rem; }
.markdown-body p { margin: 1em 0; }
.markdown-body ul, .markdown-body ol { margin: .8em 0; padding-left: 1.6em; }
.markdown-body li { margin: .3em 0; }
.markdown-body hr { border: none; border-top: 1px solid var(--border-subtle); margin: 2.5em 0; }

.markdown-body code {
  background: var(--bg-tertiary); color: var(--orange);
  padding: .15em .5em; border-radius: 4px; font-size: .9em;
  border: 1px solid var(--border-subtle);
}
.markdown-body pre {
  background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  padding: 1.25rem 1.4rem; border-radius: var(--radius); overflow-x: auto;
  margin: 1.5em 0; font-size: .9rem; line-height: 1.6;
}
.markdown-body pre code { background: none; border: none; padding: 0; color: var(--text); }

.markdown-body blockquote {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: .5rem 1.2rem; margin: 1.5em 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text);
}
.markdown-body img { max-width: 100%; border-radius: var(--radius); display: block; margin: 1.5em 0; box-shadow: var(--shadow-sm); }
.markdown-body iframe, .markdown-body video { max-width: 100%; border-radius: var(--radius); border: 0; margin: 1.5em 0; }

.markdown-body table { border-collapse: collapse; width: 100%; margin: 1.5em 0; font-size: .95rem; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border-subtle); padding: .6rem 1rem; text-align: left;
}
.markdown-body th { background: var(--bg-secondary); font-weight: 600; color: var(--text-strong); }
.markdown-body tr:nth-child(even) td { background: rgba(255, 255, 255, 0.025); }

.markdown-body a.wiki-link { border-bottom: 1px dotted var(--accent); }
.markdown-body a.wiki-missing { color: var(--red); border-bottom-color: var(--red); }
.markdown-body .toc-anchor { opacity: 0; margin-left: .5em; color: var(--text-faint); font-weight: 400; transition: opacity var(--transition-fast); }
.markdown-body h1:hover .toc-anchor, .markdown-body h2:hover .toc-anchor,
.markdown-body h3:hover .toc-anchor, .markdown-body h4:hover .toc-anchor { opacity: 1; }

.markdown-body input[type="checkbox"] { margin-right: .5em; transform: translateY(2px); accent-color: var(--accent); }

/* ============================================================
   Callouts
   ============================================================ */
.callout {
  margin: 1.5em 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow: hidden;
  animation: calloutIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: box-shadow var(--transition-norm), transform var(--transition-norm);
}
.callout:hover {
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

@keyframes calloutIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.callout-title {
  display: flex; align-items: center; gap: .65rem;
  padding: .75rem 1rem;
  font-weight: 600; font-size: .95rem;
  cursor: default;
  background: var(--accent-soft);
  color: var(--accent-hover);
}
details.callout > summary.callout-title { cursor: pointer; list-style: none; }
details.callout > summary.callout-title::-webkit-details-marker { display: none; }
details.callout > summary.callout-title::after {
  content: "▸"; margin-left: auto; transition: transform .2s ease; color: currentColor; opacity: .6;
}
details.callout[open] > summary.callout-title::after { transform: rotate(90deg); }
.callout-icon {
  width: 20px; height: 20px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 1.1rem;
  animation: iconPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: 0.1s;
}
@keyframes iconPop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.callout-icon::before { content: "🗒"; }
.callout-body { padding: .5rem 1.2rem 1rem; }
.callout-body > :first-child { margin-top: .5em; }
.callout-body > :last-child { margin-bottom: 0; }

.callout-note    { border-color: rgba(137,180,250,.3); } .callout-note    .callout-title { background: rgba(137,180,250,.12); color: var(--blue); }   .callout-icon-note::before    { content: "📝"; }
.callout-info    { border-color: rgba(148,226,213,.3); } .callout-info    .callout-title { background: rgba(148,226,213,.12); color: var(--teal); }   .callout-icon-info::before    { content: "ℹ"; }
.callout-tip     { border-color: rgba(148,226,213,.3); } .callout-tip     .callout-title { background: rgba(148,226,213,.12); color: var(--teal); }   .callout-icon-tip::before     { content: "💡"; }
.callout-success { border-color: rgba(166,227,161,.3); } .callout-success .callout-title { background: rgba(166,227,161,.12); color: var(--green); }  .callout-icon-success::before { content: "✅"; }
.callout-warning { border-color: rgba(249,226,175,.3); } .callout-warning .callout-title { background: rgba(249,226,175,.12); color: var(--yellow); } .callout-icon-warning::before { content: "⚠"; }
.callout-danger  { border-color: rgba(243,139,168,.3); } .callout-danger  .callout-title { background: rgba(243,139,168,.12); color: var(--red); }    .callout-icon-danger::before  { content: "⛔"; }
.callout-bug     { border-color: rgba(243,139,168,.3); } .callout-bug     .callout-title { background: rgba(243,139,168,.12); color: var(--red); }    .callout-icon-bug::before     { content: "🐛"; }
.callout-question{ border-color: rgba(250,179,135,.3); } .callout-question .callout-title { background: rgba(250,179,135,.12); color: var(--orange); } .callout-icon-question::before{ content: "❓"; }
.callout-todo    { border-color: rgba(250,179,135,.3); } .callout-todo    .callout-title { background: rgba(250,179,135,.12); color: var(--orange); } .callout-icon-todo::before    { content: "☑"; }
.callout-example { border-color: rgba(245,194,231,.3); } .callout-example .callout-title { background: rgba(245,194,231,.12); color: var(--pink); }   .callout-icon-example::before { content: "📚"; }
.callout-abstract{ border-color: rgba(245,194,231,.3); } .callout-abstract .callout-title { background: rgba(245,194,231,.12); color: var(--pink); }   .callout-icon-abstract::before{ content: "📄"; }
.callout-quote   { border-color: rgba(127,132,156,.3); } .callout-quote   .callout-title { background: rgba(127,132,156,.12); color: var(--text-muted); } .callout-icon-quote::before{ content: "❝"; }

/* ============================================================
   TOC rail
   ============================================================ */
.toc-rail { min-width: 0; }
.toc-sticky { position: sticky; top: calc(var(--topbar-h) + 1.5rem); }
.toc-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .1em; color: var(--text-muted); margin-bottom: .75rem; padding-left: .75rem;
}
.toc-body ul {
  list-style: none;
  padding-left: 1rem;
  margin: 0;
  border-left: 2px solid transparent;
  border-image: linear-gradient(to bottom, var(--accent), var(--blue), transparent) 1;
}
.toc-body > ul { padding-left: 0; border-left: none; border-image: none; }
.toc-body li { margin: .25rem 0; }
.toc-body a {
  color: var(--text-muted);
  font-size: .85rem;
  line-height: 1.4;
  display: block;
  padding: .2rem .6rem;
  border-radius: 4px;
  border-left: 2px solid transparent;
  margin-left: -2px;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-left-color var(--transition-fast),
    padding-left var(--transition-fast);
}
.toc-body a:hover {
  background: var(--bg-hover);
  color: var(--accent);
  text-decoration: none;
  padding-left: .9rem;
}
.toc-body a.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
  border-left-color: var(--accent);
  padding-left: .9rem;
  border-radius: 0 4px 4px 0;
}

.backlinks { margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--border-subtle); }
.backlinks h3 { margin: 0 0 1rem; font-size: 1rem; color: var(--text-muted); font-weight: 600; }

/* ============================================================
   Editor
   ============================================================ */
.edit-shell { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 5rem); }
.edit-meta { margin-bottom: .8rem; max-width: 320px; }
.editor-toolbar {
  display: flex; align-items: center; gap: .4rem; flex-wrap: wrap;
  padding: .5rem .8rem; background: var(--bg-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
}
.editor-toolbar button,
.editor-toolbar select {
  background: transparent; border: 1px solid transparent; color: var(--text);
  padding: .4rem .6rem; border-radius: 6px; cursor: pointer;
  font-size: .9rem; width: auto; font-weight: 500;
}
.editor-toolbar button:hover { background: var(--bg-hover); border-color: var(--border); }
.editor-toolbar select { background: var(--bg-tertiary); border-color: var(--border-subtle); padding: .4rem .6rem; }
.sep-v { width: 1px; height: 24px; background: var(--border-subtle); margin: 0 .1rem; }
.toolbar-hint { margin-left: auto; }

.tag-picker { margin: .5rem 0; background: var(--bg-secondary); border: 1px solid var(--border-subtle); border-radius: var(--radius); padding: .6rem 1rem; }
.tag-picker summary { cursor: pointer; color: var(--text-muted); font-size: .9rem; list-style: none; font-weight: 500; }
.tag-picker summary::-webkit-details-marker { display: none; }
.tag-picker[open] summary { margin-bottom: .8rem; }
.tag-options { display: flex; flex-wrap: wrap; gap: .5rem; }
.tag-chip {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem .7rem; background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle); border-radius: 99px;
  font-size: .85rem; cursor: pointer; margin: 0; transition: all var(--transition-fast);
}
.tag-chip:hover { border-color: var(--accent-border); background: var(--bg-hover); }
.tag-chip input { width: auto; position: absolute; opacity: 0; cursor: pointer; }
.tag-chip input:checked + span { color: var(--accent-hover); font-weight: 600; }
.tag-chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent-border); }

.split {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0; flex: 1; min-height: 400px;
  border: 1px solid var(--border-subtle); border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}
.split.preview-off { grid-template-columns: 1fr; }
.split.preview-off .preview { display: none; }
.pane { overflow: auto; min-height: 0; }
.pane textarea {
  width: 100%; height: 100%; min-height: 100%;
  border: none; border-radius: 0; background: var(--bg-primary);
  padding: 1.5rem 2rem; font-size: .95rem;
  resize: none;
}
.pane textarea:focus { box-shadow: none; }
.pane.preview {
  background: var(--bg-secondary); border-left: 1px solid var(--border-subtle);
  padding: 1.5rem 2rem;
}
.pane.preview > *:first-child { margin-top: 0; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .pane.preview { border-left: none; border-top: 1px solid var(--border-subtle); } }

/* ============================================================
   Auth
   ============================================================ */
.auth-wrap { min-height: calc(100vh - var(--topbar-h)); display: grid; place-items: center; padding: 2rem; }
.auth-card {
  width: 100%; max-width: 400px;
  background: rgba(24, 24, 37, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(167, 139, 250, 0.15);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(167, 139, 250, 0.05);
  transition: box-shadow var(--transition-norm), border-color var(--transition-norm);
  position: relative;
}
.auth-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(167,139,250,0.2), transparent 60%, rgba(137,180,250,0.1));
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-norm);
  z-index: 0;
}
.auth-card:focus-within {
  border-color: rgba(167, 139, 250, 0.3);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(167, 139, 250, 0.1),
    0 0 48px rgba(167, 139, 250, 0.12);
}
.auth-card:focus-within::before { opacity: 1; }
.auth-card > * { position: relative; z-index: 1; }
.auth-card h1 { margin: 0 0 .5rem; font-size: 1.6rem; }

/* ============================================================
   History / diff
   ============================================================ */
.timeline { list-style: none; padding: 0; }
.timeline li { padding: 1.25rem 0; border-bottom: 1px solid var(--border-subtle); }
.timeline-head { display: flex; align-items: center; gap: .65rem; }
.diff {
  background: var(--bg-tertiary); border: 1px solid var(--border-subtle);
  padding: 1rem 1.25rem; border-radius: var(--radius-sm);
  font-size: .85rem; overflow-x: auto; margin-top: .8rem; white-space: pre-wrap;
  line-height: 1.55; font-family: "JetBrains Mono", monospace;
}
.diff .diff-add { color: var(--green); background: rgba(166,227,161,.1); display: block; }
.diff .diff-rem { color: var(--red);   background: rgba(243,139,168,.1); display: block; }
.diff .diff-meta { color: var(--text-faint); }

/* ============================================================
   Command palette (⌘K)
   ============================================================ */
.cmdk-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  display: grid; place-items: start center; padding-top: 15vh;
  animation: cmdk-overlay-in 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.cmdk-overlay[hidden] { display: none; }

@keyframes cmdk-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cmdk-panel {
  width: min(640px, 92vw);
  background: rgba(24, 24, 37, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(167, 139, 250, 0.2);
  border-radius: var(--radius-lg);
  box-shadow:
    var(--shadow),
    0 0 0 1px rgba(167, 139, 250, 0.05),
    0 32px 64px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: cmdk-panel-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cmdk-panel-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#cmdkInput {
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  background: transparent;
  padding: 1.1rem 1.4rem;
  font-size: 1.05rem;
  font-weight: 500;
  transition: border-bottom-color var(--transition-fast);
}
#cmdkInput:focus {
  box-shadow: none;
  border-bottom-color: var(--accent);
}
.cmdk-results { list-style: none; padding: .5rem; margin: 0; max-height: 400px; overflow-y: auto; }
.cmdk-results li {
  padding: .6rem 1rem; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: .7rem; transition: background var(--transition-fast);
}
.cmdk-results li.active, .cmdk-results li:hover { background: var(--bg-hover); }
.cmdk-results .result-title { color: var(--text-strong); font-weight: 500; flex: 1; }
.cmdk-results .result-type { color: var(--text-muted); font-size: .75rem; background: var(--bg-tertiary); padding: 2px 8px; border-radius: 99px; }
.cmdk-results .empty { color: var(--text-muted); justify-content: center; cursor: default; padding: 2rem; }
.cmdk-results .empty:hover { background: transparent; }
.cmdk-hints {
  padding: .7rem 1.2rem; border-top: 1px solid var(--border-subtle);
  color: var(--text-faint); font-size: .8rem; display: flex; gap: 1rem;
}
.cmdk-hints kbd { margin-right: .2rem; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   Empty state
   ============================================================ */
.empty { text-align: center; padding: 5rem 1rem; }
.empty-glyph {
  font-size: 5rem;
  margin-bottom: 1.5rem;
  opacity: .6;
  filter: grayscale(10%) drop-shadow(0 0 24px rgba(167, 139, 250, 0.3));
  animation: floatGlyph 4s ease-in-out infinite;
  display: inline-block;
  will-change: transform;
}
.empty h1 { color: var(--text-strong); }

@keyframes floatGlyph {
  0%, 100% { transform: translateY(0px);    }
  50%       { transform: translateY(-12px);  }
}

/* ============================================================
   Responsive
   ============================================================ */
.mobile-only { display: none; }
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow);
    max-width: 85vw;
    overflow-x: hidden;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .mobile-only { display: inline-flex !important; }
  .content { padding: 1.5rem; }
  .article-layout { grid-template-columns: 1fr; }
  .toc-rail { display: none; }

  /* Fix button overflow in sidebar */
  .sidebar > .btn,
  .sidebar .btn-block {
    flex-shrink: 0;
    width: auto;
    max-width: calc(100% - 2.5rem);
    margin-left: 1.25rem;
    margin-right: 1.25rem;
    box-sizing: border-box;
  }

  /* Fix icon buttons on mobile */
  .sidebar .icon-btn.mobile-only {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }

  /* Ensure sidebar head doesn't overflow */
  .sidebar-head {
    overflow: hidden;
  }

  /* Ensure user pill doesn't overflow */
  .sidebar-foot .user-pill {
    min-width: 0;
  }
  .sidebar-foot .user-pill span:not(.avatar) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ============================================================
   View Transitions (page navigation fade)
   ============================================================ */
::view-transition-old(root) {
  animation: 0.2s cubic-bezier(0.4, 0, 1, 1) both page-fade-out;
}
::view-transition-new(root) {
  animation: 0.3s cubic-bezier(0, 0, 0.2, 1) both page-fade-in;
}
@keyframes page-fade-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-8px); }
}
@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
