.directive-pyide code-input {
  margin: 0;
}

/* Not a card itself: its header, the output or canvas below it, and the
   comparison panel are, together. */
.directive-pyide .container {
  border: none;
  border-radius: 0;
  background: none;
}

.directive-pyide .container > .ide-panel-header {
  border: 1px solid var(--color-spacer);
  border-radius: 8px 8px 0 0;
}

.directive-pyide .output,
.directive-pyide .input,
.directive-pyide .canvas-wrapper {
  flex: 1 1 0;
  min-height: 0;
  border: 1px solid var(--color-spacer);
  border-top: none;
  border-radius: 0 0 8px 8px;
}

/* With compare, the panel below the canvas closes its card, and goes with
   the canvas when the narrow layout shows the output instead. */
.directive-pyide .canvas-wrapper:has(+ .ide-compare) {
  border-radius: 0;
}

.directive-pyide .ide-compare {
  border: 1px solid var(--color-spacer);
  border-radius: 0 0 8px 8px;
}

.directive-pyide .canvas-wrapper.hidden + .ide-compare {
  display: none;
}

.directive-pyide .output,
.directive-pyide .input {
  white-space: pre;
  overflow: auto;
}

.directive-pyide .output {
  padding: 16px;
  margin: 0;
  font-family: hyperbook-monospace, monospace;
}

/* Prompt bar, shown while the script waits for input. Styled as its own
   console-like strip below the output/canvas panel so it reads as "the program
   is waiting for you" rather than as part of the page chrome. */
.directive-pyide .stdin {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  flex: 0 0 auto;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid var(--color-brand);
  border-radius: 8px;
  background-color: color-mix(in srgb, var(--color-brand) 7%, transparent);
}

.directive-pyide .stdin.hidden {
  display: none;
}

/* Blinking caret marks the waiting state without needing extra markup. */
.directive-pyide .stdin::before {
  content: "❯";
  flex: 0 0 auto;
  font-family: hyperbook-monospace, monospace;
  font-weight: 700;
  line-height: 1;
  color: var(--color-brand);
  animation: pyide-stdin-caret 1.4s ease-in-out infinite;
}

@keyframes pyide-stdin-caret {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .directive-pyide .stdin::before {
    animation: none;
  }
}

.directive-pyide .stdin .stdin-prompt {
  flex: 0 1 auto;
  min-width: 0;
  font-family: hyperbook-monospace, monospace;
  color: var(--color-text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.directive-pyide .stdin .stdin-prompt:empty {
  display: none;
}

/* Grows to fill the row, and wraps to its own line when the prompt is long. */
.directive-pyide .stdin .stdin-field {
  flex: 1 1 160px;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--color-spacer);
  border-radius: 6px;
  font-family: hyperbook-monospace, monospace;
  font-size: 1em;
  line-height: 1.4;
  background-color: var(--color-background);
  color: var(--color-text);
}

.directive-pyide .stdin .stdin-field:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 25%, transparent);
}

/* Overrides the shared .directive-pyide button reset, which is borderless and
   full-width for the tab/toolbar groups.

   The fill is a tint of the brand mixed into --color-background rather than
   flat --color-brand, and the label is always --color-text. That keeps the
   contrast guaranteed by the theme's own background/text pairing in both
   colour schemes: --color-brand-text is only defined for light mode, and
   --color-brand-dark falls back to --color-brand, so neither can be relied on
   to stay legible against a brand fill. */
.directive-pyide .stdin .stdin-submit {
  flex: 0 0 auto;
  padding: 8px 18px;
  border: 1px solid var(--color-brand);
  border-radius: 6px;
  background-color: color-mix(
    in srgb,
    var(--color-brand) 18%,
    var(--color-background)
  );
  color: var(--color-text);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
}

.directive-pyide .stdin .stdin-submit:hover {
  background-color: color-mix(
    in srgb,
    var(--color-brand) 32%,
    var(--color-background)
  );
}

.directive-pyide .stdin .stdin-submit:active {
  background-color: color-mix(
    in srgb,
    var(--color-brand) 45%,
    var(--color-background)
  );
}

.directive-pyide .stdin .stdin-submit:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

