/*
  Interactive article toolkit
  - GitHub Pages friendly (no build step)
  - Inspired by Distill/Tufte patterns: callouts, sidenotes, tabs, figures
*/

:root {
  /* default readable width (no margin notes) */
  --ia-max-width: 1040px;

  /* margin-note layout tuning (desktop) */
  --ia-margin-col: 250px;
  --ia-sidenote-width: 230px;
  --ia-max-width-wide: 1400px;
  --ia-text: #0b0b0c;
  --ia-muted: rgba(0, 0, 0, 0.72);
  --ia-border: rgba(127, 127, 127, 0.35);
  --ia-bg-soft: rgba(0, 0, 0, 0.04);
  --ia-code-bg: #f6f8fa;
  --ia-accent: var(--accent-color, #007acc);
  --ia-good: #137333;
  --ia-warn: #b45309;
  --ia-bad: #b91c1c;
  --ia-radius: 12px;
  --ia-font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  --ia-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

html.dark-mode {
  --ia-text: rgba(255, 255, 255, 0.92);
  --ia-muted: rgba(255, 255, 255, 0.72);
  --ia-border: rgba(255, 255, 255, 0.22);
  --ia-bg-soft: rgba(255, 255, 255, 0.06);
  --ia-code-bg: rgba(255, 255, 255, 0.06);
}

/* Make articles feel less “theme-hacker wide terminal”, more “paper” */
#main_content {
  max-width: var(--ia-max-width);
  margin: 0 auto;
  font-family: var(--ia-font-sans);
  color: var(--ia-text);
  overflow: visible;
}

/* Utility: full-bleed blocks inside the constrained article column */
.ia-bleed {
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  /* avoid accidental horizontal page scrolling due to 100vw scrollbar math */
  overflow-x: clip;
}

@media (min-width: 1100px) {
  /* Reserve a right margin column so sidenotes look like Distill/Tufte */
  #main_content {
    max-width: var(--ia-max-width-wide);
    padding-right: var(--ia-margin-col);
    /* Avoid a huge left gutter: keep the text column anchored left, with margin notes on the right */
    margin-left: 0;
    margin-right: auto;
  }
}

#main_content p,
#main_content li {
  line-height: 1.7;
}

#main_content h1,
#main_content h2,
#main_content h3 {
  letter-spacing: -0.01em;
}

/* nicer section dividers like Distill-ish galleries */
#main_content hr {
  border: 0;
  border-top: 1px solid var(--ia-border);
  margin: 2.2rem 0;
  opacity: 0.9;
}

.ia-section {
  margin: 2rem 0;
}

.ia-section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.ia-section__header h2 {
  margin: 0;
}

.ia-toc {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
  margin: 1.2rem 0 2rem 0;
}

.ia-toc a { text-decoration: none; }
.ia-toc ul { margin: 0.2rem 0 0 0; }

/* --------
 * Callouts
 * -------- */
.ia-callout {
  border-left: 4px solid var(--ia-border);
  border-radius: 0;
  background: transparent;
  padding: 0.15rem 0 0.15rem 0.9rem;
  margin: 1.1rem 0;
}

.ia-callout__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.ia-callout--info { border-left-color: var(--ia-accent); }
.ia-callout--tip { border-left-color: var(--ia-good); }
.ia-callout--warn { border-left-color: var(--ia-warn); }
.ia-callout--danger { border-left-color: var(--ia-bad); }

.ia-callout--info .ia-callout__title { color: var(--ia-accent); }
.ia-callout--tip .ia-callout__title { color: var(--ia-good); }
.ia-callout--warn .ia-callout__title { color: var(--ia-warn); }
.ia-callout--danger .ia-callout__title { color: var(--ia-bad); }

.ia-callout__body > :first-child { margin-top: 0; }
.ia-callout__body > :last-child { margin-bottom: 0; }

/* ----------------
 * Research blocks
 * ---------------- */
.ia-statement {
  border-left: 4px solid var(--ia-border);
  border-radius: 0;
  background: transparent;
  padding: 0.15rem 0 0.15rem 0.9rem;
  margin: 1.1rem 0;
}

.ia-statement__header {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
}

.ia-statement__kind {
  font-weight: 900;
  letter-spacing: 0.01em;
}

