/* ==========================================================================
   수학 정리 /with MINZKN - Core Styles
   Layout, Typography, Components
   ========================================================================== */

/* ---------- z-index 계층 ---------- */
:root {
  --z-dropdown: 200;
  --z-header: 100;
  --z-nav: 95;
  --z-overlay: 90;
  --z-float: 50;
  --z-sticky: 10;
}

/* ---------- Font Preference ---------- */
[data-font="sans"],
:root {
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
}
[data-font="serif"] {
  --font-body: Georgia, "Noto Serif KR", "Batang", "Times New Roman", serif;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

html.search-focused {
  scroll-behavior: auto !important;
}

body {
  font-family: var(--font-body);
  line-height: 1.7;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading);
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
}

h1 { font-size: 2rem; border-bottom: 2px solid var(--accent-primary); padding-bottom: 0.375em; margin-top: 0; }
h2 { font-size: 1.5rem; margin-top: 2.75rem; margin-bottom: 1rem; }
h3 { font-size: 1.25rem; margin-top: 2rem; }
h4 { font-size: 1.1rem; margin-top: 1.75rem; }
h5 { font-size: 1rem; margin-top: 1.5rem; }
h6 { font-size: 0.875rem; color: var(--text-secondary); margin-top: 1.25rem; }

h2 .section-anchor,
h3 .section-anchor,
h4 .section-anchor {
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 0.3em;
  opacity: 0.4;
  transition: opacity 0.2s;
  font-weight: 400;
}

h2:hover .section-anchor,
h3:hover .section-anchor,
h4:hover .section-anchor {
  opacity: 0.8;
}

@media (max-width: 768px) {
  h2 .section-anchor,
  h3 .section-anchor,
  h4 .section-anchor {
    opacity: 0.6;
  }
}

p { margin-bottom: 1em; }

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color 0.2s;
}

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

a[href^="http"]:not([href*="minzkn.com"])::after {
  content: " ↗";
  font-size: 0.75em;
  opacity: 0.6;
  margin-left: 0.15em;
  vertical-align: super;
}

a[href^="http"]:not([href*="minzkn.com"]):hover::after {
  opacity: 1;
}

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

ul, ol { margin-bottom: 1em; padding-left: 1.8em; }
li { margin-bottom: 0.3em; }
li > ul, li > ol { margin-top: 0.3em; margin-bottom: 0.3em; }

blockquote {
  border-left: 3px solid var(--accent-primary);
  background: var(--bg-secondary);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

blockquote p:last-child { margin-bottom: 0; }

hr {
  border: none;
  border-top: 1px solid var(--border-secondary);
  margin: 2.5rem 0;
  opacity: 0.6;
}

/* ---------- Monospace / Code ---------- */
code, pre, kbd, samp, .mono {
  font-family: "D2Coding", "D2 Coding", "Fira Code", "Source Code Pro", "Consolas", monospace;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "calt" 0;
}

code {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
  border: 1px solid var(--border-code);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border-code);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1.25rem 0;
  overflow-x: auto;
  line-height: 1.5;
  font-size: 0.875rem;
  position: relative;
  tab-size: 4;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: var(--text-primary);
}

pre .line-numbers {
  color: var(--text-muted);
  user-select: none;
  margin-right: 1em;
  text-align: right;
  min-width: 2em;
  display: inline-block;
}

kbd {
  background: var(--bg-kbd);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  padding: 0.1em 0.5em;
  font-size: 0.85em;
  box-shadow: inset 0 -1px 0 var(--border-primary);
}

/* Syntax highlighting classes */
.kw { color: var(--syntax-keyword); }
.str { color: var(--syntax-string); }
.cmt { color: var(--syntax-comment); font-style: italic; }
.fn { color: var(--syntax-function); }
.num { color: var(--syntax-number); }
.type { color: var(--syntax-type); }
.macro { color: var(--syntax-macro); }
.pp { color: var(--syntax-preprocessor); }

/* ---------- Code with Line Numbers ---------- */
pre.with-line-numbers {
  --line-number-width: calc(2ch + 1.2em);
}

pre.with-line-numbers code {
  counter-reset: line;
  display: block;
  min-width: max-content;
}

pre.with-line-numbers code .line {
  counter-increment: line;
  display: grid;
  grid-template-columns: var(--line-number-width) minmax(0, 1fr);
  align-items: baseline;
  margin: 0;
  min-height: 1.5em;
}

