:root {
  --bg: #ffffff;
  --fg: #111418;
  --muted: #5b6470;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --ok: #047857;
  --warn: #b91c1c;
  --border: #d6dbe1;
  --panel: #f5f7fa;
  --console-bg: #0b1020;
  --console-fg: #e6edf3;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --fg: #e6edf3;
    --muted: #8b949e;
    --accent: #58a6ff;
    --accent-soft: #1c2a44;
    --ok: #3fb98a;
    --warn: #ff7b72;
    --border: #30363d;
    --panel: #161b22;
    --console-bg: #010409;
    --console-fg: #e6edf3;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--fg);
  font-size: 1rem;
  margin-right: 0.25rem;
  letter-spacing: -0.01em;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
}
.brand-name { font-weight: 700; }
.tagline {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  margin-right: 0.5rem;
  white-space: nowrap;
}
@media (max-width: 720px) { .tagline { display: none; } }
header label { font-size: 0.9rem; color: var(--muted); }
header select, header button {
  font: inherit;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 4px;
  cursor: pointer;
}
header button:disabled { opacity: 0.5; cursor: not-allowed; }
header button.primary { background: var(--accent); color: white; border-color: var(--accent); }
#status {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
#status::before {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 0 currentColor;
  animation: status-pulse 1.6s ease-in-out infinite;
}
#status.ready { color: var(--ok); }
#status.ready::before { background: var(--ok); animation: none; }
#status.error { color: var(--warn); }
#status.error::before { background: var(--warn); animation: none; }
@keyframes status-pulse {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 1; }
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
}
#editor-pane { flex: 1 1 50%; min-width: 0; display: flex; }
#editor-pane .CodeMirror { flex: 1; height: auto; font-family: var(--font-mono); font-size: 13px; }
#output-pane {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}
#output {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.75rem 1rem;
  background: var(--bg);
}
#output:empty::before {
  content: "Output will appear here when you Run.";
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
  padding: 0.5rem 0.25rem;
}
#output canvas {
  max-width: min(100%, 520px);
  max-height: 65vh;
  height: auto;
  display: block;
  margin: 0.5rem auto;
}
#output .chunk-code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  margin: 0.4rem 0;
  white-space: pre;
  overflow-x: auto;
}
#output details { margin: 0.5rem 0; color: var(--muted); }
#output details pre { font-family: var(--font-mono); font-size: 12px; }
#console {
  flex: 0 0 auto;
  min-height: 4rem;
  max-height: 50%;
  overflow: auto;
  margin: 0;
  padding: 0.5rem 0.75rem;
  background: var(--console-bg);
  color: var(--console-fg);
  font-family: var(--font-mono);
  font-size: 12px;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
#console:empty::before {
  content: "› console";
  color: rgba(230, 237, 243, 0.35);
  font-style: italic;
}
#console .err { color: #ff8484; }
#console .stdin { color: #8be9fd; }

@media (max-width: 800px) {
  main { flex-direction: column; }
  #output-pane { border-left: none; border-top: 1px solid var(--border); }
}

dialog#consent {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-width: 32rem;
  background: var(--bg);
  color: var(--fg);
}
dialog#consent::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog#consent h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
dialog#consent p { margin: 0.4rem 0; line-height: 1.4; }
dialog#consent .pkglist {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: var(--panel);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
dialog#consent .actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.75rem; flex-wrap: wrap; }
dialog#consent button {
  font: inherit;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
dialog#consent button.primary { background: var(--accent); color: white; border-color: var(--accent); }

dialog#url-consent {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-width: 32rem;
  background: var(--bg);
  color: var(--fg);
}
dialog#url-consent::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog#url-consent h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }
dialog#url-consent p { margin: 0.4rem 0; line-height: 1.4; }
dialog#url-consent input.urlbox {
  display: block;
  width: 100%;
  font: inherit;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: var(--panel);
  color: var(--fg);
  padding: 0.45rem 0.6rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  outline: none;
}
dialog#url-consent input.urlbox:focus { border-color: var(--accent); }
dialog#url-consent .hint { color: var(--muted); font-size: 0.85rem; }
dialog#url-consent .actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
dialog#url-consent button {
  font: inherit;
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
dialog#url-consent button.primary { background: var(--accent); color: white; border-color: var(--accent); }

dialog#docs, dialog#imprint {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-width: 38rem;
  max-height: 80vh;
  background: var(--bg);
  color: var(--fg);
  overflow-y: auto;
}
dialog#docs::backdrop, dialog#imprint::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog#docs h2, dialog#imprint h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
dialog#docs h3 { margin: 1rem 0 0.35rem; font-size: 0.95rem; color: var(--fg); }
dialog#docs p, dialog#imprint p { margin: 0.4rem 0; line-height: 1.45; }
dialog#docs .hint { color: var(--muted); font-size: 0.85rem; }
dialog#docs dl { margin: 0.25rem 0 0.5rem; }
dialog#docs dt { margin-top: 0.5rem; font-family: var(--font-mono); font-size: 0.82rem; }
dialog#docs dt code { background: var(--panel); padding: 0.05rem 0.3rem; border-radius: 3px; border: 1px solid var(--border); }
dialog#docs dd { margin: 0.15rem 0 0.4rem 0; color: var(--fg); font-size: 0.9rem; line-height: 1.4; }
dialog#docs ul.examples { padding-left: 1.1rem; margin: 0.25rem 0; }
dialog#docs ul.examples li { font-family: var(--font-mono); font-size: 0.8rem; margin: 0.2rem 0; }
dialog#docs code, dialog#imprint code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}
dialog#imprint address {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  background: var(--panel);
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  line-height: 1.5;
}
dialog#docs .actions, dialog#imprint .actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.75rem;
}
dialog#docs button, dialog#imprint button {
  font: inherit;
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
dialog#docs button.primary, dialog#imprint button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

#site-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
}
#site-footer a,
#site-footer .footer-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted transparent;
}
#site-footer a:hover,
#site-footer .footer-link:hover { border-bottom-color: var(--accent); }
#site-footer .footer-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
}
#site-footer .sep { opacity: 0.5; }
.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.5rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.local-badge .lock-icon { display: block; }

.CodeMirror-lint-tooltip { font-family: var(--font-mono); font-size: 12px; }
