:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-alt: #1c222b;
  --border: #30363d;
  --border-strong: #484f58;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-bg: rgba(88, 166, 255, 0.14);
  --ok: #3fb950;
  --ok-bg: rgba(63, 185, 80, 0.16);
  --warn: #d29922;
  --warn-bg: rgba(210, 153, 34, 0.16);
  --err: #f85149;
  --err-bg: rgba(248, 81, 73, 0.16);
  --top: #39c5cf;
  --top-bg: rgba(57, 197, 207, 0.16);
  --absent: #8b949e;
  --absent-bg: rgba(139, 148, 158, 0.14);
  --radius: 8px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1f6feb, #39c5cf);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.view-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.tab-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: var(--surface-alt);
}

.tab-btn.active {
  color: var(--text);
  background: var(--accent-bg);
  border-color: rgba(88, 166, 255, 0.4);
}

.worker-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-main {
  max-width: 1680px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.view-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.view-panel.active {
  display: flex;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.legend-group {
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.select-input,
.text-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 13px;
  font-family: var(--font-sans);
}

.text-input {
  font-family: var(--font-mono);
}

.input-sm {
  width: 155px;
}

.input-xs {
  width: 56px;
}

.flex-1 {
  flex: 1 1 180px;
  min-width: 120px;
}

.select-input:focus,
.text-input:focus,
.code-editor:focus,
.btn:focus-visible,
.tab-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover {
  border-color: var(--border-strong);
  background: #252c37;
}

.btn-sm {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-primary {
  background: #1f6feb;
  border-color: #388bfd;
  color: #ffffff;
}

.btn-primary:hover {
  background: #388bfd;
}

.btn-secondary {
  background: var(--surface-alt);
  border-color: var(--border);
}

.btn-success {
  background: #238636;
  border-color: #2ea043;
  color: #ffffff;
}

.btn-success:hover {
  background: #2ea043;
}

.btn-warning {
  background: var(--warn-bg);
  border-color: rgba(210, 153, 34, 0.5);
  color: #f0c056;
}

.btn-warning:hover {
  background: rgba(210, 153, 34, 0.25);
}

.btn-danger-outline {
  background: var(--err-bg);
  border-color: rgba(248, 81, 73, 0.45);
  color: #ff7b72;
}

.btn-danger-outline:hover {
  background: rgba(248, 81, 73, 0.28);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-alt);
  border-color: var(--border);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.grid-lattice-results {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 14px;
}

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

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 13px;
  font-weight: 600;
}

.card-subtitle {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.subbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.5);
}

.code-editor {
  width: 100%;
  min-height: 440px;
  flex: 1;
  resize: vertical;
  border: none;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
}

.lattice-editors .code-editor {
  min-height: 240px;
}

.schema-editors .code-editor,
.compat-editors .code-editor {
  min-height: 280px;
}

.ide-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.15fr);
  gap: 14px;
  align-items: start;
}

.ide-editor-card {
  min-height: 580px;
}

.ide-file-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.ide-file-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.ide-file-tab:hover {
  color: var(--text);
  background: var(--surface-alt);
}

.ide-file-tab.active {
  color: var(--text);
  background: var(--accent-bg);
  border-color: rgba(88, 166, 255, 0.5);
}

.ide-file-tab.has-error {
  border-color: rgba(248, 81, 73, 0.55);
}

.ide-editor-meta {
  padding: 6px 12px;
}

.ide-path-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
}

.ide-code-editor {
  min-height: 500px;
}

.ide-inspector-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.ide-table-scroll {
  max-height: 170px;
}

.ide-sub-grid {
  align-items: stretch;
}

.ide-list {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow: auto;
  background: var(--bg);
  padding: 6px;
  gap: 4px;
  flex: 1;
}

.ide-list-item {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 4px 8px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ide-list-item:hover {
  background: var(--surface-alt);
  border-color: var(--border);
}

.ide-list-meta {
  color: var(--text-muted);
  font-size: 11px;
}

.ide-empty-note {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px;
}

.ide-inspector-pre {
  min-height: 120px;
  max-height: 180px;
}

.ide-completions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  max-height: 110px;
  overflow: auto;
}

.ide-completions-list:empty {
  display: none;
}

.ide-completion-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  cursor: pointer;
}

