/* ─── rl_lessons / style.css ───
 * Shared styling for the interactive RL lesson series.
 * Goal: clean, technical, readable. Optimized for "thinking-in-line".
 */

:root {
  --bg:        #ffffff;
  --bg-elev:   #f7f8fa;
  --bg-soft:   #eef1f5;
  --border:    #dde2ea;
  --text:      #1f2430;
  --text-mute: #5b6573;
  --text-dim:  #94a3b8;
  --accent:    #2563eb;
  --accent-2:  #d97706;
  --ok:        #16a34a;
  --warn:      #d97706;
  --bad:       #dc2626;
  --code-bg:   #f1f3f7;
  --mono:      "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans:      -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", sans-serif;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
}

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 28px 120px;
  overflow-wrap: break-word;
}

header.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}

header.topnav .inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 13px;
}

header.topnav .crumb {
  color: var(--text-mute);
}
header.topnav a.crumb-link {
  color: var(--accent);
  text-decoration: none;
}
header.topnav a.crumb-link:hover { text-decoration: underline; }

header.topnav .step-pill {
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-mute);
  font-family: var(--mono);
  font-size: 11px;
}

@media (max-width: 640px) {
  header.topnav .inner {
    gap: 8px 12px;
    padding: 10px 16px;
  }

  header.topnav .step-pill {
    margin-left: 0;
    width: 100%;
    max-width: max-content;
  }
}

h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 16px 0 4px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
h1 + .subtitle {
  color: var(--text-mute);
  font-size: 17px;
  margin: 0 0 28px;
}

h2 {
  font-size: 21px;
  margin: 38px 0 10px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  letter-spacing: -0.005em;
}

h3 {
  font-size: 17px;
  margin: 26px 0 8px;
  font-weight: 600;
  color: var(--text);
}

p { margin: 10px 0; }

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

code {
  font-family: var(--mono);
  font-size: 13.5px;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 14px 0;
  font-size: 13.5px;
  line-height: 1.55;
}
pre code {
  background: transparent;
  border: none;
  padding: 0;
}

.math {
  font-family: "Latin Modern Math", "STIX Two Math", Cambria, Georgia, serif;
  font-style: italic;
  font-size: 1.04em;
}
.math.block {
  display: block;
  text-align: center;
  margin: 16px 0;
  padding: 12px 8px;
  background: var(--bg-elev);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 1.08em;
}

.callout {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 4px 8px 8px 4px;
}
.callout.warn { border-left-color: var(--warn); }
.callout.bad  { border-left-color: var(--bad);  }
.callout.ok   { border-left-color: var(--ok);   }
.callout .label {
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-mute);
  margin-bottom: 4px;
}

.widget {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin: 22px 0;
}
.widget .title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}
.widget .hint {
  font-size: 13px;
  color: var(--text-mute);
  margin-bottom: 14px;
}
.widget .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 8px 0 12px;
}

button {
  font-family: var(--sans);
  font-size: 13px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover { background: #e8ecf2; border-color: #cbd5e1; }
button.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover { background: #3b82f6; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
  width: 200px;
  max-width: min(200px, 44vw);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

input[type="text"], input[type="number"] {
  background: var(--code-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-size: 13px;
}

label.inline {
  font-size: 13px;
  color: var(--text-mute);
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
}
label.inline .val {
  font-family: var(--mono);
  color: var(--text);
  min-width: 40px;
  display: inline-block;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin: 10px 0;
}
.kpi {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.kpi .k { font-size: 11px; color: var(--text-mute); font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.06em; }
.kpi .v { font-size: 18px; font-family: var(--mono); margin-top: 2px; }

.token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  font-family: var(--mono);
  font-size: 14px;
  margin: 8px 0;
}
.tok {
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--text-mute);
}
.tok.assistant { color: var(--text); background: #dbeafe; border-color: #bfdbfe; }
.tok.tool      { color: #d97706; background: #fef3c7; border-color: #fcd34d; opacity: 0.85; }
.tok.prompt    { color: var(--text-dim); }
.tok.reward    { color: var(--ok); background: #dcfce7; border-color: #86efac; }

table {
  border-collapse: collapse;
  width: 100%;
  margin: 14px 0;
  font-size: 14px;
  table-layout: fixed;
}
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
th {
  font-size: 12px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-mute);
  font-weight: 600;
}
tr:hover td { background: var(--bg-elev); }

footer.lesson-nav {
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}
footer.lesson-nav a {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  max-width: 48%;
  text-decoration: none;
}
footer.lesson-nav a:hover { background: var(--bg-elev); text-decoration: none; }
footer.lesson-nav a.next { text-align: right; align-items: flex-end; }
footer.lesson-nav .dir { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--mono); }
footer.lesson-nav .ttl { color: var(--accent); }

.ascii {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 8px;
  overflow-x: auto;
  color: var(--text);
}

.chip {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--text-mute);
}
.chip.role-rollout { color: var(--accent); }
.chip.role-ref     { color: #7c3aed; }
.chip.role-algo    { color: var(--warn); }
.chip.role-train   { color: var(--ok); }
.chip.role-sync    { color: var(--bad); }

ul, ol { padding-left: 22px; }
li { margin: 4px 0; }

.bar {
  height: 12px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
.bar > .fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.bar > .fill.neg { background: var(--bad); }
.bar > .fill.pos { background: var(--ok); }

.dist-canvas {
  width: 100%;
  height: 160px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: block;
}

.trajectory {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 6px 0;
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.trajectory .label-l { color: var(--text-mute); width: 32px; flex-shrink: 0; }
.trajectory .text { color: var(--text); flex: 1; word-break: break-all; }
.trajectory .reward-l { color: var(--ok); width: 70px; text-align: right; }
.trajectory .reward-l.zero { color: var(--text-dim); }

.diagram {
  display: block;
  width: 100%;
  height: auto;
  margin: 14px 0;
}
.diagram text { font-family: var(--sans); fill: var(--text); }
.diagram .node-bg { fill: var(--bg-elev); stroke: var(--border); stroke-width: 1; }
.diagram .node-bg.active { stroke: var(--accent); stroke-width: 2; }
.diagram .edge { stroke: var(--text-dim); stroke-width: 1.2; fill: none; }
.diagram .edge.active { stroke: var(--accent); stroke-width: 2.2; }
.diagram .edge-label { fill: var(--text-mute); font-size: 11px; font-family: var(--mono); }

.toc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 24px 0;
}
.toc-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 16px 18px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s ease;
}
.toc-card:hover { border-color: var(--accent); text-decoration: none; }
.toc-card .num {
  font-family: var(--mono);
  font-size: 22px;
  color: var(--text-dim);
  width: 32px;
  flex-shrink: 0;
}
.toc-card .ttl { font-weight: 600; font-size: 16px; color: var(--text); margin-bottom: 4px; }
.toc-card .sum { color: var(--text-mute); font-size: 14px; line-height: 1.5; }

.tag {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  color: var(--text-mute);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 6px;
  vertical-align: 2px;
}