.ia-statement__title {
  color: var(--ia-muted);
  font-weight: 700;
}

.ia-statement__body > :first-child { margin-top: 0; }
.ia-statement__body > :last-child { margin-bottom: 0; }

.ia-statement--definition .ia-statement__kind { color: var(--ia-accent); }
.ia-statement--theorem .ia-statement__kind { color: var(--ia-good); }
.ia-statement--lemma .ia-statement__kind { color: var(--ia-good); }
.ia-statement--proof .ia-statement__kind { color: var(--ia-warn); }

/* Quote */
.ia-quote {
  border-left: 4px solid var(--ia-accent);
  padding-left: 1rem;
  margin: 1.2rem 0;
}

.ia-quote__body {
  margin: 0;
  color: var(--ia-text);
  font-style: italic;
  font-size: 1.03rem;
  border: 0 !important;
  padding: 0 !important;
  background: transparent !important;
}

.ia-quote__body > :first-child { margin-top: 0; }
.ia-quote__body > :last-child { margin-bottom: 0; }

.ia-quote__cite {
  margin-top: 0.4rem;
  color: var(--ia-muted);
  font-size: 0.95rem;
}

/* TODO / checklist container */
.ia-todo {
  border-left: 4px solid var(--ia-border);
  border-radius: 0;
  background: transparent;
  padding: 0.15rem 0 0.15rem 0.9rem;
  margin: 1.1rem 0;
}

.ia-todo__header {
  font-weight: 900;
  margin-bottom: 0.45rem;
}

.ia-todo__body > :first-child { margin-top: 0; }
.ia-todo__body > :last-child { margin-bottom: 0; }

/* Strike completed tasks in markdown checklists (kramdown task lists) */
.ia-todo__body li.task-list-item {
  list-style: none;
}

.ia-todo__body li.task-list-item input[type="checkbox"] {
  margin-right: 0.55rem;
}

.ia-todo__body li.task-list-item.is-done .ia-task-text,
.ia-todo__body li.task-list-item:has(input[type="checkbox"][checked]) {
  text-decoration: line-through;
  color: var(--ia-muted);
}

/* Toggle list wrapper (details inside) */
.ia-toggles {
  margin: 1.1rem 0;
}

.ia-toggles__title {
  font-weight: 900;
  margin-bottom: 0.6rem;
}

.ia-toggles details { margin: 0.65rem 0; }

/* Nicer nested details indentation */
.ia-toggles details details {
  margin-left: 1.1rem;
}

/* Media */
.ia-media {
  margin: 1.4rem 0;
}

.ia-media__frame {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}
html.dark-mode .ia-media__frame { background: transparent; }

.ia-media__video,
.ia-media__audio {
  width: 100%;
}

.ia-media__caption {
  margin-top: 0.55rem;
  font-size: 0.95rem;
  color: var(--ia-muted);
}

/* File link */
.ia-file {
  display: inline;
  text-decoration: underline;
  text-decoration-thickness: from-font;
  text-underline-offset: 2px;
  color: var(--ia-accent);
}

.ia-file__label { font-weight: 700; }
.ia-file__meta { color: var(--ia-muted); font-size: 0.92rem; }

/* ---------
 * Figures
 * --------- */
figure.ia-figure {
  margin: 1.6rem 0;
}

.ia-figure img {
  border: 1px solid var(--ia-border);
  border-radius: 10px;
  background: #fff;
}
html.dark-mode .ia-figure img {
  background: rgba(0,0,0,0.2);
}

.ia-figure figcaption {
  margin-top: 0.55rem;
  font-size: 0.95rem;
  color: var(--ia-muted);
}

.ia-zoomable {
  cursor: zoom-in;
}

dialog.ia-lightbox {
  width: min(1200px, 96vw);
  border: 1px solid var(--ia-border);
  border-radius: 14px;
  padding: 0.8rem;
  background: rgba(255,255,255,0.98);
}
html.dark-mode dialog.ia-lightbox {
  background: rgba(0,0,0,0.9);
}

dialog.ia-lightbox::backdrop {
  background: rgba(0,0,0,0.55);
}

.ia-lightbox__img {
  width: 100%;
  height: auto;
}