.directive-pyide .output .error-line {
  color: #b42318;
}

.directive-pyide .output .pfem {
  font-family: inherit;
  font-size: 0.9em;
  line-height: 1.5;
  padding: 8px 12px;
  border-left: 3px solid #b42318;
  background: color-mix(in srgb, #b42318 8%, transparent);
  border-radius: 0 4px 4px 0;
  white-space: normal;
}

.directive-pyide .output .pfem p {
  margin: 0 0 4px;
}

.directive-pyide .output .pfem__title {
  font-weight: bold;
  color: #b42318;
  margin-bottom: 4px;
}

.directive-pyide .output .pfem__summary {
  margin-bottom: 4px;
}

.directive-pyide .output .pfem__why {
  color: var(--color-text, #555);
  font-style: italic;
  margin-bottom: 4px;
  opacity: 0.8;
}

.directive-pyide .output .pfem__steps {
  margin: 4px 0 4px 18px;
  padding: 0;
}

.directive-pyide .output .pfem__steps li {
  margin: 2px 0;
}

.directive-pyide .output .pfem__details {
  margin-top: 6px;
}

.directive-pyide .output .pfem__details > summary {
  cursor: pointer;
  opacity: 0.6;
  font-size: 0.85em;
  user-select: none;
}

.directive-pyide .output .pfem__details > summary:hover {
  opacity: 1;
}

.directive-pyide .output .pfem__details pre {
  margin: 4px 0 0;
  font-family: hyperbook-monospace, monospace;
  font-size: 0.85em;
  white-space: pre-wrap;
  color: #b42318;
  opacity: 0.85;
}

.directive-pyide .canvas-wrapper {
  overflow: auto;
  background-color: #e8e8e8;
  background-image: linear-gradient(45deg, #cccccc 25%, transparent 25%),
    linear-gradient(-45deg, #cccccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cccccc 75%),
    linear-gradient(-45deg, transparent 75%, #cccccc 75%);
  background-size: 20px 20px;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0px;
}

.directive-pyide .canvas {
  display: block;
  width: auto;
  height: auto;
}

.directive-pyide .hidden {
  display: none;
}

.directive-pyide .editor.running {
  pointer-events: none;
  opacity: 0.7;
}

.directive-pyide.locked-by-other {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

.directive-pyide.locked-by-other .buttons {
  border-color: #f59e0b;
}

.directive-pyide button.running {
  pointer-events: none;
  cursor: not-allowed;
  opacity: 0.5;
}

.directive-pyide button.stopping {
  pointer-events: auto;
  cursor: progress;
  opacity: 0.75;
}

.directive-pyide button.locked {
  color: #b45309;
  font-weight: 600;
}

.directive-pyide button.stop {
  flex: 0 0 auto;
  min-width: 96px;
  color: #b42318;
}

.directive-pyide button.stop:disabled {
  color: var(--color-text);
  opacity: 0.5;
  cursor: not-allowed;
}

/* The report of a test run, in place of the output. */
.directive-pyide .pyide-tests {
  --pyide-test-passed: #16a34a;
  --pyide-test-failed: #dc2626;
  --pyide-test-error: #d97706;
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* The output panel keeps text as printed; the report is not text. */
  white-space: normal;
  font-family: hyperbook-body, sans-serif;
}

.directive-pyide .pyide-tests-summary {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-weight: 600;
}

.directive-pyide .pyide-tests-title {
  flex: 1;
  min-width: 0;
}

.directive-pyide .pyide-tests[data-status="passed"] .pyide-tests-title {
  color: var(--pyide-test-passed);
}

.directive-pyide .pyide-tests[data-status="failed"] .pyide-tests-title {
  color: var(--pyide-test-failed);
}

/* One segment per test, coloured as it finishes. */
.directive-pyide .pyide-tests-bar {
  display: flex;
  gap: 3px;
  height: 6px;
}

.directive-pyide .pyide-tests-segment {
  flex: 1;
  border-radius: 999px;
  background-color: var(--color-spacer);
}

.directive-pyide .pyide-tests-segment[data-status="running"] {
  background-color: var(--color-brand);
  animation: pyide-test-pulse 1s ease-in-out infinite alternate;
}

.directive-pyide .pyide-tests-segment[data-status="passed"] {
  background-color: var(--pyide-test-passed);
}

.directive-pyide .pyide-tests-segment[data-status="failed"] {
  background-color: var(--pyide-test-failed);
}

.directive-pyide .pyide-tests-segment[data-status="error"] {
  background-color: var(--pyide-test-error);
}

@keyframes pyide-test-pulse {
  from {
    opacity: 0.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  .directive-pyide .pyide-tests-segment[data-status="running"] {
    animation: none;
  }
}

.directive-pyide .pyide-tests-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.directive-pyide .pyide-test {
  overflow: hidden;
  border: 1px solid var(--color-spacer);
  border-left: 4px solid var(--color-spacer);
  border-radius: 6px;
}

.directive-pyide .pyide-test[data-status="running"] {
  border-left-color: var(--color-brand);
}

.directive-pyide .pyide-test[data-status="passed"] {
  border-left-color: var(--pyide-test-passed);
}

.directive-pyide .pyide-test[data-status="failed"] {
  border-left-color: var(--pyide-test-failed);
}

.directive-pyide .pyide-test[data-status="error"] {
  border-left-color: var(--pyide-test-error);
}

.directive-pyide .pyide-test[data-status="pending"],
.directive-pyide .pyide-test[data-status="stopped"] {
  opacity: 0.6;
}

.directive-pyide .pyide-test-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
}

/* ✓, ✗ and ! in a coloured circle; a ring while running. */
.directive-pyide .pyide-test-icon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  box-sizing: border-box;
  border: 2px solid var(--color-spacer);
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  line-height: 1;
}

.directive-pyide .pyide-test[data-status="running"] .pyide-test-icon {
  border-color: var(--color-spacer);
  border-top-color: var(--color-brand);
  animation: pyide-test-spin 0.8s linear infinite;
}

.directive-pyide .pyide-test[data-status="passed"] .pyide-test-icon {
  border: none;
  background-color: var(--pyide-test-passed);
}

.directive-pyide .pyide-test[data-status="passed"] .pyide-test-icon::before {
  content: "✓";
}

.directive-pyide .pyide-test[data-status="failed"] .pyide-test-icon {
  border: none;
  background-color: var(--pyide-test-failed);
}

.directive-pyide .pyide-test[data-status="failed"] .pyide-test-icon::before {
  content: "✗";
}

.directive-pyide .pyide-test[data-status="error"] .pyide-test-icon {
  border: none;
  background-color: var(--pyide-test-error);
}

.directive-pyide .pyide-test[data-status="error"] .pyide-test-icon::before {
  content: "!";
}

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

@media (prefers-reduced-motion: reduce) {
  .directive-pyide .pyide-test[data-status="running"] .pyide-test-icon {
    animation: none;
  }
}

.directive-pyide .pyide-test-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: hyperbook-code, monospace;
  font-size: 0.9em;
}

.directive-pyide .pyide-test-status {
  flex: 0 0 auto;
  font-size: 0.85em;
  opacity: 0.8;
}

.directive-pyide .pyide-test[data-status="failed"] .pyide-test-status {
  color: var(--pyide-test-failed);
  opacity: 1;
}

.directive-pyide .pyide-test[data-status="error"] .pyide-test-status {
  color: var(--pyide-test-error);
  opacity: 1;
}

/* What the test printed, as printed. */
.directive-pyide .pyide-test-output {
  padding: 8px 10px;
  border-top: 1px solid var(--color-spacer);
  background-color: var(--color-nav);
  font-family: hyperbook-monospace, monospace;
  font-size: 0.85em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.directive-pyide .pyide-test-output[hidden] {
  display: none;
}

/* A friendly error message, in a row that is already marked. */
.directive-pyide .pyide-test-output .pfem {
  padding: 0;
  border-left: none;
  border-radius: 0;
  background: none;
  font-size: 1em;
}

.directive-pyide .pyide-test-assert {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.directive-pyide .pyide-test-assert-statement {
  color: var(--pyide-test-failed);
  font-family: inherit;
}

.directive-pyide .pyide-test-assert-message {
  font-family: hyperbook-body, sans-serif;
}
