:root {
  --editor-width: 420px;
  --bg: #ffffff;
  --panel: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --error: #dc2626;
  --warn: #d97706;
  --editor-bg: #fbfcfe;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --hl-comment: #8a94a6;
  --hl-keyword: #7c3aed;
  --hl-name: #0f172a;
  --hl-type: #0e7490;
  --hl-string: #15803d;
  --hl-expr: #b45309;
  --hl-number: #c2410c;
  --hl-setting: #2563eb;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --panel: #111827;
    --border: #1f2937;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --editor-bg: #0b1220;
    --hl-comment: #6b7a90;
    --hl-keyword: #c4b5fd;
    --hl-name: #e5e7eb;
    --hl-type: #67e8f9;
    --hl-string: #86efac;
    --hl-expr: #fcd34d;
    --hl-number: #fdba74;
    --hl-setting: #93c5fd;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-size: 14px; }
.doc-name { color: var(--muted); margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toolbar .group { display: flex; align-items: center; gap: 4px; }
.toolbar button, .toolbar select {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent); }
.toolbar button[aria-pressed="true"] { background: #eef4ff; border-color: #93b4f5; color: var(--accent); }
.zoom-level { min-width: 44px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.menu-anchor { position: relative; }
.layout-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: 340px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  padding-bottom: 6px;
}
.layout-menu .lm-title { font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.toolbar .layout-menu button {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  column-gap: 12px;
  row-gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 0;
  padding: 8px 14px;
  background: transparent;
}
.toolbar .layout-menu button:hover { background: var(--panel); }
.layout-menu button.current .lm-name { color: var(--accent); }
.layout-menu button.current .lm-name::after { content: ' ✓'; }
.layout-menu .lm-icon { width: 22px; height: 22px; grid-row: 1 / span 2; }
.url-menu { width: 440px; }
.url-form { display: flex; gap: 6px; padding: 6px 14px; }
.url-form input { flex: 1; min-width: 0; font: inherit; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; outline: none; }
.url-form input:focus { border-color: var(--accent); }
.toolbar .url-menu button { display: inline-block; width: auto; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; background: var(--bg); }
.toolbar .url-menu button:disabled { color: var(--muted); cursor: default; border-color: var(--border); }
.url-hint { margin: 2px 14px 4px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.url-menu .url-sub { border-top: 1px solid var(--border); border-bottom: 0; margin: 6px 0 0; padding: 10px 14px 2px; }
.layout-menu .lm-name { font-weight: 600; }
.layout-menu kbd {
  font: 11px var(--mono);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--muted);
  align-self: center;
}
.layout-menu .lm-desc { grid-column: 2 / span 2; color: var(--muted); font-size: 12px; line-height: 1.4; }
/* A menu of text entries without icons or shortcuts (Export). */
.toolbar .text-menu button { display: block; }
.text-menu { width: 300px; left: auto; right: 0; }
.text-menu .lm-name { display: block; }
.text-menu .lm-title { border-top: 1px solid var(--border); border-bottom: 0; margin: 4px 0 0; padding: 10px 14px 6px; font-size: 12px; color: var(--muted); }

.workspace { flex: 1; display: flex; min-height: 0; }

.editor-pane {
  position: relative;
  width: var(--editor-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--editor-bg);
}
.editor-hidden .editor-pane, .editor-hidden .splitter { display: none; }

.editor-wrap { flex: 1; display: flex; min-height: 0; }
.code { flex: 1; position: relative; min-width: 0; }
.gutter, #editor, .highlight {
  font: 12.5px/20px var(--mono);
  padding: 10px 0;
  margin: 0;
}
.gutter {
  width: 44px;
  overflow: hidden;
  text-align: right;
  color: var(--muted);
  opacity: 0.7;
  user-select: none;
  flex: none;
}
.gutter div { padding-right: 10px; }
.hl-comment { color: var(--hl-comment); }
.hl-keyword { color: var(--hl-keyword); }
.hl-name { color: var(--hl-name); }
.hl-type { color: var(--hl-type); }
.hl-string { color: var(--hl-string); }
.hl-expr { color: var(--hl-expr); }
.hl-number, .hl-colour { color: var(--hl-number); }
.hl-setting { color: var(--hl-setting); }
.hl-op { color: var(--hl-keyword); }
.hl-punct { color: var(--muted); }
#editor::selection { background: rgba(37, 99, 235, 0.25); color: transparent; }
.gutter .err { color: var(--error); opacity: 1; font-weight: 700; background: rgba(220, 38, 38, 0.1); }
.gutter .warn { color: var(--warn); opacity: 1; font-weight: 700; background: rgba(217, 119, 6, 0.1); }
#editor, .highlight {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding-left: 6px;
  padding-right: 10px;
  white-space: pre;
  tab-size: 2;
  overflow: auto;
}
.highlight { color: var(--text); overflow: hidden; pointer-events: none; }
#editor {
  color: transparent;
  caret-color: var(--text);
  z-index: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
}

