.source-code-block {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.source-code-panel {
  position: relative;
  width: 100%;
  min-width: 0;
  max-height: 480px;
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.source-code-toolbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-height: 40px;
  padding: 4px 8px;
  background: var(--surface);
  user-select: none;
}

.source-code-language {
  margin-right: auto;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}

.source-code-language:hover {
  color: var(--text);
  background: var(--hover);
}

.source-code-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 6px;
  border: 0;
  border-radius: 6px;
  outline: none;
  background: var(--transparent);
  color: var(--muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 80ms ease;
}

.source-code-button[hidden] {
  display: none;
}

.source-code-button svg {
  width: 18px;
  height: 18px;
}

.source-code-button:hover {
  background: var(--hover);
  color: var(--white);
}

.source-code-button:active {
  transform: scale(0.94);
}

.source-code-button.copied {
  color: var(--brand);
}

.source-code-button.running {
  color: var(--brand);
}

.source-code-button.running svg {
  display: none;
}

.source-code-button.running::after {
  content: "";
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--brand);
}

.source-code-surface {
  --code-lines: 1;
  --code-font-size: 14px;
  --code-line-height: 24px;
  --code-padding-top: 8px;
  --code-padding-bottom: 16px;
  --code-padding-horizontal: 16px;
  --code-max-height: 432px;
  position: relative;
  width: calc(100% - var(--code-padding-horizontal) * 2);
  min-width: 0;
  height: min(calc(var(--code-lines) * var(--code-line-height) + var(--code-padding-top) + var(--code-padding-bottom)), var(--code-max-height));
  margin: 0 var(--code-padding-horizontal);
  overflow: hidden;
}

.source-code-input,
.source-code-highlight {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: var(--code-padding-top) 0 var(--code-padding-bottom);
  border: 0;
  outline: none;
  box-sizing: border-box;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: var(--code-font-size);
  font-weight: 400;
  font-style: normal;
  line-height: var(--code-line-height);
  letter-spacing: 0;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  font-variant-ligatures: none;
  text-align: left;
}

.source-code-highlight {
  position: absolute;
  inset: 0;
  background: var(--transparent);
  color: var(--code-default);
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.source-code-highlight span {
  font-weight: inherit;
  font-style: inherit;
}

.source-code-input {
  position: relative;
  z-index: 2;
  max-height: none;
  resize: none;
  background: var(--transparent);
  color: var(--transparent);
  caret-color: var(--white);
  -webkit-text-fill-color: var(--transparent);
  overflow: auto;
}

.source-code-input::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
}

.source-code-input::selection {
  background: var(--brand-soft);
}

.source-code-output {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 0;
  max-height: 320px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--sidebar);
  overflow: hidden;
}

.source-code-output[hidden] {
  display: none;
}

.source-code-output.failed {
  border-color: var(--danger);
}

.source-output-header {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  border-bottom: 2px solid var(--border);
}

.source-output-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  color: var(--secondary);
  font-size: 12px;
  font-weight: 600;
}

.source-output-title svg {
  width: 16px;
  height: 16px;
}

.source-output-text {
  min-height: 28px;
  max-height: 240px;
  margin: 0;
  padding: 8px 4px;
  color: var(--text);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 14px;
  line-height: 160%;
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  user-select: text;
}

.source-output-status {
  min-height: 20px;
  padding: 4px;
  color: var(--muted);
  font-size: 12px;
}

.source-code-output.failed .source-output-status {
  color: var(--danger);
}

.code-language-overlay {
  position: fixed;
  inset: 0;
  z-index: 2048;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #00000088;
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 200ms ease;
}

.code-language-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.code-language-window {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 344px;
  max-width: 100%;
  max-height: calc(100dvh - 48px);
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--sidebar);
  box-shadow: 0 16px 48px var(--shadow);
  overflow-y: auto;
  transform: translateY(8px) scale(0.96);
  transition: transform 200ms var(--transition-ease);
}

.code-language-overlay.visible .code-language-window {
  transform: translateY(0) scale(1);
}

.code-language-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  padding: 4px 8px;
  font-size: 14px;
}

.code-language-search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--background);
  transition: border-color 120ms ease;
}

.code-language-search:focus-within {
  border-color: var(--brand);
}

.code-language-search svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.code-language-search input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: var(--transparent);
  color: var(--text);
  font-size: 14px;
}

.code-language-search input::-webkit-search-cancel-button {
  display: none;
}

.code-language-wheel {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  height: 180px;
  border-radius: 8px;
  background: var(--background);
  overflow: hidden;
}