.ia-lightbox__close {
  float: right;
  border: 1px solid var(--ia-border);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

html.dark-mode .ia-lightbox__close {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.92);
}

/* ---------
 * Sidenotes
 * ---------
   Desktop: margin note on the right.
   Mobile: inline block.
*/
.ia-sidenote {
  position: relative;
  display: inline;
}

.ia-sidenote__ref {
  font-variant-numeric: tabular-nums;
  font-size: 0.78em;
  vertical-align: sub;
  color: var(--ia-accent);
  cursor: pointer;
  text-decoration: none;
}

.ia-sidenote__body {
  display: inline-block;
  margin-left: 0.2rem;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-radius: 10px;
  background: var(--ia-bg-soft);
  color: var(--ia-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.ia-sidenote__label {
  color: var(--ia-accent);
  font-weight: 700;
  margin-right: 0.25rem;
}

@media (min-width: 1100px) {
  .ia-sidenote__body {
    float: right;
    clear: right;
    width: var(--ia-sidenote-width);
    max-width: var(--ia-sidenote-width);
    margin-right: calc(-1 * var(--ia-margin-col));
    margin-left: 1rem;
    margin-top: 0.2rem;
    display: block;
  }
}

/* ----------
 * Tooltips
 * ---------- */
.ia-tooltip {
  position: relative;
  border-bottom: 1px dotted var(--ia-border);
  cursor: help;
}

.ia-tooltip__bubble {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 10px);
  width: min(360px, 78vw);
  border: 1px solid var(--ia-border);
  border-radius: 12px;
  background: rgba(255,255,255,0.98);
  padding: 0.5rem 0.6rem;
  font-size: 0.95rem;
  color: var(--ia-text);
  box-shadow: 0 14px 40px rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 20;
}
html.dark-mode .ia-tooltip__bubble { background: rgba(0,0,0,0.95); }

/* -------------------------
 * Distill-ish citations
 * ------------------------- */
.ia-cite {
  font-variant-numeric: tabular-nums;
  font-size: 0.85em;
  vertical-align: super;
  color: var(--ia-accent);
  text-decoration: none;
  cursor: pointer;
}

.ia-cite__bubble {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 10px);
  width: min(420px, 86vw);
  border: 1px solid var(--ia-border);
  border-radius: 12px;
  background: rgba(255,255,255,0.98);
  padding: 0.55rem 0.65rem;
  font-size: 0.95rem;
  color: var(--ia-text);
  box-shadow: 0 14px 40px rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 30;
}
html.dark-mode .ia-cite__bubble { background: rgba(0,0,0,0.95); }

.ia-cite-wrap {
  position: relative;
  display: inline;
}

.ia-cite-wrap:hover .ia-cite__bubble,
.ia-cite-wrap:focus-within .ia-cite__bubble {
  opacity: 1;
}

/* -------------------------
 * Distill-ish stepper
 * ------------------------- */
.ia-stepper {
  border: 1px solid var(--ia-border);
  border-radius: var(--ia-radius);
  background: var(--ia-bg-soft);
  padding: 0.85rem 0.95rem;
  margin: 1.2rem 0;
}

