/* ── Reset overrides (parent app sets html,body to no-scroll) ── */

html, body {
  height: auto;
  overflow: auto;
}

body {
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
}

a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--primary-hover);
}

/* ── Top nav ── */

.topnav {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-6) 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-decoration: none;
  font-weight: 500;
}

.back-link:hover {
  color: var(--primary);
  text-decoration: none;
}

/* ── Article ── */

.article {
  max-width: 680px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-10);
}

.article h1 {
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin-top: var(--sp-4);
  color: var(--text);
}

.article h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-top: 56px;
  margin-bottom: var(--sp-4);
  color: var(--text);
}

.article h3 {
  font-size: 19px;
  font-weight: 600;
  margin-top: var(--sp-6);
  margin-bottom: var(--sp-3);
  color: var(--text);
}

.article ul:not(.examples):not(.cors-list) {
  margin: 0 0 var(--sp-5) var(--sp-5);
  color: var(--text);
}

.article ul:not(.examples):not(.cors-list) li {
  margin-bottom: var(--sp-2);
  line-height: 1.55;
}

.article p {
  margin-bottom: var(--sp-5);
  color: var(--text);
}

.article .lead {
  font-size: 22px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-top: var(--sp-3);
  margin-bottom: var(--sp-8);
  line-height: 1.45;
}

.article strong {
  font-weight: 600;
  color: var(--text);
}

.article em {
  color: var(--primary-dark);
  font-style: normal;
  background: var(--primary-light);
  padding: 0 5px;
  border-radius: 3px;
}

/* ── Diagram ── */

.diagram {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6) var(--sp-5);
  margin: var(--sp-8) 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.diagram-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 1.4fr) minmax(120px, 1fr);
  align-items: center;
  gap: var(--sp-3);
}

.actor {
  text-align: center;
}

.actor-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
  box-shadow: var(--shadow-sm);
}

.actor-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

.link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
}

.link-arrow {
  position: relative;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-align: center;
  padding: 5px 26px;
  border-radius: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 500;
}

.link-arrow-out::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border-left: 7px solid var(--primary);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

.link-arrow-in::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  border-right: 7px solid var(--text-muted);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
}

/* Animated packet that travels along each arrow.
   Duration is shared (3.6s) so request and response stay in sync.
   The bottom diagram row is offset by half a beat so the page never
   sits totally still. */
.link-arrow-out .packet,
.link-arrow-in  .packet {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  top: 50%;
  margin-top: -4px;
  pointer-events: none;
  will-change: transform, opacity;
}

.link-arrow-out .packet {
  background: var(--primary);
  left: 6px;
  box-shadow:
    0 0 6px var(--primary),
    -8px 0 4px -3px var(--primary-light),
    -14px 0 4px -4px var(--primary-light);
  animation: packet-out 3.6s ease-in-out infinite;
}

.link-arrow-in .packet {
  background: var(--success);
  right: 6px;
  box-shadow:
    0 0 6px var(--success),
    8px 0 4px -3px var(--success-light),
    14px 0 4px -4px var(--success-light);
  animation: packet-in 3.6s ease-in-out infinite;
}

/* Bottom diagram row (code <-> API) starts half a beat later, so the
   "browser asks" beat finishes before the "code asks" beat begins. */
.diagram-row:last-child .link-arrow-out .packet,
.diagram-row:last-child .link-arrow-in  .packet {
  animation-delay: 1.8s;
}

@keyframes packet-out {
  0%   { left: 6px;                    opacity: 0; }
  6%   { opacity: 1; }
  35%  { left: calc(100% - 22px);      opacity: 1; }
  40%  { left: calc(100% - 22px);      opacity: 0; }
  100% { left: 6px;                    opacity: 0; }
}

@keyframes packet-in {
  0%,
  40% { right: 6px;                    opacity: 0; }
  46% { opacity: 1; }
  75% { right: calc(100% - 22px);      opacity: 1; }
  80% { right: calc(100% - 22px);      opacity: 0; }
  100% { right: 6px;                   opacity: 0; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .link-arrow-out .packet,
  .link-arrow-in  .packet {
    animation: none;
    display: none;
  }
}

.diagram-divider {
  height: 1px;
  background: var(--border);
  margin: 0 var(--sp-2);
}

/* ── Callout (the "APIs are how programs talk to each other" line) ── */

.callout {
  font-size: 19px !important;
  font-weight: 500;
  text-align: center;
  padding: var(--sp-5) var(--sp-4);
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark) !important;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: var(--sp-6) 0 !important;
}

/* ── Examples list ── */

.examples {
  list-style: none;
  padding: 0;
  margin: var(--sp-4) 0 var(--sp-6);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--sp-2) var(--sp-4);
}

.examples li {
  padding: var(--sp-2) 0;
  color: var(--text-secondary);
  line-height: 1.5;
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}

.examples .ex-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--primary-light);
  color: var(--primary);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.examples strong {
  color: var(--text);
}

/* ── Demo block ── */

.demo {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin: var(--sp-5) 0 var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* Pill picker for switching between sample API calls. */
.demo-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px;
}

