/* ── Design Tokens ─────────────────────────────────────── */
:root {
  --bg-base: #0d0d0d;
  --bg-sidebar: #111111;
  --bg-surface: #161616;
  --bg-hover: #1e1e1e;
  --bg-active: #212121;
  --bg-code: #0a0a0a;

  --border: #2a2a2a;
  --border-subtle: #1f1f1f;

  --text-primary: #ececec;
  --text-secondary: #8a8a8a;
  --text-muted: #555555;
  --text-code: #e0c97f;

  --accent: #19c37d;
  --accent-dim: rgba(25, 195, 125, 0.12);
  --accent-glow: rgba(25, 195, 125, 0.06);

  --sidebar-w: 260px;
  --content-max: 720px;
  --header-h: 52px;

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

  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-serif: "Lora", Georgia, serif;
  --font-mono: "Geist Mono", "Fira Code", monospace;

  --transition: 0.18s ease;
}

/* ── Reset & Base ─────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition:
    transform var(--transition),
    opacity var(--transition);
  z-index: 50;
}

.sidebar-header {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  cursor: pointer;
}

.logo-mark {
  width: 28px;
  height: 28px;
  /* background: var(--accent); */
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* .logo-mark svg {
  width: 15px;
  height: 15px;
  fill: #000;
} */

.logo-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.logo-text span {
  color: var(--text-muted);
  font-weight: 300;
}

/* ── Search ───────────────────────────────────────────── */
.search-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px 7px 30px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ── Post List ────────────────────────────────────────── */
.sidebar-section-label {
  padding: 12px 16px 5px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
}

#post-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 4px 20px;
}

#post-list::-webkit-scrollbar {
  width: 4px;
}

#post-list::-webkit-scrollbar-track {
  background: transparent;
}

#post-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── VS Code–style recursive tree ───────────────────── */

/* Every row (folder or file) is a flex row with depth-based padding-left */
.tree-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding-top: 5px;
  padding-bottom: 5px;
  padding-right: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 1px;
  text-decoration: none;
  min-width: 0;
}

.tree-row:hover {
  background: var(--bg-hover);
}

/* Folder row */
.tree-folder-row {
  color: var(--text-secondary);
}

/* Chevron — rotates when open */
.tree-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.18s ease;
  margin-right: 1px;
}

.tree-folder.open > .tree-folder-row .tree-chevron {
  transform: rotate(90deg);
}

/* Icons */
.tree-icon {
  flex-shrink: 0;
}

.tree-folder-icon {
  color: var(--text-muted);
  transition: color var(--transition);
}

.tree-folder.open > .tree-folder-row .tree-folder-icon {
  color: #e8c07a;
}

.tree-file-icon {
  color: var(--text-muted);
}

/* Label text */
.tree-label {
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.tree-folder-row .tree-label {
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  transition: color var(--transition);
}

.tree-folder.open > .tree-folder-row .tree-label {
  color: var(--text-primary);
}

.tree-file-row .tree-label {
  color: var(--text-primary);
}

.tree-file-row.active .tree-label {
  color: var(--accent);
}

/* Active file highlight */
.tree-file-row.active {
  background: var(--bg-active);
  border-color: var(--border);
}

/* Collapsible children */
.tree-children {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.22s ease;
}

.tree-folder.open > .tree-children {
  max-height: 9999px;
  transition: max-height 0.4s ease;
}

/* Indent guide line — drawn on the children container */
.tree-children-inner {
  position: relative;
}

.tree-children-inner::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 4px;
  left: var(--guide-left, 16px);
  width: 1px;
  background: var(--border-subtle);
}

.tree-folder.open > .tree-children > .tree-children-inner::before {
  background: var(--border);
}

/* File meta (date / tags) shown below title */
.tree-file-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 1px;
  padding-left: 22px;
  /* align under label, past icon */
}

.post-item {
  display: block;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition);
  border: 1px solid transparent;
  margin-bottom: 1px;
}

.post-item:hover {
  background: var(--bg-hover);
}

.post-item.active {
  background: var(--bg-active);
  border-color: var(--border);
}

.post-item-title {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-item.active .post-item-title {
  color: var(--accent);
}

.post-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.post-item-date {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.post-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 20px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.post-item.active .post-tag {
  background: var(--accent-dim);
  border-color: rgba(25, 195, 125, 0.25);
  color: var(--accent);
}

/* ── Tag Filter ───────────────────────────────────────── */
.tag-filter {
  padding: 8px 12px 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-subtle);
}

.tag-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-sans);
  transition: all var(--transition);
}

