:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #eef1f5;
  --border: #c9d0dc;
  --text: #17202a;
  --muted: #5d6978;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --danger: #b42318;
  --success: #147a3d;
  --shadow: 0 16px 42px rgba(31, 41, 55, 0.12);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

button,
textarea,
input {
  font: inherit;
}

button {
  min-height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 0.75rem;
  white-space: nowrap;
}

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

button:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.28);
  outline-offset: 2px;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 1rem;
  height: 3.5rem;
  justify-content: space-between;
  padding: 0 1rem;
}

.brand {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
}

.topnav {
  display: flex;
  gap: 1rem;
}

.workspace {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(24rem, 0.92fr) minmax(24rem, 1.08fr);
  min-height: calc(100vh - 3.5rem);
  padding: 1rem;
}

.source-pane,
.preview-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.source-pane {
  flex-direction: column;
}

.preview-pane {
  flex-direction: column;
}

.pane-header {
  align-items: center;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  min-height: 3.25rem;
  padding: 0.65rem 0.75rem;
}

.pane-header h1,
.pane-header h2 {
  font-size: 0.95rem;
  margin: 0;
}

.actions,
.toggles {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.toggles label {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 0.35rem;
  min-height: 2.25rem;
  white-space: nowrap;
}

#sourceInput {
  border: 0;
  color: var(--text);
  flex: 1;
  font-family: var(--mono);
  line-height: 1.45;
  min-height: 18rem;
  padding: 1rem;
  resize: none;
  white-space: pre;
}

.console {
  background: #101820;
  border-top: 1px solid var(--border);
  color: #dbeafe;
  font-family: var(--mono);
  line-height: 1.45;
  min-height: 5.5rem;
  overflow: auto;
  padding: 0.75rem 1rem;
  white-space: pre-wrap;
}

.console.success {
  color: #b9f6ca;
}

.console.error {
  color: #fecaca;
}

.preview-canvas {
  align-items: center;
  background: #ffffff;
  display: flex;
  flex: 1;
  justify-content: center;
  min-height: 20rem;
  overflow: auto;
  padding: 1rem;
}

.preview-canvas.dark {
  background: #111827;
}

.preview-canvas svg {
  display: block;
  height: auto;
  max-height: 100%;
  max-width: 100%;
}

.preview-error {
  color: var(--danger);
  font-family: var(--mono);
  margin: 0;
  max-width: 48rem;
  white-space: pre-wrap;
}

.preview-meta {
  border-top: 1px solid var(--border);
  color: var(--muted);
  min-height: 2.5rem;
  padding: 0.65rem 0.75rem;
}

#editorButton {
  display: none;
}

.diagram-mode {
  grid-template-columns: 1fr;
}

.diagram-mode .source-pane {
  display: none;
}

.diagram-mode .preview-pane {
  min-height: calc(100vh - 5.5rem);
}

.diagram-mode #editorButton {
  display: inline-block;
}

body.canvas-mode {
  background: #fff;
}

body.canvas-mode .topbar {
  display: none;
}

body.canvas-mode .workspace {
  border: 0;
  grid-template-columns: 1fr;
  min-height: 100vh;
  padding: 0;
}

body.canvas-mode .source-pane,
body.canvas-mode .preview-pane .pane-header,
body.canvas-mode .preview-meta {
  display: none;
}

body.canvas-mode .preview-pane {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  min-height: 100vh;
}

body.canvas-mode .preview-canvas {
  align-items: flex-start;
  background: #fff;
  display: block;
  min-height: 100vh;
  overflow: auto;
  padding: 0;
}

body.canvas-mode .preview-canvas svg {
  display: block;
  max-height: none;
  max-width: none;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
    padding: 0.75rem 1rem;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .pane-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions,
  .toggles {
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .workspace {
    padding: 0.5rem;
  }

  .source-pane,
  .preview-pane {
    border-radius: 6px;
  }

  button {
    width: 100%;
  }

  .actions,
  .toggles {
    width: 100%;
  }

  .toggles label {
    width: 100%;
  }
}