.demo-pill {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 100px;
  padding: 6px 14px;
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.demo-pill:hover:not(.is-active) {
  background: var(--bg);
  color: var(--text);
}

.demo-pill.is-active {
  background: var(--primary);
  color: #fff;
}

.demo-hint {
  margin: -4px 0 0 0 !important;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1.5;
  font-style: italic;
}

.demo-url {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  overflow-x: auto;
}

.demo-url code {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--primary-dark);
  white-space: nowrap;
}

.demo-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px var(--sp-5);
  font-family: var(--font);
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  align-self: flex-start;
}

.demo-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.demo-btn:disabled {
  opacity: 0.85;
  cursor: not-allowed;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.demo-output {
  background: var(--vscode-bg);
  border-radius: var(--radius);
  overflow: hidden;
  animation: fade-in 200ms ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.demo-output pre {
  margin: 0;
  padding: var(--sp-4);
  max-height: 320px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--vscode-text);
  white-space: pre;
  line-height: 1.55;
}

/* JSON syntax highlighting (VS Code palette from variables.css) */
.tok-key    { color: var(--vscode-type); }
.tok-string { color: var(--vscode-string); }
.tok-number { color: var(--vscode-number); }
.tok-bool   { color: var(--vscode-keyword); }
.tok-null   { color: var(--vscode-keyword); }

/* ── Python code snippet (Prism handles tokens, we style the chrome) ── */

.code-snippet[class*="language-"] {
  background: var(--vscode-bg);
  border-radius: var(--radius);
  padding: var(--sp-4);
  margin: var(--sp-4) 0 var(--sp-5);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.6;
  overflow-x: auto;
  text-shadow: none;
}

.code-snippet[class*="language-"] code {
  font-family: var(--font-mono);
  font-size: inherit;
  line-height: inherit;
  background: transparent;
  text-shadow: none;
}

/* ── CORS list ── */

.cors-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.cors-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  color: var(--text-secondary);
  line-height: 1.55;
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
}

.cors-list-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.cors-list .cors-yes .cors-list-icon { color: var(--success); }
.cors-list .cors-no  .cors-list-icon { color: var(--error); }

.cors-list strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Footer ── */

.page-footer {
  text-align: center;
  padding: var(--sp-5) var(--sp-6) var(--sp-8);
  color: var(--text-muted);
  font-size: var(--text-sm);
  border-top: 1px solid var(--border-light);
  max-width: 680px;
  margin: var(--sp-8) auto 0;
}

.page-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.page-footer a:hover {
  text-decoration: underline;
}

.page-footer-sep {
  margin: 0 10px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* ── Responsive ── */

@media (max-width: 600px) {
  body {
    font-size: 16px;
  }

  .article {
    padding: var(--sp-4) var(--sp-5) var(--sp-8);
  }

  .article h1 {
    font-size: 32px;
  }

  .article h2 {
    margin-top: var(--sp-8);
    font-size: 21px;
  }

  .article .lead {
    font-size: 19px;
  }

  .diagram {
    padding: var(--sp-5) var(--sp-3);
  }

  .diagram-row {
    grid-template-columns: 1fr;
    gap: var(--sp-3);
    text-align: center;
  }

  .link {
    flex-direction: column;
    gap: 4px;
  }

  .actor-icon {
    font-size: 32px;
  }

  .examples {
    grid-template-columns: 1fr;
  }

  .demo-btn {
    align-self: stretch;
  }
}

/* ── Sven tip popup (thinking → idea on hover/click) ── */

.sven-tip {
  display: block;
  position: relative;
  width: max-content;
  margin: var(--sp-6) auto;
  cursor: pointer;
  user-select: none;
  line-height: 0;
}
.sven-img {
  width: 64px;
  height: auto;
  display: inline-block;
  transition: transform 0.25s, opacity 0.18s ease;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.15));
}
.sven-idea {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
}
.sven-tip:hover .sven-thinking,
.sven-tip.open  .sven-thinking { opacity: 0; }
.sven-tip:hover .sven-idea,
.sven-tip.open  .sven-idea     { opacity: 1; }
.sven-tip:hover .sven-img { transform: rotate(-7deg) scale(1.08); }
.sven-tip.open  .sven-img { transform: rotate(-3deg) scale(1.05); }

.sven-pop {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: 320px;
  max-width: calc(100vw - 32px);
  background: #FFF7DC;
  border: 1px solid #F0D78C;
  border-radius: 10px;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: #5A4A1A;
  text-align: left;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
  transition: opacity 0.18s, visibility 0.18s;
  z-index: 10;
}
.sven-pop::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -7px;
  border: 7px solid transparent;
  border-top-color: #F0D78C;
}
.sven-tip:hover .sven-pop,
.sven-tip.open  .sven-pop {
  visibility: visible;
  opacity: 1;
}
.sven-pop strong {
  display: block;
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 15px;
}
.sven-pop em { font-style: normal; font-weight: 600; }
.sven-pop code {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}

