:root {
  --bg: #080a0f;
  --bg-sidebar: #0c0f17;
  --panel: #121622;
  --line: rgba(255, 255, 255, 0.06);
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --dim: #475569;
  --accent: #9fb3ff;
  --accent2: #4ae3b5;
  --warn: #ffaa40;
  --font-serif: "Fraunces", Georgia, serif;
  --font-sans: "Inter", -apple-system, system-ui, sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Sidebar Navigation */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-header .brand {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #fff;
  text-decoration: none;
}

.sidebar-header .brand span {
  color: var(--accent);
}

.sidebar-header .subtitle {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-section-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  padding-left: 12px;
}

.sidebar-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-links a {
  display: block;
  padding: 8px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.sidebar-links a:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.03);
}

.sidebar-links li.active a {
  color: var(--accent);
  font-weight: 600;
  background: rgba(159, 179, 255, 0.06);
}

/* Main Container */
.main-container {
  margin-left: 300px;
  width: calc(100% - 300px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Mobile Toggle Bar */
.mobile-header {
  display: none;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
}

.mobile-header .brand {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.1em;
  color: #fff;
  text-decoration: none;
}

.mobile-header .brand span {
  color: var(--accent);
}

.mobile-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
}

/* Main Layout Grid */
.main-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 56px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 56px 40px 100px;
  flex: 1;
}

/* Page Table of Contents (Right) */
.page-toc {
  position: sticky;
  top: 40px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding-left: 20px;
  border-left: 1px solid var(--line);
}

.page-toc-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 16px;
}

.page-toc ul {
  list-style: none;
}

.page-toc li {
  margin: 8px 0;
  line-height: 1.4;
}

.page-toc a {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.2s;
  font-weight: 500;
}

.page-toc a:hover {
  color: #fff;
}

.page-toc ul ul {
  padding-left: 12px;
  margin-top: 6px;
  border-left: 1px solid var(--line);
}

.page-toc ul ul a {
  color: var(--dim);
  font-size: 12.5px;
}

.page-toc ul ul a:hover {
  color: var(--muted);
}

/* Content Area */
.prose {
  max-width: 760px;
}

/* Typography & Markdown Styles */
.prose h1 {
  font-family: var(--font-serif);
  font-size: clamp(32px, 4.5vw, 46px);
  font-weight: 500;
  color: #fff;
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin-bottom: 16px;
}

.prose .kicker {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 24px;
  font-weight: 500;
}

.prose .meta-block {
  border-bottom: 1px solid var(--line);
  padding-bottom: 32px;
  margin-bottom: 40px;
}

.prose .sub-info {
  font-size: 17px;
  color: var(--muted);
  max-width: 38em;
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: clamp(24px, 3.2vw, 30px);
  font-weight: 500;
  color: #fff;
  letter-spacing: -0.01em;
  margin-top: 56px;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 40px;
}

.prose h2:first-child,
.prose h1 + h2 {
  margin-top: 0;
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 21px;
  font-weight: 500;
  color: #fff;
  margin-top: 36px;
  margin-bottom: 12px;
  scroll-margin-top: 40px;
}

.prose h4 {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--accent2);
  text-transform: uppercase;
  margin-top: 28px;
  margin-bottom: 8px;
}

.prose p {
  margin-bottom: 20px;
  font-size: 15.5px;
  line-height: 1.7;
}

.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(159, 179, 255, 0.25);
  transition: all 0.2s;
}

.prose a:hover {
  border-bottom-color: var(--accent);
}

.prose strong {
  color: #fff;
  font-weight: 600;
}

.prose ul, .prose ol {
  margin-bottom: 24px;
  padding-left: 24px;
}

.prose li {
  margin: 8px 0;
  font-size: 15px;
}

.prose li > ul, .prose li > ol {
  margin: 8px 0;
}

.prose blockquote {
  margin: 32px 0;
  padding: 20px 24px;
  background: var(--panel);
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  color: var(--muted);
  font-style: italic;
  font-size: 15px;
}

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

.prose blockquote strong {
  color: var(--accent2);
}

/* Horizontal Rules */
.prose hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 48px 0;
}

/* Code & Pre */
.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  color: #d1d9e6;
  word-break: break-all;
}

.prose pre {
  background: #030407;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  overflow: auto;
  margin-bottom: 24px;
}

.prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.6;
  color: #cbd5e1;
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 32px 0;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
}

.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 12px 16px;
  text-align: left;
  vertical-align: top;
}

.prose th {
  background: var(--panel);
  font-weight: 600;
  color: #fff;
  font-size: 12.5px;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.prose tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.01);
}

/* MathOverflow */
mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 0;
}

/* Pager */
.pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 64px;
  border-top: 1px solid var(--line);
  padding-top: 36px;
  flex-wrap: wrap;
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 24px;
  min-width: 240px;
  transition: all 0.25s ease;
  text-decoration: none;
  flex: 1;
}

.pager a:hover {
  border-color: var(--accent);
  background: rgba(159, 179, 255, 0.02);
  transform: translateY(-2px);
}

.pager .dir {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
}

.pager .ttl {
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
}

.pager .next {
  text-align: right;
  align-items: flex-end;
}

/* Footer */
footer {
  border-top: 1px solid var(--line);
  padding: 32px 0;
  margin-top: auto;
  background: var(--bg-sidebar);
}

footer .wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 40px;
  font-size: 12.5px;
  color: var(--dim);
  text-align: center;
}

/* Grid layout under views index */
.views-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin: 32px 0;
}

.views-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: all 0.25s ease;
}

.views-card:hover {
  border-color: rgba(159, 179, 255, 0.35);
  transform: translateY(-2px);
}

.views-card .tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 12px;
}

.views-card h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: #fff;
  font-family: var(--font-sans);
  font-weight: 600;
}

.views-card p {
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 16px;
  flex: 1;
}

.views-card .cta {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  align-self: flex-start;
  border-bottom: 1px solid rgba(159, 179, 255, 0.2);
}

.views-card .cta:hover {
  border-bottom-color: var(--accent);
  text-decoration: none;
}

/* Media Queries for Responsiveness */
@media (max-width: 1040px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 32px;
  }
  .page-toc {
    display: none; /* Hide TOC on smaller screens */
  }
}

@media (max-width: 820px) {
  body {
    flex-direction: column;
  }
  .sidebar {
    display: none; /* Hide by default on mobile, can toggle with JS */
    width: 100%;
    position: fixed;
    top: 56px;
    height: calc(100vh - 56px);
    z-index: 100;
  }
  .sidebar.open {
    display: flex;
  }
  .main-container {
    margin-left: 0;
    width: 100%;
  }
  .mobile-header {
    display: flex;
    height: 56px;
  }
  .main-layout {
    padding: 32px 24px 80px;
  }
}
