/* ============================================================
   The Pattern Mirror — Shared Stylesheet
   ============================================================ */

:root {
  --bg-base:       #111827;
  --bg-surface:    #1f2937;
  --bg-code:       #0d1117;
  --border:        #374151;
  --text-primary:  #f3f4f6;
  --text-secondary:#d1d5db;
  --text-muted:    #9ca3af;
  --text-faint:    #6b7280;
  --accent-blue:   #3b82f6;
  --accent-green:  #10b981;
  --accent-amber:  #f59e0b;
  --accent-purple: #8b5cf6;
  --link:          #60a5fa;
  --link-hover:    #93c5fd;
  --ep1-color:     #1e6b8a;
  --ep2-color:     #6b3fa0;
  --ep3-color:     #c27013;
  --ep4-color:     #a63d6a;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 18px;
  scroll-behavior: smooth;
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Source Sans 3', system-ui, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; height: auto; }

/* ============================================================
   NAVIGATION BAR
   ============================================================ */

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-code);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1000;
}

.navbar-logo {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}
.navbar-logo:hover { color: #fff; text-decoration: none; }

.navbar-links { display: flex; align-items: center; gap: 6px; }

.navbar-links a {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  transition: background .2s, color .2s;
}
.navbar-links a:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
  text-decoration: none;
}
.navbar-links a.active {
  background: var(--accent-blue);
  color: #fff;
}

/* Hamburger menu (mobile) */
.navbar-toggle { display: none; }
.navbar-hamburger {
  display: none;
  width: 32px; height: 32px;
  background: none; border: none; cursor: pointer;
  flex-direction: column; justify-content: center; align-items: center; gap: 5px;
}
.navbar-hamburger span {
  display: block; width: 22px; height: 2px;
  background: var(--text-secondary); border-radius: 2px;
  transition: transform .2s;
}

@media (max-width: 700px) {
  .navbar-hamburger { display: flex; }
  .navbar-links {
    display: none;
    position: absolute;
    top: 56px; left: 0; right: 0;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 12px;
    gap: 4px;
  }
  .navbar-toggle:checked ~ .navbar-links { display: flex; }
  .navbar-links a { width: 100%; padding: 10px 16px; }
}

/* ============================================================
   READING PROGRESS BAR
   ============================================================ */

.progress-bar {
  position: fixed;
  top: 56px;
  left: 0;
  height: 4px;
  background: var(--accent-blue);
  z-index: 999;
  transition: width 50ms linear;
}

/* ============================================================
   HERO SECTION (index page)
   ============================================================ */

.hero {
  position: relative;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 100px 24px 60px;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image:
    linear-gradient(rgba(255,255,255,.4) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.4) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
}

.hero-glow-blue {
  position: absolute;
  top: -200px; right: -200px;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59,130,246,.08), transparent 70%);
  pointer-events: none;
}
.hero-glow-green {
  position: absolute;
  bottom: -150px; left: -150px;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16,185,129,.06), transparent 70%);
  pointer-events: none;
}

.hero-inner { position: relative; z-index: 1; max-width: 740px; }

.hero h1 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 3rem;
  font-weight: 900;
  color: #f9fafb;
  line-height: 1.1;
  margin: 0 0 16px;
}
.hero-subtitle {
  font-size: 1.4rem;
  color: var(--text-secondary);
  margin: 0 0 8px;
}
.hero-tagline {
  font-family: 'Source Code Pro', monospace;
  font-size: 1rem;
  color: var(--link);
  letter-spacing: 1.5px;
  margin: 0 0 24px;
}
.hero-bars {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 0 0 24px;
}
.hero-bars span {
  width: 48px; height: 4px;
  border-radius: 2px;
}
.hero-author {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0;
}

@media (max-width: 600px) {
  .hero h1 { font-size: 2rem; }
  .hero-subtitle { font-size: 1.1rem; }
}

/* ============================================================
   EPISODE CARDS (index page)
   ============================================================ */

.episodes {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px;
}
.episodes h2 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.6rem;
  color: var(--text-primary);
  margin: 0 0 32px;
  text-align: center;
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.episode-card {
  background: var(--bg-surface);
  border-radius: 14px;
  overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.episode-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0,0,0,.3);
}

