/**
 * article-base.css
 * Shared base styles for academic-style article pages.
 * Pages: areal, yarn, diffusion_models, verl_grpo, video_codec,
 *        rabitq, megatron_fp8, gae, monte_carlo_method
 *
 * Usage:
 *   <link rel="stylesheet" href="/assets/css/article-base.css">
 *   Then override/extend :root variables and add page-specific styles
 *   in a <style> block AFTER this link.
 */

/* ==========================================================================
   CSS Variables — Design Tokens
   ========================================================================== */
:root {
  --bg: #ffffff;
  --bg-alt: #f8f9fa;
  --text: #1a1a2e;
  --text-secondary: #555;
  --accent: #2563eb;
  --border: #e2e8f0;
  --font-headline: "Playfair Display", "Georgia", serif;
  --font-serif: "Cormorant Garamond", "Palatino Linotype", "Book Antiqua",
    Palatino, serif;
  --font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-math: "JetBrains Mono", monospace;
}

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

html {
  scroll-behavior: smooth;
}

::selection {
  background: rgba(37, 99, 235, 0.2);
  color: var(--text);
}

/* ==========================================================================
   Body
   ========================================================================== */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  line-height: 1.5;
  padding: 2rem 1rem;
  -webkit-text-size-adjust: 100%;
}

/* ==========================================================================
   Site Navigation
   ========================================================================== */
.site-nav {
  max-width: 860px;
  margin: 0 auto 1rem;
  padding: 0 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 0.85em;
  flex-wrap: wrap;
}
.site-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 4px;
}
.site-nav a:hover {
  color: var(--accent);
  text-decoration: underline;
}
.site-nav .nav-sep {
  color: var(--border);
  user-select: none;
}

/* ==========================================================================
   Article Container
   ========================================================================== */
.article {
  max-width: 860px;
  margin: 0 auto;
  background: var(--bg);
  padding: 0 1rem 3rem;
  position: relative;
}

/* ==========================================================================
   Masthead (Page Header)
   ========================================================================== */
.masthead {
  text-align: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.5rem;
  margin-bottom: 2.5rem;
  position: relative;
}
.masthead-title {
  font-family: var(--font-headline);
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  font-weight: 900;
  line-height: 1.1;
  margin: 0 0 10px;
  color: var(--text);
}
.masthead-sub {
  font-size: 1rem;
  font-family: var(--font-sans);
  margin-bottom: 10px;
  color: var(--text-secondary);
}
.masthead-share {
  margin-top: 12px;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.masthead-share a,
.masthead-share button {
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  text-decoration: none;
  font: inherit;
  cursor: pointer;
}
.masthead-share a:hover,
.masthead-share button:hover {
  background: var(--bg-alt);
}
.author-sig {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  margin-top: 10px;
  color: var(--text-secondary);
}
.author-sig a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.author-sig a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Language Toggle
   ========================================================================== */
.lang-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 40;
  font-family: var(--font-sans);
  padding: 6px 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  color: var(--text-secondary);
  font-weight: bold;
  border-radius: 20px;
  font-size: 0.85rem;
  transition: all 0.2s;
  touch-action: manipulation;
}
.lang-toggle:hover {
  background: var(--bg-alt);
  color: var(--text);
  border-color: var(--text-secondary);
}

/* ==========================================================================
   Progress Bar
   ========================================================================== */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--accent);
  z-index: 999;
  transition: width 0.1s;
  width: 0%;
  pointer-events: none;
}

/* ==========================================================================
   Hero / Intro Section
   ========================================================================== */
