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

/* ===== Theme Variables ===== */
:root {
  --ma2: #ff9100;
  --ma2-dim: #ff910033;
  --eos: #0077ff;
  --eos-dim: #0077ff33;
  --sidebar-width: 280px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #121212;
  --bg-secondary: #1a1a1a;
  --bg-sidebar: #161616;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #2a2a2a;
  --highlight-bg: #1e1e1e;
  --search-bg: #1e1e1e;
  --selection-bg: var(--eos-dim);
  --link: var(--eos);
  --scrollbar-thumb: #333;
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-secondary: #ffffff;
  --bg-sidebar: #f0f0f0;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #ddd;
  --highlight-bg: #f5f5f5;
  --search-bg: #fff;
  --selection-bg: var(--ma2-dim);
  --link: var(--eos);
  --scrollbar-thumb: #ccc;
}

/* ===== Selection ===== */
::selection {
  background: var(--selection-bg);
  color: var(--text);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* ===== Body ===== */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background var(--transition), color var(--transition);
}

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

/* ===== Theme Toggle ===== */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background var(--transition), border-color var(--transition);
}
.theme-toggle:hover {
  border-color: var(--ma2);
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), border-color var(--transition), transform 0.3s ease;
}

.sidebar-header {
  padding: 20px 20px 4px;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.3px;
}
.sidebar-title:hover {
  text-decoration: none;
  opacity: 0.8;
}

.search-box {
  padding: 12px 20px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  background: var(--search-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.search-box input:focus {
  border-color: var(--ma2);
}
.search-box input::placeholder {
  color: var(--text-muted);
}

.toc-list {
  list-style: none;
  padding: 0 12px 20px;
  flex: 1;
  overflow-y: auto;
}

.toc-list li {
  margin: 0;
}

/* Group headers in sidebar — these are the "pages" */
.toc-group-link {
  display: block;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  text-decoration: none;
}
.toc-group-link:hover {
  color: var(--text);
  background: var(--highlight-bg);
  text-decoration: none;
}
.toc-group-link.active {
  color: var(--ma2);
  background: var(--ma2-dim);
}

/* Sub-section links */
.toc-sublist {
  list-style: none;
  padding: 0 0 4px 8px;
  margin: 0 0 0 16px;
  border-left: 1px solid var(--border);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}
.toc-sublist.expanded {
  max-height: 500px;
  opacity: 1;
}

.toc-sublist a {
  display: block;
  padding: 4px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  line-height: 1.4;
}
.toc-sublist a:hover {
  color: var(--text);
  background: var(--highlight-bg);
  text-decoration: none;
}
.toc-sublist a.active {
  color: var(--eos);
  background: var(--eos-dim);
}

/* ===== Menu Toggle (mobile) ===== */
.menu-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition);
}

/* ===== Main Content ===== */
.content {
  margin-left: var(--sidebar-width);
  margin-right: auto;
  max-width: 800px;
  padding: 40px 48px 80px;
  transition: margin-left 0.3s ease;
}

/* Center the content area when viewport is wide enough */
@media (min-width: 1081px) {
  .content {
    margin-left: max(var(--sidebar-width), calc(50% - 400px + var(--sidebar-width) / 2));
  }
}

/* ===== Pages ===== */
.page {
  display: none;
}
.page.visible {
  display: block;
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 48px 0 40px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 40px;
}

.hero h1 {
  font-size: 2.2em;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
}

.hero .subtitle {
  font-style: italic;
  color: var(--text-muted);
  font-size: 1.1em;
  margin-bottom: 12px;
}

.hero .tagline {
  color: var(--text-muted);
  font-size: 0.95em;
  margin-bottom: 16px;
}

.hero .author {
  font-size: 0.9em;
  margin-bottom: 4px;
}

.hero .version {
  font-size: 0.8em;
  color: var(--text-muted);
}

/* ===== Home Navigation Cards ===== */
.home-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}

.home-nav-card {
  padding: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color var(--transition), transform 0.15s ease;
  text-decoration: none;
  color: var(--text);
}
.home-nav-card:hover {
  border-color: var(--ma2);
  transform: translateY(-2px);
  text-decoration: none;
}

.home-nav-card h3 {
  font-size: 1em;
  margin-bottom: 6px;
  color: var(--text);
}

.home-nav-card p {
  font-size: 0.82em;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ===== Page Header ===== */
.page-title {
  font-size: 1.8em;
  font-weight: 700;
  margin-bottom: 32px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--border);
}

/* ===== Sections ===== */
.section {
  margin-bottom: 48px;
}

.section-title {
  font-size: 1.4em;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  scroll-margin-top: 24px;
}

.section-group-title {
  font-size: 1em;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.line {
  margin-bottom: 4px;
}

.line-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ===== Color spans ===== */
.ma2 {
  color: var(--ma2);
  font-weight: 500;
}

.eos {
  color: var(--eos);
  font-weight: 500;
}

.bold-text {
  font-weight: 600;
}

.note {
  font-size: 0.9em;
  color: var(--text-muted);
  border-left: 3px solid var(--border);
  padding-left: 12px;
  margin: 12px 0;
}

/* ===== Search Results ===== */
.page-title {
  font-size: 1.3em;
  margin-bottom: 20px;
  color: var(--text-muted);
}

.search-result-item {
  padding: 16px;
  margin-bottom: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color var(--transition);
}

.search-result-item:hover {
  border-color: var(--ma2);
}

.search-result-section {
  font-size: 0.8em;
  color: var(--ma2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.search-result-text {
  font-size: 0.95em;
  line-height: 1.5;
}

.search-result-text mark {
  background: var(--ma2-dim);
  color: var(--ma2);
  border-radius: 2px;
  padding: 0 2px;
}

.no-results {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

/* ===== Page Nav (prev/next) ===== */
.page-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color var(--transition);
  max-width: 45%;
}
.page-nav a:hover {
  border-color: var(--ma2);
  text-decoration: none;
}

.page-nav .nav-label {
  font-size: 0.75em;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.page-nav .nav-title {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--text);
}

.page-nav .next {
  margin-left: auto;
  text-align: right;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .content {
    margin-left: 0;
    padding: 40px 24px 80px;
  }
  .hero h1 {
    font-size: 1.6em;
  }
  .home-nav {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .content {
    padding: 40px 16px 60px;
  }
  .hero h1 {
    font-size: 1.3em;
  }
  .section-title {
    font-size: 1.2em;
  }
}
