.diagram-exercise {
  width: 100%;
  min-width: 0;
  color: #1e293b;
  font-family: inherit;
}

.diagram-title {
  margin: 0 0 8px;
  color: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.diagram-instructions,
.diagram-status,
.diagram-solution {
  margin: 8px 0 12px;
  font-size: .88rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.diagram-instructions { color: #475569; }
.diagram-correction-heading { margin: 0 0 8px; font-size: .88rem; font-weight: 700; color: #6d28d9; }
.diagram-status { min-height: 1.5em; }
.diagram-status.is-correct { color: #166534; }
.diagram-status.is-incorrect { color: #9a3412; }

.diagram-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  background: #fff;
}

.diagram-stage svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.diagram-exercise button,
.diagram-exercise select {
  box-sizing: border-box;
  font: inherit;
}

.diagram-target {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  max-width: 46%;
  padding: 5px 9px;
  transform: translate(-50%, -50%);
  border: 2px dashed #64748b;
  border-radius: 10px;
  background: #f8fafc;
  color: #334155;
  font-size: .8rem !important;
  line-height: 1.2;
  font-weight: 700 !important;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}

.diagram-target.is-filled {
  gap: 5px;
  max-width: 112px;
  max-height: 76px;
  border-style: solid;
  border-color: #7c3aed;
  background: #f3e8ff;
  color: #5b21b6;
}
.diagram-target-number { flex-shrink: 0; }
.diagram-target-label { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.diagram-stage.has-compact-targets .diagram-target-label { display: none; }
.diagram-stage.has-compact-targets .diagram-target { width: 30px; min-width: 30px; min-height: 30px; max-height: 30px; gap: 0; padding: 4px; }

.diagram-target.is-selected {
  border-style: solid;
  border-color: #6d28d9;
  background: #6d28d9;
  color: #fff;
}

.diagram-target.is-correct { border-color: #15803d; background: #dcfce7; color: #166534; }
.diagram-target.is-incorrect { border-color: #c2410c; background: #ffedd5; color: #9a3412; }
.diagram-target:disabled { opacity: 1; cursor: default; }
.diagram-stage.is-dragging .diagram-target { outline: 2px solid #c4b5fd; outline-offset: 2px; }

.diagram-choice-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.diagram-choice {
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #c4b5fd;
  border-radius: 12px;
  background: #fff;
  color: #5b21b6;
  font-size: .88rem !important;
  overflow-wrap: anywhere;
  cursor: grab;
  touch-action: none;
}

.diagram-choice.is-selected { border-color: #6d28d9; background: #ede9fe; box-shadow: 0 0 0 2px #ddd6fe; }
.diagram-choice.is-placed { border-style: dashed; color: #475569; background: #f1f5f9; }
.diagram-choice:disabled { cursor: default; opacity: .7; }
.diagram-drag-ghost { position: fixed; z-index: 100000; max-width: 180px; padding: 10px 14px; transform: translate(-50%, -120%); border: 2px solid #6d28d9; border-radius: 12px; background: #ede9fe; color: #5b21b6; box-shadow: 0 6px 24px #0003; font: 600 .9rem system-ui, sans-serif; overflow-wrap: anywhere; pointer-events: none; }

.diagram-selects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 10px;
  margin: 12px 0;
}

.diagram-select-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  margin: 0;
}

.diagram-select-label { font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.diagram-checkbox-row { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 10px; font-size: .88rem; overflow-wrap: anywhere; cursor: pointer; }
.diagram-checkbox { width: 20px; height: 20px; flex: 0 0 20px; accent-color: #6d28d9; }
.diagram-checkbox-row:has(input:checked) { border-color: #6d28d9; background: #ede9fe; }
.diagram-select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px;
  border: 1px solid #94a3b8;
  border-radius: 9px;
  background: #fff;
  color: #1e293b;
  font-size: .88rem !important;
  text-overflow: ellipsis;
}

.diagram-select:disabled { opacity: 1; background: #f8fafc; color: #334155; }
.diagram-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.diagram-reset,
.diagram-submit {
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid #c4b5fd;
  border-radius: 10px;
  background: #fff;
  color: #5b21b6;
  cursor: pointer;
  font-weight: 600 !important;
}

.diagram-submit { border-color: #6d28d9; background: #6d28d9; color: #fff; }
.diagram-actions button:disabled { cursor: default; opacity: .45; }
.diagram-exercise button:focus-visible,
.diagram-exercise select:focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }

@media (max-width: 400px) {
  .diagram-target { min-width: 30px; min-height: 30px; padding: 4px 6px; font-size: .7rem !important; }
  .diagram-choice { flex: 1 1 auto; }
  .diagram-actions button { flex: 1; padding: 10px 8px; }
}
