/* ============================================================
   Reciprocal Materialist Socialism — Site Stylesheet
   Industrial-minimal. Sans-serif. Light + Dark mode.
   No imports. No external resources. Self-contained.
   ============================================================ */

/* --- Custom Properties (Light — default) --- */
:root,
[data-theme="light"] {
  --bg: #f7f7f7;
  --surface: #efefef;
  --raised: #e6e6e6;
  --text: rgba(20, 20, 20, 0.92);
  --text-secondary: rgba(50, 50, 50, 0.65);
  --text-faint: rgba(50, 50, 50, 0.35);
  --accent: #8b0000;
  --accent-hover: #a00000;
  --divider: rgba(50, 50, 50, 0.10);
  --link: #8b0000;
  --link-hover: #a00000;
  --code-bg: rgba(50, 50, 50, 0.05);
  --shadow: rgba(0, 0, 0, 0.08);
  --summary-hover: rgba(50, 50, 50, 0.04);
}

/* --- Dark Mode --- */
[data-theme="dark"] {
  --bg: #141414;
  --surface: #1A1A1A;
  --raised: #222222;
  --text: rgba(234, 234, 234, 0.95);
  --text-secondary: rgba(231, 231, 231, 0.55);
  --text-faint: rgba(226, 226, 226, 0.28);
  --accent: #C8102E;
  --accent-hover: #e0162b;
  --divider: rgba(255, 255, 255, 0.06);
  --link: #C8102E;
  --link-hover: #e0162b;
  --code-bg: rgba(255, 255, 255, 0.06);
  --shadow: rgba(0, 0, 0, 0.3);
  --summary-hover: rgba(255, 255, 255, 0.04);
}

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

/* --- Base --- */
html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--divider);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar__header {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.sidebar__title {
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.sidebar__title a {
  color: inherit;
  text-decoration: none;
}

.sidebar__title a:hover {
  color: var(--text);
  text-decoration: none;
}

.sidebar__controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* --- Language Selector (Dropdown) --- */
.lang-sel {
  position: relative;
  display: inline-block;
}

.lang-sel__current {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--divider);
  border-radius: 4px;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.lang-sel__current:hover {
  color: var(--text);
  border-color: var(--text-faint);
}

.lang-sel__arrow {
  font-size: 0.6em;
  opacity: 0.6;
}

.lang-sel__menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: 4px;
  box-shadow: 0 4px 12px var(--shadow);
  min-width: 140px;
  z-index: 300;
  padding: 0.25rem 0;
  list-style: none;
}

.lang-sel--open .lang-sel__menu {
  display: block;
}

.lang-sel__item {
  display: block;
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  text-decoration: none;
  color: var(--text-secondary);
  transition: color 0.15s, background 0.15s;
}

.lang-sel__item:hover {
  color: var(--text);
  background: var(--summary-hover);
  text-decoration: none;
}

.lang-sel__item--active {
  color: var(--accent);
  font-weight: 600;
}

.lang-sel__item--disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Theme Toggle Button --- */
.theme-btn {
  background: none;
  border: 1px solid var(--divider);
  border-radius: 4px;
  padding: 0.3rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

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

/* Show sun in dark mode, moon in light mode */
[data-theme="light"] .theme-btn__icon--light { display: none; }
[data-theme="light"] .theme-btn__icon--dark  { display: block; }
[data-theme="dark"]  .theme-btn__icon--light { display: block; }
[data-theme="dark"]  .theme-btn__icon--dark  { display: none; }

/* --- Table of Contents --- */
.toc {
  list-style: none;
  padding: 0.75rem 0.75rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.toc__item {
  margin: 0;
}

.toc__item a {
  display: block;
  padding: 0.45rem 0.5rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1.35;
}

.toc__item a:hover {
  color: var(--text);
  background: var(--summary-hover);
}

.toc__item--active a {
  color: var(--accent);
  font-weight: 600;
  background: var(--summary-hover);
}

/* --- Main Content --- */
.main {
  flex: 1;
  margin-left: 280px;
  padding: 2.5rem 2rem 4rem;
  max-width: 100%;
}

.article {
  max-width: 700px;
  margin: 0 auto;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text);
}

h1 {
  font-size: 2rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--divider);
}

h2 {
  font-size: 1.45rem;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
}

h3 {
  font-size: 1.15rem;
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1.25rem;
}

/* --- Links --- */
a {
  color: var(--link);
  text-decoration: none;
}

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

/* --- Lists --- */
ul, ol {
  margin-bottom: 1.25rem;
  padding-left: 1.5rem;
}

li {
  margin-bottom: 0.35rem;
}

li > ul, li > ol {
  margin-top: 0.35rem;
  margin-bottom: 0;
}

/* --- Emphasis & Strong --- */
strong {
  font-weight: 600;
}

em {
  font-style: italic;
}

/* --- Code --- */
code {
  font-family: 'SF Mono', 'Courier New', monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  background: var(--code-bg);
  padding: 1rem 1.25rem;
  border-radius: 4px;
  overflow-x: auto;
  margin-bottom: 1.25rem;
}

pre code {
  background: none;
  padding: 0;
}

/* --- Blockquotes --- */
blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.5rem 1rem;
  margin: 0 0 1.25rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* --- Horizontal Rules --- */
hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: 2rem 0;
}