.ide-completion-btn:hover {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.ide-diff-pre {
  min-height: 140px;
  max-height: 220px;
}

.ide-diag-row {
  cursor: pointer;
}

.ide-diag-row:hover {
  background: rgba(88, 166, 255, 0.08);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn.is-active {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent);
}

.ide-graph-svg-wrap {
  padding: 10px;
  background: var(--bg);
  border-radius: 6px;
  min-height: 150px;
  max-height: 280px;
  overflow: auto;
}

.ide-graph-svg {
  display: block;
  width: 100%;
  height: auto;
}

.ide-graph-edge {
  stroke: var(--border);
  stroke-width: 1.5;
  fill: none;
}

.ide-graph-edge-stdlib {
  stroke-dasharray: 4 3;
  opacity: 0.72;
}

.ide-graph-node rect {
  rx: 7;
  ry: 7;
  fill: var(--surface);
  stroke: var(--border);
  stroke-width: 1.4;
}

.ide-graph-node-root rect {
  fill: var(--accent-bg);
  stroke: var(--accent);
  stroke-width: 1.8;
}

.ide-graph-node-local rect {
  fill: var(--surface-alt);
  stroke: var(--ok);
}

.ide-graph-node-stdlib rect {
  fill: var(--surface);
  stroke: var(--border);
  stroke-dasharray: 3 2;
}

.ide-graph-node-clickable {
  cursor: pointer;
}

.ide-graph-node-clickable:hover rect {
  stroke: var(--accent);
  stroke-width: 2;
}

.ide-graph-node-label {
  fill: var(--text);
  font-family: var(--font-mono);
  font-size: 11.5px;
  dominant-baseline: middle;
  text-anchor: middle;
}

.ide-graph-node-stdlib .ide-graph-node-label {
  fill: var(--text-muted);
}

.ide-graph-pre {
  min-height: 150px;
  max-height: 260px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.code-output {
  margin: 0;
  padding: 12px;
  background: var(--bg);
  color: #c9d1d9;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  overflow: auto;
  flex: 1;
  min-height: 220px;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-output-sm {
  min-height: 120px;
  max-height: 190px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.status-pill,
.state-pill,
.kind-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.status-idle {
  background: var(--absent-bg);
  color: var(--text-muted);
}

.status-running {
  background: var(--accent-bg);
  color: var(--accent);
}

.status-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.status-warn {
  background: var(--warn-bg);
  color: #f0c056;
}

.status-err {
  background: var(--err-bg);
  color: #ff7b72;
}

.state-absent {
  background: var(--absent-bg);
  color: var(--absent);
}

.state-top {
  background: var(--top-bg);
  color: var(--top);
}

.state-constraint {
  background: var(--warn-bg);
  color: #f0c056;
}

.state-concrete {
  background: var(--ok-bg);
  color: var(--ok);
}

.state-conflict {
  background: var(--err-bg);
  color: #ff7b72;
}

.kind-badge {
  background: var(--err-bg);
  color: #ff7b72;
}

.timing-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.errors-panel {
  max-height: 220px;
  overflow: auto;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 81, 73, 0.06);
}

.table-scroll {
  overflow: auto;
  max-height: 400px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  z-index: 1;
}

.cell-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cell-code {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.path-raw {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.row-conflict {
  background: rgba(248, 81, 73, 0.08);
}

.row-converged {
  background: rgba(63, 185, 80, 0.04);
}

.side-notes {
  padding: 8px 12px;
  background: rgba(210, 153, 34, 0.1);
  border-bottom: 1px solid var(--border);
  color: #f0c056;
  font-size: 12.5px;
}

.stress-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.stress-result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 12px;
}

.stress-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-row {
  display: grid;
  grid-template-columns: 115px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.meta-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.mb-xs {
  margin-bottom: 6px;
}

.hidden {
  display: none !important;
}

.sev-breaking,
.sev-error {
  background: var(--err-bg);
  color: #ff7b72;
}

.sev-compatible,
.sev-warning {
  background: var(--ok-bg);
  color: var(--ok);
}

.sev-warn {
  background: var(--warn-bg);
  color: #f0c056;
}

.sev-info {
  background: var(--accent-bg);
  color: var(--accent);
}

.row-compatible {
  background: rgba(63, 185, 80, 0.04);
}

@media (max-width: 1120px) {
  .grid-3,
  .ide-layout {
    grid-template-columns: 1fr;
  }
  .grid-lattice-results {
    grid-template-columns: 1fr;
  }
  .code-editor {
    min-height: 260px;
  }
}

@media (max-width: 820px) {
  .grid-2,
  .stress-result-grid {
    grid-template-columns: 1fr;
  }
}