.hero-content {
  text-align: left;
  padding: 1rem 0 2rem;
}
.hero-text {
  font-size: 1.1rem;
  max-width: none;
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ==========================================================================
   Content Headings & Text
   ========================================================================== */
.phase-heading {
  font-family: var(--font-headline);
  font-size: 1.5rem;
  font-weight: 700;
  text-align: left;
  margin: 2.5rem 0 1rem;
  border-top: 2px solid var(--border);
  padding-top: 1.5rem;
  color: var(--text);
}
.phase-desc {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  text-align: left;
  max-width: none;
  margin: 0 0 15px;
  color: var(--text-secondary);
  line-height: 1.75;
}
.phase-desc a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.phase-desc a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Math & Code Blocks
   ========================================================================== */
.math {
  font-family: var(--font-math);
  background: var(--bg-alt);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-size: 0.95em;
  border: 1px solid var(--border);
  color: var(--text);
}
.math-block {
  display: block;
  text-align: center;
  padding: 1.5rem 1rem;
  background: var(--bg-alt);
  border-left: 3px solid var(--accent);
  margin: 2rem 0;
  border-radius: 4px;
  color: var(--text);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code-block {
  display: block;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.88rem;
  line-height: 1.7;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  tab-size: 2;
}
.code-block code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
}

/* Syntax highlight tokens (Catppuccin Mocha) */
.code-block .kw { color: #cba6f7; }
.code-block .fn { color: #89b4fa; }
.code-block .str { color: #a6e3a1; }
.code-block .num { color: #fab387; }
.code-block .cm { color: #6c7086; font-style: italic; }
.code-block .op { color: #89dceb; }

/* Inline code */
pre, code { font-family: var(--font-math); }
pre {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 1.5rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  margin: 1.5rem 0;
}
code {
  background: var(--bg-alt);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.9em;
}
pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

/* ==========================================================================
   TOC (Table of Contents)
   ========================================================================== */
.toc-section {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.toc-section h3 {
  font-family: var(--font-headline);
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
  color: var(--text);
}
.toc-section ol {
  padding-left: 1.25rem;
}
.toc-section li {
  margin: 0.25rem 0;
}
.toc-section a {
  color: var(--accent);
  text-decoration: none;
}
.toc-section a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Canvas / Visualization Wrappers
   ========================================================================== */
.stage-wrapper {
  width: 100%;
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin: 0 auto 35px;
  background: var(--bg-alt);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.stage-footer {
  padding: 15px 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  width: 100%;
  font-family: var(--font-sans);
  text-align: center;
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--text);
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.controls {
  padding: 15px 20px;
  background: var(--bg-alt);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 15px;
  font-family: var(--font-sans);
  flex-wrap: wrap;
  justify-content: space-between;
  width: 100%;
}

/* ==========================================================================
   Range Input
   ========================================================================== */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
  touch-action: manipulation;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  margin-top: -7px;
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Play / Action Buttons
   ========================================================================== */
.btn-play {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: bold;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: background 0.2s;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn-play:hover {
  background: #1d4ed8;
}

/* ==========================================================================
   Callout / Info Boxes
   ========================================================================== */
.callout {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text);
}
.callout strong {
  color: var(--accent);
}

/* ==========================================================================
   Foldable Deep-Dive Panels
   ========================================================================== */
details.deep-dive {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1.5rem 0;
  overflow: hidden;
}
details.deep-dive > summary {
  padding: 12px 16px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: bold;
  color: var(--accent);
  user-select: none;
  transition: background 0.2s;
  list-style: none;
}
details.deep-dive > summary::-webkit-details-marker {
  display: none;
}
details.deep-dive > summary:hover {
  background: rgba(37, 99, 235, 0.05);
}
details.deep-dive > .dd-content {
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ==========================================================================
   Fade-in Animation (Intersection Observer)
   ========================================================================== */
.fade-in-section {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.35s ease-out, transform 0.35s ease-out;
  will-change: opacity, transform;
}
.fade-in-section.is-visible {
  opacity: 1;
  transform: none;
}

/* ==========================================================================
   Key Stats Row
   ========================================================================== */
.key-stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin: 25px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 15px 0;
  font-family: var(--font-headline);
  font-weight: bold;
  color: var(--text);
}
.key-stats div {
  flex: 1;
  border-right: 1px solid var(--border);
}
.key-stats div:last-child {
  border-right: none;
}
.key-stats span {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 5px;
  font-family: var(--font-sans);
}

/* ==========================================================================
   Responsive — Mobile
   ========================================================================== */
@media (max-width: 768px) {
  body {
    padding: 1rem;
  }
  .article {
    padding: 0 1rem 2rem;
    max-width: 100%;
  }
  .lang-toggle {
    right: 10px;
    top: 10px;
  }
  .phase-heading {
    font-size: 1.25rem;
  }
  .phase-desc {
    font-size: 0.95rem;
  }
  .hero-text {
    font-size: 1rem;
  }
  .masthead-sub {
    font-size: 0.85rem;
  }
  .math-block {
    padding: 1rem 0.5rem;
    font-size: 0.9rem;
  }
  .math-block .katex {
    font-size: 0.85em;
  }
  .code-block {
    font-size: 0.78rem;
    padding: 1rem;
    margin: 1.5rem 0;
  }
  input[type="range"]::-webkit-slider-thumb {
    width: 32px;
    height: 32px;
    margin-top: -12px;
  }
  input[type="range"]::-moz-range-thumb {
    width: 32px;
    height: 32px;
  }
}

@media (max-width: 480px) {
  .phase-heading {
    font-size: 1.1rem;
  }
  .phase-desc {
    font-size: 0.9rem;
  }
  .stage-footer {
    font-size: 0.85rem;
    padding: 10px;
  }
}
