:root {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-border: #d9d9d9;
  --text: #111111;
  --muted: #666666;
  --danger: #8b1e1e;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Times New Roman", Georgia, "Noto Serif SC", serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  height: 100vh;
  padding: 16px;
}

.sidebar,
.canvas-toolbar,
.canvas {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  overflow: hidden;
}

.brand h1,
.canvas-title {
  margin: 0;
  line-height: 1.1;
}

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

.brand h1 {
  font-size: 1.85rem;
  font-weight: 600;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid #ececec;
  border-radius: 6px;
}

.tool-label {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
}

.tool-row,
.chip-row,
.canvas-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tool-row input {
  flex: 1;
}

.tool-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-row {
  flex-wrap: wrap;
}

input,
select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #bdbdbd;
  border-radius: 4px;
  background: #ffffff;
  outline: none;
  font-size: 1rem;
}

input:focus,
select:focus {
  border-color: #111111;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

button {
  border: 1px solid #111111;
  border-radius: 4px;
  padding: 10px 14px;
  cursor: pointer;
  color: #111111;
  background: #ffffff;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: #111111;
  color: #ffffff;
}

button.danger {
  border-color: #b9b9b9;
  color: var(--danger);
  background: #fafafa;
}

.workspace {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  gap: 12px;
}

.canvas-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.canvas-title {
  font-size: 1.2rem;
  font-weight: 600;
}

.canvas-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.canvas-actions input {
  width: 220px;
}

.canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.edges,
.nodes {
  position: absolute;
  inset: 0;
}

.edges {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.edges path {
  fill: none;
  stroke: #111111;
  stroke-width: 1.55;
  marker-end: url(#arrow);
  stroke-linecap: square;
}

.edges path.selected {
  stroke: #4b4b4b;
  stroke-width: 2.1;
}

#arrow path {
  fill: #111111;
}

.edge-handle {
  fill: #ffffff;
  stroke: #8a8a8a;
  stroke-width: 1.2;
  cursor: grab;
}

.edge-handle.dragging {
  stroke: #111111;
  cursor: grabbing;
}

.node {
  position: absolute;
  min-width: 40px;
  max-width: 220px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  text-align: center;
  user-select: none;
  font-size: 1.65rem;
  box-shadow: none;
}

.node.selected {
  border-color: #9b9b9b;
}

.node-title {
  display: block;
  line-height: 1.15;
  white-space: nowrap;
  pointer-events: none;
}

.node.conditioned {
  border-color: #111111;
  background: #ffffff;
}

.node sub {
  font-size: 0.62em;
  line-height: 0;
  vertical-align: -0.32em;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .sidebar {
    overflow: visible;
  }

  .canvas {
    min-height: 560px;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .canvas-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .canvas-actions {
    justify-content: flex-start;
  }
}
