.term {
  --term-pad: 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--code-bg);
  color: var(--code-fg);
  overflow: hidden;
}

.term-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 6px 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.term-icon {
  display: inline-flex;
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--ok);
}

.term-icon svg,
.term-btn svg,
.term-jump svg {
  width: 100%;
  height: 100%;
}

.term-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-code);
  font-size: 13px;
}

.term-tools {
  display: inline-flex;
  flex: none;
  gap: 2px;
}

.term-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 6px;
  border: 0;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.term-btn:hover:not(:disabled) {
  background: var(--raised);
  color: var(--text);
}

.term-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.term-btn[hidden] {
  display: none;
}

.term-btn:first-child:not(:disabled) {
  color: var(--ok);
}

.term-btn-stop:not(:disabled) {
  color: var(--bad);
}

.term-btn:focus-visible,
.term-send:focus-visible,
.term-jump:focus-visible,
.term-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.term-body-wrap {
  position: relative;
  min-height: 0;
}

.term-body {
  max-height: var(--term-height, 340px);
  min-height: 72px;
  overflow: auto;
  padding: 10px var(--term-pad);
  font-family: var(--font-code);
  font-size: 13.5px;
  line-height: 1.5;
  overscroll-behavior: contain;
}

.term-output {
  min-width: 0;
}

.term-line {
  min-height: 1.5em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.term-trimmed {
  color: var(--faint);
  font-style: italic;
}

.term-k-err {
  color: var(--bad);
}

.term-k-sys {
  color: var(--muted);
}

.term-k-in {
  color: var(--ok);
}

.term-k-warn {
  color: var(--warn);
}

.term-input {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.term-input[hidden] {
  display: none;
}

.term-prompt {
  flex: none;
  color: var(--accent);
  font-weight: 700;
}

.term-field {
  flex: 1 1 auto;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ok);
  font: inherit;
}

.term-field:focus {
  border-color: var(--accent);
  outline: none;
  background: var(--code-line);
}

.term-field::placeholder {
  color: var(--faint);
}

.term-send {
  flex: none;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
}

.term-send:hover {
  border-color: var(--accent);
}

.term-jump {
  position: absolute;
  right: 12px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 8px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-body);
  font-size: 13px;
  box-shadow: var(--shadow-1);
  cursor: pointer;
}

.term-jump svg {
  width: 14px;
  height: 14px;
}

.term-jump[hidden] {
  display: none;
}

.term-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 4px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.term-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--faint);
}

.term-status[data-state="running"] .term-dot {
  background: var(--info);
  animation: term-pulse 1.1s ease-in-out infinite;
}

.term-status[data-state="ok"] .term-dot {
  background: var(--ok);
}

.term-status[data-state="bad"] .term-dot {
  background: var(--bad);
}

.term-status[data-state="warn"] .term-dot {
  background: var(--warn);
}

.term-status[data-state="info"] .term-dot {
  background: var(--info);
}

.term-status[data-state="ok"] .term-status-text {
  color: var(--ok);
}

.term-status[data-state="bad"] .term-status-text {
  color: var(--bad);
}

.term-status[data-state="warn"] .term-status-text {
  color: var(--warn);
}

@keyframes term-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.term-copy-buffer {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.ansi-bold {
  font-weight: 700;
}

.ansi-dim {
  opacity: 0.7;
}

.ansi-italic {
  font-style: italic;
}

.ansi-underline {
  text-decoration: underline;
}

.ansi-strike {
  text-decoration: line-through;
}

.ansi-inverse {
  background: var(--code-fg);
  color: var(--code-bg);
}

.ansi-fg-0 { color: var(--faint); }
.ansi-fg-1 { color: var(--bad); }
.ansi-fg-2 { color: var(--ok); }
.ansi-fg-3 { color: var(--warn); }
.ansi-fg-4 { color: color-mix(in srgb, var(--info) 55%, var(--accent)); }
.ansi-fg-5 { color: var(--deep); }
.ansi-fg-6 { color: var(--info); }
.ansi-fg-7 { color: var(--code-fg); }
.ansi-fg-8 { color: var(--muted); }
.ansi-fg-9 { color: color-mix(in srgb, var(--bad) 75%, var(--code-fg)); }
.ansi-fg-10 { color: color-mix(in srgb, var(--ok) 75%, var(--code-fg)); }
.ansi-fg-11 { color: color-mix(in srgb, var(--warn) 75%, var(--code-fg)); }
.ansi-fg-12 { color: color-mix(in srgb, var(--accent) 75%, var(--code-fg)); }
.ansi-fg-13 { color: color-mix(in srgb, var(--deep) 75%, var(--code-fg)); }
.ansi-fg-14 { color: color-mix(in srgb, var(--info) 75%, var(--code-fg)); }
.ansi-fg-15 { color: var(--text); }
.ansi-bg-0 { background: var(--raised); }
.ansi-bg-1 { background: var(--bad-soft); }
.ansi-bg-2 { background: var(--ok-soft); }
.ansi-bg-3 { background: var(--warn-soft); }
.ansi-bg-4 { background: var(--accent-soft); }
.ansi-bg-5 { background: var(--deep-soft); }
.ansi-bg-6 { background: var(--info-soft); }
.ansi-bg-7 { background: var(--code-line); }
.ansi-bg-8 { background: var(--raised); }
.ansi-bg-9 { background: var(--bad-soft); }
.ansi-bg-10 { background: var(--ok-soft); }
.ansi-bg-11 { background: var(--warn-soft); }
.ansi-bg-12 { background: var(--accent-soft); }
.ansi-bg-13 { background: var(--deep-soft); }
.ansi-bg-14 { background: var(--info-soft); }
.ansi-bg-15 { background: var(--code-line); }

.ed {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--code-bg);
  overflow: hidden;
}