pre.with-line-numbers code .line::before {
  content: counter(line);
  grid-column: 1;
  padding-right: 0.8em;
  text-align: right;
  color: var(--text-muted);
  user-select: none;
  border-right: 1px solid var(--border-primary);
}

pre.with-line-numbers code .line .line-content {
  grid-column: 2;
  padding-left: 0.8em;
  white-space: pre;
}

pre.with-line-numbers code .line .line-content:empty::after {
  content: '\200b';
}

pre.with-line-numbers code .line:hover::before {
  color: var(--accent-primary);
}

/* ---------- Code block label ---------- */
pre[data-lang]::before {
  content: attr(data-lang);
  position: absolute;
  top: 0;
  right: 0;
  padding: 0.2em 0.8em;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-bottom-left-radius: 6px;
  border-top-right-radius: 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- 3-Column Grid Layout ---------- */
.page-wrapper {
  display: grid;
  grid-template-columns: 260px 1fr 220px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header header"
    "nav    main   toc"
    "footer footer footer";
  min-height: 100vh;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Header ---------- */
.site-header {
  grid-area: header;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  padding: 0 1.5em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  overflow-anchor: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.8em;
}

.header-logo {
  width: 32px;
  height: 32px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-heading);
  white-space: nowrap;
  text-decoration: none;
}

.header-brand .title-accent {
  color: var(--accent-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.8em;
}

/* ---------- Search ---------- */
.mobile-search-toggle {
  display: none;
  color: var(--text-primary);
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 0.5em;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  align-items: center;
  line-height: 1;
}

.search-mobile {
  display: none;
  position: relative;
}

.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: var(--z-header);
}

.search-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.search-container {
  position: relative;
  overflow-anchor: none;
}

.search-results {
  overflow-anchor: none;
}

.search-input {
  background: var(--bg-search);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.4em 0.8em 0.4em 2.2em;
  min-height: 44px;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 280px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--border-active);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 0.7em;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-icon svg {
  display: block;
  width: 16px;
  height: 16px;
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 0 0 8px 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: var(--z-dropdown);
  display: none;
  box-shadow: var(--shadow-lg);
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 0.6em 1em;
  border-bottom: 1px solid var(--border-secondary);
  transition: background 0.15s;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-heading);
}

.search-result-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2em;
}

.search-no-results {
  padding: 1em;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Theme Switcher ---------- */
.theme-switcher {
  position: relative;
}

.theme-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.4em 0.55em;
  min-height: 44px;
  min-width: 44px;
  color: var(--text-primary);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
}

.theme-btn:hover {
  border-color: var(--border-active);
}

.theme-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 0.4em 0;
  min-width: 180px;
  z-index: var(--z-dropdown);
  display: none;
  box-shadow: var(--shadow-lg);
}

.theme-dropdown.active {
  display: block;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.5em 1em;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.theme-option:hover {
  background: var(--bg-hover);
}

.theme-option.active {
  color: var(--accent-primary);
  font-weight: 600;
}

.theme-option .theme-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border-primary);
  flex-shrink: 0;
}

/* ---------- Font Switcher ---------- */
.font-switcher {
  position: relative;
}

.font-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  padding: 0.4em 0.55em;
  min-height: 44px;
  min-width: 44px;
  color: var(--text-primary);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s;
}

.font-btn:hover {
  border-color: var(--border-active);
}

/* ---------- Mobile Menu Toggle ---------- */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  padding: 0.5em;
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
  align-items: center;
}

.mobile-menu-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

body.nav-open {
  overflow: hidden;
}

