:root { --python-editor-font-size: 19px; }

.ls3-python-editor #ls3PythonSource {
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: 0;
  padding: 0.875rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: var(--python-editor-font-size);
  line-height: 1.55;
  tab-size: 4;
}

.ls3-python-editor .ls3-p5-codemirror.CodeMirror {
  font-size: var(--python-editor-font-size);
}

.ls3-python-editor .ls3-p5-language[disabled] {
  cursor: default;
  opacity: 1;
}

.ls3-python-editor .ls3-p5-language[disabled]:hover {
  background: transparent;
}

.ls3-python-editor .is-python-running-block {
  background: color-mix(in srgb, var(--color-accent) 9%, transparent);
  box-shadow: inset 2px 0 var(--color-accent);
}

.ls3-python-header-controls {
  position: absolute;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  transform: translateX(-50%);
}

.ls3-python-header-controls button {
  display: grid;
  width: var(--workspace-header-control-size);
  height: var(--workspace-header-control-size);
  padding: 0;
  border: 0;
  border-radius: 0.375rem;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  place-items: center;
}

.ls3-python-header-controls button[data-python-action="run"],
.ls3-python-header-controls button[data-python-action="run-block"] {
  color: var(--color-accent);
}

.ls3-python-header-controls button:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ls3-python-header-controls button:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.ls3-python-header-controls button:disabled {
  cursor: default;
  opacity: 0.38;
}

.ls3-python-header-controls svg {
  width: 0.875rem;
  height: 0.875rem;
}

.ls3-python-output {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(9rem, 34%) auto;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.ls3-python-results-panel,
.ls3-python-variables-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
}

.ls3-python-results-panel > header,
.ls3-python-variables-panel > header {
  display: flex;
  min-height: 2rem;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0 0.7rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 0.65rem;
}

.ls3-python-results-panel > header {
  height: var(--ai-header-height);
  min-height: var(--ai-header-height);
}

.ls3-python-variables-panel > header strong {
  color: var(--text-primary);
  font-size: 0.7rem;
}

.ls3-python-output-tabs {
  align-items: center;
}

.ls3-python-output-tab:hover,
.ls3-python-output-tab:focus-visible {
  color: var(--text-primary);
}

.ls3-python-figures-count {
  display: inline-grid;
  min-width: 0.9rem;
  height: 0.9rem;
  margin-left: 0.12rem;
  border-radius: 999px;
  background: var(--color-accent);
  color: white;
  font-size: 0.52rem;
  line-height: 1;
  place-items: center;
}

.ls3-python-figures-count[hidden] { display: none; }

.ls3-python-clear-console {
  display: grid;
  width: calc(var(--workspace-header-control-size) - 4px);
  height: calc(var(--workspace-header-control-size) - 4px);
  padding: 0;
  border: 0;
  border-radius: 0.4375rem;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  place-items: center;
}

.ls3-python-clear-console svg {
  width: 0.875rem;
  height: 0.875rem;
}

.ls3-python-clear-console:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ls3-python-console-view,
.ls3-python-figures-view {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
}

.ls3-python-console-view {
  display: flex;
  flex-direction: column;
}

.ls3-python-console-view[hidden],
.ls3-python-figures-view[hidden] {
  display: none;
}

.ls3-python-console {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  margin: 0;
  padding: 0.8rem;
  outline: 0;
  background: color-mix(in srgb, var(--bg-primary) 62%, var(--bg-secondary));
  color: var(--text-primary);
  font: 0.73rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  tab-size: 4;
  white-space: pre-wrap;
  word-break: break-word;
}

.ls3-python-console:empty::before {
  color: var(--text-tertiary);
  content: 'Program output appears here.';
}

.ls3-python-figures-view {
  overflow: auto;
  background: color-mix(in srgb, var(--bg-primary) 62%, var(--bg-secondary));
}

.ls3-python-figures {
  display: grid;
  align-content: start;
  gap: 0.75rem;
  min-height: 100%;
  padding: 0.8rem;
}

.ls3-python-figures-empty {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 0.68rem;
}

.ls3-python-figure {
  min-width: 0;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--border-light);
  border-radius: 0.55rem;
  background: white;
}

.ls3-python-figure img {
  display: block;
  width: 100%;
  max-height: clamp(14rem, 48vh, 30rem);
  object-fit: contain;
}

