.pyrepl-drawer,
.pyrepl-toggle {
  /*
    Match programmareinpython.it palette (see `pip.css`).
    - Accent: Yellow 1 (#ECBE13)
    - Accent hover: Yellow 3 (#FFD558)
    - Surfaces: Academy Darkness (#22272E) / Tailwind-ish dark (#111827, #1f2937)
  */
  --pyrepl-accent: #ecbe13;
  --pyrepl-accent-rgb: 236, 190, 19;
  --pyrepl-accent-contrast: #18364d;
  --pyrepl-accent-hover: #ffd558;

  --pyrepl-bg: #22272e;
  --pyrepl-surface: #1f2937;
  --pyrepl-surface-2: #111827;
  --pyrepl-text: #e5e7eb;
  --pyrepl-text-muted: rgba(229, 231, 235, 0.7);

  /* Icon buttons sizing - larger for better touch targets */
  --pyrepl-icon-btn-size: 42px;
  --pyrepl-icon-size: 20px;
}

.pyrepl-toggle {
  border: 0;
  width: 100%;
  height: 100%;
  padding: 10px 14px;
  font-weight: 800;
  background: transparent;
  color: var(--pyrepl-text);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  letter-spacing: 0.2px;
}

.pyrepl-toggle:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.pyrepl-toggle:active:not(:disabled) {
  transform: translateY(1px);
}

.pyrepl-toggle:focus {
  outline: 2px solid rgba(var(--pyrepl-accent-rgb), 0.85);
  outline-offset: -2px;
}

.pyrepl-launchbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  z-index: 10050;
  background: rgba(
    17,
    24,
    39,
    0.92
  ); /* --pyrepl-surface-2, with transparency */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
}

.pyrepl-launchbar::before {
  /* Subtle accent line (static, non-distracting) */
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    rgba(var(--pyrepl-accent-rgb), 0) 0%,
    rgba(var(--pyrepl-accent-rgb), 0.9) 50%,
    rgba(var(--pyrepl-accent-rgb), 0) 100%
  );
  opacity: 0.65;
  pointer-events: none;
}

.pyrepl-launchbar-inner {
  height: 100%;
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 10px;
  display: flex;
  align-items: stretch;
}

