/* ============================================================
   JavaScript sub-pillar theme — "Warm Beige + Amber"
   Concept: warm beige paper, JS amber accent, TS blue secondary.
   Modern, friendly, low-contrast for reading marathon.
   ============================================================ */

:root {
  /* Backgrounds */
  --bg:           #f4ede1;
  --bg-card:      #fffdf7;
  --bg-alt:       #eae0cf;

  /* Text */
  --text:         #2a241b;
  --text-soft:    #524838;
  --text-muted:   #837866;
  --ink:          #181208;

  /* Primary accent (JS amber — desaturated, not loud) */
  --accent:       #c8961a;
  --accent-deep:  #97700f;
  --accent-soft:  #f5e4ba;

  /* Secondary accent (TS blue, for TypeScript chapters) */
  --ts-blue:      #3178c6;
  --ts-blue-deep: #1f4e80;
  --ts-blue-soft: #d4e4f5;

  /* Highlight gold (Dart-like, slightly warmer) */
  --gold:         #a87018;
  --gold-soft:    #f0dfb3;

  /* Borders */
  --border:       #ddd0b5;
  --border-soft:  #e6dcc4;

  /* Fonts */
  --font-body:    "Inter", "Helvetica Neue", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-display: "Fraunces", "Crimson Pro", "Iowan Old Style", Georgia, serif;
  --font-mono:    "JetBrains Mono", "Fira Code", "Menlo", "Consolas", monospace;

  /* Code block (warm dark — not pure black) */
  --code-bg:        #2a2520;
  --code-fg:        #e6ddc9;
  --code-inline-bg: #efe2c2;
  --code-inline-fg: #6a4f10;

  /* Syntax highlight tokens (works on warm dark code-bg) */
  --syn-kw:    #f0b56f;   /* keyword (function, const, return) */
  --syn-type:  #88c1f0;   /* type name (string, number — TS) */
  --syn-str:   #c8d99a;   /* string literal */
  --syn-num:   #f4a3ee;   /* number literal */
  --syn-com:   #9c8f7c;   /* comment */
  --syn-fn:    #ffd476;   /* function name */
  --syn-op:    #d6cab0;   /* operator */
  --syn-cls:   #88c1f0;   /* class name */
}

/* Custom font Fraunces (variable serif, modern optical-size) */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&display=swap');

