:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #d5d9e0;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2f6fed;
  --error: #c62828;
  --error-bg: #fdecea;
  --canvas-bg: #fbfbfc;
  --isolation-stripe: rgba(232, 113, 10, 0.05);
  --block-fill: #ffffff;
  --block-head: #e3ebfb;
  --block-stroke: #5b6b8c;
  --link: #5b6b8c;
  --link-hi: #e8710a;
  --block-head-hi: #fff3e6;
  --on-hi: #ffffff;
  --port-text: #3a4256;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1c1f26;
    --border: #333844;
    --text: #e4e7ee;
    --muted: #8f97a8;
    --accent: #6a9bff;
    --error: #ff8a80;
    --error-bg: #3a1f1f;
    --canvas-bg: #16181d;
    --isolation-stripe: rgba(255, 169, 77, 0.04);
    --block-fill: #232733;
    --block-head: #2f3a55;
    --block-stroke: #8b9ac0;
    --link: #8b9ac0;
    --link-hi: #ffa94d;
    --block-head-hi: #3a3023;
    --on-hi: #1c1f26;
    --port-text: #c5cbdb;
  }
}

* { box-sizing: border-box; }

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

#app { display: flex; height: 100%; height: 100dvh; }

#input-pane {
  width: var(--input-width, 360px);
  flex-shrink: 0;
  min-width: 220px;
  max-width: 70vw;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  padding: 14px;
  gap: 10px;
}

h1 { font-size: 17px; margin: 0 0 4px; }
.hint { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

#input {
  flex: 1;
  min-height: 120px;
  resize: none;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  tab-size: 4;
}
#input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Diagram errors below the input text area */
#errors {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 30%;
  overflow: auto;
}
#errors:empty { display: none; }
#errors li {
  margin-bottom: 4px;
  padding: 4px 12px;
  border: 1px solid var(--error);
  border-radius: 14px;
  background: var(--error-bg);
  color: var(--error);
  font-size: 12px;
  cursor: pointer;
}

footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
footer .label { color: var(--muted); font-size: 12px; }
#stats { flex-basis: 100%; color: var(--muted); font-size: 12px; }

button {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }

#splitter {
  width: 5px;
  flex-shrink: 0;
  touch-action: none;
  cursor: col-resize;
  background: var(--border);
}
#splitter:hover, #splitter.dragging { background: var(--accent); }

#diagram-pane {
  position: relative;
  flex: 1;
  min-width: 0;
  background: var(--canvas-bg);
  overflow: hidden;
}
#diagram-pane::before {
  content: '';
  position: absolute;
  inset: 0;
  background-color: var(--block-head-hi);
  background-image: repeating-linear-gradient(135deg, transparent 0, transparent 12px, var(--isolation-stripe) 12px, var(--isolation-stripe) 13px);
  opacity: 0;
  transition: opacity 300ms ease;
  pointer-events: none;
}
#diagram-pane.is-isolated::before { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  #diagram-pane::before { transition: none; }
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#canvas.panning { cursor: grabbing; }

/* Navigation hints stacked in the top-left corner of the diagram */
#hint {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: calc(100% - 230px);
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}
#hint:not([hidden]) { display: flex; }
.hint-pill {
  max-width: 100%;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
}

#toolbar { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; }
#toolbar button { min-width: 32px; }

@media (max-width: 48rem), (pointer: coarse) {
  button, #toolbar button { min-width: 44px; min-height: 44px; }
  #input { font-size: 16px; }
  #hint { max-width: calc(100% - 20px); }
  #toolbar { top: auto; bottom: 10px; bottom: max(10px, env(safe-area-inset-bottom)); }
}

@media (max-width: 48rem) {
  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }
  #input-pane {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 12px;
    gap: 8px;
  }
  #input { flex: none; height: 24vh; height: 24dvh; min-height: 8rem; max-height: 14rem; }
  #errors { max-height: 6rem; }
  #splitter { display: none; }
  #diagram-pane { flex: 1 0 22rem; min-height: 22rem; border-top: 1px solid var(--border); }
}