/* ---------- Side Navigation ---------- */
.side-nav {
  grid-area: nav;
  background: var(--bg-nav);
  border-right: 1px solid var(--border-primary);
  padding: 1.2em 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section { margin-bottom: 0.8em; }

.nav-section-title {
  padding: 0.4em 1.2em;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.nav-link {
  display: block;
  padding: 0.35em 1.2em 0.35em 1.6em;
  font-size: 0.9rem;
  color: var(--text-nav);
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-left 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-nav-active);
  text-decoration: none;
}

.nav-link.active {
  background: var(--bg-active);
  color: var(--text-nav-active);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

.nav-home { margin-bottom: 0.8em; padding: 0 1.2em; }

.nav-home-link {
  display: block;
  padding: 0.5em 0.4em;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-nav);
  text-decoration: none;
  border-bottom: 1px solid var(--border-color);
  transition: color 0.15s;
}

.nav-home-link:hover {
  color: var(--text-nav-active);
  text-decoration: none;
}

.nav-home-link.active {
  color: var(--accent-primary);
}

.nav-category { margin-bottom: 0.8em; }

.nav-category-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.6em 1.2em;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: transparent;
  border: none;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.nav-category-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

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

.nav-category-icon {
  flex-shrink: 0;
  margin-left: 0.5em;
  opacity: 0.6;
  transition: transform 0.2s ease;
}

.nav-category-toggle.active .nav-category-icon {
  transform: rotate(180deg);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.nav-list.active {
  max-height: 5000px;
}

/* ---------- Main Content ---------- */
.main-content {
  grid-area: main;
  padding: 2rem;
  min-width: 0;
  max-width: 100%;
}

.content-header { margin-bottom: 2em; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.breadcrumb a { color: var(--text-secondary); }
.breadcrumb .separator { color: var(--text-muted); }

.page-description {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-top: 0.5em;
  line-height: 1.6;
}

/* ---------- Right-side TOC ---------- */
.toc-sidebar {
  grid-area: toc;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 1.5em 1em;
  border-left: 1px solid var(--border-primary);
  background: var(--bg-toc);
}

.toc-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-list li { margin-bottom: 0.2em; }

.toc-list a {
  display: block;
  padding: 0.2em 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  padding-left: 0.8em;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.4;
}

.toc-list a:hover {
  color: var(--text-nav-active);
  text-decoration: none;
}

.toc-list a.active {
  color: var(--text-nav-active);
  border-left-color: var(--accent-primary);
  font-weight: 600;
}

.toc-list .toc-h3 { padding-left: 1.6em; font-size: 0.78rem; }
.toc-list .toc-h4 { padding-left: 2.4em; font-size: 0.75rem; }

/* ---------- Inline TOC ---------- */
.inline-toc {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1em 1.5em;
  margin-bottom: 2em;
}

.inline-toc-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 0.8em;
}

.inline-toc .toc-list a { font-size: 0.88rem; }

/* ---------- Home Icon ---------- */
.home-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.4rem;
  text-decoration: none;
  flex-shrink: 0;
  line-height: 1;
}

.home-icon:hover {
  text-decoration: none;
  opacity: 0.8;
}

/* ---------- Footer ---------- */
.site-footer {
  grid-area: footer;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-secondary);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5em;
  margin-bottom: 0.5em;
}

.footer-links a { color: var(--text-secondary); }

.footer-license { margin-top: 0.3em; font-size: 0.8rem; color: var(--text-muted); }
.footer-license a { color: var(--text-secondary); }

.footer-powered { margin-top: 0.5em; font-size: 0.8rem; color: var(--text-muted); }
.footer-powered a { color: var(--text-secondary); }

.footer-tribute {
  margin-top: 1.2em;
  padding-top: 1em;
  border-top: 1px solid var(--border-color);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--text-secondary);
  font-style: italic;
  max-width: 40em;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin: 1.5rem 0;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  padding: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-primary);
}

.card a {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card-icon { font-size: 1.8rem; margin-bottom: 0.5em; }

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 0.4em;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.5;
  flex-grow: 1;
}

.card-tags {
  display: flex;
  gap: 0.4em;
  flex-wrap: wrap;
  margin-top: 0.8em;
}

.tag {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 0.15em 0.6em;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ---------- Tables ---------- */
.table-responsive { overflow-x: auto; margin: 1em 0; }

.table-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1em 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.92rem;
  border-radius: 8px;
  overflow: hidden;
}

.table-scroll-wrapper > table { margin: 0; }

th, td {
  padding: 0.8em 1.2em;
  border: 1px solid var(--border-primary);
  text-align: left;
  vertical-align: top;
  line-height: 1.6;
}

th {
  background: var(--bg-table-header);
  font-weight: 600;
  color: var(--text-heading);
}

td { transition: background-color 0.2s ease; }
tr:nth-child(even) { background: var(--bg-table-stripe); }
tbody tr:hover { background: var(--bg-hover); }

tbody td:first-child {
  font-weight: 500;
  color: var(--text-heading);
}

/* ---------- Info / Warning / Tip Boxes ---------- */
.info-box {
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  border-left: 4px solid;
  position: relative;
}