.ls3-python-figure figcaption {
  display: flex;
  min-height: 2rem;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border-top: 1px solid #e5e7eb;
  background: #f8fafc;
  color: #334155;
  font-size: 0.64rem;
  font-weight: 650;
}

.ls3-python-figure figcaption span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ls3-python-figure figcaption a {
  display: grid;
  width: 1.45rem;
  height: 1.45rem;
  flex: 0 0 auto;
  border-radius: 0.32rem;
  color: #64748b;
  place-items: center;
}

.ls3-python-figure figcaption a:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.ls3-python-figure figcaption svg {
  width: 0.82rem;
  height: 0.82rem;
}

.ls3-python-stream-stderr { color: #b91c1c; }
.ls3-python-stream-input { color: var(--color-accent); }
[data-theme="dark"] .ls3-python-stream-stderr { color: #fca5a5; }

.ls3-python-input {
  flex: 0 0 auto;
  border-top: 1px solid var(--border-light);
  background: var(--bg-secondary);
}

.ls3-python-input summary {
  padding: 0.38rem 0.7rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.625rem;
  font-weight: 650;
  user-select: none;
}

.ls3-python-input label {
  display: block;
  padding: 0 0.7rem 0.6rem;
}

.ls3-python-input label span {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text-tertiary);
  font-size: 0.6rem;
}

.ls3-python-input textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 0.45rem;
  outline: 0;
  padding: 0.45rem 0.55rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font: 0.7rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.ls3-python-input textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 0.14rem color-mix(in srgb, var(--color-accent) 15%, transparent);
}

.ls3-python-variables-panel {
  border-top: 1px solid var(--border);
}

.ls3-python-variables-panel > header span {
  color: var(--text-tertiary);
  font-size: 0.6rem;
}

.ls3-python-variables {
  min-height: 0;
  overflow: auto;
  padding: 0.35rem 0.5rem 0.65rem;
}

.ls3-python-variables-empty {
  margin: 0;
  padding: 0.75rem 0.25rem;
  color: var(--text-tertiary);
  font-size: 0.65rem;
}

.ls3-python-variable {
  min-width: 0;
  border-radius: 0.38rem;
}

.ls3-python-variable[open] {
  background: color-mix(in srgb, var(--color-accent) 5%, transparent);
}

.ls3-python-variable-heading {
  display: grid;
  grid-template-columns: minmax(4rem, 0.7fr) minmax(2.8rem, auto) minmax(5rem, 1.5fr);
  min-width: 0;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.32rem 0.45rem;
  color: var(--text-primary);
  font-size: 0.65rem;
  list-style-position: inside;
}

summary.ls3-python-variable-heading { cursor: pointer; }

.ls3-python-variable-heading strong,
.ls3-python-variable-heading small,
.ls3-python-variable-heading code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ls3-python-variable-heading strong {
  color: var(--p5-syntax-variable, #0369a1);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.ls3-python-variable-heading small { color: var(--text-tertiary); }
.ls3-python-variable-heading code { color: var(--text-secondary); }
.ls3-python-variable-preview {
  overflow: auto;
  margin: 0 0.45rem 0.42rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.32rem;
  background: color-mix(in srgb, var(--bg-primary) 68%, var(--bg-secondary));
  color: var(--text-secondary);
  font: 0.61rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre;
}
.ls3-python-variable-children { padding: 0 0.25rem 0.28rem 0.85rem; }
.ls3-python-variable.is-child .ls3-python-variable-heading { font-size: 0.61rem; }

.ls3-python-controls {
  display: flex;
  min-height: 1.75rem;
  align-items: center;
  gap: 0.38rem;
  padding: 0 0.55rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.ls3-python-status {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  margin: 0;
  color: var(--text-tertiary);
  font-size: 0.625rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ls3-python-status[data-state="error"] { color: #b91c1c; }
[data-theme="dark"] .ls3-python-status[data-state="error"] { color: #fca5a5; }

@media (max-width: 760px) {
  .ls3-python-output { grid-template-rows: minmax(0, 1fr) minmax(7rem, 30%) auto; }
  .ls3-python-variables-panel > header span { display: none; }
  .ls3-python-status { display: none; }
}
