/* ═══════════════════════════════════════════════════════════════════════
   Idea Vault — Notion-inspired Design
   Inspired by https://getdesign.md/notion/design-md
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  /* ── Notion Color Palette ────────────────────────────────── */
  --primary: #0075de;
  --primary-hover: #005bab;
  --primary-light: #e8f4fd;

  --ink: #000000;
  --ink-secondary: #31302e;
  --ink-muted: #615d59;
  --ink-faint: #a39e98;

  --canvas: #ffffff;
  --canvas-soft: #f6f5f4;
  --hairline: #e6e6e6;

  --sidebar-bg: #f6f5f4;
  --sidebar-w: 260px;
  --toc-w: 200px;

  /* ── Accent palette (decorative) ─────────────────────────── */
  --accent-sky: #62aef0;
  --accent-green: #1aae39;

  /* ── Shadows (barely-there layered, never hard cast) ─────── */
  --shadow-sm: 0 0 0 1px rgba(0,0,0,0.02), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 0 0 1px rgba(0,0,0,0.02), 0 2px 4px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);

  /* ── Border Radii (Notion split system) ──────────────────── */
  --radius-form: 4px;
  --radius-btn: 8px;
  --radius-card: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Serif', 'Noto Serif SC', serif;
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink-secondary);
  background: var(--canvas-soft);
  display: flex;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

/* ── Source banner ────────────────────────────────────────── */
.source-banner {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-btn);
  padding: 0.5rem 0.85rem;
  margin-bottom: 1.25rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
}
.source-banner a {
  color: var(--primary);
  word-break: break-all;
}

/* ── Sidebar (left) — Notion warm sidebar ────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--hairline);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 0.75rem;
}

.sidebar-logo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.015em;
  text-decoration: none;
}
.sidebar-logo:hover { color: var(--primary); text-decoration: none; }

.search-box {
  padding: 0 0.75rem 0.75rem;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-btn);
  font-size: 0.82rem;
  font-family: inherit;
  background: var(--canvas);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0.75rem;
  right: 0.75rem;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-btn);
  box-shadow: var(--shadow-md);
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
}

.search-results.hidden { display: none; }

.search-result-item {
  display: block;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--ink-secondary);
  border-bottom: 1px solid var(--hairline);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--primary-light); text-decoration: none; }

/* Nav items */
.sidebar nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.75rem;
}

.nav-section {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 0.65rem 0.5rem 0.3rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.nav-section::-webkit-details-marker { display: none; }
.nav-section::before {
  content: '▸';
  font-size: 0.55rem;
  transition: transform 0.15s;
  display: inline-block;
  width: 10px;
}

details[open] > .nav-section::before {
  transform: rotate(90deg);
}

.nav-group { margin: 0; }
.nav-group .nav-sub { padding-left: 1.25rem; font-size: 0.78rem; }

.nav-item {
  display: block;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
  color: var(--ink-secondary);
  border-radius: var(--radius-btn);
  transition: background 0.1s;
}

.nav-item:hover { background: var(--primary-light); text-decoration: none; }
.nav-item.active { color: var(--primary); font-weight: 600; background: var(--primary-light); }

/* ── Main content ─────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem;
  max-width: 780px;
}

/* Article card — white canvas on warm bg */
.content {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: 2.5rem 2.75rem;
  box-shadow: var(--shadow-sm);
}

/* ── Article-level typography ─────────────────────────────── */
.content h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.015em;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.content h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--hairline);
}

.content h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 1.4rem;
  margin-bottom: 0.35rem;
}

.content h4 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 1rem;
}

.content p {
  margin-bottom: 0.7em;
  line-height: 1.75;
}

.content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-form);
  margin: 0.75rem 0;
}

.content ul, .content ol {
  padding-left: 1.5rem;
  margin-bottom: 0.7em;
}

.content li { margin-bottom: 0.2em; }

.content blockquote {
  border-left: 3px solid var(--primary);
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  color: var(--ink-muted);
  background: var(--sidebar-bg);
  border-radius: 0 var(--radius-form) var(--radius-form) 0;
  font-size: 0.92em;
}

.content hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 1.5rem 0;
}

/* Tables */
.content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 1rem 0;
  border-radius: var(--radius-btn);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.content th {
  background: var(--sidebar-bg);
  font-weight: 600;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
  color: var(--ink-secondary);
}

.content td {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--hairline);
}

.content tr:last-child td { border-bottom: none; }