.ed.ed-focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.ed-fallback {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 14em;
  height: var(--ed-height, 420px);
  padding: 10px 12px;
  border: 0;
  background: var(--code-bg);
  color: var(--code-fg);
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.55;
  tab-size: 4;
  resize: vertical;
  white-space: pre;
  overflow: auto;
}

.ed-auto .ed-fallback {
  height: auto;
  min-height: 12em;
}

.ed-fallback:focus {
  outline: none;
}

.ed-fallback[hidden] {
  display: none;
}

.ed-hint {
  display: none;
  padding: 3px 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.ed-focused .ed-hint {
  display: block;
}

.ed .CodeMirror {
  height: var(--ed-height, 420px);
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.55;
}

.ed-auto .CodeMirror {
  height: auto;
}

.ed-auto .CodeMirror-scroll {
  min-height: 6em;
}

.cm-s-guide.CodeMirror {
  background: var(--code-bg);
  color: var(--code-fg);
}

.cm-s-guide .CodeMirror-gutters {
  background: var(--code-bg);
  border-right: 1px solid var(--line);
}

.cm-s-guide .CodeMirror-linenumber {
  padding: 0 10px 0 6px;
  color: var(--code-gutter);
}

.cm-s-guide .CodeMirror-cursor {
  border-left: 2px solid var(--text);
}

.cm-s-guide .CodeMirror-activeline-background {
  background: var(--code-line);
}

.cm-s-guide .CodeMirror-activeline-gutter .CodeMirror-linenumber {
  color: var(--text);
}

.cm-s-guide .CodeMirror-selected,
.cm-s-guide.CodeMirror-focused .CodeMirror-selected,
.cm-s-guide .CodeMirror-line::selection,
.cm-s-guide .CodeMirror-line > span::selection,
.cm-s-guide .CodeMirror-line > span > span::selection {
  background: var(--code-sel);
}

.cm-s-guide .CodeMirror-matchingbracket {
  color: inherit !important;
  outline: 1px solid var(--accent);
  background: var(--accent-soft);
}

.cm-s-guide .CodeMirror-nonmatchingbracket {
  color: var(--bad) !important;
  text-decoration: underline wavy var(--bad);
}

.cm-s-guide .CodeMirror-lines {
  padding: 8px 0;
}

.cm-s-guide .CodeMirror-line {
  padding: 0 12px 0 10px;
}

.cm-s-guide .ed-line-error {
  background: var(--bad-soft);
}

.cm-s-guide .ed-line-error .CodeMirror-linenumber {
  color: var(--bad);
  font-weight: 700;
}

.cm-s-guide .ed-line-warn {
  background: var(--warn-soft);
}

.cm-s-guide .ed-line-flash {
  animation: ed-flash 1.2s ease-out;
}

@keyframes ed-flash {
  from {
    background: var(--accent-soft);
  }
  to {
    background: transparent;
  }
}

.ed-msg {
  margin: 2px 12px 4px 10px;
  padding: 4px 10px;
  border-left: 3px solid var(--bad);
  border-radius: var(--radius-s);
  background: var(--bad-soft);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.4;
  white-space: normal;
}

.ed-msg-warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.ed-probe {
  position: absolute !important;
  left: -9999px !important;
  top: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.run-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

figure.code.run-editing > .code-scroll {
  display: none;
}

.run-editor .ed {
  border-radius: var(--radius-s);
}

.run-term .term {
  border-radius: var(--radius-s);
}

.run-hint {
  padding: 8px 12px;
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-s);
  background: var(--warn-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.run-hint[hidden],
.run-note[hidden] {
  display: none;
}

.run-note {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.run-sample {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 14px;
}

.run-sample-text {
  font-family: var(--font-code);
  color: var(--text);
}

.code-btn.code-btn-stop {
  color: var(--bad);
}

.code-btn[hidden] {
  display: none;
}

.code-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

@media (max-width: 560px) {
  .term-body {
    font-size: 12.5px;
    --term-pad: 10px;
  }

  .ed .CodeMirror,
  .ed-fallback {
    font-size: 13px;
  }

  .run-panel {
    padding: 8px;
  }

  .term-send {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .term-status[data-state="running"] .term-dot,
  .cm-s-guide .ed-line-flash {
    animation: none;
  }
}