.pyrepl-launchbar-main {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pyrepl-launchbar .pyrepl-toggle .fa {
  color: rgba(var(--pyrepl-accent-rgb), 0.95);
  font-size: 18px;
  flex: 0 0 auto;
}

.pyrepl-launchbar-text {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  gap: 2px;
}

.pyrepl-launchbar-title {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.1;
}

.pyrepl-launchbar-subtitle {
  font-size: 12px;
  line-height: 1.1;
  color: var(--pyrepl-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: min(760px, 70vw);
}

.pyrepl-launchbar-cta {
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
  /* Simpler, professional pastel/flat look */
  background: var(--pyrepl-accent);
  color: var(--pyrepl-accent-contrast);
  font-weight: 700;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition:
    background 140ms ease,
    transform 140ms ease,
    box-shadow 140ms ease;
}

/* Shine effect removed (less flashy) */
.pyrepl-launchbar-cta::before {
  content: none;
  display: none;
}

.pyrepl-toggle:hover:not(:disabled) .pyrepl-launchbar-cta,
.pyrepl-toggle:focus .pyrepl-launchbar-cta {
  background: var(--pyrepl-accent-hover);
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

/* Simplify animations: remove the pulse on the CTA */
body:not(.pyrepl-launchbar-open) .pyrepl-launchbar-cta {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  body:not(.pyrepl-launchbar-open) .pyrepl-launchbar .fa-terminal,
  body:not(.pyrepl-launchbar-open) .pyrepl-launchbar-cta {
    animation: none !important;
  }
}

/* Ensure content isn't hidden behind the bar (only on pages that include this CSS). */
body {
  padding-bottom: 64px;
}

/* Hide the launcher while open (mobile + desktop). */
body.pyrepl-launchbar-open .pyrepl-launchbar {
  display: none;
}

/* On mobile we don't apply `.pyrepl-open`, so avoid leaving a blank gap when open. */
body.pyrepl-launchbar-open:not(.pyrepl-open) {
  padding-bottom: 0;
}

.pyrepl-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10040;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.pyrepl-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.pyrepl-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--pyrepl-drawer-height, min(70vh, 720px));
  z-index: 10060;
  transform: translateY(105%);
  transition: transform 220ms ease;

  display: flex;
  flex-direction: column;
  background: var(--pyrepl-bg);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
}

.pyrepl-resize-handle {
  flex: 0 0 auto;
  height: 10px;
  cursor: ns-resize;
  position: relative;
  touch-action: none;
  user-select: none;
}

.pyrepl-desktop-resize-handle {
  /* Desktop-only (dock-right) resize handle; hidden by default. */
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: -6px; /* sit on the seam between page and panel */
  width: 12px;
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  z-index: 5;
}

.pyrepl-desktop-resize-handle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 56px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.pyrepl-desktop-resize-handle:focus {
  outline: 2px solid rgba(var(--pyrepl-accent-rgb), 0.7);
  outline-offset: 2px;
}

.pyrepl-resize-handle::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.pyrepl-drawer.is-open {
  transform: translateY(0);
}

.pyrepl-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.pyrepl-status {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 120px;
  font-size: 12px;
  color: var(--pyrepl-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.pyrepl-status.is-visible {
  opacity: 1;
}

.pyrepl-status.is-loading::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: rgba(var(--pyrepl-accent-rgb), 0.95);
  animation: pyreplSpin 800ms linear infinite;
  flex: 0 0 auto;
}

@keyframes pyreplSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Loading overlay + progress bar (hide terminal UI while Pyodide loads) */
.pyrepl-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  background: rgba(17, 24, 39, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none; /* allow header buttons (close) to work */
  transition: opacity 160ms ease;
}

.pyrepl-drawer.is-loading .pyrepl-loading-overlay {
  opacity: 1;
}

.pyrepl-drawer.is-loading .pyrepl-body {
  visibility: hidden;
}

.pyrepl-loading-title {
  font-weight: 900;
  font-size: 13px;
  color: var(--pyrepl-text);
  text-align: center;
}

.pyrepl-loading-subtitle {
  font-size: 12px;
  color: var(--pyrepl-text-muted);
  text-align: center;
  max-width: 680px;
}

.pyrepl-progress {
  width: min(560px, 88vw);
}

.pyrepl-progress-track {
  position: relative;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.pyrepl-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: rgba(var(--pyrepl-accent-rgb), 0.95);
  transition: width 140ms ease;
}

.pyrepl-progress-track.is-indeterminate .pyrepl-progress-bar {
  width: 40%;
  position: absolute;
  left: -40%;
  animation: pyreplIndeterminate 1200ms ease-in-out infinite;
  transition: none;
}

@keyframes pyreplIndeterminate {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}

.pyrepl-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--pyrepl-text-muted);
}