.ia-stepper__controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ia-stepper__controls button {
  border: 1px solid var(--ia-border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.ia-stepper__progress {
  color: var(--ia-muted);
  font-size: 0.95rem;
}

.ia-stepper__panel {
  margin-top: 0.75rem;
}

.ia-stepper__panel[hidden] { display: none; }

/* -------------------------
 * Horizontal sequence scroller (x-axis)
 * ------------------------- */
.ia-xscrolly {
  /* single, full-width widget (figure + horizontal rail) */
  display: block;
  margin: 1.2rem 0;
}

@media (max-width: 900px) {
  .ia-xscrolly {
    display: block;
  }
}

.ia-xscrolly__figure {
  border: 1px solid var(--ia-border);
  border-radius: var(--ia-radius);
  background: var(--ia-bg-soft);
  padding: 0.75rem;
  width: 100%;
}

.ia-xscrolly__figure canvas {
  width: 100%;
  height: auto;
  display: block;
  cursor: ew-resize;
  touch-action: none;
}

.ia-xscrolly__hint {
  margin-top: 0.55rem;
  color: var(--ia-muted);
  font-size: 0.92rem;
}

.ia-tooltip:hover .ia-tooltip__bubble,
.ia-tooltip:focus-within .ia-tooltip__bubble {
  opacity: 1;
}

/* ----
 * Tabs
 * ---- */
.ia-tabs {
  border: 1px solid var(--ia-border);
  border-radius: 10px;
  overflow: clip;
  margin: 1.2rem 0;
}

.ia-tabs__tablist {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem;
  background: transparent;
  border-bottom: 1px solid var(--ia-border);
  flex-wrap: wrap;
}

.ia-tabs__tab {
  border: 1px solid var(--ia-border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 0.95rem;
}

.ia-tabs__tab[aria-selected="true"] {
  background: rgba(0,0,0,0.08);
}
html.dark-mode .ia-tabs__tab[aria-selected="true"] {
  background: rgba(255,255,255,0.08);
}

.ia-tabs__panel {
  padding: 0.8rem 0.9rem;
}

/* Remove extra vertical spacing inside tab panels (Rouge wraps with div.highlight) */
.ia-tabs__panel .highlight { margin: 0; }

.ia-tabs__panel[hidden] { display: none; }

/* -------------
 * Code features
 * ------------- */
pre {
  position: relative;
}

/* Avoid “double boxing”: if Rouge adds a border/background via theme CSS,
   let this stylesheet keep code blocks minimal. */
pre, pre code, .highlight {
  border: 0;
  box-shadow: none;
}

/* Override main.css light-mode borders on Rouge wrappers to avoid double boxes */
html:not(.dark-mode) pre,
html:not(.dark-mode) .highlight,
html:not(.dark-mode) pre.highlight,
html:not(.dark-mode) .highlight pre {
  border: 0 !important;
}

/* Keep a single “code block” visual: background + subtle rounding on the pre only */
pre {
  background: var(--ia-code-bg);
  border-radius: 10px;
}

/* In dark mode, keep code blocks clearly framed */
html.dark-mode pre,
html.dark-mode pre.highlight,
html.dark-mode .highlight pre {
  border: 1px solid rgba(255, 255, 255, 0.32);
}

/* If Rouge wraps as .highlight > pre, make wrapper transparent */
.highlight {
  background: transparent !important;
}

.ia-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.8rem;
  border: 1px solid var(--ia-border);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  background: rgba(255,255,255,0.9);
  color: #111;
  z-index: 10;
  font-weight: 700;
}
html.dark-mode .ia-copy {
  background: rgba(255,255,255,0.10);
  border-color: rgba(255,255,255,0.22);
  color: rgba(255,255,255,0.92);
}

.ia-code-runner {
  border: 1px solid var(--ia-border);
  border-radius: 10px;
  overflow: hidden;
  margin: 1.2rem 0;
}

.ia-code-runner__toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.7rem;
  background: transparent;
  border-bottom: 1px solid var(--ia-border);
}

.ia-code-runner__toolbar button {
  border: 1px solid var(--ia-border);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.ia-code-runner__editor {
  width: 100%;
  font-family: var(--ia-font-mono);
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.7rem;
  border: 0;
  outline: none;
  background: var(--ia-code-bg);
  color: inherit;
  min-height: 160px;
  resize: vertical;
}

.ia-code-runner__output {
  padding: 0.7rem;
  border-top: 1px solid var(--ia-border);
  background: transparent;
  font-family: var(--ia-font-mono);
  white-space: pre-wrap;
}
html.dark-mode .ia-code-runner__output { background: rgba(255,255,255,0.03); }

/* ------------
 * Demo widgets
 * ------------ */
.ia-widget {
  border: 1px solid var(--ia-border);
  border-radius: 10px;
  padding: 0.9rem;
  margin: 1.2rem 0;
  background: transparent;
}

/* -----------------------------
 * Details (native accordion)
 * ----------------------------- */
details {
  border: 0;
  border-left: 3px solid var(--ia-border);
  border-radius: 0;
  padding: 0.2rem 0 0.2rem 0.85rem;
  background: transparent;
  margin: 0.85rem 0;
}

details > summary {
  cursor: pointer;
}

details[open] > summary {
  margin-bottom: 0.55rem;
}

