/* Tighter line height for body text */
.md-typeset {
  line-height: 1.65;
}

/* Better display equations */
.md-typeset .arithmatex {
  overflow-x: auto;
}

/* Subtle figure captions */
.md-typeset figure figcaption {
  font-size: 0.85em;
  color: var(--md-default-fg-color--light);
  text-align: center;
  margin-top: 0.5em;
}

/* Chapter-opening hero */
.chapter-hero {
  background: linear-gradient(135deg, #5e35b1 0%, #3949ab 100%);
  color: white;
  padding: 2rem 1.5rem;
  border-radius: 8px;
  margin: 1rem 0 2rem 0;
}
.chapter-hero h1 { color: white; margin-top: 0; }

/* Difficulty badges for exercises */
.diff-easy, .diff-med, .diff-hard {
  display: inline-block;
  padding: 0.1em 0.6em;
  border-radius: 999px;
  font-size: 0.75em;
  font-weight: 600;
  margin-right: 0.5em;
}
.diff-easy { background: #c8e6c9; color: #1b5e20; }
.diff-med  { background: #fff9c4; color: #6d4c00; }
.diff-hard { background: #ffcdd2; color: #b71c1c; }

/* Print styles */
@media print {
  .md-header, .md-tabs, .md-sidebar, .md-footer { display: none !important; }
  .md-main__inner { margin: 0; }
  .md-content { max-width: 100%; }
  .pyodide-wrap .pyodide-run-btn { display: none; }
}

/* ----- Inline Pyodide Run buttons ----- */

.pyodide-wrap {
  position: relative;
  margin: 1em 0;
}

.pyodide-run-btn {
  position: absolute;
  top: 0.4em;
  right: 0.4em;
  background: rgba(94, 53, 177, 0.92);
  color: #fff;
  border: none;
  padding: 0.25em 0.75em;
  font-size: 0.78em;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  z-index: 2;
  transition: background 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

.pyodide-run-btn:hover:not(:disabled) {
  background: rgba(69, 39, 160, 1);
}

.pyodide-run-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.pyodide-icon {
  font-size: 0.85em;
  line-height: 1;
}

.pyodide-output {
  margin-top: 0.5em;
  padding: 0.75em 1em;
  background: var(--md-code-bg-color, #f5f5f5);
  border-left: 3px solid #5e35b1;
  border-radius: 0 4px 4px 0;
  font-size: 0.85em;
  overflow-x: auto;
}

.pyodide-output pre {
  margin: 0;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--md-code-font-family, "JetBrains Mono", monospace);
}

.pyodide-stdout {
  color: var(--md-default-fg-color, #1a1a1a);
}

.pyodide-error {
  color: #c62828;
  background: rgba(198, 40, 40, 0.06);
  padding: 0.5em;
  border-radius: 4px;
  margin-top: 0.5em;
}

[data-md-color-scheme="slate"] .pyodide-error {
  color: #ef9a9a;
  background: rgba(239, 154, 154, 0.1);
}

.pyodide-note {
  color: var(--md-default-fg-color--light, #666);
  font-style: italic;
}

.pyodide-note code {
  font-style: normal;
}

.pyodide-plot {
  display: block;
  max-width: 100%;
  margin-top: 0.5em;
  border-radius: 4px;
  background: #fff;
  padding: 4px;
}

[data-md-color-scheme="slate"] .pyodide-plot {
  background: #1e1e2a;
}

/* ----- Interactive slider widgets ----- */

.pyodide-widget-panel {
  margin: 1em 0 0 0;
  padding: 0.6em 0.9em 0.7em 0.9em;
  background: linear-gradient(135deg, rgba(94, 53, 177, 0.08) 0%, rgba(57, 73, 171, 0.08) 100%);
  border: 1px solid rgba(94, 53, 177, 0.35);
  border-radius: 6px 6px 0 0;
  border-bottom: none;
  font-size: 0.85em;
}

[data-md-color-scheme="slate"] .pyodide-widget-panel {
  background: linear-gradient(135deg, rgba(94, 53, 177, 0.18) 0%, rgba(57, 73, 171, 0.18) 100%);
  border-color: rgba(149, 117, 205, 0.5);
}

.pyodide-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4em;
  font-size: 0.9em;
}

.pyodide-widget-title {
  font-weight: 600;
  color: #5e35b1;
  letter-spacing: 0.02em;
}

[data-md-color-scheme="slate"] .pyodide-widget-title {
  color: #b39ddb;
}

.pyodide-widget-status {
  font-size: 0.85em;
  color: var(--md-default-fg-color--light, #666);
  font-style: italic;
}

.pyodide-slider-row {
  display: grid;
  grid-template-columns: minmax(8em, 14em) 1fr 4em;
  align-items: center;
  gap: 0.6em;
  padding: 0.18em 0;
}

.pyodide-slider-label {
  font-weight: 500;
  color: var(--md-default-fg-color, #1a1a1a);
}

.pyodide-slider {
  width: 100%;
  accent-color: #5e35b1;
  cursor: pointer;
}

.pyodide-slider-value {
  font-family: var(--md-code-font-family, "JetBrains Mono", monospace);
  font-size: 0.9em;
  color: #5e35b1;
  text-align: right;
}

[data-md-color-scheme="slate"] .pyodide-slider-value {
  color: #b39ddb;
}

/* When a widget is active, square off the top of the code block so the
   slider panel and the code visually belong together. */
.pyodide-widget-panel + div[class*="language-python"] > pre {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.pyodide-widget-output {
  margin-top: 0.5em;
}

@media (max-width: 600px) {
  .pyodide-slider-row {
    grid-template-columns: 1fr;
    gap: 0.15em;
  }
  .pyodide-slider-value {
    text-align: left;
  }
}