/* Desktop bottom-dock (NOT right-dock): keep the header much thinner. */
body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-header {
  /* Top padding = 0 when docked at bottom */
  padding: 0 10px 6px;
  gap: 8px;
  /* Remove separator line between header and body in bottom dock */
  border-bottom: 0;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-actions {
  gap: 6px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-title {
  font-size: 13px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-header .pyrepl-btn {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 9px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-drawer {
  --pyrepl-icon-btn-size: 36px;
  --pyrepl-icon-size: 18px;
}

/* Bottom dock: make the overall UI ~1/3 smaller (keep right-dock unchanged). */
body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-drawer {
  /* Reduce default height by ~1/3 (user-resize still wins via --pyrepl-drawer-height). */
  height: var(--pyrepl-drawer-height, min(46vh, 480px));
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-body {
  padding: 6px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-pane--code,
body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-pane--output {
  border-radius: 10px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-pane--code {
  padding: 8px;
  gap: 6px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-output {
  padding: 8px 10px;
  font-size: 12px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-input {
  min-height: 96px;
  padding: 8px 10px;
  font-size: 12px;
}

/* CodeMirror compact sizing (bottom dock) */
body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-pane--code .CodeMirror,
body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-input {
  min-height: 96px;
  padding: 8px 10px;
  font-size: 12px;
  border-radius: 10px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-footer {
  margin-top: 6px;
  gap: 8px;
}

body.pyrepl-open:not(.pyrepl-dock-right) .pyrepl-hint {
  margin-top: 4px;
  font-size: 11px;
}

.pyrepl-title {
  font-weight: 800;
  font-size: 14px;
  color: var(--pyrepl-text);
  margin: 0;
}

.pyrepl-title .fa {
  margin-right: 8px;
}

.pyrepl-visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.pyrepl-btn--icon {
  /* Marker class; real layout is defined on `.pyrepl-btn.pyrepl-btn--icon` below. */
}

.pyrepl-actions {
  display: flex;
  gap: 8px;
}

.pyrepl-btn {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--pyrepl-text);
  border-radius: 10px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 13px;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
}

/* Icon buttons: override generic/header paddings and center precisely */
.pyrepl-btn.pyrepl-btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--pyrepl-icon-btn-size);
  height: var(--pyrepl-icon-btn-size);
  padding: 0;
  line-height: 1;
}

.pyrepl-btn.pyrepl-btn--icon .fa {
  display: block;
  margin: 0;
  font-size: var(--pyrepl-icon-size);
  line-height: 1;
}

/* Header has its own padding rules; force icon buttons to remain centered */
body.pyrepl-open:not(.pyrepl-dock-right)
  .pyrepl-header
  .pyrepl-btn.pyrepl-btn--icon {
  padding: 0;
}

.pyrepl-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.26);
}

.pyrepl-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.pyrepl-btn:focus {
  outline: 2px solid rgba(var(--pyrepl-accent-rgb), 0.7);
  outline-offset: 2px;
}

.pyrepl-btn--ghost {
  background: rgba(255, 255, 255, 0.04);
}

.pyrepl-btn--primary {
  background: var(--pyrepl-accent);
  border-color: rgba(0, 0, 0, 0.15);
  color: var(--pyrepl-accent-contrast);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
}

.pyrepl-btn--primary:hover:not(:disabled) {
  /* Avoid "weird" filtered hover; use the site's accent hover color instead. */
  background: var(--pyrepl-accent-hover);
  filter: none;
}

.pyrepl-btn--primary:focus {
  outline: 2px solid rgba(var(--pyrepl-accent-rgb), 0.9);
  outline-offset: 2px;
}

.pyrepl-btn--primary .fa {
  margin-right: 8px;
}

.pyrepl-btn.is-attention:not(:disabled) {
  animation: pyreplPulse 1.35s ease-in-out infinite;
}

@keyframes pyreplPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(var(--pyrepl-accent-rgb), 0.55);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(var(--pyrepl-accent-rgb), 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(var(--pyrepl-accent-rgb), 0);
  }
}

.pyrepl-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.pyrepl-body {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--pyrepl-code-col, 1fr) var(
      --pyrepl-splitter-size,
      10px
    ) 1fr;
  min-height: 0;
  padding: 10px;
}

.pyrepl-pane {
  min-height: 0; /* allow internal scroll areas in CSS grid */
}

.pyrepl-pane--code {
  padding: 12px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--pyrepl-surface);
  /* Very faint border (almost borderless) */
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  overflow: hidden;
}

/* CodeMirror editor styling (MIT licensed) */
.pyrepl-pane--code .CodeMirror {
  flex: 1 1 auto;
  width: 100%;
  min-height: 120px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: var(--pyrepl-surface-2);
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.pyrepl-pane--code .CodeMirror-focused {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.pyrepl-pane--code .CodeMirror-scroll {
  min-height: 120px;
}

.pyrepl-splitter {
  cursor: col-resize;
  background: transparent;
  touch-action: none;
  user-select: none;
  position: relative;
}

.pyrepl-splitter::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.pyrepl-splitter:focus {
  outline: 2px solid rgba(var(--pyrepl-accent-rgb), 0.7);
  outline-offset: -2px;
}

.pyrepl-pane--output {
  background: var(--pyrepl-surface);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  overflow: hidden;
}

.pyrepl-output {
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  white-space: pre-wrap;
  min-height: 100%;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 13px;
  color: var(--pyrepl-text);
}

.pyrepl-input {
  width: 100%;
  min-height: 120px;
  flex: 1 1 auto;
  resize: none;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: var(--pyrepl-surface-2);
  color: var(--pyrepl-text);
  padding: 10px 12px;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 13px;
}

.pyrepl-input::selection {
  background: rgba(var(--pyrepl-accent-rgb), 0.35);
}

.pyrepl-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.16);
}

.pyrepl-run-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
}

.pyrepl-run-callout {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(var(--pyrepl-accent-rgb), 0.95);
  color: var(--pyrepl-accent-contrast);
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
  pointer-events: none;
  z-index: 2;
}

.pyrepl-run-callout::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 100%;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(var(--pyrepl-accent-rgb), 0.95);
}

