/* =====================================================================
   Mossen Developer Documentation
   Design system — refined editorial minimalism with teal accent
   ===================================================================== */

/* -------- Theme tokens -------- */
:root {
  /* Brand */
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-glow: rgba(13, 148, 136, 0.18);

  /* Light theme */
  --bg: #fafaf9;
  --bg-subtle: #f5f5f4;
  --bg-card: #ffffff;
  --bg-hover: #f5f5f4;
  --bg-code: #f5f5f4;
  --bg-code-header: #efeeec;

  --border: #e7e5e4;
  --border-soft: #f0eeec;
  --border-strong: #d6d3d1;

  --text: #1c1917;
  --text-muted: #57534e;
  --text-subtle: #a8a29e;
  --text-faint: #d6d3d1;

  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.04);
  --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 12px 40px rgba(28, 25, 23, 0.08);
  --shadow-pop: 0 8px 32px rgba(28, 25, 23, 0.12);

  /* Layout */
  --nav-h: 64px;
  --sidebar-w: 288px;
  --toc-w: 240px;
  --content-max: 760px;

  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
}

[data-theme="dark"] {
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #134e4a;
  --accent-glow: rgba(45, 212, 191, 0.22);

  --bg: #0c0a09;
  --bg-subtle: #161312;
  --bg-card: #1c1917;
  --bg-hover: #292524;
  --bg-code: #161312;
  --bg-code-header: #1c1917;

  --border: #292524;
  --border-soft: #1f1c1a;
  --border-strong: #44403c;

  --text: #f5f5f4;
  --text-muted: #a8a29e;
  --text-subtle: #78716c;
  --text-faint: #44403c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.55);
}

/* -------- Reset -------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 24px); }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.3s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* -------- Reading progress -------- */
.reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  z-index: 1001;
  transition: width 0.1s ease-out;
  box-shadow: 0 0 12px var(--accent-glow);
}

/* -------- Top nav -------- */
.topnav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid transparent;
  z-index: 100;
  transition: border-color 0.2s, background 0.3s;
}
.topnav.scrolled {
  border-bottom-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.topnav-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  max-width: 100%;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text) !important;
  flex-shrink: 0;
}
.brand-mark { color: var(--accent); flex-shrink: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.brand-accent { color: var(--accent); font-style: italic; }
.brand-divider {
  width: 1px; height: 18px;
  background: var(--border-strong);
  margin: 0 4px;
}
.brand-section {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Icon buttons */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}
.menu-toggle { display: none; }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.topnav-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

/* Search */
.search {
  position: relative;
  flex: 1;
  max-width: 420px;
  margin-left: 8px;
}
.search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}
.search input {
  width: 100%;
  height: 38px;
  padding: 0 64px 0 38px;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  outline: none;
  transition: all 0.15s;
}
.search input::placeholder { color: var(--text-subtle); }
.search input:focus {
  background: var(--bg-card);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-kbd {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-subtle);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px 6px;
  pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  max-height: 480px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}
.search-results.open { display: block; }
.search-result {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active {
  background: var(--bg-hover);
}
.search-result-title {
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
}
.search-result-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-doc {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 3px;
}
.search-result mark {
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 0 2px;
  border-radius: 2px;
}
.search-empty {
  padding: 24px;
  text-align: center;
  color: var(--text-subtle);
  font-size: 13px;
}

/* -------- Layout -------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  gap: 0;
  margin-top: var(--nav-h);
  min-height: calc(100vh - var(--nav-h));
}

/* -------- Sidebar -------- */
.sidebar {
  position: fixed;
  top: var(--nav-h);
  left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  padding: 24px 16px 24px 24px;
  border-right: 1px solid var(--border);
  background: var(--bg);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar-nav { padding-bottom: 24px; }

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 20px 12px 20px;
}
.sidebar-group { margin-bottom: 24px; }
.sidebar-group-title {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
  padding: 0 12px;
  margin-bottom: 8px;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  margin-bottom: 1px;
  transition: all 0.12s;
  position: relative;
}
.sidebar-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sidebar-link.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}
.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.sidebar-sublink {
  display: block;
  padding: 5px 12px 5px 28px;
  font-size: 13px;
  color: var(--text-subtle);
  border-radius: var(--r-sm);
  margin-bottom: 1px;
  transition: all 0.12s;
}
.sidebar-sublink:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.sidebar-sublink.active {
  color: var(--accent);
  font-weight: 500;
}

/* Sidebar footer */
.sidebar-footer { margin-top: 32px; padding: 0 4px; }
.sidebar-footer-card {
  padding: 16px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}
.sidebar-footer-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.sidebar-footer-text {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}
.sidebar-footer-link {
  font-size: 13px;
  font-weight: 500;
}

/* -------- Main content -------- */
.content {
  grid-column: 2;
  min-width: 0;
  padding: 48px 56px 96px;
  max-width: calc(var(--content-max) + 112px);
  margin: 0 auto;
  width: 100%;
}

