.webr-sandbox-wrapper {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 1.5rem 0;
  width: 100%;
}

.webr-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background-color: #fef2f2;
  color: #ef4444;
  border: 1px solid #fecaca;
  margin-bottom: 8px;
}

.webr-status-badge.ready {
  background-color: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}

[data-theme="dark"] .webr-status-badge,
body.dark .webr-status-badge {
  background-color: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .webr-status-badge.ready,
body.dark .webr-status-badge.ready {
  background-color: rgba(220, 38, 38, 0.18);
  color: #f87171;
  border-color: rgba(220, 38, 38, 0.35);
}

.webr-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

.webr-island {
  display: flex;
  flex-direction: column;
  width: 100%;
  background-color: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin: 0;
  overflow: hidden;
  box-shadow: 0 4px 18px -2px rgba(0, 0, 0, 0.06);
  box-sizing: border-box;
}

[data-theme="dark"] .webr-island,
body.dark .webr-island {
  background-color: #111827;
  color: #f3f4f6;
  border-color: #374151;
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.45);
}

.webr-island-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background-color: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}

[data-theme="dark"] .webr-island-header,
body.dark .webr-island-header {
  background-color: #1f2937;
  border-color: #374151;
}

.webr-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.webr-island-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #dc2626;
}

[data-theme="dark"] .webr-island-title,
body.dark .webr-island-title {
  color: #f87171;
}

.webr-run-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background-color: #dc2626 !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.25);
  transition: background-color 0.15s ease, transform 0.15s ease;
}

.webr-run-btn:hover {
  background-color: #b91c1c !important;
  transform: translateY(-1px);
}

.webr-run-btn:disabled {
  background-color: #94a3b8 !important;
  cursor: not-allowed;
  transform: none;
  opacity: 0.7;
}

.webr-island-body {
  display: flex;
  flex-direction: column;
}

@media (min-width: 768px) {
  .webr-island-body {
    flex-direction: row;
  }
}

.webrsource {
  flex: 1;
  min-width: 0;
  display: flex;
  position: relative;
  background-color: #fcfcfd;
  border-bottom: 1px solid #e2e8f0;
}

[data-theme="dark"] .webrsource,
body.dark .webrsource {
  background-color: #0d1117;
  border-color: #374151;
}

@media (min-width: 768px) {
  .webrsource {
    border-bottom: none;
    border-right: 1px solid #e2e8f0;
  }
  [data-theme="dark"] .webrsource,
  body.dark .webrsource {
    border-right-color: #374151;
  }
}

.webr-gutter {
  width: 42px;
  flex-shrink: 0;
  padding: 12px 8px 12px 0;
  text-align: right;
  background-color: #f1f5f9;
  border-right: 1px solid #e2e8f0;
  color: #94a3b8;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  user-select: none;
  box-sizing: border-box;
  overflow: hidden;
  white-space: pre;
}

[data-theme="dark"] .webr-gutter,
body.dark .webr-gutter {
  background-color: #161b22;
  border-right-color: #30363d;
  color: #6e7681;
}

.webrsource textarea {
  flex: 1;
  min-width: 0;
  min-height: 160px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: #0f172a;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  box-sizing: border-box;
  tab-size: 2;
  white-space: pre;
  overflow-x: auto;
}

[data-theme="dark"] .webrsource textarea,
body.dark .webrsource textarea {
  color: #e6edf3;
}

.webr-outputs-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.webrterm {
  flex: 1;
  min-width: 0;
  background-color: #f8fafc;
  padding: 12px 16px;
  min-height: 160px;
  max-height: 320px;
  overflow-y: auto;
  box-sizing: border-box;
}

[data-theme="dark"] .webrterm,
body.dark .webrterm {
  background-color: #030712;
}

.webrterm pre {
  margin: 0;
  padding: 0;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
  background: transparent !important;
}

[data-theme="dark"] .webrterm pre,
body.dark .webrterm pre {
  color: #9ca3af;
}

.webr-err {
  color: #dc2626 !important;
  font-weight: 500;
}

[data-theme="dark"] .webr-err,
body.dark .webr-err {
  color: #f87171 !important;
}

/* Plot Support */
.webr-plot-container {
  display: none;
  position: relative;
  background-color: #ffffff;
  border-top: 1px solid #e2e8f0;
  padding: 12px;
  align-items: center;
  justify-content: center;
}

.webr-plot-container.has-plot {
  display: flex;
}

[data-theme="dark"] .webr-plot-container,
body.dark .webr-plot-container {
  background-color: #080d16;
  border-top-color: #374151;
}

.webr-plot-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background-color: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.webr-plot-download-btn {
  position: absolute;
  top: 18px;
  right: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.webr-plot-download-btn:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

[data-theme="dark"] .webr-plot-download-btn,
body.dark .webr-plot-download-btn {
  background: rgba(17, 24, 39, 0.8);
  color: #f3f4f6;
  border-color: rgba(55, 65, 81, 0.8);
}