/* ============================================================
   MIDAS WIKI — Stylesheet
   Brand: #0D0D0D black, #FFE400 yellow, white text
   Taste: VARIANCE 3, MOTION 3, DENSITY 7
   ============================================================ */

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

:root {
  --black: #0D0D0D;
  --yellow: #FFE400;
  --white: #FFFFFF;
  --gray: #A0A0A0;
  --dark-gray: #1A1A1A;
  --border: rgba(255,255,255,0.1);
  --card-bg: rgba(255,255,255,0.03);
  --card-bg-hover: rgba(255,255,255,0.05);
  --sidebar-w: 272px;
  --toc-w: 220px;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--black);
  color: var(--white);
  line-height: 1.6;
  overflow-x: hidden;
}

::selection {
  background: var(--yellow);
  color: var(--black);
}

:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

a { color: var(--yellow); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ============================================================
   MOBILE BAR
   ============================================================ */
.mobile-bar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--black);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
}

.mobile-bar-title {
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: -0.01em;
}

.menu-btn, .search-btn {
  background: none; border: none; color: var(--white);
  cursor: pointer; padding: 8px; display: flex; align-items: center;
}

.menu-btn {
  flex-direction: column; gap: 4px; width: 36px; height: 36px;
  justify-content: center;
}
.menu-btn span {
  display: block; width: 18px; height: 1.5px;
  background: var(--white); border-radius: 1px;
  transition: transform 0.25s var(--ease), opacity 0.2s;
}
.menu-btn.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.menu-btn.active span:nth-child(2) { opacity: 0; }
.menu-btn.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--black);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 150;
  overflow: hidden;
}

.sidebar-brand {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--white);
  text-decoration: none;
}

.sidebar-logo { border-radius: 4px; }

.sidebar-title {
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

/* Sidebar search */
.sidebar-search { padding: 12px 16px; }

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--dark-gray);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  height: 34px;
  cursor: text;
}

.search-icon { color: var(--gray); flex-shrink: 0; }

.search-field input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  min-width: 0;
}
.search-field input::placeholder { color: rgba(255,255,255,0.3); }

.search-kbd {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--gray);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
  flex-shrink: 0;
}

/* Sidebar nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-category {
  margin-bottom: 2px;
}

.nav-category-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 16px 6px 16px;
  background: none; border: none;
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.nav-category-btn:hover { background: var(--card-bg-hover); }

.nav-chevron {
  width: 14px; height: 14px;
  color: var(--gray);
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
}
.nav-category.open .nav-chevron { transform: rotate(90deg); }

.nav-category-label { flex: 1; }

.nav-category-count {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--gray);
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  padding: 0 5px;
  line-height: 1.6;
}

.nav-pages {
  display: none;
  padding: 2px 0 6px;
}
.nav-category.open .nav-pages { display: block; }

.nav-page-link {
  display: block;
  padding: 4px 16px 4px 36px;
  color: var(--gray);
  font-size: 0.8125rem;
  font-weight: 400;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  line-height: 1.4;
  border-left: 2px solid transparent;
}
.nav-page-link:hover {
  color: var(--white);
  background: var(--card-bg);
  text-decoration: none;
}
.nav-page-link.active {
  color: var(--yellow);
  border-left-color: var(--yellow);
  background: rgba(255,228,0,0.04);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-stats {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--gray);
}

.sidebar-agent-link {
  display: block;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--gray);
  text-decoration: none;
  transition: color 0.15s ease;
}

.sidebar-agent-link:hover {
  color: var(--yellow, #FFE400);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 140;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main {
  margin-left: var(--sidebar-w);
  margin-right: var(--toc-w);
  min-height: 100dvh;
  padding: 0;
}

.main-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 48px 120px;
}

/* ============================================================
   TABLE OF CONTENTS (right rail)
   ============================================================ */
.toc {
  position: fixed;
  top: 0; right: 0;
  width: var(--toc-w);
  height: 100dvh;
  padding: 40px 20px 40px 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.toc:empty, .toc.hidden { display: none; }

.toc-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray);
  margin-bottom: 12px;
  padding-left: 12px;
}

.toc-nav { display: flex; flex-direction: column; }

.toc-link {
  display: block;
  padding: 3px 12px;
  font-size: 0.75rem;
  color: var(--gray);
  text-decoration: none;
  border-left: 1px solid var(--border);
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.5;
}
.toc-link:hover { color: var(--white); text-decoration: none; }
.toc-link.active {
  color: var(--yellow);
  border-left-color: var(--yellow);
}
.toc-link[data-depth="3"] { padding-left: 24px; }

/* ============================================================
   HOME VIEW
   ============================================================ */
.home-header {
  margin-bottom: 48px;
}

.home-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 8px;
}

.home-subtitle {
  font-size: 0.9375rem;
  color: var(--gray);
  line-height: 1.5;
  max-width: 480px;
}

.home-stats {
  display: flex;
  gap: 24px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.home-stat {
  display: flex;
  flex-direction: column;
}

.home-stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--yellow);
  letter-spacing: -0.02em;
}

.home-stat-label {
  font-size: 0.75rem;
  color: var(--gray);
  margin-top: 2px;
}