.pyrepl-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.pyrepl-run-callout.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.pyrepl-hint {
  margin-top: 8px;
  /* Slight yellow tint (site accent), still subtle */
  color: rgba(var(--pyrepl-accent-rgb), 0.78);
  font-size: 12px;
}

@media (max-width: 576px) {
  .pyrepl-drawer {
    /* Larger touch targets for mobile */
    --pyrepl-icon-btn-size: 48px;
    --pyrepl-icon-size: 22px;
  }

  /* Hide dock toggle on mobile - only meaningful on desktop */
  #pyrepl-dock-toggle {
    display: none;
  }

  /* Hide keyboard shortcut hint on mobile - not applicable */
  .pyrepl-hint {
    display: none;
  }

  /* Hide title text on mobile - keep icon, save space */
  .pyrepl-title-text {
    display: none;
  }

  .pyrepl-header .pyrepl-btn.pyrepl-btn--icon {
    padding: 0;
  }

  .pyrepl-drawer {
    height: var(--pyrepl-drawer-height, 78vh);
  }
  .pyrepl-launchbar {
    height: 72px;
  }

  body {
    padding-bottom: 72px;
  }

  body.pyrepl-launchbar-open:not(.pyrepl-open) {
    padding-bottom: 0;
  }

  /* On very small screens, allow the hint to wrap to 2 lines. */
  .pyrepl-launchbar-subtitle {
    white-space: normal;
    max-width: 100%;
  }

  /* Mobile (always bottom drawer): compact header. */
  .pyrepl-header {
    /* Top padding = 0 when docked at bottom */
    padding: 0 10px 8px;
    gap: 8px;
  }

  /* Mobile: remove header/body separator line. */
  .pyrepl-header {
    border-bottom: 0;
  }

  .pyrepl-actions {
    gap: 8px;
  }

  /* Only apply compact padding to non-icon buttons */
  .pyrepl-header .pyrepl-btn:not(.pyrepl-btn--icon) {
    padding: 6px 10px;
    font-size: 12px;
  }

  /* Ensure icon buttons stay square and don't get squished */
  .pyrepl-header .pyrepl-btn.pyrepl-btn--icon {
    min-width: var(--pyrepl-icon-btn-size);
    width: var(--pyrepl-icon-btn-size);
    height: var(--pyrepl-icon-btn-size);
    flex-shrink: 0;
  }

  .pyrepl-body {
    grid-template-columns: 1fr;
    grid-template-rows: var(--pyrepl-code-row, 1fr) var(
        --pyrepl-splitter-size,
        10px
      ) 1fr;
    padding: 10px;
  }

  .pyrepl-splitter {
    cursor: row-resize;
  }

  .pyrepl-splitter::before {
    width: 44px;
    height: 3px;
  }

  /* Keep the Run button visible: stack hint + button vertically. */
  .pyrepl-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .pyrepl-run-wrap {
    width: 100%;
    justify-content: stretch;
  }

  #pyrepl-run {
    width: 100%;
    justify-content: center;
  }
}