.episode-card-border { height: 3px; }
.episode-card-body { padding: 24px; }

.episode-card-number {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 3rem;
  font-weight: 900;
  opacity: 0.08;
  line-height: 1;
  margin-bottom: 4px;
}
.episode-card-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.episode-card-excerpt {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 16px;
}
.episode-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-faint);
}
.read-time-badge {
  background: var(--bg-code);
  padding: 3px 8px;
  border-radius: 4px;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.75rem;
}
.episode-card-link {
  display: inline-block;
  margin-top: 12px;
  font-weight: 600;
  font-size: 0.9rem;
}

@media (max-width: 900px) {
  .episode-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   CAROUSEL PREVIEW (index page)
   ============================================================ */

.carousel-preview {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
  text-align: center;
}
.carousel-preview h2 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.4rem;
  margin: 0 0 24px;
}
.carousel-preview iframe {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-code);
}
.carousel-preview .carousel-link {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .carousel-preview iframe { display: none; }
  .carousel-preview .carousel-link-mobile { display: block; }
}
@media (min-width: 641px) {
  .carousel-preview .carousel-link-mobile { display: none; }
}

/* ============================================================
   ABOUT SECTION (index page)
   ============================================================ */

.about {
  max-width: 740px;
  margin: 0 auto;
  padding: 48px 24px;
  text-align: center;
}
.about h2 {
  font-family: 'Merriweather', Georgia, serif;
  margin: 0 0 16px;
}
.about p {
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ============================================================
   ARTICLE LAYOUT
   ============================================================ */

.article-wrapper {
  margin-top: 56px;
  display: flex;
  justify-content: center;
  gap: 48px;
  padding: 32px 24px 80px;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

.article-content {
  max-width: 740px;
  width: 100%;
  min-width: 0;
}

/* Metadata strip */
.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-faint);
  margin-bottom: 32px;
  font-family: 'Source Code Pro', monospace;
}
.article-meta .ep-badge {
  background: var(--bg-surface);
  padding: 3px 10px;
  border-radius: 4px;
  font-weight: 600;
}
.article-meta .sep { opacity: 0.4; }

/* ============================================================
   PROSE ELEMENTS
   ============================================================ */

.article-content h1 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1.2;
  margin: 0 0 8px;
  color: var(--text-primary);
}

.article-content h2 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 48px 0 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.article-content h3 {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.11rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 32px 0 12px;
  color: var(--text-primary);
}

.article-content p {
  margin: 0 0 18px;
  color: var(--text-secondary);
}

.article-content strong { color: var(--text-primary); }
.article-content em { font-style: italic; }

.article-content ul,
.article-content ol {
  margin: 0 0 18px;
  padding-left: 24px;
  color: var(--text-secondary);
}
.article-content li { margin-bottom: 6px; }

.article-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 40px 0;
}

/* Inline code */
.article-content code {
  background: var(--bg-code);
  border-radius: 4px;
  padding: 2px 6px;
  color: #7dd3fc;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.875em;
}

/* Code blocks */
.article-content pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
  overflow-x: auto;
  margin: 0 0 24px;
  line-height: 1.6;
}
.article-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Blockquotes */
.article-content blockquote {
  border-left: 3px solid var(--accent-amber);
  background: var(--bg-surface);
  padding: 16px 20px;
  border-radius: 0 8px 8px 0;
  margin: 0 0 24px;
  font-style: italic;
}
.article-content blockquote p { margin-bottom: 8px; }
.article-content blockquote p:last-child { margin-bottom: 0; }
.article-content blockquote h3 { margin-top: 0; }

/* Tables */
.article-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 24px;
  font-size: 0.9rem;
}
.article-content th {
  background: var(--bg-code);
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
}
.article-content td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.article-content tr:nth-child(even) td {
  background: var(--bg-surface);
}

/* Links in prose */
.article-content a { color: var(--link); }
.article-content a:hover { color: var(--link-hover); text-decoration: underline; }

/* ============================================================
   CALLOUT BOXES
   ============================================================ */