.article { animation: fadeIn 0.4s ease-out; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Typography */
.article h1 {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.025em;
  color: var(--text);
  margin-bottom: 12px;
}
.article h1 + p {
  font-size: 17px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 32px;
  font-weight: 400;
}
.article h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin-top: 48px;
  margin-bottom: 16px;
  padding-top: 24px;
  border-top: 1px solid var(--border-soft);
  scroll-margin-top: calc(var(--nav-h) + 24px);
}
.article h3 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 32px;
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--nav-h) + 24px);
}
.article h4 {
  font-size: 15px;
  font-weight: 700;
  margin-top: 24px;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}
.article p {
  margin-bottom: 16px;
  color: var(--text);
}
.article ul, .article ol {
  margin-bottom: 16px;
  padding-left: 24px;
}
.article li { margin-bottom: 6px; }
.article li::marker { color: var(--text-subtle); }

.article a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 30%, transparent);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}
.article a:hover { text-decoration-color: var(--accent); }

.article strong { font-weight: 650; color: var(--text); }

/* Code — inline */
.article code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.875em;
  font-weight: 500;
  background: var(--bg-code);
  color: var(--accent-hover);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-soft);
}
[data-theme="dark"] .article code:not(pre code) { color: var(--accent); }

/* Code — blocks */
.article pre {
  margin: 0 0 20px;
  background: var(--bg-code) !important;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  position: relative;
}
.code-block {
  margin: 0 0 20px;
  position: relative;
}
.code-block pre { margin: 0; border: none; border-radius: var(--r-lg); }
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-code-header);
  border-bottom: 1px solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-subtle);
}
.code-lang { text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-subtle);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 3px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.copy-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.copy-btn.copied {
  color: var(--accent);
  border-color: var(--accent);
}
.code-block pre { border-radius: 0 0 var(--r-lg) var(--r-lg); }
.article pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  padding: 16px 18px !important;
  display: block;
  background: transparent !important;
  overflow-x: auto;
}

/* Tables */
.article table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.article th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-subtle);
  background: var(--bg-subtle);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.article td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  color: var(--text);
}
.article tr:last-child td { border-bottom: none; }
.article td code { white-space: nowrap; }

/* Blockquote */
.article blockquote {
  margin: 0 0 20px;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--bg-subtle);
  border-radius: 0 var(--r-md) var(--r-md) 0;
  color: var(--text-muted);
}
.article blockquote p { margin-bottom: 0; }
.article blockquote p:first-child { margin-bottom: 6px; }

/* HR */
.article hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 40px 0;
}

/* Pager */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 64px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}
.pager-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  color: var(--text);
  transition: all 0.15s;
  max-width: 48%;
}
.pager-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.pager-link.next { margin-left: auto; text-align: right; }
.pager-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
  font-weight: 600;
}
.pager-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

/* -------- TOC (right) -------- */
.toc {
  position: fixed;
  top: var(--nav-h);
  right: 0;
  width: var(--toc-w);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
  padding: 40px 24px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.toc-inner { position: relative; }
.toc-title {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 12px;
}
.toc-list { display: flex; flex-direction: column; gap: 2px; }
.toc-link {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0 4px 12px;
  border-left: 2px solid var(--border);
  line-height: 1.45;
  transition: all 0.12s;
}
.toc-link:hover { color: var(--text); }
.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.toc-link.h3 { padding-left: 24px; font-size: 12.5px; }

.toc-footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12.5px;
}
.toc-footer a { color: var(--text-muted); }
.toc-footer a:hover { color: var(--accent); }

/* -------- Backdrop (mobile) -------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

/* -------- Loading skeleton -------- */
.article.loading {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.article.loading::before {
  content: '';
  height: 40px;
  width: 60%;
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  animation: pulse 1.5s ease-in-out infinite;
}
.article.loading::after {
  content: '';
  height: 200px;
  background: var(--bg-subtle);
  border-radius: var(--r-md);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 1280px) {
  .toc { display: none; }
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }
  .menu-toggle { display: inline-flex; }
  .brand-divider, .brand-section { display: none; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .layout { grid-template-columns: 1fr; }
  .content {
    padding: 32px 24px 80px;
    max-width: 100%;
  }
  .article h1 { font-size: 32px; }
  .article h2 { font-size: 22px; }
  .article h3 { font-size: 17px; }

  .topnav-inner { padding: 0 16px; gap: 12px; }
  .search { max-width: none; }
  .search-kbd { display: none; }

  .pager { flex-direction: column; }
  .pager-link { max-width: 100%; text-align: left !important; }
  .pager-link.next { margin-left: 0; }
}

@media (max-width: 480px) {
  .article h1 { font-size: 26px; }
  .article pre code { font-size: 12px; padding: 12px !important; }
  .content { padding: 24px 16px 64px; }
}

/* =====================================================================
   Highlight.js theme tweaks
   ===================================================================== */
.hljs { background: var(--bg-code) !important; color: var(--text) !important; }
[data-theme="light"] .hljs { background: #fafaf9 !important; }
[data-theme="dark"] .hljs { background: #161312 !important; }

/* Print */
@media print {
  .topnav, .sidebar, .toc, .pager, .reading-progress, .backdrop { display: none !important; }
  .content { padding: 0; max-width: 100%; }
  .article pre { border: 1px solid #ccc; }
}
