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

:root {
  --sidebar-width: 260px;
  --header-height: 52px;

  --color-bg: #ffffff;
  --color-sidebar-bg: #f7f7f7;
  --color-sidebar-border: #e2e2e2;
  --color-text: #1a1a1a;
  --color-text-muted: #6b6b6b;
  --color-active-bg: #eef2ff;
  --color-active-text: #2a3fbf;
  --color-active-bar: #2a3fbf;
  --color-category-text: #444444;
  --color-hover-bg: #eeeeee;
  --color-breadcrumb: #888888;
  --color-rule: #e8e8e8;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ── Mobile header ── */
#mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--color-sidebar-bg);
  border-bottom: 1px solid var(--color-sidebar-border);
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  z-index: 200;
}

#mobile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

#hamburger {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: transform 0.2s, opacity 0.2s;
}

#hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
#hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── Sidebar overlay (mobile) ── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 149;
}

#sidebar-overlay.active { display: block; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 150;
}

#sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
}

#site-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

#nav-container {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0 24px;
}

/* ── Category group ── */
.nav-category {
  margin-bottom: 2px;
}

.category-btn {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 18px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-category-text);
  text-align: left;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s;
}

.category-btn:hover { color: var(--color-text); }

.category-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.2s;
  opacity: 0.5;
}

.nav-category.open .category-chevron { transform: rotate(90deg); }

/* ── Topic list ── */
.topic-list {
  display: none;
  padding: 2px 0 6px;
}

.nav-category.open .topic-list { display: block; }

.topic-link {
  display: block;
  padding: 6px 18px 6px 26px;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--color-text-muted);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  cursor: pointer;
}

.topic-link:hover {
  background: var(--color-hover-bg);
  color: var(--color-text);
}

.topic-link.active {
  background: var(--color-active-bg);
  color: var(--color-active-text);
  border-left-color: var(--color-active-bar);
  font-weight: 500;
}

/* ── Main content ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#breadcrumb {
  padding: 10px 40px;
  font-size: 12px;
  color: var(--color-breadcrumb);
  border-bottom: 1px solid var(--color-rule);
  min-height: 38px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#breadcrumb span { margin: 0 6px; opacity: 0.5; }

#content-area {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px 80px;
  max-width: 860px;
}

/* ── Welcome screen ── */
#welcome h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--color-text);
}

#welcome p {
  color: var(--color-text-muted);
  font-size: 14px;
}

/* ── Markdown content ── */
#content-area h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--color-rule);
  color: var(--color-text);
  line-height: 1.3;
}

#content-area h2 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 10px;
  color: var(--color-text);
}

#content-area h3 {
  font-size: 14px;
  font-weight: 600;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--color-text);
}

#content-area p {
  margin-bottom: 14px;
  color: var(--color-text);
  line-height: 1.7;
}

#content-area ul, #content-area ol {
  margin: 0 0 14px 20px;
  line-height: 1.7;
}

#content-area li { margin-bottom: 4px; }

#content-area table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin-bottom: 20px;
}

#content-area th {
  background: var(--color-sidebar-bg);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--color-rule);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
}

#content-area td {
  padding: 8px 12px;
  border: 1px solid var(--color-rule);
  vertical-align: top;
}

#content-area tr:nth-child(even) td { background: #fafafa; }

#content-area code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: #f0f0f0;
  padding: 2px 5px;
  border-radius: 3px;
  color: #c7254e;
}

#content-area pre {
  background: #f6f6f6;
  border: 1px solid var(--color-rule);
  border-radius: 4px;
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 20px;
}

#content-area pre code {
  background: none;
  padding: 0;
  color: var(--color-text);
  font-size: 13px;
}

#content-area blockquote {
  border-left: 3px solid var(--color-active-bar);
  margin: 0 0 16px;
  padding: 8px 16px;
  background: var(--color-active-bg);
  border-radius: 0 4px 4px 0;
  color: var(--color-text-muted);
  font-size: 14px;
}

#content-area hr {
  border: none;
  border-top: 1px solid var(--color-rule);
  margin: 28px 0;
}

#content-area img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  border: 1px solid var(--color-rule);
  margin: 16px 0;
  display: block;
}

#content-area a {
  color: var(--color-active-text);
  text-decoration: none;
}

#content-area a:hover { text-decoration: underline; }

#content-area strong { font-weight: 600; }
#content-area em { font-style: italic; }

/* ── Loading state ── */
#content-area.loading { opacity: 0.5; }

/* ── Responsive ── */
@media (max-width: 768px) {
  #mobile-header { display: flex; }

  #app { flex-direction: column; padding-top: var(--header-height); }

  #sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    height: calc(100vh - var(--header-height));
    z-index: 150;
  }

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

  #breadcrumb { padding: 8px 16px; }

  #content-area { padding: 24px 20px 60px; }
}

/* ── Scrollbar (webkit) ── */
#nav-container::-webkit-scrollbar,
#content-area::-webkit-scrollbar { width: 5px; }

#nav-container::-webkit-scrollbar-track,
#content-area::-webkit-scrollbar-track { background: transparent; }

#nav-container::-webkit-scrollbar-thumb,
#content-area::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 3px; }
