:root {
  --bg: #ffffff;
  --bg-sidebar: #f6f8fa;
  --bg-hover: #eaeef2;
  --bg-active: #ddf4ff;
  --border: #d0d7de;
  --text: #1f2328;
  --text-muted: #59636e;
  --link: #0969da;
  --accent: #0969da;
  --code-bg: #f6f8fa;
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-sidebar: #161b22;
  --bg-hover: #21262d;
  --bg-active: #1f3a52;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --link: #4493f8;
  --accent: #4493f8;
  --code-bg: #161b22;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  overflow: hidden;
}

body {
  padding: 0 28px;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-corner { background: transparent; }
*::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: var(--text-muted);
  background-clip: padding-box;
}

#app {
  display: grid;
  grid-template-columns: 280px 1fr 240px;
  height: 100vh;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

#sidebar, #toc-panel {
  background: var(--bg-sidebar);
  overflow-y: auto;
  padding: 12px;
}

#sidebar { border-right: 1px solid var(--border); }
#toc-panel { border-left: 1px solid var(--border); }

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#sidebar-header { gap: 8px; }
#root-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
#sidebar-header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

#open-folder, #open-folder-empty {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}
#open-folder:hover, #open-folder-empty:hover { background: var(--bg-hover); color: var(--text); }
#open-folder:disabled { opacity: 0.4; cursor: not-allowed; }

#sidebar-empty {
  padding: 16px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12.5px;
}
#sidebar-empty p { margin: 0 0 10px; }
#sidebar-empty-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
#sidebar-empty-brand img { border-radius: 6px; }
#sidebar-empty #open-folder-empty { padding: 6px 14px; font-size: 12.5px; }

#theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.15s ease, transform 0.2s ease;
}
#theme-toggle:hover { background: var(--bg-hover); }
#theme-toggle:active { transform: rotate(20deg) scale(0.9); }

#check-links {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 12px;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
#check-links:hover { background: var(--bg-hover); }
#check-links:active { transform: scale(0.9); }
#check-links:disabled { opacity: 0.5; cursor: wait; }

