/* ============================================
   Memento Wiki - Custom Theme
   Centered layout: sidebar + content as one block
   ============================================ */

/* ============================================
   1. CSS Variables
   ============================================ */

:root, [data-theme="light"] {
  --wiki-shell-width: 1180px;
  --wiki-shell-half: 590px;
  --wiki-sidebar-width: 272px;
  --wiki-nav-height: 56px;
  --wiki-shell-edge: max(24px, calc(50vw - var(--wiki-shell-half)));

  --bg-body: #ffffff;
  --bg-nav: rgba(255,255,255,0.92);
  --bg-sidebar: #f4f7fb;
  --bg-content: #ffffff;
  --bg-code: #f6f8fa;
  --bg-code-inline: #f0f1f3;
  --bg-table-stripe: #f8f9fa;
  --bg-table-header: #f1f3f5;

  --text-primary: #1f2328;
  --text-secondary: #656d76;
  --text-heading: #1a1a2e;
  --text-sidebar: #1f2328;
  --text-muted: #8b949e;

  --border-color: #d0d7de;
  --border-light: #e8eaed;

  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-dim: rgba(9, 105, 218, 0.08);
  --active-bg: #e6f0ff;

  --shadow-nav: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 3px 6px rgba(0,0,0,0.08);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

[data-theme="dark"] {
  --bg-body: #0d1117;
  --bg-nav: rgba(13,17,23,0.92);
  --bg-sidebar: #10161f;
  --bg-content: #0d1117;
  --bg-code: #161b22;
  --bg-code-inline: #1c2128;
  --bg-table-stripe: #161b22;
  --bg-table-header: #21262d;

  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-heading: #f0f6fc;
  --text-sidebar: #e6edf3;
  --text-muted: #6e7681;

  --border-color: #2b3139;
  --border-light: #21262d;

  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-dim: rgba(88, 166, 255, 0.12);
  --active-bg: rgba(88, 166, 255, 0.14);

  --shadow-nav: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 3px 6px rgba(0,0,0,0.4);
}

/* ============================================
   2. Reset & Body
   ============================================ */

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

body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
               "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px; line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-body);
  -webkit-font-smoothing: antialiased;
}

.wiki-layout {
  overflow-x: clip;
}

.wiki-layout > main {
  width: 100%;
  min-width: 0;
}

/* ============================================
   3. Centered shell and navigation
   ============================================ */

.wiki-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--wiki-nav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-nav);
}

.wiki-nav-inner {
  width: calc(100% - 48px);
  max-width: var(--wiki-shell-width);
  height: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--wiki-sidebar-width) minmax(0, 1fr) 36px;
  gap: 24px;
  align-items: center;
}

.wiki-nav-title {
  min-width: 0;
  padding-left: 20px;
  overflow: hidden;
  color: var(--text-heading);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wiki-nav-title:hover { color: var(--accent); }

.wiki-nav-search {
  position: relative;
  width: min(100%, 420px);
  min-width: 0;
  justify-self: center;
}

.wiki-nav-theme {
  width: 32px;
  height: 32px;
  justify-self: end;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: color 0.2s, border-color 0.2s;
}
.wiki-nav-theme:hover { color: var(--accent); border-color: var(--accent); }

.sidebar {
  position: fixed !important;
  top: var(--wiki-nav-height) !important;
  bottom: 0 !important;
  left: var(--wiki-shell-edge) !important;
  width: var(--wiki-sidebar-width) !important;
  display: flex;
  flex-direction: column;
  padding: 24px 0 32px !important;
  overflow: hidden;
  background: var(--bg-sidebar) !important;
  border-right: 1px solid var(--border-light) !important;
  z-index: 10;
}

body.close .sidebar {
  left: var(--wiki-shell-edge) !important;
  transform: none !important;
}

.sidebar .app-name,
.sidebar > .close { display: none !important; }

.sidebar-nav {
  min-height: 0;
  padding: 0 20px;
  overflow-y: auto !important;
}

.sidebar-nav ul { list-style: none; padding: 0; margin: 0; }
.sidebar-nav li { margin: 0; line-height: 1.5; }

.sidebar-nav li > strong {
  display: block;
  margin: 22px 10px 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.sidebar-nav > ul > li:first-child + li > strong { margin-top: 14px; }

.sidebar-nav a {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--text-sidebar) !important;
  font-size: 13.5px;
  text-decoration: none;
  transition: color 0.15s, background-color 0.15s;
}

.sidebar-nav ul ul a {
  padding-left: 20px;
  color: var(--text-secondary) !important;
  font-size: 13px;
}

.sidebar-nav .app-sub-sidebar {
  margin: 2px 0 10px 10px;
  padding: 4px 0 4px 10px;
  border-left: 1px solid var(--border-light);
}

.sidebar-nav .app-sub-sidebar ul { padding-left: 10px; }

.sidebar-nav .app-sub-sidebar li::before { display: none !important; }

.sidebar-nav .app-sub-sidebar a {
  min-height: 30px;
  padding: 5px 8px;
  color: var(--text-muted) !important;
  font-size: 12px;
}

.sidebar-nav .app-sub-sidebar .active > a {
  background: transparent;
  color: var(--accent) !important;
  font-weight: 500;
}

.sidebar-nav a:hover {
  color: var(--accent) !important;
  background: var(--accent-dim);
  text-decoration: none;
}

.sidebar-nav .active > a {
  color: var(--accent) !important;
  background: var(--active-bg);
  font-weight: 600;
}

.content,
body.close .content {
  position: relative !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: 0 !important;
  min-width: 0;
  min-height: 100vh;
  max-width: none;
  margin-left: calc(var(--wiki-shell-edge) + var(--wiki-sidebar-width)) !important;
  margin-right: var(--wiki-shell-edge) !important;
  padding-top: var(--wiki-nav-height) !important;
  background: var(--bg-content);
  transition: none !important;
}

.markdown-section {
  max-width: 908px !important;
  margin: 0 auto;
  padding: 48px 48px 64px;
  overflow-wrap: anywhere;
}

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  scroll-margin-top: calc(var(--wiki-nav-height) + 16px);
}