/* ============================================================
   "What is a Series?" note + interactive Python walkthrough
   ============================================================ */

.series-note {
  background: var(--primary-light);
  border: 1px solid #b9cfe0;
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-6) 0 var(--sp-4);
}

.series-note-title {
  margin: 0 0 var(--sp-2);
  font-size: 16px;
  font-weight: 600;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.series-note p {
  margin: 0 0 var(--sp-2);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}

.series-note p:last-child { margin-bottom: 0; }

/* Inline code chip (note, captions, arrows) */
code.inl {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(55, 114, 163, 0.12);
  color: var(--primary-dark);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.walk {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  margin: var(--sp-4) 0 var(--sp-6);
}

/* Step dots */
.walk-steps { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); }

.walk-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.walk-dot:hover { border-color: var(--primary); color: var(--primary); }

.walk-dot.is-done {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary-light);
}

.walk-dot.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Code panel with per-step line highlighting */
.walk-code {
  background: var(--vscode-bg);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  overflow-x: auto;
  margin-bottom: var(--sp-4);
  /* Hold height steady so the panel does not jump between 1 and 2 line steps */
  min-height: 72px;
}

.walk-code pre { margin: 0; }

.walk-code code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--vscode-text);
  white-space: pre;
}

.wl {
  display: block;
  padding: 0 var(--sp-2);
  margin: 0 calc(-1 * var(--sp-2));
  border-left: 2px solid transparent;
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition);
}

.wl-on {
  background: rgba(55, 114, 163, 0.25);
  border-left-color: #5b9bd5;
}

.wl-cmt { color: var(--vscode-comment); }

/* The star of the lesson: typ="series" */
.walk-key {
  background: rgba(245, 158, 11, 0.22);
  border-radius: var(--radius-sm);
  padding: 0 3px;
  transition: background var(--transition), box-shadow var(--transition);
}

.walk--spot .walk-key {
  background: rgba(245, 158, 11, 0.45);
  box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.6);
}

/* Visual stage */
.walk-stage {
  min-height: 150px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) 0;
}

.panel { flex: 0 1 auto; }

.panel-var {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--primary-dark);
  background: var(--primary-light);
  padding: 3px var(--sp-3);
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid #c4d6e5;
  border-bottom: none;
}

/* Series rendered as a label -> value table */
.ser {
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  overflow: hidden;
  min-width: 210px;
  background: var(--surface);
}

.ser-head {
  display: flex;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.ser-head span { padding: 5px var(--sp-3); }

.ser-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
  transition: opacity var(--transition), background var(--transition);
}

.ser-row:last-child { border-bottom: none; }

.ser-label,
.ser-head .ser-label {
  width: 44%;
  flex-shrink: 0;
  padding: 7px var(--sp-3);
  border-right: 1px solid var(--border);
}

.ser-row .ser-label {
  background: var(--bg);
  color: var(--primary-dark);
  font-weight: 600;
}

.ser-val {
  flex: 1;
  padding: 7px var(--sp-3);
  color: var(--text);
}

.ser-val.nested { color: var(--text-secondary); font-style: italic; }

.ser-row.is-hi .ser-label { background: var(--primary); color: #fff; }
.ser-row.is-hi .ser-val { background: var(--primary-light); color: var(--text); }
.ser-row.is-dim { opacity: 0.4; }

/* Connector between panels */
.walk-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
  text-align: center;
}

.walk-arrow i { font-size: 18px; color: var(--primary); }

/* Final value chip */
.result {
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--success);
  background: var(--success-light);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-5);
}

.result-var {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.result-num {
  font-size: 22px;
  font-weight: 700;
  color: #047857;
  font-family: var(--font-mono);
}

/* Raw JSON view (matches the live demo output palette) */
.raw {
  width: 100%;
  box-sizing: border-box;
  background: var(--vscode-bg);
  color: var(--vscode-text);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  overflow-x: auto;
}

.raw .k { color: var(--vscode-type); }
.raw .s { color: var(--vscode-string); }
.raw .n { color: var(--vscode-number); }

/* print() output strip */
.walk-out {
  width: 100%;
  box-sizing: border-box;
  background: var(--vscode-bg);
  color: var(--vscode-text);
  border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: 13px;
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
}

.walk-out .lbl {
  color: var(--text-muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Caption (scoped to beat .article p specificity) */
.walk .walk-caption {
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border-radius: var(--radius);
  padding: var(--sp-3) var(--sp-4);
  margin: 0 0 var(--sp-4);
  min-height: 3em;
}

/* Nav */
.walk-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.walk-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px var(--sp-4);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background var(--transition-fast);
}

.walk-btn:hover:not(:disabled) { background: var(--primary-hover); }
.walk-btn:disabled { opacity: 0.4; cursor: default; }

.walk-progress {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 600px) {
  .walk-stage { flex-direction: column; align-items: stretch; }
  .panel, .ser { min-width: 0; width: 100%; }
  .walk-arrow { flex-direction: row; justify-content: center; gap: var(--sp-2); }
  .walk-arrow i { transform: rotate(90deg); }
}