.link-report { max-width: 720px; margin: 0 auto; }
.link-report-summary {
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  margin-bottom: 16px;
}
.link-report-summary.all-clear { background: rgba(45, 164, 78, 0.15); color: #2da44e; }
.link-report-summary.has-broken { background: rgba(207, 34, 46, 0.12); color: #cf222e; }
.link-report-file {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.link-report-file-name {
  padding: 8px 12px;
  background: var(--bg-sidebar);
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease;
}
.link-report-file-name:hover { color: var(--accent); }
.link-report-item {
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.link-report-item code { background: var(--code-bg); padding: 0.1em 0.4em; border-radius: 4px; }

body, #sidebar, #toc-panel, #content, #doc-toolbar, #search, #search-results, #doc {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

#search {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

#search-results {
  margin-bottom: 10px;
  max-height: 45vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
#search-results:not([hidden]) { animation: fadeSlideDown 0.15s ease; }
#search-results .sr-empty {
  padding: 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.sr-file { border-bottom: 1px solid var(--border); }
.sr-file:last-child { border-bottom: none; }
.sr-file-name {
  padding: 6px 8px 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.sr-file-name:hover { color: var(--accent); }
.sr-match {
  padding: 3px 10px 3px 16px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, monospace;
}
.sr-match:hover { background: var(--bg-hover); color: var(--text); }
.sr-match mark, .sr-file-name mark { background: #fff3a3; color: #111; border-radius: 2px; padding: 0 1px; }

#file-tree ul { list-style: none; margin: 0; padding-left: 14px; }
#file-tree > ul { padding-left: 0; }

.tree-dir > .tree-label {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  user-select: none;
}
.tree-dir > .tree-label { transition: background-color 0.15s ease; }
.tree-dir > .tree-label:hover { background: var(--bg-hover); }
.tree-dir > ul {
  overflow: hidden;
  max-height: 3000px;
  opacity: 1;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}
.tree-dir.collapsed > ul {
  max-height: 0;
  opacity: 0;
  transition: max-height 0.2s ease, opacity 0.15s ease;
}
.tree-caret { display: inline-block; width: 10px; transition: transform 0.2s ease; }
.tree-dir.collapsed .tree-caret { transform: rotate(-90deg); }

.tree-file a {
  display: block;
  padding: 4px 6px 4px 20px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tree-file a:hover { background: var(--bg-hover); }
.tree-file.active > a { background: var(--bg-active); color: var(--accent); font-weight: 600; }
.tree-file.hidden { display: none; }

#content {
  overflow-y: auto;
  padding: 0 32px 80px;
}

#doc-toolbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  border-bottom: 1px solid var(--border);
}

#doc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-family: ui-monospace, monospace;
}

#doc-actions { display: flex; gap: 6px; }
#doc-actions button {
  border: 1px solid var(--border);
  background: var(--bg-sidebar);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
#doc-actions button:hover { color: var(--text); background: var(--bg-hover); }
#doc-actions button:active { transform: scale(0.94); }

#section-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
}
#section-tabs:empty { display: none; }
.section-tab {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  font-size: 12.5px;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.section-tab:hover { color: var(--text); transform: translateY(-1px); }
.section-tab:active { transform: translateY(0) scale(0.96); }
.section-tab.active { background: var(--bg-active); color: var(--accent); border-color: var(--accent); font-weight: 600; }

#doc {
  max-width: 860px;
  margin: 0 auto;
  padding-top: 20px;
  line-height: 1.6;
}

#doc:empty::before {
  content: "Pick a README from the left to view it.";
  color: var(--text-muted);
}

#doc h1, #doc h2, #doc h3, #doc h4 { scroll-margin-top: 60px; }
#doc h1 { border-bottom: 1px solid var(--border); padding-bottom: 8px; }
#doc h2 { border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-top: 32px; }
#doc a { color: var(--link); }
#doc img { max-width: 100%; }
#doc pre { position: relative; background: var(--code-bg); padding: 12px; border-radius: 8px; overflow-x: auto; }
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s ease, transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
#doc pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; transform: translateY(0); }
.copy-btn:hover { background: var(--bg-hover); color: var(--text); }
.copy-btn.copied { color: #2da44e; border-color: #2da44e; opacity: 1; transform: translateY(0); }
#doc code { background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 4px; font-size: 0.9em; }
#doc pre code { background: none; padding: 0; }
#doc table { border-collapse: collapse; width: 100%; }
#doc th, #doc td { border: 1px solid var(--border); padding: 6px 10px; }
#doc blockquote { border-left: 3px solid var(--border); margin: 0; padding-left: 14px; color: var(--text-muted); }

.md-alert {
  border-left-width: 4px;
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  background: var(--bg-sidebar);
}
.md-alert-title { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.md-alert-note { border-left-color: #0969da; }
.md-alert-tip { border-left-color: #1a7f37; }
.md-alert-important { border-left-color: #8250df; }
.md-alert-warning { border-left-color: #9a6700; }
.md-alert-caution { border-left-color: #cf222e; }

.mermaid {
  display: flex;
  justify-content: center;
  background: var(--code-bg);
  border-radius: 8px;
  padding: 16px;
  margin: 12px 0;
  overflow-x: auto;
}
.mermaid svg { max-width: 100%; height: auto; }
.mermaid-error { color: var(--text-muted); font-size: 12.5px; }
.mermaid-error::before { content: "Couldn't render this diagram."; }

.md-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.md-section-toggle:hover { opacity: 0.75; }
.md-section-toggle > * { margin: 0; }
.section-caret {
  flex-shrink: 0;
  display: inline-block;
  font-size: 12px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  margin-top: 2px;
}
.md-section.collapsed > .md-section-toggle .section-caret { transform: rotate(-90deg); }

.md-section-body {
  overflow: hidden;
  max-height: 10000px;
  opacity: 1;
  transition: max-height 0.35s ease, opacity 0.25s ease;
}
.md-section.collapsed > .md-section-body {
  max-height: 0;
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.15s ease;
}

@keyframes docFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.doc-anim { animation: docFadeIn 0.25s ease; }

@keyframes searchHitFlash {
  0% { background-color: #ffcf33; }
  100% { background-color: #fff3a3; }
}
#doc mark.search-hit {
  background: #fff3a3;
  color: #111;
  border-radius: 2px;
  padding: 0 1px;
  scroll-margin-top: 120px;
  animation: searchHitFlash 1s ease;
}

#toc-header {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
}

#toc a {
  display: block;
  padding: 3px 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12.5px;
  border-left: 2px solid transparent;
  padding-left: 8px;
  transition: color 0.15s ease, border-color 0.15s ease;
}
#toc a:hover { color: var(--text); }
#toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
#toc a.lvl-3 { padding-left: 18px; }
#toc a.lvl-4 { padding-left: 28px; }
#toc a.lvl-5, #toc a.lvl-6 { padding-left: 38px; }

@media (max-width: 1100px) {
  #app { grid-template-columns: 240px 1fr; }
  #toc-panel { display: none; }
}