/* Category sections on home */
.home-category {
  margin-bottom: 36px;
}

.home-category-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.home-category-name {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--yellow);
}

.home-category-desc {
  font-size: 0.75rem;
  color: var(--gray);
}

.home-page-list { list-style: none; }

.home-page-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  align-items: baseline;
}
.home-page-item:last-child { border-bottom: none; }

.home-page-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--white);
  text-decoration: none;
  transition: color 0.15s;
}
.home-page-link:hover { color: var(--yellow); text-decoration: none; }

.home-page-desc {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

/* ============================================================
   ARTICLE VIEW
   ============================================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--gray);
  margin-bottom: 24px;
}

.breadcrumb a {
  color: var(--gray);
  text-decoration: none;
  transition: color 0.15s;
}
.breadcrumb a:hover { color: var(--yellow); }

.breadcrumb-sep {
  color: rgba(255,255,255,0.2);
  font-size: 0.625rem;
}

/* Markdown article styles */
.article h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 8px;
}

.article h1 + p {
  color: var(--gray);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 32px;
}

.article h2 {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-top: 40px;
  margin-bottom: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.article h2:first-of-type {
  margin-top: 24px;
}

.article h3 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin-top: 28px;
  margin-bottom: 8px;
  color: rgba(255,255,255,0.9);
}

.article h4 {
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 6px;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.article p {
  font-size: 0.9375rem;
  line-height: 1.7;
  margin-bottom: 14px;
  color: rgba(255,255,255,0.85);
}

.article strong { color: var(--white); font-weight: 600; }

.article ul, .article ol {
  margin-bottom: 14px;
  padding-left: 20px;
}

.article li {
  font-size: 0.9375rem;
  line-height: 1.6;
  margin-bottom: 4px;
  color: rgba(255,255,255,0.85);
}

.article li::marker {
  color: var(--gray);
}

/* Nested lists */
.article ul ul, .article ol ol, .article ul ol, .article ol ul {
  margin-top: 4px;
  margin-bottom: 4px;
}

.article a {
  color: var(--yellow);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.15s;
}
.article a:hover { opacity: 0.8; text-decoration: underline; }

/* Wiki cross-reference links */
.article a.wiki-link {
  background: rgba(255,228,0,0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.875rem;
}
.article a.wiki-link:hover {
  background: rgba(255,228,0,0.15);
  text-decoration: none;
}

/* Code */
.article code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: var(--dark-gray);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.article pre {
  background: var(--dark-gray);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.article pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.8125rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.8);
}

/* Tables */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
  font-size: 0.8125rem;
}

.article thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--yellow);
  padding: 8px 12px;
  border-bottom: 2px solid rgba(255,228,0,0.2);
}

.article tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.8);
  line-height: 1.5;
}

.article tbody tr:hover td {
  background: var(--card-bg);
}

/* Blockquotes */
.article blockquote {
  border-left: 3px solid var(--yellow);
  padding: 8px 16px;
  margin: 0 0 16px 0;
  background: rgba(255,228,0,0.03);
  border-radius: 0 6px 6px 0;
}

.article blockquote p {
  color: rgba(255,255,255,0.7);
  font-size: 0.875rem;
  margin-bottom: 0;
}

.article blockquote strong {
  color: var(--yellow);
}

/* Horizontal rules */
.article hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

/* Source citations */
.article p:last-child:has(a[href*="Source"]),
.article .source-citation {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--gray);
}

/* ============================================================
   SEARCH MODAL (Cmd+K)
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 500;
  justify-content: center;
  padding-top: 20vh;
}
.modal-overlay.open { display: flex; }

.modal-box {
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: 440px;
  background: #141414;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.modal-search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-search-field svg { color: var(--gray); flex-shrink: 0; }

.modal-search-field input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.9375rem;
}
.modal-search-field input::placeholder { color: rgba(255,255,255,0.3); }

.modal-kbd {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--gray);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
}

.modal-results {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.modal-result {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s;
}
.modal-result:hover, .modal-result.highlighted {
  background: var(--card-bg-hover);
  text-decoration: none;
}

.modal-result-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--white);
}

.modal-result-meta {
  font-size: 0.6875rem;
  color: var(--gray);
  margin-top: 2px;
}

.modal-result-cat {
  font-family: var(--font-mono);
  color: var(--yellow);
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.modal-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--gray);
  font-size: 0.8125rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* Hide TOC on smaller screens */
@media (max-width: 1200px) {
  .toc { display: none; }
  .main { margin-right: 0; }
}

/* Tablet */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; }

  .mobile-bar { display: flex; }

  .main {
    margin-left: 0;
    padding-top: 56px;
  }

  .main-inner {
    padding: 24px 24px 100px;
  }

  .home-page-desc { display: none; }
  .home-page-item { grid-template-columns: 1fr; }
}

/* Mobile */
@media (max-width: 480px) {
  .main-inner { padding: 20px 16px 80px; }
  .home-title { font-size: 1.5rem; }
  .article h1 { font-size: 1.375rem; }
  .article h2 { font-size: 1.0625rem; }
  .home-stats { gap: 16px; }
  .home-stat-value { font-size: 1.25rem; }
}