/* ============================================================
   Fenced Directives — Collapsible Layers
   ============================================================ */

.layer {
  margin: 1.75rem 0;
  border-radius: 4px;
  overflow: hidden;
}

.layer summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
}

.layer summary::-webkit-details-marker {
  display: none;
}

.layer summary::before {
  content: '▸';
  font-size: 0.8em;
  transition: transform 0.2s;
  flex-shrink: 0;
}

.layer[open] summary::before {
  transform: rotate(90deg);
}

.layer summary:hover {
  background: var(--summary-hover);
}

.layer__content {
  padding: 0.75rem 1rem 1rem;
}

/* Deep-dive: accent left border */
.layer--deep-dive {
  border-left: 3px solid var(--accent);
  background: var(--summary-hover);
}

.layer--deep-dive summary {
  color: var(--accent);
}

/* Theory: muted, slightly smaller */
.layer--theory {
  border-left: 3px solid var(--text-faint);
  background: var(--summary-hover);
}

.layer--theory summary {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.layer--theory .layer__content {
  font-size: 0.92rem;
  color: var(--text-secondary);
}

/* ============================================================
   Previous / Next Navigation
   ============================================================ */

.prev-next {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--divider);
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.prev-next__link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  transition: background 0.15s;
  max-width: 48%;
}

.prev-next__link:hover {
  background: var(--summary-hover);
  text-decoration: none;
}

.prev-next__link--next {
  text-align: right;
  margin-left: auto;
}

.prev-next__link--empty {
  visibility: hidden;
}

.prev-next__label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 0.25rem;
}

.prev-next__title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
}

/* ============================================================
   Index Page
   ============================================================ */

.main--index {
  margin-left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4rem 2rem;
}

.index-header {
  text-align: center;
  margin-bottom: 3rem;
  max-width: 700px;
}

.index-header__title {
  font-size: 2.2rem;
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0.5rem;
}

.index-header__subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
  margin-bottom: 1.25rem;
}

.index-header__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.index-list {
  list-style: none;
  padding: 0;
  max-width: 700px;
  width: 100%;
}

.index-item {
  margin-bottom: 0;
}

.index-item__link {
  display: block;
  padding: 1rem 1.25rem;
  border-radius: 4px;
  text-decoration: none;
  transition: background 0.15s;
}

.index-item__link:hover {
  background: var(--summary-hover);
  text-decoration: none;
}

.index-item__title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  display: block;
}

.index-item__summary {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
  margin-bottom: 0;
}

/* ============================================================
   Mobile Sidebar Toggle
   ============================================================ */

/* Mobile top bar — hidden on desktop */
.mobile-bar {
  display: none;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-toggle__bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 1px;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--divider);
    position: sticky;
    top: 0;
    z-index: 150;
  }

  .mobile-bar__title {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    text-decoration: none;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-bar__title:hover {
    color: var(--text);
  }

  .sidebar {
    display: none;
    width: 280px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
  }

  .sidebar--open {
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px var(--shadow);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main {
    margin-left: 0;
    padding: 2rem 1.25rem 3rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .prev-next {
    flex-direction: column;
  }

  .prev-next__link {
    max-width: 100%;
  }

  .prev-next__link--next {
    text-align: left;
  }
}

/* ============================================================
   Print — expand all, hide nav
   ============================================================ */

@media print {
  .sidebar, .sidebar-toggle, .theme-btn, .lang-sel, .prev-next {
    display: none !important;
  }

  .main {
    margin-left: 0;
    padding: 0;
  }

  body {
    background: white;
    color: black;
  }

  .layer {
    border-left-color: #ccc !important;
  }

  .layer[open],
  .layer {
    /* Force open for print */
  }

  details {
    display: block;
  }

  details > summary {
    display: block;
  }

  details[open] > summary ~ * {
    display: block;
  }

  /* Attempt to force details open */
  details:not([open]) > *:not(summary) {
    display: block !important;
  }
}

/* --- Footnotes --- */
.fn-ref {
  font-size: 0.75em;
  line-height: 1;
  vertical-align: super;
  margin-left: 1px;
}

.fn-ref a {
  color: var(--accent);
  text-decoration: none;
  padding: 0 2px;
}

.fn-ref a:hover {
  text-decoration: underline;
}

.footnotes {
  margin-top: 3rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.footnotes hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin-bottom: 1.25rem;
}

.footnotes ol {
  padding-left: 1.5rem;
}

.footnotes li {
  margin-bottom: 0.5rem;
  line-height: 1.55;
}

.footnotes li p {
  margin: 0;
  display: inline;
}

.fn-back {
  color: var(--accent);
  text-decoration: none;
  margin-left: 0.35em;
  font-size: 0.85em;
}

.fn-back:hover {
  text-decoration: underline;
}

/* --- Bibliography page --- */
.bibliography {
  list-style: none;
  padding: 0;
}

.bib-entry {
  margin-bottom: 1rem;
  padding-left: 2rem;
  text-indent: -2rem;
  line-height: 1.6;
  color: var(--text);
}

.bib-entry em {
  font-style: italic;
}

.bib-entry a {
  color: var(--link);
  word-break: break-all;
}
