:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --pane: #ffffff;
  --line: #d6dde5;
  --ink: #17202a;
  --muted: #617083;
  --accent: #1677ff;
  --good: #0f7a4f;
  --warn: #a45b00;
  --code-bg: #fbfcfe;
  --code-gutter: #eef3f8;
  --code-line: #cbd5e1;
  --code-text: #17202a;
  --code-muted: #6b7280;
  --code-active: #eaf2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: minmax(360px, 1.12fr) minmax(300px, 0.88fr);
  gap: 12px;
  height: 100vh;
  padding: 12px;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--pane);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.toolbar {
  min-height: 72px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.toolbar > div:first-child {
  min-width: 0;
}

.toolbar h1,
.toolbar h2,
.metrics h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.runtime-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.runtime-rail span {
  min-width: 0;
  border: 1px solid #d7e1eb;
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  padding: 4px 7px;
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}

.runtime-rail b {
  color: var(--ink);
  font-weight: 700;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.target-chip {
  flex: 0 0 auto;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
}

.code-editor {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--code-bg);
  overflow: hidden;
}

.editor-mount {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.code-editor .cm-editor {
  height: 100%;
  background: var(--code-bg);
  color: var(--code-text);
  outline: none;
}

.code-editor .cm-focused {
  outline: none;
}

.code-editor .cm-scroller {
  font: 13px/1.55 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.code-editor .cm-content {
  padding: 14px 0 18px;
  caret-color: var(--accent);
}

.code-editor .cm-line {
  padding: 0 18px;
}

.code-editor .cm-gutters {
  background: var(--code-gutter);
  color: var(--code-muted);
  border-right: 1px solid var(--code-line);
}

.code-editor .cm-lineNumbers .cm-gutterElement {
  padding: 0 10px 0 14px;
}

.code-editor .cm-activeLine,
.code-editor .cm-activeLineGutter {
  background: var(--code-active);
}

.code-editor .cm-selectionBackground,
.code-editor .cm-content ::selection {
  background: rgba(22, 119, 255, 0.18) !important;
}

.code-editor:focus-within {
  box-shadow: inset 0 0 0 1px rgba(22, 119, 255, 0.45);
}

.editor-status {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  background: var(--code-gutter);
  color: var(--code-muted);
  font: 12px/1.2 "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  border-top: 1px solid var(--code-line);
}

#preview {
  flex: 1;
  min-height: 260px;
  width: 100%;
  border: 0;
  background: #fff;
}

.runtime-status {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  background: #fbfcfe;
}

.runtime-status div {
  min-width: 0;
}

.runtime-status b,
.runtime-status span {
  display: block;
}

.runtime-status b {
  font-size: 12px;
  line-height: 1.2;
}

.runtime-status span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.runtime-status a {
  border: 1px solid #bbf7d0;
  border-radius: 6px;
  background: #f0fdf4;
  color: #166534;
  padding: 6px 8px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}

.runtime-status a:hover {
  border-color: #22c55e;
}

.metrics {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfe;
}

.metric b {
  display: block;
  font-size: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.metric.good b {
  color: var(--good);
}

.metric.warn b {
  color: var(--warn);
}

@media (max-width: 720px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .pane {
    min-height: 520px;
  }

  .toolbar {
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: flex-start;
  }

  .runtime-status {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .runtime-status a {
    justify-self: start;
  }
}