.callout {
  border-radius: 0 8px 8px 0;
  padding: 16px 20px;
  margin: 0 0 24px;
  border-left: 3px solid;
}
.callout p { margin-bottom: 8px; }
.callout p:last-child { margin-bottom: 0; }
.callout h3 { margin-top: 0; font-size: 1rem; }

.callout-note {
  border-color: var(--accent-blue);
  background: rgba(59,130,246,.08);
}
.callout-warning {
  border-color: var(--accent-amber);
  background: rgba(245,158,11,.08);
}
.callout-tip {
  border-color: var(--accent-green);
  background: rgba(16,185,129,.08);
}
.callout-math {
  border-color: var(--accent-amber);
  background: var(--bg-surface);
}
.callout-math .callout-label {
  display: inline-block;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-amber);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
  background: rgba(245,158,11,.1);
  padding: 2px 8px;
  border-radius: 4px;
}

/* Math foundation banner */
.math-banner {
  background: var(--bg-surface);
  border-left: 4px solid var(--accent-amber);
  border-radius: 0 8px 8px 0;
  padding: 20px 24px;
  margin: 0 0 24px;
}
.math-banner .math-label {
  display: inline-block;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-amber);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
  background: rgba(245,158,11,.1);
  padding: 3px 10px;
  border-radius: 4px;
}
.math-banner p {
  font-size: 1.05rem;
  margin-bottom: 10px;
}
.math-banner p:last-child { margin-bottom: 0; }

/* ============================================================
   TABLE OF CONTENTS (sticky sidebar)
   ============================================================ */

.toc {
  position: sticky;
  top: 80px;
  width: 220px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  flex-shrink: 0;
}
.toc-label {
  font-family: 'Source Code Pro', monospace;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc li {
  margin-bottom: 2px;
}
.toc li a {
  display: block;
  padding: 4px 0 4px 12px;
  font-size: 13px;
  color: var(--text-faint);
  border-left: 2px solid transparent;
  transition: color .15s, border-color .15s;
  text-decoration: none;
  line-height: 1.3;
}
.toc li a:hover {
  color: var(--text-secondary);
  text-decoration: none;
}
.toc li a.active {
  color: var(--link);
  border-left-color: var(--accent-blue);
}
.toc .toc-h3 a { padding-left: 24px; font-size: 12px; }

@media (max-width: 1100px) {
  .toc { display: none; }
}

/* ============================================================
   PREV / NEXT EPISODE NAV
   ============================================================ */

.episode-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-code);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  padding: 10px 24px;
  z-index: 999;
}
.episode-nav a {
  background: var(--bg-surface);
  color: var(--text-secondary);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: background .2s;
}
.episode-nav a:hover {
  background: var(--border);
  text-decoration: none;
}
.episode-nav .spacer { flex: 1; }

/* ============================================================
   FOOTER
   ============================================================ */

footer {
  background: var(--bg-code);
  border-top: 1px solid var(--border);
  padding: 48px 24px 32px;
  text-align: center;
}
footer .footer-title {
  font-family: 'Merriweather', Georgia, serif;
  font-size: 1.1rem;
  color: var(--text-primary);
  margin: 0 0 6px;
}
footer .footer-tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 24px;
}
footer .footer-links {
  display: flex;
  justify-content: center;
  gap: 32px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
footer .footer-col h4 {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 0 0 8px;
}
footer .footer-col a {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
footer .footer-attribution {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin: 0;
}

/* ============================================================
   CAROUSEL PAGE
   ============================================================ */

.carousel-page {
  margin-top: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
  min-height: calc(100vh - 56px);
}

.carousel-container {
  width: 100%;
  max-width: 560px;
  position: relative;
}

.carousel-slide {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-base);
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.carousel-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.carousel-btn {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.carousel-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.carousel-dots {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
}
.carousel-dot {
  width: 8px; height: 8px;
  border-radius: 4px;
  border: none;
  background: var(--border);
  cursor: pointer;
  transition: all .25s;
}
.carousel-dot.active {
  width: 22px;
  background: var(--accent-blue);
}

.carousel-label {
  text-align: center;
  margin-top: 12px;
  font-family: 'Source Code Pro', monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}