/* Desktop: bottom dock by default (page contracts, no overlay) */
@media (min-width: 992px) {
  /* Keep the page interactive on desktop. */
  .pyrepl-overlay {
    display: none;
  }

  /* Default open state: reserve space below for the docked terminal. */
  body.pyrepl-open {
    padding-bottom: calc(
      var(--pyrepl-open-height, var(--pyrepl-drawer-height, min(70vh, 720px))) +
        16px
    );
  }

  /* Dock-right mode (toggled by button) */
  body.pyrepl-open.pyrepl-dock-right {
    padding-bottom: 0;
    padding-right: calc(var(--pyrepl-desktop-width, 420px) + 32px);
  }

  body.pyrepl-open.pyrepl-dock-right .pyrepl-drawer {
    left: auto;
    right: 16px;
    bottom: 16px;
    top: var(--pyrepl-desktop-top, 76px);
    width: var(--pyrepl-desktop-width, 420px);
    height: auto;

    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    overflow: hidden;

    /* Slide in from the right when opened in dock-right mode */
    transform: translateX(calc(100% + 24px));
  }

  body.pyrepl-open.pyrepl-dock-right .pyrepl-drawer.is-open {
    transform: translateX(0);
  }

  body.pyrepl-open.pyrepl-dock-right .pyrepl-desktop-resize-handle {
    display: block;
  }

  /* The height-resize handle is only meaningful for the bottom dock */
  body.pyrepl-open.pyrepl-dock-right .pyrepl-resize-handle {
    display: none;
  }

  /* Right dock should be stacked: code (top) + output (bottom) */
  body.pyrepl-open.pyrepl-dock-right .pyrepl-body {
    grid-template-columns: 1fr;
    grid-template-rows: var(--pyrepl-code-row, 1fr) var(
        --pyrepl-splitter-size,
        10px
      ) 1fr;
  }

  body.pyrepl-open.pyrepl-dock-right .pyrepl-splitter {
    cursor: row-resize;
  }

  body.pyrepl-open.pyrepl-dock-right .pyrepl-splitter::before {
    width: 44px;
    height: 3px;
  }

  /* Avoid header button cropping when wrapping */
  .pyrepl-header {
    flex-wrap: wrap;
  }

  /* Dedicated dock button: hide on mobile-only layouts */
  #pyrepl-dock-toggle {
    display: inline-flex;
  }
}

/* Fullscreen mode overrides */
.pyrepl-drawer.is-fullscreen {
  /* Override user-resized height/width */
  height: 100% !important;
  width: 100% !important;
  top: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  transform: none !important; /* Ensure no translation hacks affect it */
  border-radius: 0 !important;
  border: 0 !important;
  z-index: 10100; /* Higher than normal drawer/overlay */
}

.pyrepl-drawer.is-fullscreen .pyrepl-resize-handle,
.pyrepl-drawer.is-fullscreen .pyrepl-desktop-resize-handle {
  display: none !important;
}

/* Ensure body doesn't scroll when fullscreen */
body.pyrepl-fullscreen-active {
  overflow: hidden;
  /* Reset dock paddings so they don't affect the page behind (cleaner) */
  padding-right: 0 !important;
  padding-bottom: 0 !important;
}