/* Code */
.content code {
  background: var(--sidebar-bg);
  border-radius: var(--radius-form);
  padding: 0.1em 0.35em;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--ink);
  border: 1px solid var(--hairline);
}

.content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 1.25rem;
  border-radius: var(--radius-btn);
  overflow-x: auto;
  margin: 0.75rem 0;
  font-size: 0.8rem;
  line-height: 1.5;
}

.content pre code {
  background: transparent;
  padding: 0;
  border: none;
  color: inherit;
}

/* Wikilinks */
.wikilink { color: var(--primary); border-bottom: 1px dotted var(--primary); }
.wikilink-broken { color: var(--ink-faint); text-decoration: line-through; }

/* Admonition-style callouts */
.content .admonition {
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  padding: 0.5rem 1rem;
  margin: 0.75rem 0;
  border-radius: 0 var(--radius-btn) var(--radius-btn) 0;
}

/* ── Article Prev/Next Navigation ─────────────────────────── */
.article-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hairline);
}

.article-nav-prev,
.article-nav-next {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-btn);
  background: var(--canvas);
  color: var(--ink-secondary);
  font-size: 0.82rem;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s ease;
  flex: 1;
  max-width: 50%;
  line-height: 1.4;
}

.article-nav-prev span,
.article-nav-next span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.article-nav-prev:hover,
.article-nav-next:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.article-nav-prev { text-align: left; }
.article-nav-next { text-align: right; justify-content: flex-end; }

.article-nav-prev .arrow,
.article-nav-next .arrow {
  flex-shrink: 0;
  font-size: 1.1em;
}

/* ── Right TOC ────────────────────────────────────────────── */
.toc-sidebar {
  width: var(--toc-w);
  min-width: var(--toc-w);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 2rem 1rem 2rem 0;
  font-size: 0.78rem;
}

.toc-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 0.75rem;
}

.toc-nav ul { list-style: none; padding: 0; }
.toc-nav li { margin-bottom: 0.25rem; }

.toc-nav a {
  color: var(--ink-muted);
  display: block;
  padding: 0.15rem 0;
  font-size: 0.76rem;
}

.toc-nav a:hover { color: var(--ink); text-decoration: none; }
.toc-nav li ul { padding-left: 0.75rem; }

/* ── Mobile nav ───────────────────────────────────────────── */
.nav-toggle, .nav-overlay { display: none; }

/* ── Pygments code highlighting overrides ─────────────────── */
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #6a9955; font-style: italic }
.highlight .k { color: #569cd6 }
.highlight .s { color: #ce9178 }
.highlight .n { color: #d4d4d4 }

/* ════════════════════════════════════════════════════════════
   MOBILE  —  ≤ 900px
   ════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .toc-sidebar { display: none; }
  .main { padding: 1rem 0.75rem; max-width: 100%; }
  .content { padding: 1.5rem; border-radius: var(--radius-btn); }
  .content h1 { font-size: 1.3rem; }
}

/* ════════════════════════════════════════════════════════════
   TABLET / SMALL  —  ≤ 768px
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  body {
    font-size: 15px;
    flex-direction: column;
    background: var(--canvas);
  }

  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    z-index: 200;
    width: 280px;
    min-width: 280px;
    transition: left 0.25s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,0.08);
  }

  body.nav-open .sidebar { left: 0; }
  body.nav-open .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.25);
    z-index: 150;
  }

  .nav-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 300;
    background: var(--canvas);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-btn);
    padding: 0.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
  }

  .nav-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--ink);
    border-radius: 1px;
  }

  .main { padding: 3rem 0.5rem 1.5rem; }

  .content {
    border: none;
    border-radius: 0;
    padding: 1.25rem;
    box-shadow: none;
  }

  .content h1 { font-size: 1.15rem; }
  .content h2 { font-size: 1rem; }
  .content h3 { font-size: 0.9rem; }

  .content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .article-nav {
    flex-direction: column;
    gap: 0.5rem;
  }

  .article-nav-prev,
  .article-nav-next {
    max-width: 100%;
  }
}

/* ════════════════════════════════════════════════════════════
   PHONE  —  ≤ 480px
   ════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  body { font-size: 14px; }
  .content { padding: 1rem; }
  .content h1 { font-size: 1.08rem; }
  .content h2 { font-size: 0.95rem; }
  .content h3 { font-size: 0.85rem; }
  .content table { font-size: 0.72rem; }
}