/* JS logo mark in header */
.site-logo .mark.mark-js {
  background: linear-gradient(135deg, #c8961a 0%, #8c6610 100%);
  color: #fffaee;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.site-logo .mark.mark-ts {
  background: linear-gradient(135deg, #3178c6 0%, #1f4e80 100%);
  color: #ffffff;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* JavaScript-specific hero treatment */
.hero.js-hero {
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(200,150,26,0.10) 0%, transparent 70%),
    linear-gradient(to bottom, var(--bg), var(--bg));
}
.hero.js-hero h1 em {
  color: var(--accent);
  font-style: italic;
  position: relative;
  font-family: var(--font-display);
}
.hero.js-hero h1 em::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  bottom: 4px;
  height: 10px;
  background: var(--gold-soft);
  z-index: -1;
  border-radius: 4px;
}

/* TypeScript section — distinguishable via accent change */
.ts-section {
  --accent: var(--ts-blue);
  --accent-deep: var(--ts-blue-deep);
  --accent-soft: var(--ts-blue-soft);
}
.ts-section .chapter-num,
.ts-section .quiz-num,
.ts-section .tag {
  background: var(--ts-blue-soft);
  color: var(--ts-blue);
}
.ts-section .exercise::before,
.ts-section .chapter-header { background: var(--ts-blue); }
.ts-section .chapter-header {
  border-top-color: var(--ts-blue);
  background: transparent; /* reset */
  border-top: 4px solid var(--ts-blue);
}

/* Chapter accent stripe */
.chapter-header {
  border-top: 4px solid var(--accent);
  padding-top: 36px;
}

/* Chapter number badge */
.chapter-num {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 12px;
  border-radius: 4px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

/* TS-flavored chapter num (chapter 9-12) */
.chapter-num.ts {
  color: var(--ts-blue);
  background: var(--ts-blue-soft);
}

/* Display heading — Fraunces optical-size tweak for large h1 */
.prose h1, .chapter-header h1, .hero h1 {
  font-variation-settings: "opsz" 144;
}
.prose h2 { font-variation-settings: "opsz" 32; }
.prose h3, .prose h4 { font-variation-settings: "opsz" 18; }

/* Quiz number JS-amber by default */
.quiz-num { background: var(--accent-soft); color: var(--accent); }
.exercise::before { background: var(--accent); }

/* Code block — JS-specific filename label */
.code-wrap .code-meta {
  background: linear-gradient(to right, color-mix(in srgb, var(--code-bg) 80%, var(--accent) 8%), color-mix(in srgb, var(--code-bg) 90%, var(--bg) 10%));
}

/* JS playground widget (interactive sandbox) */
.js-playground {
  margin: 24px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  overflow: hidden;
}
.js-playground-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-deep);
  font-weight: 600;
}
.js-playground-label .run-btn {
  background: var(--accent);
  color: var(--bg-card);
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.js-playground-label .run-btn:hover { background: var(--accent-deep); }
.js-playground textarea {
  width: 100%;
  min-height: 180px;
  padding: 14px 18px;
  background: var(--code-bg);
  color: var(--code-fg);
  border: none;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.js-playground .output {
  background: #1a1614;
  color: #c8d99a;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  padding: 12px 18px;
  border-top: 1px solid #3a3530;
  white-space: pre-wrap;
  min-height: 40px;
  max-height: 220px;
  overflow-y: auto;
}
.js-playground .output.error { color: #f0a8a8; }
.js-playground .output.empty { color: #6a5f50; font-style: italic; }

/* Event loop visualizer */
.event-loop-viz {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin: 24px 0;
}
.event-loop-viz .zones {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 14px 0;
}
.event-loop-viz .zone {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  min-height: 90px;
}
.event-loop-viz .zone-title {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.event-loop-viz .item-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-deep);
  padding: 2px 9px;
  margin: 3px 4px 3px 0;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
}
.event-loop-viz .item-pill.task { background: #f5e4ba; color: #97700f; }
.event-loop-viz .item-pill.micro { background: #d4e4f5; color: #1f4e80; }
.event-loop-viz .item-pill.api { background: #e0e5d0; color: #4f5d24; }
.event-loop-viz .controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.event-loop-viz .controls button {
  background: var(--accent);
  color: var(--bg-card);
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.event-loop-viz .controls button:hover { background: var(--accent-deep); }
.event-loop-viz .controls .reset { background: var(--text-muted); }
.event-loop-viz .log {
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 12px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  min-height: 60px;
  max-height: 140px;
  overflow-y: auto;
}

/* Pillar card variations on Pillar 9 index */
.subpillar-card.subpillar-js {
  --card-accent: var(--accent);
  background: linear-gradient(135deg, #fffdf7 0%, #f3e2bb 100%);
}

/* Pretty inline code in JS prose */
.prose p code, .prose li code {
  border-color: var(--gold-soft);
}

/* JS feature block (similar to dart-feature) */
.js-feature {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin: 20px 0;
  position: relative;
  padding-left: 56px;
}
.js-feature::before {
  content: "JS";
  position: absolute;
  left: 14px; top: 18px;
  width: 32px; height: 32px;
  background: var(--accent);
  color: var(--bg-card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
}
.js-feature.ts-flavor::before { content: "TS"; background: var(--ts-blue); font-size: 0.78rem; }
.js-feature h4 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  color: var(--ink);
}
.js-feature p:last-child { margin-bottom: 0; }

/* Footer accent */
.site-footer {
  background: linear-gradient(to bottom, var(--bg), var(--bg-alt));
}

/* Hero typography enhancement */
.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-variation-settings: "opsz" 144;
  letter-spacing: -0.02em;
}
