body {
  font-family: "Open Sans", Arial, sans-serif;
  margin: 0;
  background: #ebebeb;
  color: #111827;
}

main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1rem;
}

h1 {
  margin-bottom: 0.2rem;
}

.subtitle {
  margin-top: 0;
  color: #4b5563;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 1rem;
}

.panel {
  background: #ffffff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

form {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
}

input,
textarea,
select,
button {
  font: inherit;
  padding: 0.5rem;
}

button {
  border: 0;
  background: #1d4ed8;
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  padding: .5rem 1.5rem;
}

button.secondary {
  background: #374151;
}

[data-action="delete"] {
  background: #7f1d1d;
  color: #fffcfc;
}

[data-action="delete"]:hover {
  background: #991b1b;
}

[data-action="new"] {
  background: #14532d;
  color: #ffffff;
}

[data-action="new"]:hover {
  background: #166534;
}

ul,
ol {
  margin: 0;
  padding-left: 1.2rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.scenario-controls {
  display: flex;
  align-items: end;
  gap: 0.5rem;
  margin-top: 0.7rem;
  margin-bottom: 0.5rem;
}

.scenario-controls label {
  min-width: 150px;
}

.scenario-controls button {
  width: 36px;
  height: 36px;
  min-width: unset;
  padding: 0;
  font-size: 1rem;
}

.scenario-pick-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 0.4rem 0 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 0.3rem;
  box-sizing: border-box;
  padding-left: 10px;
}

.scenario-pick-btn {
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  min-width: unset;
}

.scenario-pick-btn:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.scenario-pick-btn.active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.work-list-header-empty {
  font-size: 0.82rem;
  color: #9ca3af;
  margin: 0.4rem 0;
}


.scenario-step-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 5px 10px;
  border-radius: 5px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  font-size: 0.8rem;
  color: #374151;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.scenario-step-item:hover {
  background: #e9eaf0;
  border-color: #d1d5db;
}

.scenario-step-item.selected {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1e40af;
}

.scenario-step-item.selected .step-number {
  background: #3b82f6;
  color: #fff;
}

.scenario-step-item.playing {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
  font-weight: 600;
}

.scenario-step-item.playing .step-number {
  background: #dc2626;
  color: #fff;
}

.scenario-step-item.dragging {
  opacity: 0.4;
}

.scenario-step-item.drag-over {
  border-color: #6366f1;
  background: #eef2ff;
}

.step-drag-handle {
  color: #9ca3af;
  font-size: 1rem;
  cursor: grab;
  flex-shrink: 0;
  user-select: none;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #d1d5db;
  color: #111827;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.scenario-step-item.playing .step-route {
  color: #b91c1c;
}

.step-type {
  font-weight: 600;
  flex-shrink: 0;
}

.step-route {
  color: #6b7280;
  flex: 1;
}


.step-note {
  font-style: italic;
  color: #9ca3af;
  font-size: 0.75rem;
}

.work-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0.6rem 0;
  width: 100%;
  background: #66758a;
  border: 1px solid #93c5fd;
  border-radius: 10px;
  padding: 0.6rem;
  box-sizing: border-box;
}

.tab-button {
  min-width: 200px;
  background: #1d4ed8;
  color: #fff;
}

.tab-button.active {
  background: #ffffff;
  color: #000;
  font-weight: bold;
}

.work-area {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.work-list-wrap {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  max-height: 240px;
  overflow: auto;
  background: #fff;
}

.work-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.work-list-item {
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  border-bottom: 1px solid #e5e7eb;
}

.work-list-item:nth-child(odd) {
  background: #f9fafb;
}

.work-list-item:nth-child(even) {
  background: #eef2ff;
}

.work-list-item.active {
  outline: 2px solid #1d4ed8;
  background: #dbeafe;
}

.work-detail {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0.7rem;
  background: #f8fafc;
}

.work-detail .actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.hint {
  color: #4b5563;
  margin-bottom: 0;
}

#networkGrid {
  position: relative;
  min-height: 560px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background-image:
    linear-gradient(to right, #e5e7eb 1px, transparent 1px),
    linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
  background-size: 24px 24px;
  background-color: #fff;
  overflow: hidden;
  cursor: grab;
}

#networkGrid:active {
  cursor: grabbing;
}

#gridCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}

.zoom-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 6px;
  padding: 4px 6px;
  border: 1px solid #d1d5db;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.zoom-controls button {
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

#zoomLabel {
  font-size: 0.8rem;
  min-width: 36px;
  text-align: center;
  color: #374151;
  font-weight: 600;
}

.connection-line {
  height: 2px;
  width: 100%;
  background: #6b7280;
  transition: background 0.4s, height 0.4s;
}

.connection-line.active {
  height: 3px;
}

.connection-wrap {
  position: absolute;
  height: 18px;
  transform-origin: 0 50%;
  display: flex;
  align-items: center;
}

.connection-delete {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  padding: 0;
  opacity: 0;
  transition: opacity 0.12s ease;
  background: #111827;
  color: #fff;
  line-height: 16px;
}

.connection-wrap:hover .connection-delete {
  opacity: 1;
}

.node {
  position: absolute;
  width: 130px;
  min-height: 58px;
  background: #1d4fd8d6;
  color: #fff;
  border-radius: 6px;
  padding: 0.8rem 0.8rem .4rem 0.8rem;
  cursor: move;
  user-select: none;
  touch-action: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  transition: background 0.4s, outline-color 0.4s;
}
.node:hover {
  opacity: 1;
}

.node.pending-link {
  outline: 3px solid #f59e0b;
}

.node small {
  color: #dbeafe;
}

.node.selected {
  outline: 3px solid #22c55e;
}

.node.active {
  outline-offset: 1px;
}

.node.preview {
  outline-offset: 1px;
}

.connection-line.preview {
  height: 3px;
}

.step-type-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.port {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  box-sizing: border-box;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #0f172a;
  transform: translateY(-50%);
  cursor: crosshair;
  padding: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
}

.port-left {
  left: -12px;
}

.port-right {
  right: -12px;
}

#selectedNodePanel {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0.6rem;
  margin-bottom: 1rem;
  background: #f9fafb;
}

#status {
  min-height: 1rem;
  font-weight: 600;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .work-area {
    grid-template-columns: 1fr;
  }
}