/* --- Headings --- */
.markdown-section h1 {
  font-size: 1.75em; font-weight: 700;
  margin: 0 0 0.5em 0; padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-heading);
  letter-spacing: -0.02em; line-height: 1.3;
}
.markdown-section h2 {
  font-size: 1.35em; font-weight: 600;
  margin: 2em 0 0.5em 0; padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-heading);
  letter-spacing: -0.01em;
}
.markdown-section h3 {
  font-size: 1.15em; font-weight: 600;
  margin: 1.6em 0 0.4em 0; color: var(--text-heading);
}
.markdown-section h4 {
  font-size: 1.05em; font-weight: 600;
  margin: 1.3em 0 0.3em 0; color: var(--text-heading);
}

/* --- Paragraphs & Links --- */
.markdown-section p { margin: 0 0 1em 0; color: var(--text-primary); }
.markdown-section a { color: var(--accent); text-decoration: none; }
.markdown-section a:hover { color: var(--accent-hover); text-decoration: underline; }
.markdown-section strong { color: var(--text-heading); font-weight: 600; }
.markdown-section hr {
  border: none; height: 1px;
  background: var(--border-light); margin: 2.5em 0;
}

/* ============================================
   7. Code
   ============================================ */

.markdown-section code {
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 0.85em; background: var(--bg-code-inline);
  color: var(--text-primary); padding: 0.15em 0.4em;
  border-radius: 3px; border: 1px solid var(--border-light);
}
.markdown-section pre {
  background: var(--bg-code) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 0 !important;
  margin: 1.2em 0; overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.markdown-section pre code {
  display: block; padding: 16px 20px;
  background: transparent; border: none; border-radius: 0;
  font-size: 0.82em; line-height: 1.65; overflow-x: auto;
  color: var(--text-primary);
}

/* Dark theme code highlighting */
[data-theme="dark"] .token.comment,
[data-theme="dark"] .token.prolog,
[data-theme="dark"] .token.doctype,
[data-theme="dark"] .token.cdata { color: #8b949e; }
[data-theme="dark"] .token.punctuation { color: #c9d1d9; }
[data-theme="dark"] .token.property,
[data-theme="dark"] .token.tag,
[data-theme="dark"] .token.boolean,
[data-theme="dark"] .token.number,
[data-theme="dark"] .token.constant,
[data-theme="dark"] .token.symbol,
[data-theme="dark"] .token.deleted { color: #79c0ff; }
[data-theme="dark"] .token.selector,
[data-theme="dark"] .token.attr-name,
[data-theme="dark"] .token.string,
[data-theme="dark"] .token.char,
[data-theme="dark"] .token.builtin,
[data-theme="dark"] .token.inserted { color: #a5d6ff; }
[data-theme="dark"] .token.operator,
[data-theme="dark"] .token.entity,
[data-theme="dark"] .token.url { color: #d2a8ff; }
[data-theme="dark"] .token.atrule,
[data-theme="dark"] .token.attr-value,
[data-theme="dark"] .token.keyword { color: #ff7b72; }
[data-theme="dark"] .token.function,
[data-theme="dark"] .token.class-name { color: #d2a8ff; }
[data-theme="dark"] .token.regex,
[data-theme="dark"] .token.important,
[data-theme="dark"] .token.variable { color: #ffa657; }

/* ============================================
   8. Tables
   ============================================ */

.markdown-section table {
  display: block;
  width: 100%;
  border-collapse: separate; border-spacing: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md); overflow-x: auto;
  margin: 1.2em 0; font-size: 0.92em;
  box-shadow: var(--shadow-sm);
}
.markdown-section table th {
  background: var(--bg-table-header); color: var(--text-heading);
  font-weight: 600; text-align: left;
  padding: 10px 16px; border-bottom: 2px solid var(--border-color);
  white-space: nowrap; font-size: 0.95em;
}
.markdown-section table td {
  padding: 10px 16px; border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}
.markdown-section table tr:last-child td { border-bottom: none; }
.markdown-section table tr:nth-child(even) td { background: var(--bg-table-stripe); }

/* ============================================
   9. Blockquotes
   ============================================ */

.markdown-section blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-dim);
  margin: 1.2em 0; padding: 12px 20px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-primary);
}
.markdown-section blockquote p { margin: 0; }
.markdown-section blockquote p + p { margin-top: 0.6em; }

/* ============================================
   10. Lists
   ============================================ */

.markdown-section ul, .markdown-section ol {
  padding-left: 1.6em; margin: 0 0 1em 0;
}
.markdown-section li { margin-bottom: 0.25em; }
.markdown-section li > ul, .markdown-section li > ol {
  margin-top: 0.25em; margin-bottom: 0;
}

.markdown-section ul { list-style: none; padding-left: 1.4em; }
.markdown-section ul li::before {
  content: "\2022"; color: var(--accent); font-weight: bold;
  display: inline-block; width: 1em; margin-left: -1em; font-size: 1.1em;
}

/* ============================================
   11. Search
   ============================================ */

.wiki-nav-search .search {
  position: relative;
  margin: 0;
  padding: 0;
}
.wiki-nav-search .search input {
  background: var(--bg-body) !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-md) !important;
  padding: 7px 12px 7px 32px !important;
  font-size: 13px !important; width: 100% !important;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.wiki-nav-search .search input:focus {
  border-color: var(--accent) !important; outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.wiki-nav-search .search input::placeholder { color: var(--text-muted); }
.wiki-nav-search .search .results-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  background: var(--bg-body) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
}

/* ============================================
   12. Scrollbar
   ============================================ */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================
   13. Docsify UI Overrides
   ============================================ */

/* Hide sidebar toggle button on desktop */
.sidebar-toggle { display: none !important; }

/* Hide GitHub corner */
.github-corner { display: none; }

/* Hide cover */
.cover, .cover-show { display: none !important; }

/* ============================================
   14. Responsive drawer
   ============================================ */

@media (max-width: 1023px) {
  .wiki-nav-inner {
    width: 100%;
    max-width: none;
    grid-template-columns: minmax(140px, 1fr) minmax(180px, 360px) 36px;
    gap: 12px;
    padding: 0 16px;
  }

  .wiki-nav-title { padding-left: 40px; }

  .sidebar {
    position: fixed !important;
    top: var(--wiki-nav-height) !important;
    left: 0 !important;
    bottom: 0 !important;
    width: min(320px, 86vw) !important;
    padding-top: 20px !important;
    transform: translateX(-100%) !important;
    transition: transform 250ms ease !important;
    border-right: 1px solid var(--border-color) !important;
    z-index: 90;
  }
  body.close .sidebar {
    left: 0 !important;
    transform: translateX(-100%) !important;
  }
  body:not(.close) .sidebar {
    left: 0 !important;
    transform: translateX(0) !important;
  }

  .sidebar-nav a { min-height: 44px; }
  .sidebar-nav .app-sub-sidebar a { min-height: 36px; }

  .content,
  body.close .content,
  body:not(.close) .content {
    left: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-top: var(--wiki-nav-height) !important;
  }

  .sidebar-toggle {
    display: block !important;
    position: fixed;
    top: 10px !important;
    left: 12px;
    z-index: 120;
    width: 36px;
    height: 36px;
    padding: 9px !important;
    border: 0;
    border-radius: 50%;
    background: transparent !important;
  }
  .sidebar-toggle span { background-color: var(--text-secondary) !important; }

  .markdown-section { max-width: none; padding: 40px 24px 56px; }
}

@media (max-width: 640px) {
  .wiki-nav-inner {
    grid-template-columns: minmax(84px, 1fr) minmax(112px, 1.4fr) 32px;
    gap: 8px;
  }

  .wiki-nav-title { font-size: 13px; }
  .wiki-nav-theme { width: 32px; height: 32px; }
  .wiki-nav-search .search input { font-size: 12px !important; }
  .markdown-section { padding: 32px 20px 48px; }
  .markdown-section h1 { font-size: 1.5em; }
  .markdown-section h2 { font-size: 1.2em; }
}
