body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  background: #1a1b20;
  color: #c8c8d0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Toolbar */
#toolbar {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  background: #14151a;
  border-bottom: 1px solid #2a2b33;
  transition:
    transform 0.25s ease,
    opacity 0.2s ease,
    height 0.25s ease;
  will-change: transform, opacity, height;
}
#toolbar input,
#toolbar select,
#toolbar button {
  background: #1e1f26;
  color: #b8b8c4;
  border: 1px solid #2e2f38;
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
#toolbar input:hover,
#toolbar select:hover,
#toolbar button:hover {
  background: #282930;
}
#srcPanel {
  z-index: 1000;
}
#toolbar.collapsed {
  transform: translateY(-100%);
  opacity: 0;
  height: 0;
  padding: 0;
  overflow: hidden;
  border: none;
}
#srcPanel.collapsed {
  transform: translateY(-100%);
  opacity: 0;
  height: 0;
  padding: 0 8px;
  overflow: hidden;
}

/* Node highlight styling */
svg .node rect,
svg .node polygon,
svg .node path {
  transition:
    fill 120ms ease,
    filter 120ms ease;
}

svg .node:hover rect,
svg .node:hover polygon,
svg .node:hover path {
  fill: rgba(0, 170, 255, 0.25);
  filter: drop-shadow(0 0 11px rgba(0, 170, 255, 0.6));
}

svg g.node.selected-node rect,
svg g.node.selected-node polygon,
svg g.node.selected-node path {
  fill: rgba(0, 170, 255, 0.28);
  filter: drop-shadow(0 0 14px rgba(0, 170, 255, 0.9));
  transition:
    fill 120ms ease,
    filter 120ms ease;
}

p,
div,
div > *:not(textarea):not(input) {
  user-select: none;
}

#toggleToolbar {
  cursor: pointer;
  background: #1e1f26;
  color: #a0a0b0;
  border: 1px solid #2e2f38;
  border-radius: 6px;
  padding: 4px 8px;
}

/* Preview */
#preview svg {
  width: 100%;
  height: auto;
  padding: 12px;
  position: relative;
  overflow: visible;
  display: block;
  margin: 0;
  transform-origin: 0 0;
}
#preview svg g {
  transform-origin: 0 0;
}

/* Main layout - resizable */
#main {
  display: flex;
  height: 100%;
  overflow: hidden;
}
#srcPanel {
  width: 35%;
  min-width: 150px;
  height: 100%;
  background: #14151a;
  color: #c0c0cc;
  border: none;
  padding: 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
}

/* Resizer divider */
#resizer {
  width: 5px;
  cursor: col-resize;
  background: #2a2b33;
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
}
#resizer:hover,
#resizer.active {
  background: #4a8df8;
}
#preview {
  flex: 1;
  overflow: auto;
  background: #1a1b20;
}

.toolbar-sep {
  width: 1px;
  background: #2e2f38;
  margin: 0 4px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}
.modal.hidden {
  display: none;
}
.modal-content {
  background: #1e1f26;
  border: 1px solid #2e2f38;
  border-radius: 10px;
  padding: 20px;
  min-width: 360px;
  max-width: 90vw;
  color: #c8c8d0;
}
.modal-content h3 {
  margin: 0 0 12px;
  color: #e0e0ea;
}
.modal-content input {
  width: 100%;
  box-sizing: border-box;
  background: #14151a;
  color: #c8c8d0;
  border: 1px solid #2e2f38;
  border-radius: 4px;
  padding: 6px 10px;
  font-family: monospace;
  margin: 8px 0;
}
.modal-content label {
  display: block;
  font-size: 13px;
  color: #8888a0;
  margin-top: 8px;
}
.modal-content code {
  background: #282930;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
  color: #a0a0b0;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  justify-content: flex-end;
}
.modal-actions button {
  background: #1e1f26;
  color: #b8b8c4;
  border: 1px solid #2e2f38;
  border-radius: 4px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-actions button:hover {
  background: #282930;
}

/* File browser */
.modal-wide {
  min-width: 520px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}
.breadcrumb {
  font-size: 13px;
  color: #6a6a80;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.breadcrumb span {
  cursor: pointer;
  color: #5b8fd4;
}
.breadcrumb span:hover {
  text-decoration: underline;
  color: #7aadf0;
}
.file-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  border: 1px solid #2e2f38;
  border-radius: 6px;
  margin: 6px 0;
}
.file-list .file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  border-bottom: 1px solid #22232a;
}
.file-list .file-item:hover {
  background: #282930;
}
.file-list .file-item:last-child {
  border-bottom: none;
}
.file-list .file-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
}
.file-list .file-name {
  flex: 1;
  font-size: 14px;
}
.file-list .loading-msg,
.file-list .error-msg {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: #6a6a80;
}
.file-list .error-msg {
  color: #d4736a;
}

/* Save area in file browser */
.gh-save-area {
  margin-top: 8px;
  flex-shrink: 0;
}
.gh-save-area.hidden {
  display: none;
}
.gh-save-area label {
  display: block;
  font-size: 13px;
  color: #8888a0;
  margin-top: 6px;
}
.gh-save-area input {
  width: 100%;
  box-sizing: border-box;
  background: #14151a;
  color: #c8c8d0;
  border: 1px solid #2e2f38;
  border-radius: 4px;
  padding: 6px 10px;
  font-family: monospace;
  margin-top: 4px;
}

/* Error bar - fixed bottom left */
#errorBar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 35%;
  min-width: 150px;
  max-height: 120px;
  overflow-y: auto;
  background: #1e1416;
  border-top: 1px solid #4a2028;
  border-right: 1px solid #4a2028;
  padding: 8px 12px;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #d4736a;
  z-index: 1500;
  display: none;
  box-sizing: border-box;
}
#errorBar.visible {
  display: block;
}
#errorBar .error-close {
  position: absolute;
  top: 4px;
  right: 8px;
  cursor: pointer;
  color: #6a6a80;
  font-size: 14px;
  background: none;
  border: none;
  padding: 0 4px;
}
#errorBar .error-close:hover {
  color: #d4736a;
}