.code-language-list {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 72px 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-snap-type: y mandatory;
  scroll-padding-block: 72px;
  mask-image: linear-gradient(to bottom, #00000000, #000000 40%, #000000 60%, #00000000);
}

.code-language-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 36px;
  padding: 0 8px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  scroll-snap-align: center;
  cursor: pointer;
  transition: color 80ms ease;
}

.code-language-item.selected {
  color: var(--brand);
  font-size: 18px;
  font-weight: 600;
}

.code-language-indicator {
  position: absolute;
  top: 72px;
  left: 6px;
  right: 6px;
  height: 36px;
  border-radius: 6px;
  background: var(--selected);
  pointer-events: none;
}

.code-language-empty {
  height: 36px;
  color: var(--muted);
  font-size: 12px;
  line-height: 36px;
  text-align: center;
}

.code-language-count {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.code-language-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.source-code-highlight .hljs-keyword,
.source-code-highlight .hljs-literal,
.source-code-highlight .hljs-selector-tag {
  color: var(--code-keyword);
}

.source-code-highlight .hljs-string,
.source-code-highlight .hljs-regexp,
.source-code-highlight .hljs-doctag {
  color: var(--code-string);
}

.source-code-highlight .hljs-number,
.source-code-highlight .hljs-symbol {
  color: var(--code-number);
}

.source-code-highlight .hljs-title,
.source-code-highlight .hljs-title.function_,
.source-code-highlight .hljs-function {
  color: var(--code-function);
}

.source-code-highlight .hljs-type,
.source-code-highlight .hljs-title.class_,
.source-code-highlight .hljs-built_in {
  color: var(--code-type);
}

.source-code-highlight .hljs-comment,
.source-code-highlight .hljs-quote {
  color: var(--code-comment);
}

.source-code-highlight .hljs-variable,
.source-code-highlight .hljs-attribute,
.source-code-highlight .hljs-attr,
.source-code-highlight .hljs-property,
.source-code-highlight .hljs-params {
  color: var(--code-variable);
}

.source-code-highlight .hljs-meta,
.source-code-highlight .hljs-meta .hljs-keyword,
.source-code-highlight .hljs-section {
  color: var(--code-meta);
}

.source-code-highlight .hljs-tag,
.source-code-highlight .hljs-name,
.source-code-highlight .hljs-selector-class,
.source-code-highlight .hljs-selector-id {
  color: var(--code-keyword);
}

.source-code-highlight .hljs-bullet,
.source-code-highlight .hljs-link,
.source-code-highlight .hljs-strong,
.source-code-highlight .hljs-emphasis {
  color: var(--code-function);
}

.source-code-highlight .hljs-addition {
  color: var(--code-added);
  background: var(--code-added-background);
}

.source-code-highlight .hljs-deletion {
  color: var(--code-removed);
  background: var(--code-removed-background);
}

.source-code-terminal {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 8px 16px 16px;
  gap: 8px;
}

.source-code-terminal-output {
  display: block;
  min-width: 0;
  min-height: 24px;
  max-height: 320px;
  margin: 0;
  padding: 0;
  overflow: auto;
  scrollbar-width: none;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 14px;
  line-height: 24px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
}

.source-code-terminal-output::-webkit-scrollbar {
  display: none;
}

.source-code-terminal-stdout {
  color: #D4D4D4;
}

.source-code-terminal-stderr {
  color: #F48771;
}

.source-code-terminal-status {
  min-height: 20px;
  font-size: 12px;
  line-height: 20px;
  color: #888888;
}

.source-code-terminal-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.source-code-terminal-input {
  flex: 1;
  width: 0;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid #383838;
  border-radius: 4px;
  outline: none;
  background: #181818;
  color: #D4D4D4;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 14px;
  box-sizing: border-box;
}

.source-code-terminal-input:focus {
  border-color: #C0FF00;
}

.source-code-terminal-input:disabled {
  opacity: 0.4;
}

.source-code-terminal-button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid #383838;
  border-radius: 4px;
  outline: none;
  background: #242424;
  color: #D4D4D4;
  font-size: 12px;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.source-code-terminal-button:hover:not(:disabled) {
  background: #C0FF00;
  color: #000000;
}

.source-code-terminal-button:disabled {
  opacity: 0.4;
  cursor: default;
}

@media (max-width: 768px) {
  .source-code-terminal {
    padding: 8px 12px 12px;
  }

  .source-code-terminal-output {
    font-size: 12px;
    line-height: 20px;
    max-height: 240px;
  }

  .source-code-terminal-input {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .source-code-button,
  .code-language-overlay,
  .code-language-window,
  .youtube-overlay,
  .youtube-window {
    transition: none;
  }
}