.tag-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── No Results ───────────────────────────────────────── */
.no-results {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Main Area ────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Top bar (mobile) ─────────────────────────────────── */
#topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--border-subtle);
  display: none;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  background: var(--bg-base);
}

#menu-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#topbar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Content ──────────────────────────────────────────── */
#content {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 80px;
  scroll-behavior: smooth;
}

#content::-webkit-scrollbar {
  width: 5px;
}

#content::-webkit-scrollbar-track {
  background: transparent;
}

#content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.content-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding-top: 52px;
}

/* ── Welcome / Home Screen ────────────────────────────── */
#home-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  padding: 40px 24px;
}

.home-icon {
  width: 56px;
  height: 56px;
  background: var(--accent-dim);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(25, 195, 125, 0.2);
  margin-bottom: 8px;
}

.home-icon svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

#home-screen h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

#home-screen p {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 360px;
  line-height: 1.7;
}

/* ── Article typography ───────────────────────────────── */
#article {
  display: none;
}

.article-header {
  margin-bottom: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--border-subtle);
}

.article-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.article-tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(25, 195, 125, 0.2);
  font-weight: 500;
  letter-spacing: 0.03em;
}

.article-header h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.article-byline {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.article-date {
  font-size: 13px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.article-author {
  font-size: 13px;
  color: var(--text-secondary);
}

.article-reading-time {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Prose ────────────────────────────────────────────── */
.prose {
  font-family: var(--font-serif);
  font-size: 16.5px;
  line-height: 1.85;
  color: #d4d4d4;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-weight: 500;
  letter-spacing: -0.02em;
  margin: 2em 0 0.6em;
  line-height: 1.3;
}

.prose h1 {
  font-size: 26px;
}

.prose h2 {
  font-size: 21px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.prose h3 {
  font-size: 17px;
}

.prose h4 {
  font-size: 15px;
}

.prose p {
  margin: 0 0 1.4em;
}

.prose strong {
  color: var(--text-primary);
  font-weight: 600;
  font-family: var(--font-serif);
}

.prose em {
  font-style: italic;
  color: #c8c8c8;
}

.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(25, 195, 125, 0.3);
  transition: border-color var(--transition);
}

.prose a:hover {
  border-color: var(--accent);
}

.prose ul,
.prose ol {
  margin: 0 0 1.4em 1.4em;
}

.prose li {
  margin-bottom: 0.4em;
}

.prose blockquote {
  margin: 1.6em 0;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  background: var(--accent-glow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-style: italic;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.prose img {
  max-width: 100%;
  border-radius: var(--radius-md);
  margin: 1.6em 0;
  border: 1px solid var(--border);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.6em 0;
  font-size: 14px;
  font-family: var(--font-sans);
}

.prose th {
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.prose td {
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.prose tr:nth-child(even) td {
  background: var(--bg-surface);
}

/* ── Inline code ─────────────────────────────────────── */
.prose code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 2px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-code);
}

/* ── Code blocks ──────────────────────────────────────── */
.code-block-wrapper {
  position: relative;
  margin: 1.6em 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: #0f0f0f;
  border-bottom: 1px solid var(--border-subtle);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.copy-btn {
  font-size: 11.5px;
  font-family: var(--font-sans);
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.code-block-wrapper pre {
  margin: 0 !important;
  border-radius: 0 !important;
  background: var(--bg-code) !important;
  padding: 18px 20px !important;
  overflow-x: auto;
  font-size: 13.5px !important;
  line-height: 1.7 !important;
}

.code-block-wrapper pre code {
  font-family: var(--font-mono) !important;
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  font-size: inherit !important;
}

/* ── Overlay (mobile sidebar) ─────────────────────────── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* ── Loading / Error ──────────────────────────────────── */
.state-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.state-screen p {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Article fade-in ──────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.article-fade {
  animation: fadeUp 0.3s ease forwards;
}

/* ── Mobile ───────────────────────────────────────────── */
@media (max-width: 768px) {
  #topbar {
    display: flex;
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #overlay.show {
    display: block;
  }

  #content {
    padding: 0 16px 80px;
  }

  .content-inner {
    padding-top: 36px;
  }

  .article-header h1 {
    font-size: 26px;
  }

  .prose {
    font-size: 15.5px;
  }
}

@media (max-width: 480px) {
  .article-header h1 {
    font-size: 22px;
  }
}

/* ── Smooth scrollbar ─────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