.search-marks { color: transparent; }
.line-mark {
  position: absolute;
  left: 0;
  right: 0;
  height: 20px;
  background: rgba(245, 158, 11, 0.18);
  border-left: 3px solid #f59e0b;
  pointer-events: none;
}
.search-marks mark { color: transparent; background: rgba(250, 204, 21, 0.35); border-radius: 2px; }
.search-marks mark.cur { background: rgba(249, 115, 22, 0.6); }

.search {
  position: absolute;
  top: 6px;
  right: 14px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.18);
}
.search[hidden] { display: none; }
.search input {
  width: 180px;
  font: 12.5px var(--mono);
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 6px;
  outline: 0;
}
.search input:focus { border-color: var(--accent); }
.search.none input { border-color: var(--error); }
.search-count { min-width: 52px; text-align: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.search button { font: inherit; color: inherit; background: none; border: 0; border-radius: 4px; padding: 2px 6px; cursor: pointer; }
.search button:hover { background: var(--border); }

.problems { border-top: 1px solid var(--border); font-size: 12px; display: flex; flex-direction: column; max-height: 30%; min-height: 0; }
.pr-head { display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; }
.pr-head button { font: inherit; background: transparent; border: 0; padding: 2px 6px; border-radius: 4px; cursor: pointer; color: inherit; }
.pr-toggle { flex: 1; text-align: left; font-weight: 600; }
.pr-toggle::before { content: '▾ '; color: var(--muted); }
.problems.collapsed .pr-toggle::before { content: '▸ '; }
.problems.collapsed .pr-list { display: none; }
.pr-suggest { color: var(--accent) !important; border: 1px solid var(--border) !important; }
.pr-head button:hover { background: var(--panel); }
.pr-list { list-style: none; margin: 0; padding: 0 0 4px; overflow: auto; }
.pr-list li { display: flex; gap: 8px; padding: 3px 12px; cursor: pointer; line-height: 1.4; }
.pr-list li:hover { background: var(--panel); }
.pr-list li::before { flex: none; width: 10px; text-align: center; }
.pr-list li.warning::before { content: '▲'; color: var(--warn); }
.pr-list li.info::before { content: '●'; color: var(--muted); font-size: 9px; line-height: 17px; }
.pr-list li.suggest::before { content: '+'; color: var(--accent); font-weight: 700; }
.pr-line { flex: none; min-width: 32px; color: var(--muted); font: 11px/17px var(--mono); text-align: right; order: -1; }

#status {
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  color: var(--muted);
  font-size: 12px;
  min-height: 30px;
}
#status.error { color: var(--error); cursor: pointer; }

.splitter { width: 5px; cursor: col-resize; background: var(--border); flex: none; }
.splitter:hover { background: var(--accent); }

.canvas-pane { flex: 1; min-width: 0; position: relative; }
#diagram {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #f6f8fb;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
#diagram.dragging { cursor: grabbing; }
#diagram .od-table, #diagram .od-group-handle, #diagram .od-group-label { cursor: move; }

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 360px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #0f172a;
  color: #f1f5f9;
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  pointer-events: none;
}
.tooltip code { font-family: var(--mono); font-size: 11.5px; color: #93c5fd; }
.tooltip .tt-flags, .tooltip .tt-muted { color: #94a3b8; }
.tooltip .tt-note { margin-top: 4px; color: #fde68a; }
.tooltip .tt-note p, .tooltip .tt-note ul, .tooltip .tt-note ol, .tooltip .tt-note pre { margin: 0 0 4px; }
.tooltip .tt-note ul, .tooltip .tt-note ol { padding-left: 16px; }
.tooltip .tt-refs, .tooltip .tt-enum, .tooltip .tt-props { margin-top: 4px; color: #cbd5e1; }
.tooltip .tt-props span { color: #94a3b8; }
.tooltip .tt-records { margin-top: 6px; border-collapse: collapse; font-size: 11px; }
.tooltip .tt-records th, .tooltip .tt-records td { border: 1px solid #334155; padding: 1px 5px; text-align: left; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tooltip .tt-records th { color: #94a3b8; font-weight: 600; }

.project-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  font-size: 13px;
  line-height: 1.55;
}
.project-panel .pp-close {
  position: sticky;
  top: 0;
  float: right;
  border: 0;
  background: none;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.project-panel .pp-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.project-panel h1, .project-panel h2, .project-panel h3 { margin: 12px 0 6px; line-height: 1.3; }
.project-panel h1 { font-size: 17px; }
.project-panel h2 { font-size: 15px; }
.project-panel h3 { font-size: 13px; }
.project-panel p, .project-panel ul, .project-panel ol { margin: 0 0 8px; }
.project-panel ul, .project-panel ol { padding-left: 20px; }
.project-panel code { font-family: var(--mono); font-size: 12px; background: var(--panel); border-radius: 3px; padding: 0 3px; }
.project-panel pre { background: var(--panel); padding: 8px; border-radius: 6px; overflow: auto; }
.project-panel pre code { padding: 0; }

@media (max-width: 720px) {
  .editor-pane { width: 100%; }
  .workspace { flex-direction: column; }
  .splitter { display: none; }
  .editor-pane { height: 40%; }
}
