:root {
  --bg: #f7f5f0;
  --bg-elev: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e5e4;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --link: #0f766e;
  --code-bg: #f5f5f4;
  --sidebar-w: 280px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 8px 24px rgba(28, 25, 23, 0.06);
}

[data-theme="dark"] {
  --bg: #0c0a09;
  --bg-elev: #1c1917;
  --text: #fafaf9;
  --muted: #a8a29e;
  --border: #292524;
  --accent: #2dd4bf;
  --accent-soft: #134e4a;
  --link: #5eead4;
  --code-bg: #292524;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem 2rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 20;
}

.brand-link {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.brand-sub { margin: 0.25rem 0 0; font-size: 0.8rem; color: var(--muted); }

.theme-toggle {
  margin: 0.9rem 0 1rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.nav-section { margin-bottom: 1.25rem; }
.nav-title {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.4rem 0.35rem;
  font-weight: 600;
}
.nav a {
  display: block;
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--accent-soft); }
.nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav .layer { color: var(--muted); font-size: 0.75rem; margin-left: 0.35rem; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elev) 85%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.menu-btn {
  display: none;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 8px;
  width: 2.25rem;
  height: 2.25rem;
  cursor: pointer;
}
.crumb { font-size: 0.85rem; color: var(--muted); word-break: break-all; }

.content {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.home-hero {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.4rem;
  margin-bottom: 1.5rem;
}
.home-hero h1 { margin: 0 0 0.5rem; font-size: 1.75rem; line-height: 1.3; }
.home-hero p { margin: 0.4rem 0; color: var(--muted); }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.85rem;
  margin: 1.25rem 0;
}
.card {
  display: block;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card h3 { margin: 0 0 0.35rem; font-size: 1rem; color: var(--accent); }
.card p { margin: 0; font-size: 0.85rem; color: var(--muted); }

.markdown-body h1 { font-size: 1.7rem; margin: 0 0 1rem; line-height: 1.3; }
.markdown-body h2 { font-size: 1.3rem; margin: 1.75rem 0 0.75rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; }
.markdown-body h3 { font-size: 1.1rem; margin: 1.35rem 0 0.5rem; }
.markdown-body p, .markdown-body li { font-size: 1rem; }
.markdown-body a { color: var(--link); }
.markdown-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.markdown-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1rem 0;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
  vertical-align: top;
}
.markdown-body th { background: var(--code-bg); }
.markdown-body blockquote {
  margin: 1rem 0;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
.loading, .error { color: var(--muted); }
.error { color: #dc2626; }

.path-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--code-bg);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 15;
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
}