.info-box:has(.box-icon) {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.info-box .box-icon { font-size: 1.2rem; flex-shrink: 0; line-height: 1.5; }
.info-box .box-content { flex: 1; min-width: 0; }

.info-box .box-content p:last-child,
.info-box > p:last-child,
.info-box > ul:last-child,
.info-box > ol:last-child { margin-bottom: 0; }

.info-box.info { background: var(--info-bg-info); border-color: var(--accent-info); }
.info-box.warning { background: var(--info-bg-warning); border-color: var(--accent-warning); }
.info-box.danger { background: var(--info-bg-danger); border-color: var(--accent-danger); }
.info-box.tip { background: var(--accent-glow); border-color: var(--accent-primary); }

/* ---------- Diagrams (Inline SVG) ---------- */
.diagram-container {
  background: var(--diagram-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  text-align: center;
}

.diagram-container svg {
  max-width: 100%;
  height: auto;
}

.diagram-container svg text {
  fill: var(--diagram-text);
  font-family: "D2Coding", monospace;
  font-size: 13px;
}

.diagram-container svg rect,
.diagram-container svg .box {
  fill: var(--diagram-fill);
  stroke: var(--diagram-stroke);
  stroke-width: 2;
}

.diagram-container svg .box-accent {
  fill: var(--diagram-fill);
  stroke: var(--diagram-accent);
  stroke-width: 2;
}

.diagram-container svg line,
.diagram-container svg polyline,
.diagram-container svg path.arrow {
  stroke: var(--diagram-arrow);
  stroke-width: 1.5;
  fill: none;
}

.diagram-container svg marker path {
  fill: var(--diagram-arrow);
}

.diagram-caption {
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.8em;
  font-style: italic;
}

/* ---------- Hero Section ---------- */
.hero {
  background: var(--bg-hero);
  border-bottom: 1px solid var(--border-primary);
  padding: 3rem 2rem;
  text-align: center;
}

.hero h1 {
  font-size: 2.4rem;
  border: none;
  margin-bottom: 0.3em;
  padding: 0;
}

.hero .subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 2em;
}

.page-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: -0.5em;
  margin-bottom: 1.5em;
}

.hero .doc-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -0.5em auto 2em;
  letter-spacing: 0.02em;
}

.hero .doc-meta strong {
  color: var(--accent-primary);
  font-weight: 600;
}

/* ---------- Section separators ---------- */
.section-divider {
  display: flex;
  align-items: center;
  gap: 1em;
  margin: 2.5em 0 1.5em;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.section-divider::before,
.section-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--border-primary);
}

/* ---------- Previous/Next Navigation ---------- */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-secondary);
}

.page-nav a {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--border-primary);
  border-radius: 8px;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s;
  max-width: 48%;
}

.page-nav a:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

.page-nav .nav-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

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

/* ---------- Back to Top ---------- */
.back-to-top {
  position: fixed;
  bottom: 2em;
  right: 2em;
  background: var(--accent-primary);
  color: var(--bg-primary);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: var(--z-float);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

.back-to-top.visible { opacity: 1; transform: translateY(0); }
.back-to-top:hover { transform: translateY(-2px); }

/* ---------- Mobile Nav Overlay ---------- */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: var(--z-overlay);
}

.nav-overlay.active { display: block; }

/* ---------- Skip Link ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 9999;
  padding: 0.6em 1.2em;
  background: var(--accent-primary);
  color: var(--bg-primary);
  border-radius: 0 0 6px 6px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}

/* ---------- SR-Only ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Focus Visible ---------- */
:focus-visible {
  outline: 2px solid var(--border-active);
  outline-offset: 2px;
}

/* ---------- Selection ---------- */
::selection {
  background: var(--accent-primary);
  color: var(--bg-primary);
}

/* ---------- Search Highlight ---------- */
.search-result-title mark,
.search-result-desc mark {
  background: var(--accent-glow, rgba(57, 211, 83, 0.25));
  color: inherit;
  padding: 0 0.1em;
  border-radius: 2px;
}

/* ---------- MathJax Styles ---------- */
.math-display {
  overflow-x: auto;
  margin: 1.5em 0;
  padding: 1em;
  background: var(--bg-code);
  border: 1px solid var(--border-code);
  border-radius: 8px;
}

.math-inline {
  padding: 0.1em 0.2em;
}

/* ---------- Print ---------- */
@media print {
  .side-nav, .toc-sidebar, .site-header, .site-footer,
  .theme-switcher, .font-switcher, .search-container, .back-to-top,
  .mobile-menu-toggle, .page-nav,
  .skip-link, .inline-toc {
    display: none !important;
  }
  .page-wrapper { display: block; }
  .main-content { padding: 0; }
  body { color: #000; background: #fff; }
  table, .diagram-container, figure, pre, .info-box {
    page-break-inside: avoid;
  }
  h2, h3, h4 { page-break-after: avoid; }
}
